Import Cobalt 6.18938 Change-Id: Ief58a17a0507849f192d40268256b4e4f695405d
diff --git a/src/cobalt/build/build.id b/src/cobalt/build/build.id index 40a5cc2..66145f8 100644 --- a/src/cobalt/build/build.id +++ b/src/cobalt/build/build.id
@@ -1 +1 @@ -16440 \ No newline at end of file +18938 \ No newline at end of file
diff --git a/src/cobalt/dom/font_cache.cc b/src/cobalt/dom/font_cache.cc index 9c9750e..831d15e 100644 --- a/src/cobalt/dom/font_cache.cc +++ b/src/cobalt/dom/font_cache.cc
@@ -35,7 +35,7 @@ : cached_remote_typeface_reference_( new loader::font::CachedRemoteTypefaceReferenceWithCallbacks( cached_remote_typeface, typeface_load_event_callback, - typeface_load_event_callback, typeface_load_event_callback)), + typeface_load_event_callback)), request_timer_(new base::Timer(false, false)) { request_timer_->Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kRequestTimerDelay),
diff --git a/src/cobalt/dom/font_cache_test.cc b/src/cobalt/dom/font_cache_test.cc index a46b631..b283272 100644 --- a/src/cobalt/dom/font_cache_test.cc +++ b/src/cobalt/dom/font_cache_test.cc
@@ -98,7 +98,7 @@ CreateFontFaceMapHelper(family_name, postscript_font_name); font_cache_->SetFontFaceMap(ffm.Pass()); - EXPECT_CALL(loader_factory_, CreateTypefaceLoaderMock(_, _, _, _, _)) + EXPECT_CALL(loader_factory_, CreateTypefaceLoaderMock(_, _, _, _)) .Times(0); EXPECT_CALL(mock_resource_provider_, @@ -122,7 +122,7 @@ EXPECT_CALL(mock_resource_provider_, GetLocalTypefaceIfAvailableMock(invalid_postscript_font_name)) .Times(1); - EXPECT_CALL(loader_factory_, CreateTypefaceLoaderMock(_, _, _, _, _)); + EXPECT_CALL(loader_factory_, CreateTypefaceLoaderMock(_, _, _, _)); FontListFont::State state; scoped_refptr<render_tree::Font> f =
diff --git a/src/cobalt/dom/html_element.cc b/src/cobalt/dom/html_element.cc index fbd71cd..14c79f4 100644 --- a/src/cobalt/dom/html_element.cc +++ b/src/cobalt/dom/html_element.cc
@@ -1060,8 +1060,7 @@ &HTMLElement::OnBackgroundImageLoaded, base::Unretained(this)); cached_images.push_back( new loader::image::CachedImageReferenceWithCallbacks( - cached_image, loaded_callback, base::Closure(), - base::Closure())); + cached_image, loaded_callback, base::Closure())); } }
diff --git a/src/cobalt/dom/html_image_element.cc b/src/cobalt/dom/html_image_element.cc index 007192d..f3f2fa7 100644 --- a/src/cobalt/dom/html_image_element.cc +++ b/src/cobalt/dom/html_image_element.cc
@@ -143,8 +143,6 @@ new loader::image::CachedImage::OnLoadedCallbackHandler( cached_image, base::Bind(&HTMLImageElement::OnLoadingSuccess, base::Unretained(this)), - base::Bind(&HTMLImageElement::OnLoadingFailure, - base::Unretained(this)), base::Bind(&HTMLImageElement::OnLoadingError, base::Unretained(this)))); node_document()->IncreaseLoadingCounter(); @@ -157,14 +155,6 @@ cached_image_loaded_callback_handler_.reset(); } -void HTMLImageElement::OnLoadingFailure() { - TRACE_EVENT0("cobalt::dom", "HTMLImageElement::OnLoadingFailure()"); - // No event is dispatched. - AllowGarbageCollection(); - node_document()->DecreaseLoadingCounterAndMaybeDispatchLoadEvent(); - cached_image_loaded_callback_handler_.reset(); -} - void HTMLImageElement::OnLoadingError() { TRACE_EVENT0("cobalt::dom", "HTMLImageElement::OnLoadingError()"); AllowGarbageCollectionAfterEventIsDispatched(base::Tokens::error());
diff --git a/src/cobalt/dom/html_image_element.h b/src/cobalt/dom/html_image_element.h index 8fcf822..3a871a5 100644 --- a/src/cobalt/dom/html_image_element.h +++ b/src/cobalt/dom/html_image_element.h
@@ -64,7 +64,6 @@ void UpdateImageData(); void OnLoadingSuccess(); - void OnLoadingFailure(); void OnLoadingError(); void PreventGarbageCollectionUntilEventIsDispatched(base::Token event_name);
diff --git a/src/cobalt/loader/font/typeface_decoder.cc b/src/cobalt/loader/font/typeface_decoder.cc index 9d2e6db..81fcedc 100644 --- a/src/cobalt/loader/font/typeface_decoder.cc +++ b/src/cobalt/loader/font/typeface_decoder.cc
@@ -23,15 +23,12 @@ TypefaceDecoder::TypefaceDecoder( render_tree::ResourceProvider* resource_provider, const SuccessCallback& success_callback, - const FailureCallback& failure_callback, const ErrorCallback& error_callback) : resource_provider_(resource_provider), success_callback_(success_callback), error_callback_(error_callback), is_raw_data_too_large_(false), suspended_(false) { - UNREFERENCED_PARAMETER(failure_callback); - DCHECK(resource_provider_); DCHECK(!success_callback_.is_null()); DCHECK(!error_callback_.is_null());
diff --git a/src/cobalt/loader/font/typeface_decoder.h b/src/cobalt/loader/font/typeface_decoder.h index 83ed308..2a611c4 100644 --- a/src/cobalt/loader/font/typeface_decoder.h +++ b/src/cobalt/loader/font/typeface_decoder.h
@@ -36,12 +36,10 @@ public: typedef base::Callback<void(const scoped_refptr<render_tree::Typeface>&)> SuccessCallback; - typedef base::Callback<void(const std::string&)> FailureCallback; typedef base::Callback<void(const std::string&)> ErrorCallback; TypefaceDecoder(render_tree::ResourceProvider* resource_provider, const SuccessCallback& success_callback, - const FailureCallback& failure_callback, const ErrorCallback& error_callback); // From Decoder.
diff --git a/src/cobalt/loader/font/typeface_decoder_test.cc b/src/cobalt/loader/font/typeface_decoder_test.cc index 4d12892..ad4046d 100644 --- a/src/cobalt/loader/font/typeface_decoder_test.cc +++ b/src/cobalt/loader/font/typeface_decoder_test.cc
@@ -40,7 +40,6 @@ typeface = value; } - MOCK_METHOD1(FailureCallback, void(const std::string& message)); MOCK_METHOD1(ErrorCallback, void(const std::string& message)); scoped_refptr<render_tree::Typeface> typeface; @@ -59,7 +58,6 @@ scoped_refptr<render_tree::Typeface> Typeface(); - void ExpectCallWithFailure(const std::string& message); void ExpectCallWithError(const std::string& message); protected: @@ -73,8 +71,6 @@ &resource_provider_, base::Bind(&MockTypefaceDecoderCallback::SuccessCallback, base::Unretained(&typeface_decoder_callback_)), - base::Bind(&MockTypefaceDecoderCallback::FailureCallback, - base::Unretained(&typeface_decoder_callback_)), base::Bind(&MockTypefaceDecoderCallback::ErrorCallback, base::Unretained(&typeface_decoder_callback_)))); } @@ -96,10 +92,6 @@ return typeface_decoder_callback_.typeface; } -void MockTypefaceDecoder::ExpectCallWithFailure(const std::string& message) { - EXPECT_CALL(typeface_decoder_callback_, FailureCallback(message)); -} - void MockTypefaceDecoder::ExpectCallWithError(const std::string& message) { EXPECT_CALL(typeface_decoder_callback_, ErrorCallback(message)); }
diff --git a/src/cobalt/loader/image/image_decoder.cc b/src/cobalt/loader/image/image_decoder.cc index eb95ee6..b50c0dc 100644 --- a/src/cobalt/loader/image/image_decoder.cc +++ b/src/cobalt/loader/image/image_decoder.cc
@@ -81,11 +81,9 @@ ImageDecoder::ImageDecoder(render_tree::ResourceProvider* resource_provider, const SuccessCallback& success_callback, - const FailureCallback& failure_callback, const ErrorCallback& error_callback) : resource_provider_(resource_provider), success_callback_(success_callback), - failure_callback_(failure_callback), error_callback_(error_callback), state_(kWaitingForHeader) { TRACE_EVENT0("cobalt::loader::image", "ImageDecoder::ImageDecoder()"); @@ -111,20 +109,20 @@ // The server successfully processed the request and expected some contents, // but it is not returning any content. state_ = kNotApplicable; - CacheMessage(&failure_message_, "No content returned, but expected some."); + CacheMessage(&error_message_, "No content returned, but expected some."); } if (headers->response_code() == net::HTTP_NO_CONTENT) { // The server successfully processed the request, but is not returning any // content. state_ = kNotApplicable; - CacheMessage(&failure_message_, "No content returned."); + CacheMessage(&error_message_, "No content returned."); } bool success = headers->GetMimeType(&mime_type_); if (!success || !net::IsSupportedImageMimeType(mime_type_)) { state_ = kNotApplicable; - CacheMessage(&failure_message_, "Not an image mime type."); + CacheMessage(&error_message_, "Not an image mime type."); } return kLoadResponseContinue; @@ -171,7 +169,7 @@ case kWaitingForHeader: if (signature_cache_.position == 0) { // no image is available. - failure_callback_.Run(failure_message_); + error_callback_.Run(error_message_); } else { error_callback_.Run("No enough image data for header."); } @@ -180,14 +178,14 @@ error_callback_.Run("Unsupported image format."); break; case kNoResourceProvider: - failure_callback_.Run("No resource provider was passed to the decoder."); + error_callback_.Run("No resource provider was passed to the decoder."); break; case kSuspended: DLOG(WARNING) << __FUNCTION__ << "[" << this << "] while suspended."; break; case kNotApplicable: // no image is available. - failure_callback_.Run(failure_message_); + error_callback_.Run(error_message_); break; } }
diff --git a/src/cobalt/loader/image/image_decoder.h b/src/cobalt/loader/image/image_decoder.h index 00902bc..53e6cba 100644 --- a/src/cobalt/loader/image/image_decoder.h +++ b/src/cobalt/loader/image/image_decoder.h
@@ -38,12 +38,10 @@ public: typedef base::Callback<void(const scoped_refptr<render_tree::Image>&)> SuccessCallback; - typedef base::Callback<void(const std::string&)> FailureCallback; typedef base::Callback<void(const std::string&)> ErrorCallback; ImageDecoder(render_tree::ResourceProvider* resource_provider, const SuccessCallback& success_callback, - const FailureCallback& failure_callback, const ErrorCallback& error_callback); // From Decoder. @@ -83,12 +81,11 @@ render_tree::ResourceProvider* resource_provider_; const SuccessCallback success_callback_; - const FailureCallback failure_callback_; const ErrorCallback error_callback_; scoped_ptr<ImageDataDecoder> decoder_; SignatureCache signature_cache_; State state_; - std::string failure_message_; + std::string error_message_; std::string mime_type_; };
diff --git a/src/cobalt/loader/image/image_decoder_test.cc b/src/cobalt/loader/image/image_decoder_test.cc index dafc54b..b2aa170 100644 --- a/src/cobalt/loader/image/image_decoder_test.cc +++ b/src/cobalt/loader/image/image_decoder_test.cc
@@ -40,7 +40,6 @@ image = value; } - MOCK_METHOD1(FailureCallback, void(const std::string& message)); MOCK_METHOD1(ErrorCallback, void(const std::string& message)); scoped_refptr<render_tree::Image> image; @@ -63,7 +62,6 @@ scoped_refptr<render_tree::Image> Image(); - void ExpectCallWithFailure(const std::string& message); void ExpectCallWithError(const std::string& message); protected: @@ -77,8 +75,6 @@ new ImageDecoder(&resource_provider_, base::Bind(&MockImageDecoderCallback::SuccessCallback, base::Unretained(&image_decoder_callback_)), - base::Bind(&MockImageDecoderCallback::FailureCallback, - base::Unretained(&image_decoder_callback_)), base::Bind(&MockImageDecoderCallback::ErrorCallback, base::Unretained(&image_decoder_callback_)))); } @@ -105,10 +101,6 @@ return image_decoder_callback_.image; } -void MockImageDecoder::ExpectCallWithFailure(const std::string& message) { - EXPECT_CALL(image_decoder_callback_, FailureCallback(message)); -} - void MockImageDecoder::ExpectCallWithError(const std::string& message) { EXPECT_CALL(image_decoder_callback_, ErrorCallback(message)); } @@ -164,7 +156,7 @@ TEST(ImageDecoderTest, DecodeImageWithContentLength0) { MockImageDecoder image_decoder; - image_decoder.ExpectCallWithFailure( + image_decoder.ExpectCallWithError( "No content returned, but expected some."); const char kImageWithContentLength0Headers[] = { @@ -188,7 +180,7 @@ TEST(ImageDecoderTest, DecodeNonImageTypeWithContentLength0) { MockImageDecoder image_decoder; - image_decoder.ExpectCallWithFailure( + image_decoder.ExpectCallWithError( "No content returned, but expected some. Not an image mime type."); const char kHTMLWithContentLength0Headers[] = { @@ -212,7 +204,7 @@ TEST(ImageDecoderTest, DecodeNonImageType) { MockImageDecoder image_decoder; - image_decoder.ExpectCallWithFailure("Not an image mime type."); + image_decoder.ExpectCallWithError("Not an image mime type."); const char kHTMLHeaders[] = { "HTTP/1.1 200 OK\0" @@ -237,7 +229,7 @@ TEST(ImageDecoderTest, DecodeNoContentType) { MockImageDecoder image_decoder; - image_decoder.ExpectCallWithFailure("Not an image mime type."); + image_decoder.ExpectCallWithError("Not an image mime type."); const char kHTMLHeaders[] = { "HTTP/1.1 200 OK\0" @@ -261,7 +253,7 @@ TEST(ImageDecoderTest, DecodeImageWithNoContent) { MockImageDecoder image_decoder; - image_decoder.ExpectCallWithFailure( + image_decoder.ExpectCallWithError( "No content returned. Not an image mime type."); const char kHTMLWithNoContentHeaders[] = {
diff --git a/src/cobalt/loader/image/sandbox/image_decoder_sandbox.cc b/src/cobalt/loader/image/sandbox/image_decoder_sandbox.cc index 9281e53..9371a8b 100644 --- a/src/cobalt/loader/image/sandbox/image_decoder_sandbox.cc +++ b/src/cobalt/loader/image/sandbox/image_decoder_sandbox.cc
@@ -45,10 +45,6 @@ image = value; } - void FailureCallback(const std::string& failure_message) { - LOG(WARNING) << failure_message; - } - void ErrorCallback(const std::string& error_message) { LOG(ERROR) << error_message; } @@ -107,8 +103,6 @@ scoped_ptr<Decoder> image_decoder(new ImageDecoder( resource_provider, base::Bind(&ImageDecoderCallback::SuccessCallback, base::Unretained(&image_decoder_result)), - base::Bind(&ImageDecoderCallback::FailureCallback, - base::Unretained(&image_decoder_result)), base::Bind(&ImageDecoderCallback::ErrorCallback, base::Unretained(&image_decoder_result))));
diff --git a/src/cobalt/loader/image/threaded_image_decoder_proxy.cc b/src/cobalt/loader/image/threaded_image_decoder_proxy.cc index 53fa8ce..18d4437 100644 --- a/src/cobalt/loader/image/threaded_image_decoder_proxy.cc +++ b/src/cobalt/loader/image/threaded_image_decoder_proxy.cc
@@ -56,7 +56,6 @@ ThreadedImageDecoderProxy::ThreadedImageDecoderProxy( render_tree::ResourceProvider* resource_provider, const SuccessCallback& success_callback, - const FailureCallback& failure_callback, const ErrorCallback& error_callback, MessageLoop* load_message_loop) : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), ALLOW_THIS_IN_INITIALIZER_LIST( @@ -69,8 +68,6 @@ &PostToMessageLoopChecked<SuccessCallback, scoped_refptr<render_tree::Image> >, weak_this_, success_callback, result_message_loop_), - base::Bind(&PostToMessageLoopChecked<FailureCallback, std::string>, - weak_this_, failure_callback, result_message_loop_), base::Bind(&PostToMessageLoopChecked<ErrorCallback, std::string>, weak_this_, error_callback, result_message_loop_))) { DCHECK(load_message_loop_);
diff --git a/src/cobalt/loader/image/threaded_image_decoder_proxy.h b/src/cobalt/loader/image/threaded_image_decoder_proxy.h index c6b559b..e8a9322 100644 --- a/src/cobalt/loader/image/threaded_image_decoder_proxy.h +++ b/src/cobalt/loader/image/threaded_image_decoder_proxy.h
@@ -40,12 +40,10 @@ public: typedef base::Callback<void(const scoped_refptr<render_tree::Image>&)> SuccessCallback; - typedef base::Callback<void(const std::string&)> FailureCallback; typedef base::Callback<void(const std::string&)> ErrorCallback; ThreadedImageDecoderProxy(render_tree::ResourceProvider* resource_provider, const SuccessCallback& success_callback, - const FailureCallback& failure_callback, const ErrorCallback& error_callback, MessageLoop* load_message_loop_);
diff --git a/src/cobalt/loader/loader_factory.cc b/src/cobalt/loader/loader_factory.cc index c227ed2..13240d0 100644 --- a/src/cobalt/loader/loader_factory.cc +++ b/src/cobalt/loader/loader_factory.cc
@@ -43,14 +43,13 @@ scoped_ptr<Loader> LoaderFactory::CreateImageLoader( const GURL& url, const csp::SecurityCallback& url_security_callback, const image::ImageDecoder::SuccessCallback& success_callback, - const image::ImageDecoder::FailureCallback& failure_callback, const image::ImageDecoder::ErrorCallback& error_callback) { DCHECK(thread_checker_.CalledOnValidThread()); scoped_ptr<Loader> loader(new Loader( MakeFetcherCreator(url, url_security_callback), scoped_ptr<Decoder>(new image::ThreadedImageDecoderProxy( - resource_provider_, success_callback, failure_callback, + resource_provider_, success_callback, error_callback, load_thread_.message_loop())), error_callback, base::Bind(&LoaderFactory::OnLoaderDestroyed, base::Unretained(this)))); @@ -61,7 +60,6 @@ scoped_ptr<Loader> LoaderFactory::CreateTypefaceLoader( const GURL& url, const csp::SecurityCallback& url_security_callback, const font::TypefaceDecoder::SuccessCallback& success_callback, - const font::TypefaceDecoder::FailureCallback& failure_callback, const font::TypefaceDecoder::ErrorCallback& error_callback) { DCHECK(thread_checker_.CalledOnValidThread()); @@ -69,7 +67,7 @@ MakeFetcherCreator(url, url_security_callback), scoped_ptr<Decoder>( new font::TypefaceDecoder(resource_provider_, success_callback, - failure_callback, error_callback)), + error_callback)), error_callback, base::Bind(&LoaderFactory::OnLoaderDestroyed, base::Unretained(this)))); OnLoaderCreated(loader.get());
diff --git a/src/cobalt/loader/loader_factory.h b/src/cobalt/loader/loader_factory.h index 86bf2a4..b14ca10 100644 --- a/src/cobalt/loader/loader_factory.h +++ b/src/cobalt/loader/loader_factory.h
@@ -44,14 +44,12 @@ scoped_ptr<Loader> CreateImageLoader( const GURL& url, const csp::SecurityCallback& url_security_callback, const image::ImageDecoder::SuccessCallback& success_callback, - const image::ImageDecoder::FailureCallback& failure_callback, const image::ImageDecoder::ErrorCallback& error_callback); // Creates a loader that fetches and decodes a render_tree::Typeface. scoped_ptr<Loader> CreateTypefaceLoader( const GURL& url, const csp::SecurityCallback& url_security_callback, const font::TypefaceDecoder::SuccessCallback& success_callback, - const font::TypefaceDecoder::FailureCallback& failure_callback, const font::TypefaceDecoder::ErrorCallback& error_callback); // Clears out the loader factory's resource provider, aborting any in-progress
diff --git a/src/cobalt/loader/mock_loader_factory.h b/src/cobalt/loader/mock_loader_factory.h index b5314d6..fe21d1b 100644 --- a/src/cobalt/loader/mock_loader_factory.h +++ b/src/cobalt/loader/mock_loader_factory.h
@@ -33,20 +33,18 @@ class MockLoaderFactory { public: - MOCK_METHOD5(CreateImageLoaderMock, + MOCK_METHOD4(CreateImageLoaderMock, loader::Loader*( const GURL& url, const csp::SecurityCallback& url_security_callback, const image::ImageDecoder::SuccessCallback& success_callback, - const image::ImageDecoder::FailureCallback& failure_callback, const image::ImageDecoder::ErrorCallback& error_callback)); - MOCK_METHOD5( + MOCK_METHOD4( CreateTypefaceLoaderMock, loader::Loader*( const GURL& url, const csp::SecurityCallback& url_security_callback, const font::TypefaceDecoder::SuccessCallback& success_callback, - const font::TypefaceDecoder::FailureCallback& failure_callback, const font::TypefaceDecoder::ErrorCallback& error_callback)); // This workaround is required since scoped_ptr has no copy constructor. @@ -55,21 +53,19 @@ scoped_ptr<Loader> CreateImageLoader( const GURL& url, const csp::SecurityCallback& url_security_callback, const image::ImageDecoder::SuccessCallback& success_callback, - const image::ImageDecoder::FailureCallback& failure_callback, const image::ImageDecoder::ErrorCallback& error_callback) { return scoped_ptr<Loader>( CreateImageLoaderMock(url, url_security_callback, success_callback, - failure_callback, error_callback)); + error_callback)); } scoped_ptr<Loader> CreateTypefaceLoader( const GURL& url, const csp::SecurityCallback& url_security_callback, const font::TypefaceDecoder::SuccessCallback& success_callback, - const font::TypefaceDecoder::FailureCallback& failure_callback, const font::TypefaceDecoder::ErrorCallback& error_callback) { return scoped_ptr<Loader>( CreateTypefaceLoaderMock(url, url_security_callback, success_callback, - failure_callback, error_callback)); + error_callback)); } MOCK_METHOD0(Suspend, void());
diff --git a/src/cobalt/loader/resource_cache.h b/src/cobalt/loader/resource_cache.h index 1c3e4e6..2847057 100644 --- a/src/cobalt/loader/resource_cache.h +++ b/src/cobalt/loader/resource_cache.h
@@ -49,7 +49,6 @@ enum CallbackType { kOnLoadingSuccessCallbackType, - kOnLoadingFailureCallbackType, kOnLoadingErrorCallbackType, kCallbackTypeCount, }; @@ -71,10 +70,9 @@ typedef base::Callback<scoped_ptr<Loader>( const GURL&, const csp::SecurityCallback&, const base::Callback<void(const scoped_refptr<ResourceType>&)>&, - const base::Callback<void(const std::string&)>&, const base::Callback<void(const std::string&)>&)> CreateLoaderFunction; - // This class can be used to attach success, failure, or error callbacks to + // This class can be used to attach success or error callbacks to // CachedResource objects that are executed when the resource finishes // loading. // The callbacks are removed when the object is destroyed. If the resource has @@ -84,7 +82,6 @@ OnLoadedCallbackHandler( const scoped_refptr<CachedResource>& cached_resource, const base::Closure& success_callback, - const base::Closure& failure_callback, const base::Closure& error_callback); ~OnLoadedCallbackHandler(); @@ -93,11 +90,9 @@ scoped_refptr<CachedResource> cached_resource_; base::Closure success_callback_; - base::Closure failure_callback_; base::Closure error_callback_; CallbackListIterator success_callback_list_iterator_; - CallbackListIterator failure_callback_list_iterator_; CallbackListIterator error_callback_list_iterator_; DISALLOW_COPY_AND_ASSIGN(OnLoadedCallbackHandler); @@ -139,8 +134,6 @@ // // Notify that the resource is loaded successfully. void OnLoadingSuccess(const scoped_refptr<ResourceType>& resource); - // Notify the loading failure and could be treated differently than error. - void OnLoadingFailure(const std::string& warning); // Notify the loading error. void OnLoadingError(const std::string& error); @@ -172,10 +165,9 @@ CachedResource<CacheType>::OnLoadedCallbackHandler::OnLoadedCallbackHandler( const scoped_refptr<CachedResource>& cached_resource, const base::Closure& success_callback, - const base::Closure& failure_callback, const base::Closure& error_callback) + const base::Closure& error_callback) : cached_resource_(cached_resource), success_callback_(success_callback), - failure_callback_(failure_callback), error_callback_(error_callback) { DCHECK(cached_resource_); @@ -187,11 +179,6 @@ } } - if (!failure_callback_.is_null()) { - failure_callback_list_iterator_ = cached_resource_->AddCallback( - kOnLoadingFailureCallbackType, failure_callback_); - } - if (!error_callback_.is_null()) { error_callback_list_iterator_ = cached_resource_->AddCallback( kOnLoadingErrorCallbackType, error_callback_); @@ -205,11 +192,6 @@ success_callback_list_iterator_); } - if (!failure_callback_.is_null()) { - cached_resource_->RemoveCallback(kOnLoadingFailureCallbackType, - failure_callback_list_iterator_); - } - if (!error_callback_.is_null()) { cached_resource_->RemoveCallback(kOnLoadingErrorCallbackType, error_callback_list_iterator_); @@ -231,7 +213,6 @@ loader_ = create_loader_function.Run( url, security_callback, base::Bind(&CachedResource::OnLoadingSuccess, base::Unretained(this)), - base::Bind(&CachedResource::OnLoadingFailure, base::Unretained(this)), base::Bind(&CachedResource::OnLoadingError, base::Unretained(this))); } @@ -280,21 +261,10 @@ } template <typename CacheType> -void CachedResource<CacheType>::OnLoadingFailure(const std::string& message) { - DCHECK(cached_resource_thread_checker_.CalledOnValidThread()); - - LOG(WARNING) << "Warning while loading '" << url_ << "': " << message; - - loader_.reset(); - resource_cache_->NotifyResourceLoadingComplete(this, - kOnLoadingFailureCallbackType); -} - -template <typename CacheType> void CachedResource<CacheType>::OnLoadingError(const std::string& error) { DCHECK(cached_resource_thread_checker_.CalledOnValidThread()); - LOG(ERROR) << "Error while loading '" << url_ << "': " << error; + LOG(WARNING) << "Error while loading '" << url_ << "': " << error; loader_.reset(); resource_cache_->NotifyResourceLoadingComplete(this, @@ -351,13 +321,11 @@ CachedResourceReferenceWithCallbacks( const scoped_refptr<CachedResourceType>& cached_resource, const base::Closure& success_callback, - const base::Closure& failure_callback, const base::Closure& error_callback) : cached_resource_(cached_resource), cached_resource_loaded_callback_handler_( new CachedResourceTypeOnLoadedCallbackHandler( - cached_resource, success_callback, failure_callback, - error_callback)) {} + cached_resource, success_callback, error_callback)) {} scoped_refptr<CachedResourceType> cached_resource() { return cached_resource_;
diff --git a/src/cobalt/script/mozjs/mozjs_engine.cc b/src/cobalt/script/mozjs/mozjs_engine.cc index 7b62f3f..fcd8c52 100644 --- a/src/cobalt/script/mozjs/mozjs_engine.cc +++ b/src/cobalt/script/mozjs/mozjs_engine.cc
@@ -20,6 +20,7 @@ #include "base/debug/trace_event.h" #include "base/logging.h" +#include "base/message_loop.h" #include "cobalt/base/c_val.h" #include "cobalt/browser/stack_size_constants.h" #include "cobalt/script/mozjs/mozjs_global_environment.h" @@ -33,6 +34,9 @@ // After this many bytes have been allocated, the garbage collector will run. const uint32_t kGarbageCollectionThresholdBytes = 8 * 1024 * 1024; +// Trigger garbage collection this many seconds after the last one. +const int kGarbageCollectionIntervalSeconds = 60; + JSBool CheckAccessStub(JSContext*, JS::Handle<JSObject*>, JS::Handle<jsid>, JSAccessMode, JS::MutableHandle<JS::Value>) { return true; @@ -140,6 +144,12 @@ js::SetPreserveWrapperCallback(runtime_, DummyPreserveWrapperCallback); EngineStats::GetInstance()->EngineCreated(); + + if (MessageLoop::current()) { + gc_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds( + kGarbageCollectionIntervalSeconds), + this, &MozjsEngine::TimerGarbageCollect); + } } MozjsEngine::~MozjsEngine() { @@ -173,6 +183,11 @@ return EngineStats::GetInstance()->UpdateMemoryStatsAndReturnReserved(); } +void MozjsEngine::TimerGarbageCollect() { + TRACE_EVENT0("cobalt::script", "MozjsEngine::TimerGarbageCollect()"); + CollectGarbage(); +} + JSBool MozjsEngine::ContextCallback(JSContext* context, unsigned context_op) { JSRuntime* runtime = JS_GetRuntime(context); MozjsEngine* engine = @@ -195,6 +210,10 @@ static_cast<MozjsEngine*>(JS_GetRuntimePrivate(runtime)); if (status == JSGC_END) { engine->accumulated_extra_memory_cost_ = 0; + // Reset the GC timer to avoid having the timed GC come soon after this one. + if (engine->gc_timer_.IsRunning()) { + engine->gc_timer_.Reset(); + } } for (int i = 0; i < engine->contexts_.size(); ++i) { MozjsGlobalEnvironment* global_environment =
diff --git a/src/cobalt/script/mozjs/mozjs_engine.h b/src/cobalt/script/mozjs/mozjs_engine.h index 393f98d..5529394 100644 --- a/src/cobalt/script/mozjs/mozjs_engine.h +++ b/src/cobalt/script/mozjs/mozjs_engine.h
@@ -19,6 +19,7 @@ #include <vector> #include "base/threading/thread_checker.h" +#include "base/timer.h" #include "cobalt/script/javascript_engine.h" #include "third_party/mozjs/js/src/jsapi.h" @@ -37,6 +38,7 @@ size_t UpdateMemoryStatsAndReturnReserved() OVERRIDE; private: + void TimerGarbageCollect(); static JSBool ContextCallback(JSContext* context, unsigned context_op); static void GCCallback(JSRuntime* runtime, JSGCStatus status); static void FinalizeCallback(JSFreeOp* free_op, JSFinalizeStatus status, @@ -54,6 +56,9 @@ // The amount of externally allocated memory since last forced GC. size_t accumulated_extra_memory_cost_; + + // Used to trigger a garbage collection periodically. + base::RepeatingTimer<MozjsEngine> gc_timer_; }; } // namespace mozjs } // namespace script