diff --git a/android_webview/browser/aw_content_browser_client.cc b/android_webview/browser/aw_content_browser_client.cc index 92ee93524a30b..3ca2f8ca1bdbe 100644 --- a/android_webview/browser/aw_content_browser_client.cc +++ b/android_webview/browser/aw_content_browser_client.cc @@ -887,7 +887,7 @@ AwContentBrowserClient::CreateLoginDelegate( bool AwContentBrowserClient::HandleExternalProtocol( const GURL& url, - content::WebContents::Getter web_contents_getter, + content::WebContents::OnceGetter web_contents_getter, int child_id, content::NavigationUIData* navigation_data, bool is_main_frame, diff --git a/android_webview/browser/aw_content_browser_client.h b/android_webview/browser/aw_content_browser_client.h index 6c639fe3e811c..e1ca9d4739524 100644 --- a/android_webview/browser/aw_content_browser_client.h +++ b/android_webview/browser/aw_content_browser_client.h @@ -183,7 +183,7 @@ class AwContentBrowserClient : public content::ContentBrowserClient { LoginAuthRequiredCallback auth_required_callback) override; bool HandleExternalProtocol( const GURL& url, - content::WebContents::Getter web_contents_getter, + content::WebContents::OnceGetter web_contents_getter, int child_id, content::NavigationUIData* navigation_data, bool is_main_frame, diff --git a/chrome/browser/accessibility/accessibility_ui.cc b/chrome/browser/accessibility/accessibility_ui.cc index 110cca0778589..18a6966a2eb73 100644 --- a/chrome/browser/accessibility/accessibility_ui.cc +++ b/chrome/browser/accessibility/accessibility_ui.cc @@ -163,7 +163,7 @@ bool ShouldHandleAccessibilityRequestCallback(const std::string& path) { void HandleAccessibilityRequestCallback( content::BrowserContext* current_context, const std::string& path, - const content::WebUIDataSource::GotDataCallback& callback) { + content::WebUIDataSource::GotDataCallback callback) { DCHECK(ShouldHandleAccessibilityRequestCallback(path)); base::DictionaryValue data; @@ -250,7 +250,7 @@ void HandleAccessibilityRequestCallback( std::string json_string; base::JSONWriter::Write(data, &json_string); - callback.Run(base::RefCountedString::TakeString(&json_string)); + std::move(callback).Run(base::RefCountedString::TakeString(&json_string)); } bool MatchesPropertyFilters( diff --git a/chrome/browser/apps/app_service/app_icon_source.cc b/chrome/browser/apps/app_service/app_icon_source.cc index 997b847e8c0c2..4744dfad96aa1 100644 --- a/chrome/browser/apps/app_service/app_icon_source.cc +++ b/chrome/browser/apps/app_service/app_icon_source.cc @@ -24,7 +24,7 @@ namespace apps { namespace { -void LoadDefaultImage(const content::URLDataSource::GotDataCallback& callback) { +void LoadDefaultImage(content::URLDataSource::GotDataCallback callback) { base::StringPiece contents = ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale( IDR_APP_DEFAULT_ICON, apps_util::GetPrimaryDisplayUIScaleFactor()); @@ -32,18 +32,18 @@ void LoadDefaultImage(const content::URLDataSource::GotDataCallback& callback) { base::RefCountedBytes* image_bytes = new base::RefCountedBytes(); image_bytes->data().assign(contents.data(), contents.data() + contents.size()); - callback.Run(image_bytes); + std::move(callback).Run(image_bytes); } -void RunCallback(const content::URLDataSource::GotDataCallback& callback, +void RunCallback(content::URLDataSource::GotDataCallback callback, apps::mojom::IconValuePtr iv) { if (!iv->compressed.has_value() || iv->compressed.value().empty()) { - LoadDefaultImage(callback); + LoadDefaultImage(std::move(callback)); return; } base::RefCountedBytes* image_bytes = new base::RefCountedBytes(iv->compressed.value()); - callback.Run(image_bytes); + std::move(callback).Run(image_bytes); } } // namespace @@ -59,7 +59,7 @@ std::string AppIconSource::GetSource() { void AppIconSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { const std::string path_lower = base::ToLowerASCII(content::URLDataSource::URLToRequestPath(url)); std::vector<std::string> path_parts = base::SplitString( @@ -67,7 +67,7 @@ void AppIconSource::StartDataRequest( // Check data exists, load default image if it doesn't. if (path_lower.empty() || path_parts.size() < 2) { - LoadDefaultImage(callback); + LoadDefaultImage(std::move(callback)); return; } @@ -76,7 +76,7 @@ void AppIconSource::StartDataRequest( std::string size_param = path_parts[1]; int size = 0; if (!base::StringToInt(size_param, &size)) { - LoadDefaultImage(callback); + LoadDefaultImage(std::move(callback)); return; } constexpr bool quantize_to_supported_scale_factor = true; @@ -86,7 +86,7 @@ void AppIconSource::StartDataRequest( apps::AppServiceProxy* app_service_proxy = apps::AppServiceProxyFactory::GetForProfile(profile_); if (!app_service_proxy) { - LoadDefaultImage(callback); + LoadDefaultImage(std::move(callback)); return; } @@ -95,7 +95,8 @@ void AppIconSource::StartDataRequest( constexpr bool allow_placeholder_icon = false; app_service_proxy->LoadIcon( app_type, app_id, apps::mojom::IconCompression::kCompressed, size_in_dip, - allow_placeholder_icon, base::BindOnce(&RunCallback, callback)); + allow_placeholder_icon, + base::BindOnce(&RunCallback, std::move(callback))); } std::string AppIconSource::GetMimeType(const std::string&) { diff --git a/chrome/browser/apps/app_service/app_icon_source.h b/chrome/browser/apps/app_service/app_icon_source.h index 296036d09478e..4a2c03cda3fa0 100644 --- a/chrome/browser/apps/app_service/app_icon_source.h +++ b/chrome/browser/apps/app_service/app_icon_source.h @@ -39,7 +39,7 @@ class AppIconSource : public content::URLDataSource { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; std::string GetMimeType(const std::string&) override; bool AllowCaching() override; bool ShouldReplaceExistingSource() override; diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 8ebb3cc88d918..b39e5a01fd94c 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -940,13 +940,13 @@ chrome::mojom::PrerenderCanceler* GetPrerenderCanceller( } void LaunchURL(const GURL& url, - const content::WebContents::Getter& web_contents_getter, + content::WebContents::OnceGetter web_contents_getter, ui::PageTransition page_transition, bool has_user_gesture, const base::Optional<url::Origin>& initiating_origin) { // If there is no longer a WebContents, the request may have raced with tab // closing. Don't fire the external request. (It may have been a prerender.) - content::WebContents* web_contents = web_contents_getter.Run(); + content::WebContents* web_contents = std::move(web_contents_getter).Run(); if (!web_contents) return; @@ -4768,7 +4768,7 @@ ChromeContentBrowserClient::CreateLoginDelegate( bool ChromeContentBrowserClient::HandleExternalProtocol( const GURL& url, - content::WebContents::Getter web_contents_getter, + content::WebContents::OnceGetter web_contents_getter, int child_id, content::NavigationUIData* navigation_data, bool is_main_frame, @@ -4799,8 +4799,8 @@ bool ChromeContentBrowserClient::HandleExternalProtocol( base::PostTask( FROM_HERE, {BrowserThread::UI}, - base::BindOnce(&LaunchURL, url, web_contents_getter, page_transition, - has_user_gesture, initiating_origin)); + base::BindOnce(&LaunchURL, url, std::move(web_contents_getter), + page_transition, has_user_gesture, initiating_origin)); return true; } diff --git a/chrome/browser/chrome_content_browser_client.h b/chrome/browser/chrome_content_browser_client.h index eac552d585d7e..7995a32481fa1 100644 --- a/chrome/browser/chrome_content_browser_client.h +++ b/chrome/browser/chrome_content_browser_client.h @@ -549,7 +549,7 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient { LoginAuthRequiredCallback auth_required_callback) override; bool HandleExternalProtocol( const GURL& url, - content::WebContents::Getter web_contents_getter, + content::WebContents::OnceGetter web_contents_getter, int child_id, content::NavigationUIData* navigation_data, bool is_main_frame, diff --git a/chrome/browser/chrome_service_worker_browsertest.cc b/chrome/browser/chrome_service_worker_browsertest.cc index 84a34c789e380..b5aa3d6b34b73 100644 --- a/chrome/browser/chrome_service_worker_browsertest.cc +++ b/chrome/browser/chrome_service_worker_browsertest.cc @@ -699,9 +699,9 @@ class StaticURLDataSource : public content::URLDataSource { std::string GetSource() override { return source_; } void StartDataRequest(const GURL& url, const content::WebContents::Getter& wc_getter, - const GotDataCallback& callback) override { + GotDataCallback callback) override { std::string data(content_); - callback.Run(base::RefCountedString::TakeString(&data)); + std::move(callback).Run(base::RefCountedString::TakeString(&data)); } std::string GetMimeType(const std::string& path) override { return "application/javascript"; diff --git a/chrome/browser/chromeos/file_manager/file_manager_jstest_base.cc b/chrome/browser/chromeos/file_manager/file_manager_jstest_base.cc index c48bc4666ff34..dd338561ab250 100644 --- a/chrome/browser/chromeos/file_manager/file_manager_jstest_base.cc +++ b/chrome/browser/chromeos/file_manager/file_manager_jstest_base.cc @@ -38,23 +38,24 @@ class TestFilesDataSource : public content::URLDataSource { ~TestFilesDataSource() override {} private: - // This has to match kTestResourceURL + // This has to match TestResourceUrl() std::string GetSource() override { return "file_manager_test"; } void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override { + content::URLDataSource::GotDataCallback callback) override { const std::string path = content::URLDataSource::URLToRequestPath(url); - base::PostTask(FROM_HERE, - {base::ThreadPool(), base::MayBlock(), - base::TaskPriority::USER_BLOCKING}, - base::BindOnce(&TestFilesDataSource::ReadFile, - base::Unretained(this), path, callback)); + base::PostTask( + FROM_HERE, + {base::ThreadPool(), base::MayBlock(), + base::TaskPriority::USER_BLOCKING}, + base::BindOnce(&TestFilesDataSource::ReadFile, base::Unretained(this), + path, std::move(callback))); } void ReadFile(const std::string& path, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { if (source_root_.empty()) { CHECK(base::PathService::Get(base::DIR_SOURCE_ROOT, &source_root_)); } @@ -85,7 +86,7 @@ class TestFilesDataSource : public content::URLDataSource { scoped_refptr<base::RefCountedString> response = base::RefCountedString::TakeString(&content); - callback.Run(response.get()); + std::move(callback).Run(response.get()); } // It currently only serves HTML/JS/CSS. @@ -138,6 +139,11 @@ class TestWebUIProvider base::LazyInstance<TestWebUIProvider>::DestructorAtExit test_webui_provider_ = LAZY_INSTANCE_INITIALIZER; +static const GURL TestResourceUrl() { + static GURL url(content::GetWebUIURLString("file_manager_test")); + return url; +} + } // namespace FileManagerJsTestBase::FileManagerJsTestBase(const base::FilePath& base_path) @@ -145,9 +151,6 @@ FileManagerJsTestBase::FileManagerJsTestBase(const base::FilePath& base_path) FileManagerJsTestBase::~FileManagerJsTestBase() {} -const std::string FileManagerJsTestBase::kTestResourceURL = - content::GetWebUIURLString("file_manager_test"); - void FileManagerJsTestBase::RunTest(const base::FilePath& file) { base::FilePath root_path; ASSERT_TRUE(base::PathService::Get(base::DIR_SOURCE_ROOT, &root_path)); @@ -196,15 +199,14 @@ void FileManagerJsTestBase::SetUpOnMainThread() { std::make_unique<TestChromeWebUIControllerFactory>(); content::WebUIControllerFactory::RegisterFactory( webui_controller_factory_.get()); - webui_controller_factory_->AddFactoryOverride(GURL(kTestResourceURL).host(), + webui_controller_factory_->AddFactoryOverride(TestResourceUrl().host(), test_webui_provider_.Pointer()); } void FileManagerJsTestBase::TearDownOnMainThread() { InProcessBrowserTest::TearDownOnMainThread(); - webui_controller_factory_->RemoveFactoryOverride( - GURL(kTestResourceURL).host()); + webui_controller_factory_->RemoveFactoryOverride(TestResourceUrl().host()); content::WebUIControllerFactory::UnregisterFactoryForTesting( webui_controller_factory_.get()); diff --git a/chrome/browser/chromeos/login/users/avatar/user_image_loader.cc b/chrome/browser/chromeos/login/users/avatar/user_image_loader.cc index 81db0cbae2d25..ea09a65532aa8 100644 --- a/chrome/browser/chromeos/login/users/avatar/user_image_loader.cc +++ b/chrome/browser/chromeos/login/users/avatar/user_image_loader.cc @@ -32,17 +32,21 @@ struct ImageInfo { ImageInfo(const base::FilePath& file_path, int pixels_per_side, ImageDecoder::ImageCodec image_codec, - const LoadedCallback& loaded_cb) + LoadedCallback loaded_cb) : file_path(file_path), pixels_per_side(pixels_per_side), image_codec(image_codec), - loaded_cb(loaded_cb) {} + loaded_cb(std::move(loaded_cb)) {} + + ImageInfo(ImageInfo&&) = default; + ImageInfo& operator=(ImageInfo&&) = default; + ~ImageInfo() {} - const base::FilePath file_path; - const int pixels_per_side; - const ImageDecoder::ImageCodec image_codec; - const LoadedCallback loaded_cb; + base::FilePath file_path; + int pixels_per_side; + ImageDecoder::ImageCodec image_codec; + LoadedCallback loaded_cb; }; // Crops |image| to the square format and downsizes the image to @@ -106,10 +110,10 @@ user_manager::UserImage::ImageFormat ChooseImageFormatFromCodec( class UserImageRequest : public ImageDecoder::ImageRequest { public: UserImageRequest( - const ImageInfo& image_info, + ImageInfo image_info, const std::string& image_data, scoped_refptr<base::SequencedTaskRunner> background_task_runner) - : image_info_(image_info), + : image_info_(std::move(image_info)), // TODO(crbug.com/593251): Remove the data copy here. image_data_(new base::RefCountedBytes( reinterpret_cast<const unsigned char*>(image_data.data()), @@ -134,7 +138,7 @@ class UserImageRequest : public ImageDecoder::ImageRequest { bool image_bytes_regenerated); private: - const ImageInfo image_info_; + ImageInfo image_info_; scoped_refptr<base::RefCountedBytes> image_data_; scoped_refptr<base::SequencedTaskRunner> background_task_runner_; @@ -200,19 +204,20 @@ void UserImageRequest::OnImageFinalized( image_info_.image_codec == ImageDecoder::ROBUST_PNG_CODEC || image_bytes_regenerated) user_image->MarkAsSafe(); - image_info_.loaded_cb.Run(std::move(user_image)); + std::move(image_info_.loaded_cb).Run(std::move(user_image)); delete this; } void UserImageRequest::OnDecodeImageFailed() { - image_info_.loaded_cb.Run(base::WrapUnique(new user_manager::UserImage)); + std::move(image_info_.loaded_cb) + .Run(base::WrapUnique(new user_manager::UserImage)); delete this; } // Starts decoding the image with ImageDecoder for the image |data| if // |data_is_ready| is true. void DecodeImage( - const ImageInfo& image_info, + ImageInfo image_info, scoped_refptr<base::SequencedTaskRunner> background_task_runner, const std::string* data, bool data_is_ready) { @@ -220,15 +225,15 @@ void DecodeImage( base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce( - image_info.loaded_cb, + std::move(image_info.loaded_cb), base::Passed(base::WrapUnique(new user_manager::UserImage)))); return; } - UserImageRequest* image_request = - new UserImageRequest(image_info, *data, background_task_runner); - ImageDecoder::StartWithOptions(image_request, *data, image_info.image_codec, - false); + ImageDecoder::ImageCodec codec = image_info.image_codec; + UserImageRequest* image_request = new UserImageRequest( + std::move(image_info), *data, background_task_runner); + ImageDecoder::StartWithOptions(image_request, *data, codec, false); } } // namespace @@ -238,14 +243,15 @@ void StartWithFilePath( const base::FilePath& file_path, ImageDecoder::ImageCodec image_codec, int pixels_per_side, - const LoadedCallback& loaded_cb) { + LoadedCallback loaded_cb) { std::string* data = new std::string; base::PostTaskAndReplyWithResult( background_task_runner.get(), FROM_HERE, - base::Bind(&base::ReadFileToString, file_path, data), - base::Bind(&DecodeImage, - ImageInfo(file_path, pixels_per_side, image_codec, loaded_cb), - background_task_runner, base::Owned(data))); + base::BindOnce(&base::ReadFileToString, file_path, data), + base::BindOnce(&DecodeImage, + ImageInfo(file_path, pixels_per_side, image_codec, + std::move(loaded_cb)), + background_task_runner, base::Owned(data))); } void StartWithData( @@ -253,10 +259,10 @@ void StartWithData( std::unique_ptr<std::string> data, ImageDecoder::ImageCodec image_codec, int pixels_per_side, - const LoadedCallback& loaded_cb) { - DecodeImage( - ImageInfo(base::FilePath(), pixels_per_side, image_codec, loaded_cb), - background_task_runner, data.get(), true /* data_is_ready */); + LoadedCallback loaded_cb) { + DecodeImage(ImageInfo(base::FilePath(), pixels_per_side, image_codec, + std::move(loaded_cb)), + background_task_runner, data.get(), true /* data_is_ready */); } } // namespace user_image_loader diff --git a/chrome/browser/chromeos/login/users/avatar/user_image_loader.h b/chrome/browser/chromeos/login/users/avatar/user_image_loader.h index dc36329cb24dd..b48d3ba93e84d 100644 --- a/chrome/browser/chromeos/login/users/avatar/user_image_loader.h +++ b/chrome/browser/chromeos/login/users/avatar/user_image_loader.h @@ -25,8 +25,8 @@ class UserImage; namespace chromeos { namespace user_image_loader { -typedef base::Callback<void(std::unique_ptr<user_manager::UserImage>)> - LoadedCallback; +using LoadedCallback = + base::OnceCallback<void(std::unique_ptr<user_manager::UserImage>)>; // Loads an image with |image_codec| in the background and calls |loaded_cb| // with the resulting UserImage (which may be empty in case of error). If @@ -41,13 +41,13 @@ void StartWithFilePath( const base::FilePath& file_path, ImageDecoder::ImageCodec image_codec, int pixels_per_side, - const LoadedCallback& loaded_cb); + LoadedCallback loaded_cb); void StartWithData( scoped_refptr<base::SequencedTaskRunner> background_task_runner, std::unique_ptr<std::string> data, ImageDecoder::ImageCodec image_codec, int pixels_per_side, - const LoadedCallback& loaded_cb); + LoadedCallback loaded_cb); } // namespace user_image_loader } // namespace chromeos diff --git a/chrome/browser/devtools/devtools_sanity_browsertest.cc b/chrome/browser/devtools/devtools_sanity_browsertest.cc index b52a10b9231f1..dc5e64556705d 100644 --- a/chrome/browser/devtools/devtools_sanity_browsertest.cc +++ b/chrome/browser/devtools/devtools_sanity_browsertest.cc @@ -2154,9 +2154,9 @@ class StaticURLDataSource : public content::URLDataSource { std::string GetSource() override { return source_; } void StartDataRequest(const GURL& url, const content::WebContents::Getter& wc_getter, - const GotDataCallback& callback) override { + GotDataCallback callback) override { std::string data(content_); - callback.Run(base::RefCountedString::TakeString(&data)); + std::move(callback).Run(base::RefCountedString::TakeString(&data)); } std::string GetMimeType(const std::string& path) override { return "text/html"; diff --git a/chrome/browser/push_messaging/push_messaging_service_impl.cc b/chrome/browser/push_messaging/push_messaging_service_impl.cc index 42cc6038aceb5..b97c0e7070c49 100644 --- a/chrome/browser/push_messaging/push_messaging_service_impl.cc +++ b/chrome/browser/push_messaging/push_messaging_service_impl.cc @@ -726,31 +726,33 @@ void PushMessagingServiceImpl::GetSubscriptionInfo( int64_t service_worker_registration_id, const std::string& sender_id, const std::string& subscription_id, - const SubscriptionInfoCallback& callback) { + SubscriptionInfoCallback callback) { PushMessagingAppIdentifier app_identifier = PushMessagingAppIdentifier::FindByServiceWorker( profile_, origin, service_worker_registration_id); if (app_identifier.is_null()) { - callback.Run(false /* is_valid */, GURL::EmptyGURL() /*endpoint*/, - std::vector<uint8_t>() /* p256dh */, - std::vector<uint8_t>() /* auth */); + std::move(callback).Run( + false /* is_valid */, GURL::EmptyGURL() /*endpoint*/, + std::vector<uint8_t>() /* p256dh */, std::vector<uint8_t>() /* auth */); return; } const GURL endpoint = CreateEndpoint(subscription_id); const std::string& app_id = app_identifier.app_id(); - base::Callback<void(bool)> validate_cb = base::Bind( - &PushMessagingServiceImpl::DidValidateSubscription, - weak_factory_.GetWeakPtr(), app_id, sender_id, endpoint, callback); + base::OnceCallback<void(bool)> validate_cb = + base::BindOnce(&PushMessagingServiceImpl::DidValidateSubscription, + weak_factory_.GetWeakPtr(), app_id, sender_id, endpoint, + std::move(callback)); if (PushMessagingAppIdentifier::UseInstanceID(app_id)) { GetInstanceIDDriver()->GetInstanceID(app_id)->ValidateToken( NormalizeSenderInfo(sender_id), kGCMScope, subscription_id, - validate_cb); + std::move(validate_cb)); } else { GetGCMDriver()->ValidateRegistration( - app_id, {NormalizeSenderInfo(sender_id)}, subscription_id, validate_cb); + app_id, {NormalizeSenderInfo(sender_id)}, subscription_id, + std::move(validate_cb)); } } @@ -758,31 +760,32 @@ void PushMessagingServiceImpl::DidValidateSubscription( const std::string& app_id, const std::string& sender_id, const GURL& endpoint, - const SubscriptionInfoCallback& callback, + SubscriptionInfoCallback callback, bool is_valid) { if (!is_valid) { - callback.Run(false /* is_valid */, GURL::EmptyGURL() /* endpoint */, - std::vector<uint8_t>() /* p256dh */, - std::vector<uint8_t>() /* auth */); + std::move(callback).Run( + false /* is_valid */, GURL::EmptyGURL() /* endpoint */, + std::vector<uint8_t>() /* p256dh */, std::vector<uint8_t>() /* auth */); return; } GetEncryptionInfoForAppId( app_id, sender_id, base::BindOnce(&PushMessagingServiceImpl::DidGetEncryptionInfo, - weak_factory_.GetWeakPtr(), endpoint, callback)); + weak_factory_.GetWeakPtr(), endpoint, + std::move(callback))); } void PushMessagingServiceImpl::DidGetEncryptionInfo( const GURL& endpoint, - const SubscriptionInfoCallback& callback, + SubscriptionInfoCallback callback, std::string p256dh, std::string auth_secret) const { // I/O errors might prevent the GCM Driver from retrieving a key-pair. bool is_valid = !p256dh.empty(); - callback.Run(is_valid, endpoint, - std::vector<uint8_t>(p256dh.begin(), p256dh.end()), - std::vector<uint8_t>(auth_secret.begin(), auth_secret.end())); + std::move(callback).Run( + is_valid, endpoint, std::vector<uint8_t>(p256dh.begin(), p256dh.end()), + std::vector<uint8_t>(auth_secret.begin(), auth_secret.end())); } // Unsubscribe methods --------------------------------------------------------- diff --git a/chrome/browser/push_messaging/push_messaging_service_impl.h b/chrome/browser/push_messaging/push_messaging_service_impl.h index d84b5b3c0b90f..514abf5a7706a 100644 --- a/chrome/browser/push_messaging/push_messaging_service_impl.h +++ b/chrome/browser/push_messaging/push_messaging_service_impl.h @@ -105,7 +105,7 @@ class PushMessagingServiceImpl : public content::PushMessagingService, int64_t service_worker_registration_id, const std::string& sender_id, const std::string& subscription_id, - const SubscriptionInfoCallback& callback) override; + SubscriptionInfoCallback callback) override; void Unsubscribe(blink::mojom::PushUnregistrationReason reason, const GURL& requesting_origin, int64_t service_worker_registration_id, @@ -199,11 +199,11 @@ class PushMessagingServiceImpl : public content::PushMessagingService, void DidValidateSubscription(const std::string& app_id, const std::string& sender_id, const GURL& endpoint, - const SubscriptionInfoCallback& callback, + SubscriptionInfoCallback callback, bool is_valid); void DidGetEncryptionInfo(const GURL& endpoint, - const SubscriptionInfoCallback& callback, + SubscriptionInfoCallback callback, std::string p256dh, std::string auth_secret) const; diff --git a/chrome/browser/search/local_ntp_source.cc b/chrome/browser/search/local_ntp_source.cc index 620f789667f3e..33ebff2ba22b3 100644 --- a/chrome/browser/search/local_ntp_source.cc +++ b/chrome/browser/search/local_ntp_source.cc @@ -329,10 +329,9 @@ std::string ReadBackgroundImageData(const base::FilePath& profile_path) { return data_string; } -void ServeBackgroundImageData( - const content::URLDataSource::GotDataCallback& callback, - std::string data_string) { - callback.Run(base::RefCountedString::TakeString(&data_string)); +void ServeBackgroundImageData(content::URLDataSource::GotDataCallback callback, + std::string data_string) { + std::move(callback).Run(base::RefCountedString::TakeString(&data_string)); } std::string GetLocalNtpPath() { @@ -665,8 +664,8 @@ class LocalNtpSource::DesktopLogoObserver { // Get the cached logo. void GetCachedLogo(LogoService* service, - const content::URLDataSource::GotDataCallback& callback) { - StartGetLogo(service, callback, /*from_cache=*/true); + content::URLDataSource::GotDataCallback callback) { + StartGetLogo(service, std::move(callback), /*from_cache=*/true); } // Get the fresh logo corresponding to a previous request for a cached logo. @@ -679,13 +678,13 @@ class LocalNtpSource::DesktopLogoObserver { // request, or perhaps one newer. void GetFreshLogo(LogoService* service, int requested_version, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { bool from_cache = (requested_version <= version_finished_); - StartGetLogo(service, callback, from_cache); + StartGetLogo(service, std::move(callback), from_cache); } private: - void OnLogoAvailable(const content::URLDataSource::GotDataCallback& callback, + void OnLogoAvailable(content::URLDataSource::GotDataCallback callback, LogoCallbackReason type, const base::Optional<EncodedLogo>& logo) { scoped_refptr<base::RefCountedString> response; @@ -714,21 +713,19 @@ class LocalNtpSource::DesktopLogoObserver { base::JSONWriter::Write(*ddl, &js); js = "var ddl = " + js + ";"; response = base::RefCountedString::TakeString(&js); - callback.Run(response); + std::move(callback).Run(response); } - void OnCachedLogoAvailable( - const content::URLDataSource::GotDataCallback& callback, - LogoCallbackReason type, - const base::Optional<EncodedLogo>& logo) { - OnLogoAvailable(callback, type, logo); + void OnCachedLogoAvailable(content::URLDataSource::GotDataCallback callback, + LogoCallbackReason type, + const base::Optional<EncodedLogo>& logo) { + OnLogoAvailable(std::move(callback), type, logo); } - void OnFreshLogoAvailable( - const content::URLDataSource::GotDataCallback& callback, - LogoCallbackReason type, - const base::Optional<EncodedLogo>& logo) { - OnLogoAvailable(callback, type, logo); + void OnFreshLogoAvailable(content::URLDataSource::GotDataCallback callback, + LogoCallbackReason type, + const base::Optional<EncodedLogo>& logo) { + OnLogoAvailable(std::move(callback), type, logo); OnRequestCompleted(type, logo); } @@ -738,21 +735,21 @@ class LocalNtpSource::DesktopLogoObserver { } void StartGetLogo(LogoService* service, - const content::URLDataSource::GotDataCallback& callback, + content::URLDataSource::GotDataCallback callback, bool from_cache) { EncodedLogoCallback cached, fresh; LogoCallbacks callbacks; if (from_cache) { callbacks.on_cached_encoded_logo_available = base::BindOnce(&DesktopLogoObserver::OnCachedLogoAvailable, - weak_ptr_factory_.GetWeakPtr(), callback); + weak_ptr_factory_.GetWeakPtr(), std::move(callback)); callbacks.on_fresh_encoded_logo_available = base::BindOnce(&DesktopLogoObserver::OnRequestCompleted, weak_ptr_factory_.GetWeakPtr()); } else { callbacks.on_fresh_encoded_logo_available = base::BindOnce(&DesktopLogoObserver::OnFreshLogoAvailable, - weak_ptr_factory_.GetWeakPtr(), callback); + weak_ptr_factory_.GetWeakPtr(), std::move(callback)); } if (!observing()) { ++version_started_; @@ -826,7 +823,7 @@ std::string LocalNtpSource::GetSource() { void LocalNtpSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); // TODO(crbug/1009127): Simplify usages of |path| since |url| is available. @@ -834,12 +831,13 @@ void LocalNtpSource::StartDataRequest( std::string stripped_path = StripParameters(path); if (stripped_path == kConfigDataFilename) { std::string config_data_js = search_config_provider_->config_data_js(); - callback.Run(base::RefCountedString::TakeString(&config_data_js)); + std::move(callback).Run( + base::RefCountedString::TakeString(&config_data_js)); return; } if (stripped_path == kThemeCSSFilename) { std::string theme_css = GetThemeCSS(profile_); - callback.Run(base::RefCountedString::TakeString(&theme_css)); + std::move(callback).Run(base::RefCountedString::TakeString(&theme_css)); return; } @@ -849,24 +847,24 @@ void LocalNtpSource::StartDataRequest( {base::ThreadPool(), base::TaskPriority::USER_VISIBLE, base::MayBlock()}, base::BindOnce(&ReadBackgroundImageData, profile_->GetPath()), - base::BindOnce(&ServeBackgroundImageData, callback)); + base::BindOnce(&ServeBackgroundImageData, std::move(callback))); return; } if (stripped_path == kNtpBackgroundCollectionScriptFilename) { if (!ntp_background_service_) { - callback.Run(nullptr); + std::move(callback).Run(nullptr); return; } ntp_background_collections_requests_.emplace_back(base::TimeTicks::Now(), - callback); + std::move(callback)); ntp_background_service_->FetchCollectionInfo(); return; } if (stripped_path == kNtpBackgroundImageScriptFilename) { if (!ntp_background_service_) { - callback.Run(nullptr); + std::move(callback).Run(nullptr); return; } std::string collection_id_param; @@ -874,28 +872,28 @@ void LocalNtpSource::StartDataRequest( if (net::GetValueForKeyInQuery(path_url, "collection_id", &collection_id_param)) { ntp_background_image_info_requests_.emplace_back(base::TimeTicks::Now(), - callback); + std::move(callback)); ntp_background_service_->FetchCollectionImageInfo(collection_id_param); } else { - callback.Run(nullptr); + std::move(callback).Run(nullptr); } return; } if (stripped_path == kOneGoogleBarScriptFilename) { if (!one_google_bar_service_) { - callback.Run(nullptr); + std::move(callback).Run(nullptr); } else { - ServeOneGoogleBarWhenAvailable(callback); + ServeOneGoogleBarWhenAvailable(std::move(callback)); } return; } if (stripped_path == kPromoScriptFilename) { if (!promo_service_) { - callback.Run(nullptr); + std::move(callback).Run(nullptr); } else { - ServePromoWhenAvailable(callback); + ServePromoWhenAvailable(std::move(callback)); } return; } @@ -904,7 +902,7 @@ void LocalNtpSource::StartDataRequest( // refresh the data until the old data is used. if (stripped_path == kSearchSuggestionsScriptFilename) { if (!search_suggest_service_) { - callback.Run(nullptr); + std::move(callback).Run(nullptr); return; } @@ -914,11 +912,12 @@ void LocalNtpSource::StartDataRequest( if (one_google_bar_service_->language_code() != kEnUSLanguageCode) { std::string no_suggestions = "var searchSuggestions = {suggestionsHtml: ''}"; - callback.Run(base::RefCountedString::TakeString(&no_suggestions)); + std::move(callback).Run( + base::RefCountedString::TakeString(&no_suggestions)); return; } - ServeSearchSuggestionsIfAvailable(callback); + ServeSearchSuggestionsIfAvailable(std::move(callback)); pending_search_suggest_request_ = base::TimeTicks::Now(); search_suggest_service_->Refresh(); @@ -927,7 +926,7 @@ void LocalNtpSource::StartDataRequest( if (stripped_path == kDoodleScriptFilename) { if (!logo_service_) { - callback.Run(nullptr); + std::move(callback).Run(nullptr); return; } @@ -936,9 +935,9 @@ void LocalNtpSource::StartDataRequest( GURL url = GURL(chrome::kChromeSearchLocalNtpUrl).Resolve(path); if (net::GetValueForKeyInQuery(url, "v", &version_string) && base::StringToInt(version_string, &version)) { - logo_observer_->GetFreshLogo(logo_service_, version, callback); + logo_observer_->GetFreshLogo(logo_service_, version, std::move(callback)); } else { - logo_observer_->GetCachedLogo(logo_service_, callback); + logo_observer_->GetCachedLogo(logo_service_, std::move(callback)); } return; } @@ -1049,7 +1048,7 @@ void LocalNtpSource::StartDataRequest( ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); base::StringPiece html = bundle.GetRawDataResource(IDR_LOCAL_NTP_HTML); std::string replaced = ui::ReplaceTemplateExpressions(html, replacements); - callback.Run(base::RefCountedString::TakeString(&replaced)); + std::move(callback).Run(base::RefCountedString::TakeString(&replaced)); return; } @@ -1064,11 +1063,11 @@ void LocalNtpSource::StartDataRequest( scoped_refptr<base::RefCountedMemory> response( ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( kResources[i].identifier, scale_factor)); - callback.Run(response.get()); + std::move(callback).Run(response.get()); return; } } - callback.Run(nullptr); + std::move(callback).Run(nullptr); } std::string LocalNtpSource::GetMimeType(const std::string& path) { @@ -1149,8 +1148,8 @@ void LocalNtpSource::OnCollectionInfoAvailable() { result = base::RefCountedString::TakeString(&js); base::TimeTicks now = base::TimeTicks::Now(); - for (const auto& request : ntp_background_collections_requests_) { - request.callback.Run(result); + for (auto& request : ntp_background_collections_requests_) { + std::move(request.callback).Run(result); base::TimeDelta delta = now - request.start_time; UMA_HISTOGRAM_MEDIUM_TIMES( "NewTabPage.BackgroundService.Collections.RequestLatency", delta); @@ -1187,8 +1186,8 @@ void LocalNtpSource::OnCollectionImagesAvailable() { result = base::RefCountedString::TakeString(&js); base::TimeTicks now = base::TimeTicks::Now(); - for (const auto& request : ntp_background_image_info_requests_) { - request.callback.Run(result); + for (auto& request : ntp_background_image_info_requests_) { + std::move(request.callback).Run(result); base::TimeDelta delta = now - request.start_time; UMA_HISTOGRAM_MEDIUM_TIMES( "NewTabPage.BackgroundService.Images.RequestLatency", delta); @@ -1292,7 +1291,7 @@ void LocalNtpSource::OnSearchSuggestServiceShuttingDown() { } void LocalNtpSource::ServeSearchSuggestionsIfAvailable( - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { base::Optional<SearchSuggestData> data = search_suggest_service_->search_suggest_data(); @@ -1305,7 +1304,7 @@ void LocalNtpSource::ServeSearchSuggestionsIfAvailable( base::JSONWriter::Write(*ConvertSearchSuggestDataToDict(data), &js); js = "var searchSuggestions = " + js + ";"; result = base::RefCountedString::TakeString(&js); - callback.Run(result); + std::move(callback).Run(result); } void LocalNtpSource::ServeOneGoogleBar( @@ -1331,22 +1330,22 @@ void LocalNtpSource::ServeOneGoogleBar( UMA_HISTOGRAM_MEDIUM_TIMES("NewTabPage.OneGoogleBar.RequestLatency.Failure", delta); } - for (const auto& callback : one_google_bar_callbacks_) { - callback.Run(result); + for (auto& callback : one_google_bar_callbacks_) { + std::move(callback).Run(result); } pending_one_google_bar_request_ = base::nullopt; one_google_bar_callbacks_.clear(); } void LocalNtpSource::ServeOneGoogleBarWhenAvailable( - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { base::Optional<OneGoogleBarData> data = one_google_bar_service_->one_google_bar_data(); if (!pending_one_google_bar_request_.has_value()) { - callback.Run(GetOGBString(data)); + std::move(callback).Run(GetOGBString(data)); } else { - one_google_bar_callbacks_.emplace_back(callback); + one_google_bar_callbacks_.push_back(std::move(callback)); } } @@ -1376,21 +1375,21 @@ void LocalNtpSource::ServePromo(const base::Optional<PromoData>& data) { UMA_HISTOGRAM_MEDIUM_TIMES("NewTabPage.Promos.RequestLatency2.Failure", delta); } - for (const auto& callback : promo_callbacks_) { - callback.Run(result); + for (auto& callback : promo_callbacks_) { + std::move(callback).Run(result); } pending_promo_request_ = base::nullopt; promo_callbacks_.clear(); } void LocalNtpSource::ServePromoWhenAvailable( - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { base::Optional<PromoData> data = promo_service_->promo_data(); if (!pending_promo_request_.has_value()) { - callback.Run(GetPromoString(data)); + std::move(callback).Run(GetPromoString(data)); } else { - promo_callbacks_.emplace_back(callback); + promo_callbacks_.push_back(std::move(callback)); } } @@ -1407,10 +1406,12 @@ void LocalNtpSource::InitiatePromoAndOGBRequests() { LocalNtpSource::NtpBackgroundRequest::NtpBackgroundRequest( base::TimeTicks start_time, - const content::URLDataSource::GotDataCallback& callback) - : start_time(start_time), callback(callback) {} + content::URLDataSource::GotDataCallback callback) + : start_time(start_time), callback(std::move(callback)) {} LocalNtpSource::NtpBackgroundRequest::NtpBackgroundRequest( - const NtpBackgroundRequest&) = default; + NtpBackgroundRequest&&) = default; +LocalNtpSource::NtpBackgroundRequest& LocalNtpSource::NtpBackgroundRequest:: +operator=(NtpBackgroundRequest&&) = default; LocalNtpSource::NtpBackgroundRequest::~NtpBackgroundRequest() = default; diff --git a/chrome/browser/search/local_ntp_source.h b/chrome/browser/search/local_ntp_source.h index 765e28a20bf54..0d299a5f2600e 100644 --- a/chrome/browser/search/local_ntp_source.h +++ b/chrome/browser/search/local_ntp_source.h @@ -59,10 +59,10 @@ class LocalNtpSource : public content::URLDataSource, class DesktopLogoObserver; struct NtpBackgroundRequest { - NtpBackgroundRequest( - base::TimeTicks start_time, - const content::URLDataSource::GotDataCallback& callback); - NtpBackgroundRequest(const NtpBackgroundRequest&); + NtpBackgroundRequest(base::TimeTicks start_time, + content::URLDataSource::GotDataCallback callback); + NtpBackgroundRequest(NtpBackgroundRequest&&); + NtpBackgroundRequest& operator=(NtpBackgroundRequest&&); ~NtpBackgroundRequest(); base::TimeTicks start_time; @@ -74,7 +74,7 @@ class LocalNtpSource : public content::URLDataSource, void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; std::string GetMimeType(const std::string& path) override; bool AllowCaching() override; bool ShouldServiceRequest(const GURL& url, @@ -110,7 +110,7 @@ class LocalNtpSource : public content::URLDataSource, // is returned immediately, otherwise it is returned when it becomes available // in ServeOneGoogleBar. void ServeOneGoogleBarWhenAvailable( - const content::URLDataSource::GotDataCallback& callback); + content::URLDataSource::GotDataCallback callback); // Called when the promo data is available and serves |data| to any pending // requests from the NTP. @@ -119,12 +119,12 @@ class LocalNtpSource : public content::URLDataSource, // is returned immediately, otherwise it is returned when it becomes // available in ServePromo. void ServePromoWhenAvailable( - const content::URLDataSource::GotDataCallback& callback); + content::URLDataSource::GotDataCallback callback); // If suggestion data is available return it immediately, otherwise no search // suggestions will be shown on this NTP load. void ServeSearchSuggestionsIfAvailable( - const content::URLDataSource::GotDataCallback& callback); + content::URLDataSource::GotDataCallback callback); // Start requests for the promo and OGB. void InitiatePromoAndOGBRequests(); diff --git a/chrome/browser/search/most_visited_iframe_source.cc b/chrome/browser/search/most_visited_iframe_source.cc index 4d4314e677cdc..45792f50783d0 100644 --- a/chrome/browser/search/most_visited_iframe_source.cc +++ b/chrome/browser/search/most_visited_iframe_source.cc @@ -63,54 +63,55 @@ std::string MostVisitedIframeSource::GetSource() { void MostVisitedIframeSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { // TODO(crbug/1009127): Simplify usages of |path| since |url| is available. const std::string path(url.path()); if (path == kSingleHTMLPath) { - SendResource(IDR_MOST_VISITED_SINGLE_HTML, callback); + SendResource(IDR_MOST_VISITED_SINGLE_HTML, std::move(callback)); } else if (path == kSingleCSSPath) { - SendResource(IDR_MOST_VISITED_SINGLE_CSS, callback); + SendResource(IDR_MOST_VISITED_SINGLE_CSS, std::move(callback)); } else if (path == kSingleJSPath) { - SendJSWithOrigin(IDR_MOST_VISITED_SINGLE_JS, wc_getter, callback); + SendJSWithOrigin(IDR_MOST_VISITED_SINGLE_JS, wc_getter, + std::move(callback)); } else if (path == kTitleHTMLPath) { - SendResource(IDR_MOST_VISITED_TITLE_HTML, callback); + SendResource(IDR_MOST_VISITED_TITLE_HTML, std::move(callback)); } else if (path == kTitleCSSPath) { - SendResource(IDR_MOST_VISITED_TITLE_CSS, callback); + SendResource(IDR_MOST_VISITED_TITLE_CSS, std::move(callback)); } else if (path == kTitleJSPath) { - SendResource(IDR_MOST_VISITED_TITLE_JS, callback); + SendResource(IDR_MOST_VISITED_TITLE_JS, std::move(callback)); } else if (path == kUtilJSPath) { - SendJSWithOrigin(IDR_MOST_VISITED_UTIL_JS, wc_getter, callback); + SendJSWithOrigin(IDR_MOST_VISITED_UTIL_JS, wc_getter, std::move(callback)); } else if (path == kCommonCSSPath) { - SendResource(IDR_MOST_VISITED_IFRAME_CSS, callback); + SendResource(IDR_MOST_VISITED_IFRAME_CSS, std::move(callback)); } else if (path == kDontShowPngPath) { - SendResource(IDR_MOST_VISITED_DONT_SHOW_PNG, callback); + SendResource(IDR_MOST_VISITED_DONT_SHOW_PNG, std::move(callback)); } else if (path == kDontShow2XPngPath) { - SendResource(IDR_MOST_VISITED_DONT_SHOW_2X_PNG, callback); + SendResource(IDR_MOST_VISITED_DONT_SHOW_2X_PNG, std::move(callback)); } else if (path == kEditHTMLPath) { - SendResource(IDR_CUSTOM_LINKS_EDIT_HTML, callback); + SendResource(IDR_CUSTOM_LINKS_EDIT_HTML, std::move(callback)); } else if (path == kEditCSSPath) { - SendResource(IDR_CUSTOM_LINKS_EDIT_CSS, callback); + SendResource(IDR_CUSTOM_LINKS_EDIT_CSS, std::move(callback)); } else if (path == kEditJSPath) { - SendJSWithOrigin(IDR_CUSTOM_LINKS_EDIT_JS, wc_getter, callback); + SendJSWithOrigin(IDR_CUSTOM_LINKS_EDIT_JS, wc_getter, std::move(callback)); } else if (path == kAddSvgPath) { - SendResource(IDR_CUSTOM_LINKS_ADD_SVG, callback); + SendResource(IDR_CUSTOM_LINKS_ADD_SVG, std::move(callback)); } else if (path == kAddWhiteSvgPath) { - SendResource(IDR_CUSTOM_LINKS_ADD_WHITE_SVG, callback); + SendResource(IDR_CUSTOM_LINKS_ADD_WHITE_SVG, std::move(callback)); } else if (path == kEditMenuSvgPath) { - SendResource(IDR_CUSTOM_LINKS_EDIT_MENU_SVG, callback); + SendResource(IDR_CUSTOM_LINKS_EDIT_MENU_SVG, std::move(callback)); } else if (path == kLocalNTPCommonCSSPath) { - SendResource(IDR_LOCAL_NTP_COMMON_CSS, callback); + SendResource(IDR_LOCAL_NTP_COMMON_CSS, std::move(callback)); } else if (path == kAnimationsCSSPath) { - SendResource(IDR_LOCAL_NTP_ANIMATIONS_CSS, callback); + SendResource(IDR_LOCAL_NTP_ANIMATIONS_CSS, std::move(callback)); } else if (path == kAnimationsJSPath) { - SendResource(IDR_LOCAL_NTP_ANIMATIONS_JS, callback); + SendResource(IDR_LOCAL_NTP_ANIMATIONS_JS, std::move(callback)); } else if (path == kLocalNTPUtilsJSPath) { - SendResource(IDR_LOCAL_NTP_UTILS_JS, callback); + SendResource(IDR_LOCAL_NTP_UTILS_JS, std::move(callback)); } else if (path == kAssertJsPath) { - SendResource(IDR_WEBUI_JS_ASSERT, callback); + SendResource(IDR_WEBUI_JS_ASSERT, std::move(callback)); } else { - callback.Run(nullptr); + std::move(callback).Run(nullptr); } } @@ -163,18 +164,19 @@ bool MostVisitedIframeSource::ServesPath(const std::string& path) const { void MostVisitedIframeSource::SendResource( int resource_id, - const content::URLDataSource::GotDataCallback& callback) { - callback.Run(ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes( - resource_id)); + content::URLDataSource::GotDataCallback callback) { + std::move(callback).Run( + ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes( + resource_id)); } void MostVisitedIframeSource::SendJSWithOrigin( int resource_id, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { std::string origin; if (!GetOrigin(wc_getter, &origin)) { - callback.Run(nullptr); + std::move(callback).Run(nullptr); return; } @@ -182,7 +184,7 @@ void MostVisitedIframeSource::SendJSWithOrigin( ui::ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); std::string response(template_js.as_string()); base::ReplaceFirstSubstringAfterOffset(&response, 0, "{{ORIGIN}}", origin); - callback.Run(base::RefCountedString::TakeString(&response)); + std::move(callback).Run(base::RefCountedString::TakeString(&response)); } bool MostVisitedIframeSource::GetOrigin( diff --git a/chrome/browser/search/most_visited_iframe_source.h b/chrome/browser/search/most_visited_iframe_source.h index 6f9703453600b..c0ecdacffab8d 100644 --- a/chrome/browser/search/most_visited_iframe_source.h +++ b/chrome/browser/search/most_visited_iframe_source.h @@ -25,7 +25,7 @@ class MostVisitedIframeSource : public content::URLDataSource { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; std::string GetMimeType(const std::string& path_and_query) override; bool AllowCaching() override; bool ShouldDenyXFrameOptions() override; @@ -39,13 +39,12 @@ class MostVisitedIframeSource : public content::URLDataSource { // Sends unmodified resource bytes. void SendResource(int resource_id, - const content::URLDataSource::GotDataCallback& callback); + content::URLDataSource::GotDataCallback callback); // Sends Javascript with an expected postMessage origin interpolated. - void SendJSWithOrigin( - int resource_id, - const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback); + void SendJSWithOrigin(int resource_id, + const content::WebContents::Getter& wc_getter, + content::URLDataSource::GotDataCallback callback); // This is exposed for testing and should not be overridden. // Sets |origin| to the URL of the WebContents identified by |wc_getter|. diff --git a/chrome/browser/search/most_visited_iframe_source_unittest.cc b/chrome/browser/search/most_visited_iframe_source_unittest.cc index 1b13b8d06dc72..f126ba07f285a 100644 --- a/chrome/browser/search/most_visited_iframe_source_unittest.cc +++ b/chrome/browser/search/most_visited_iframe_source_unittest.cc @@ -48,7 +48,7 @@ class TestMostVisitedIframeSource : public MostVisitedIframeSource { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override {} + content::URLDataSource::GotDataCallback callback) override {} // RenderFrameHost is hard to mock in concert with everything else, so stub // this method out for testing. @@ -85,12 +85,16 @@ class MostVisitedIframeSourceTest : public testing::Test { } void SendResource(int resource_id) { - source()->SendResource(resource_id, callback_); + source()->SendResource( + resource_id, base::BindOnce(&MostVisitedIframeSourceTest::SaveResponse, + base::Unretained(this))); } void SendJSWithOrigin(int resource_id) { - source()->SendJSWithOrigin(resource_id, content::WebContents::Getter(), - callback_); + source()->SendJSWithOrigin( + resource_id, content::WebContents::Getter(), + base::BindOnce(&MostVisitedIframeSourceTest::SaveResponse, + base::Unretained(this))); } bool ShouldService(const std::string& path, int process_id) { @@ -101,8 +105,6 @@ class MostVisitedIframeSourceTest : public testing::Test { private: void SetUp() override { source_ = std::make_unique<TestMostVisitedIframeSource>(); - callback_ = base::Bind(&MostVisitedIframeSourceTest::SaveResponse, - base::Unretained(this)); instant_io_context_ = new InstantIOContext; InstantIOContext::SetUserDataOnIO(&resource_context_, instant_io_context_); source_->set_origin(kInstantOrigin); @@ -122,7 +124,6 @@ class MostVisitedIframeSourceTest : public testing::Test { net::TestURLRequestContext test_url_request_context_; content::MockResourceContext resource_context_; std::unique_ptr<TestMostVisitedIframeSource> source_; - content::URLDataSource::GotDataCallback callback_; scoped_refptr<InstantIOContext> instant_io_context_; scoped_refptr<base::RefCountedMemory> response_; }; diff --git a/chrome/browser/search/ntp_icon_source.cc b/chrome/browser/search/ntp_icon_source.cc index e3aa430ee2e8f..00cc241534478 100644 --- a/chrome/browser/search/ntp_icon_source.cc +++ b/chrome/browser/search/ntp_icon_source.cc @@ -226,17 +226,20 @@ SkColor GetBackgroundColorForUrl(const GURL& icon_url) { } // namespace struct NtpIconSource::NtpIconRequest { - NtpIconRequest(const content::URLDataSource::GotDataCallback& cb, + NtpIconRequest(content::URLDataSource::GotDataCallback cb, const GURL& path, int icon_size_in_pixels, float scale, bool show_fallback_monogram) - : callback(cb), + : callback(std::move(cb)), path(path), icon_size_in_pixels(icon_size_in_pixels), device_scale_factor(scale), show_fallback_monogram(show_fallback_monogram) {} - NtpIconRequest(const NtpIconRequest& other) = default; + + NtpIconRequest(NtpIconRequest&& other) = default; + NtpIconRequest& operator=(NtpIconRequest&& other) = default; + ~NtpIconRequest() {} content::URLDataSource::GotDataCallback callback; @@ -262,7 +265,7 @@ std::string NtpIconSource::GetSource() { void NtpIconSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { favicon::FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(profile_, ServiceAccessType::EXPLICIT_ACCESS); @@ -273,7 +276,7 @@ void NtpIconSource::StartDataRequest( if (parsed.url.is_valid()) { int icon_size_in_pixels = std::ceil(parsed.size_in_dip * parsed.device_scale_factor); - NtpIconRequest request(callback, parsed.url, icon_size_in_pixels, + NtpIconRequest request(std::move(callback), parsed.url, icon_size_in_pixels, parsed.device_scale_factor, parsed.show_fallback_monogram); @@ -295,10 +298,10 @@ void NtpIconSource::StartDataRequest( gfx::ImageSkiaOperations::CreateResizedImage( image.AsImageSkia(), skia::ImageOperations::RESIZE_BEST, target_size); - ReturnRenderedIconForRequest(request, + ReturnRenderedIconForRequest(std::move(request), gfx::Image(resized_image).AsBitmap()); } else { - ReturnRenderedIconForRequest(request, image.AsBitmap()); + ReturnRenderedIconForRequest(std::move(request), image.AsBitmap()); } return; } @@ -311,11 +314,11 @@ void NtpIconSource::StartDataRequest( favicon_service->GetRawFaviconForPageURL( parsed.url, {favicon_base::IconType::kFavicon}, icon_size_in_pixels, fallback_to_host, - base::Bind(&NtpIconSource::OnLocalFaviconAvailable, - weak_ptr_factory_.GetWeakPtr(), request), + base::BindOnce(&NtpIconSource::OnLocalFaviconAvailable, + weak_ptr_factory_.GetWeakPtr(), std::move(request)), &cancelable_task_tracker_); } else { - callback.Run(nullptr); + std::move(callback).Run(nullptr); } } @@ -338,7 +341,7 @@ bool NtpIconSource::ShouldServiceRequest( } void NtpIconSource::OnLocalFaviconAvailable( - const NtpIconRequest& request, + NtpIconRequest request, const favicon_base::FaviconRawBitmapResult& bitmap_result) { if (bitmap_result.is_valid()) { // A local favicon was found. Decode it to an SkBitmap so it can eventually @@ -348,12 +351,12 @@ void NtpIconSource::OnLocalFaviconAvailable( gfx::PNGCodec::Decode(bitmap_result.bitmap_data.get()->front(), bitmap_result.bitmap_data.get()->size(), &bitmap); DCHECK(result); - ReturnRenderedIconForRequest(request, bitmap); + ReturnRenderedIconForRequest(std::move(request), bitmap); } else { // Since a local favicon was not found, attempt to fetch a server icon if // the url is known to the server (this last check is important to avoid // leaking private history to the server). - RequestServerFavicon(request); + RequestServerFavicon(std::move(request)); } } @@ -374,14 +377,14 @@ bool NtpIconSource::IsRequestedUrlInServerSuggestions(const GURL& url) { return position != profile.suggestions().end(); } -void NtpIconSource::RequestServerFavicon(const NtpIconRequest& request) { +void NtpIconSource::RequestServerFavicon(NtpIconRequest request) { // Only fetch a server icon if the page url is known to the server. This check // is important to avoid leaking private history to the server. const GURL server_favicon_url = GURL(base::StringPrintf(kServerFaviconURL, request.path.spec().c_str())); if (!server_favicon_url.is_valid() || !IsRequestedUrlInServerSuggestions(request.path)) { - ReturnRenderedIconForRequest(request, SkBitmap()); + ReturnRenderedIconForRequest(std::move(request), SkBitmap()); return; } @@ -412,13 +415,13 @@ void NtpIconSource::RequestServerFavicon(const NtpIconRequest& request) { gfx::Size(request.icon_size_in_pixels, request.icon_size_in_pixels)); image_fetcher_->FetchImage( server_favicon_url, - base::Bind(&NtpIconSource::OnServerFaviconAvailable, - weak_ptr_factory_.GetWeakPtr(), request), + base::BindOnce(&NtpIconSource::OnServerFaviconAvailable, + weak_ptr_factory_.GetWeakPtr(), std::move(request)), std::move(params)); } void NtpIconSource::OnServerFaviconAvailable( - const NtpIconRequest& request, + NtpIconRequest request, const gfx::Image& fetched_image, const image_fetcher::RequestMetadata& metadata) { // If a server icon was not found, |fetched_bitmap| will be empty and a @@ -432,10 +435,10 @@ void NtpIconSource::OnServerFaviconAvailable( request.icon_size_in_pixels, request.icon_size_in_pixels); } - ReturnRenderedIconForRequest(request, fetched_bitmap); + ReturnRenderedIconForRequest(std::move(request), fetched_bitmap); } -void NtpIconSource::ReturnRenderedIconForRequest(const NtpIconRequest& request, +void NtpIconSource::ReturnRenderedIconForRequest(NtpIconRequest request, const SkBitmap& favicon) { // Only use even pixel sizes to avoid issues when centering the fallback // monogram. @@ -478,5 +481,6 @@ void NtpIconSource::ReturnRenderedIconForRequest(const NtpIconRequest& request, std::vector<unsigned char> bitmap_data; bool result = gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &bitmap_data); DCHECK(result); - request.callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data)); + std::move(request.callback) + .Run(base::RefCountedBytes::TakeVector(&bitmap_data)); } diff --git a/chrome/browser/search/ntp_icon_source.h b/chrome/browser/search/ntp_icon_source.h index 314b757609d82..ee59f152eee8d 100644 --- a/chrome/browser/search/ntp_icon_source.h +++ b/chrome/browser/search/ntp_icon_source.h @@ -39,7 +39,7 @@ class NtpIconSource : public content::URLDataSource { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; std::string GetMimeType(const std::string& path) override; bool ShouldServiceRequest(const GURL& url, content::ResourceContext* resource_context, @@ -48,19 +48,19 @@ class NtpIconSource : public content::URLDataSource { private: struct NtpIconRequest; void OnLocalFaviconAvailable( - const NtpIconRequest& request, + NtpIconRequest request, const favicon_base::FaviconRawBitmapResult& bitmap_result); // Returns whether |url| is in the set of server suggestions. bool IsRequestedUrlInServerSuggestions(const GURL& url); - void RequestServerFavicon(const NtpIconRequest& request); - void OnServerFaviconAvailable(const NtpIconRequest& request, + void RequestServerFavicon(NtpIconRequest request); + void OnServerFaviconAvailable(NtpIconRequest request, const gfx::Image& fetched_image, const image_fetcher::RequestMetadata& metadata); // Will call |request.callback| with the rendered icon. |bitmap| can be empty, // in which case the returned icon is a fallback circle with a letter drawn // into it. - void ReturnRenderedIconForRequest(const NtpIconRequest& request, + void ReturnRenderedIconForRequest(NtpIconRequest request, const SkBitmap& bitmap); base::CancelableTaskTracker cancelable_task_tracker_; diff --git a/chrome/browser/search/suggestions/suggestions_ui.cc b/chrome/browser/search/suggestions/suggestions_ui.cc index 524599df88503..f459d4e01b946 100644 --- a/chrome/browser/search/suggestions/suggestions_ui.cc +++ b/chrome/browser/search/suggestions/suggestions_ui.cc @@ -29,7 +29,7 @@ class SuggestionsSourceWrapper : public content::URLDataSource { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; std::string GetMimeType(const std::string& path) override; private: @@ -52,9 +52,9 @@ std::string SuggestionsSourceWrapper::GetSource() { void SuggestionsSourceWrapper::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { suggestions_source_.StartDataRequest( - content::URLDataSource::URLToRequestPath(url), callback); + content::URLDataSource::URLToRequestPath(url), std::move(callback)); } std::string SuggestionsSourceWrapper::GetMimeType(const std::string& path) { diff --git a/chrome/browser/sharing/sharing_device_registration_unittest.cc b/chrome/browser/sharing/sharing_device_registration_unittest.cc index 727e8301cd896..9c6e7e349297e 100644 --- a/chrome/browser/sharing/sharing_device_registration_unittest.cc +++ b/chrome/browser/sharing/sharing_device_registration_unittest.cc @@ -85,7 +85,7 @@ class FakeInstanceID : public instance_id::InstanceID { void ValidateToken(const std::string& authorized_entity, const std::string& scope, const std::string& token, - const ValidateTokenCallback& callback) override { + ValidateTokenCallback callback) override { NOTIMPLEMENTED(); } diff --git a/chrome/browser/sync/test/integration/sync_test.h b/chrome/browser/sync/test/integration/sync_test.h index 068f7dcc58cb7..91cfa3c3823fe 100644 --- a/chrome/browser/sync/test/integration/sync_test.h +++ b/chrome/browser/sync/test/integration/sync_test.h @@ -113,7 +113,7 @@ class SyncTest : public InProcessBrowserTest { void ValidateToken(const std::string& authorized_entity, const std::string& scope, const std::string& token, - const ValidateTokenCallback& callback) override {} + ValidateTokenCallback callback) override {} void DeleteToken(const std::string& authorized_entity, const std::string& scope, diff --git a/chrome/browser/ui/web_applications/system_web_app_ui_utils.cc b/chrome/browser/ui/web_applications/system_web_app_ui_utils.cc index 81055ab9a817b..d19a0b899620f 100644 --- a/chrome/browser/ui/web_applications/system_web_app_ui_utils.cc +++ b/chrome/browser/ui/web_applications/system_web_app_ui_utils.cc @@ -184,9 +184,10 @@ void SetManifestRequestFilter(content::WebUIDataSource* source, [](const std::string& path) { return path == "manifest.json"; }), base::BindRepeating( [](const std::string& response, const std::string& path, - const content::WebUIDataSource::GotDataCallback& callback) { + content::WebUIDataSource::GotDataCallback callback) { std::string response_copy = response; - callback.Run(base::RefCountedString::TakeString(&response_copy)); + std::move(callback).Run( + base::RefCountedString::TakeString(&response_copy)); }, std::move(response))); } diff --git a/chrome/browser/ui/webui/about_ui.cc b/chrome/browser/ui/webui/about_ui.cc index 53acc4dbd9125..948e17345ab45 100644 --- a/chrome/browser/ui/webui/about_ui.cc +++ b/chrome/browser/ui/webui/about_ui.cc @@ -181,9 +181,9 @@ class ChromeOSTermsHandler : public base::RefCountedThreadSafe<ChromeOSTermsHandler> { public: static void Start(const std::string& path, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { scoped_refptr<ChromeOSTermsHandler> handler( - new ChromeOSTermsHandler(path, callback)); + new ChromeOSTermsHandler(path, std::move(callback))); handler->StartOnUIThread(); } @@ -191,9 +191,9 @@ class ChromeOSTermsHandler friend class base::RefCountedThreadSafe<ChromeOSTermsHandler>; ChromeOSTermsHandler(const std::string& path, - const content::URLDataSource::GotDataCallback& callback) + content::URLDataSource::GotDataCallback callback) : path_(path), - callback_(callback), + callback_(std::move(callback)), // Previously we were using "initial locale" http://crbug.com/145142 locale_(g_browser_process->GetApplicationLocale()) {} @@ -343,7 +343,7 @@ class ChromeOSTermsHandler // Do nothing if OEM EULA or Play Store ToS load failed. if (contents_.empty() && path_.empty()) contents_ = l10n_util::GetStringUTF8(IDS_TERMS_HTML); - callback_.Run(base::RefCountedString::TakeString(&contents_)); + std::move(callback_).Run(base::RefCountedString::TakeString(&contents_)); } // Path in the URL. @@ -365,19 +365,18 @@ class ChromeOSCreditsHandler : public base::RefCountedThreadSafe<ChromeOSCreditsHandler> { public: static void Start(const std::string& path, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { scoped_refptr<ChromeOSCreditsHandler> handler( - new ChromeOSCreditsHandler(path, callback)); + new ChromeOSCreditsHandler(path, std::move(callback))); handler->StartOnUIThread(); } private: friend class base::RefCountedThreadSafe<ChromeOSCreditsHandler>; - ChromeOSCreditsHandler( - const std::string& path, - const content::URLDataSource::GotDataCallback& callback) - : path_(path), callback_(callback) {} + ChromeOSCreditsHandler(const std::string& path, + content::URLDataSource::GotDataCallback callback) + : path_(path), callback_(std::move(callback)) {} virtual ~ChromeOSCreditsHandler() {} @@ -415,7 +414,7 @@ class ChromeOSCreditsHandler ui::ResourceBundle::GetSharedInstance().LoadDataResourceString( IDR_OS_CREDITS_HTML); } - callback_.Run(base::RefCountedString::TakeString(&contents_)); + std::move(callback_).Run(base::RefCountedString::TakeString(&contents_)); } // Path in the URL. @@ -434,9 +433,9 @@ class LinuxCreditsHandler : public base::RefCountedThreadSafe<LinuxCreditsHandler> { public: static void Start(const std::string& path, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { scoped_refptr<LinuxCreditsHandler> handler( - new LinuxCreditsHandler(path, callback)); + new LinuxCreditsHandler(path, std::move(callback))); handler->StartOnUIThread(); } @@ -444,8 +443,8 @@ class LinuxCreditsHandler friend class base::RefCountedThreadSafe<LinuxCreditsHandler>; LinuxCreditsHandler(const std::string& path, - const content::URLDataSource::GotDataCallback& callback) - : path_(path), callback_(callback) {} + content::URLDataSource::GotDataCallback callback) + : path_(path), callback_(std::move(callback)) {} virtual ~LinuxCreditsHandler() {} @@ -485,7 +484,7 @@ class LinuxCreditsHandler ui::ResourceBundle::GetSharedInstance().LoadDataResourceString( IDR_OS_CREDITS_HTML); } - callback_.Run(base::RefCountedString::TakeString(&contents_)); + std::move(callback_).Run(base::RefCountedString::TakeString(&contents_)); } // Path in the URL. @@ -597,7 +596,7 @@ std::string AboutUIHTMLSource::GetSource() { void AboutUIHTMLSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { // TODO(crbug/1009127): Simplify usages of |path| since |url| is available. const std::string path = content::URLDataSource::URLToRequestPath(url); std::string response; @@ -624,16 +623,16 @@ void AboutUIHTMLSource::StartDataRequest( #endif #if defined(OS_CHROMEOS) } else if (source_name_ == chrome::kChromeUIOSCreditsHost) { - ChromeOSCreditsHandler::Start(path, callback); + ChromeOSCreditsHandler::Start(path, std::move(callback)); return; } else if (source_name_ == chrome::kChromeUILinuxCreditsHost) { - LinuxCreditsHandler::Start(path, callback); + LinuxCreditsHandler::Start(path, std::move(callback)); return; #endif #if !defined(OS_ANDROID) } else if (source_name_ == chrome::kChromeUITermsHost) { #if defined(OS_CHROMEOS) - ChromeOSTermsHandler::Start(path, callback); + ChromeOSTermsHandler::Start(path, std::move(callback)); return; #else response = l10n_util::GetStringUTF8(IDS_TERMS_HTML); @@ -641,14 +640,14 @@ void AboutUIHTMLSource::StartDataRequest( #endif } - FinishDataRequest(response, callback); + FinishDataRequest(response, std::move(callback)); } void AboutUIHTMLSource::FinishDataRequest( const std::string& html, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { std::string html_copy(html); - callback.Run(base::RefCountedString::TakeString(&html_copy)); + std::move(callback).Run(base::RefCountedString::TakeString(&html_copy)); } std::string AboutUIHTMLSource::GetMimeType(const std::string& path) { diff --git a/chrome/browser/ui/webui/about_ui.h b/chrome/browser/ui/webui/about_ui.h index 485fa5b1779fe..8a77e03b6532c 100644 --- a/chrome/browser/ui/webui/about_ui.h +++ b/chrome/browser/ui/webui/about_ui.h @@ -27,16 +27,15 @@ class AboutUIHTMLSource : public content::URLDataSource { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; std::string GetMimeType(const std::string& path) override; bool ShouldAddContentSecurityPolicy() override; std::string GetAccessControlAllowOriginForOrigin( const std::string& origin) override; // Send the response data. - void FinishDataRequest( - const std::string& html, - const content::URLDataSource::GotDataCallback& callback); + void FinishDataRequest(const std::string& html, + content::URLDataSource::GotDataCallback callback); Profile* profile() { return profile_; } diff --git a/chrome/browser/ui/webui/app_launcher_page_ui.cc b/chrome/browser/ui/webui/app_launcher_page_ui.cc index 553d3f24d13ff..f4d500f5ffc81 100644 --- a/chrome/browser/ui/webui/app_launcher_page_ui.cc +++ b/chrome/browser/ui/webui/app_launcher_page_ui.cc @@ -101,7 +101,7 @@ std::string AppLauncherPageUI::HTMLSource::GetSource() { void AppLauncherPageUI::HTMLSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { DCHECK_CURRENTLY_ON(BrowserThread::UI); NTPResourceCache* resource = AppResourceCacheFactory::GetForProfile(profile_); @@ -114,7 +114,7 @@ void AppLauncherPageUI::HTMLSource::StartDataRequest( scoped_refptr<base::RefCountedMemory> html_bytes( resource->GetNewTabHTML(win_type)); - callback.Run(html_bytes.get()); + std::move(callback).Run(html_bytes.get()); } std::string AppLauncherPageUI::HTMLSource::GetMimeType( diff --git a/chrome/browser/ui/webui/app_launcher_page_ui.h b/chrome/browser/ui/webui/app_launcher_page_ui.h index 011f557998a03..280e600384533 100644 --- a/chrome/browser/ui/webui/app_launcher_page_ui.h +++ b/chrome/browser/ui/webui/app_launcher_page_ui.h @@ -41,7 +41,7 @@ class AppLauncherPageUI : public content::WebUIController { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; std::string GetMimeType(const std::string&) override; bool ShouldReplaceExistingSource() override; bool AllowCaching() override; diff --git a/chrome/browser/ui/webui/chromeos/cellular_setup/mobile_setup_ui.cc b/chrome/browser/ui/webui/chromeos/cellular_setup/mobile_setup_ui.cc index 2d32689190047..98688041836a6 100644 --- a/chrome/browser/ui/webui/chromeos/cellular_setup/mobile_setup_ui.cc +++ b/chrome/browser/ui/webui/chromeos/cellular_setup/mobile_setup_ui.cc @@ -112,12 +112,11 @@ base::string16 GetActivationErrorMessage(MobileActivator::ActivationError error, MobileActivator::ActivationError::kActivationFailed, carrier); } -void DataRequestFailed( - const std::string& service_path, - const content::URLDataSource::GotDataCallback& callback) { +void DataRequestFailed(const std::string& service_path, + content::URLDataSource::GotDataCallback callback) { NET_LOG(ERROR) << "Data Request Failed for Mobile Setup: " << service_path; scoped_refptr<base::RefCountedBytes> html_bytes(new base::RefCountedBytes); - callback.Run(html_bytes.get()); + std::move(callback).Run(html_bytes.get()); } // Keys for the dictionary that is set to activation UI and that contains the @@ -179,7 +178,7 @@ class MobileSetupUIHTMLSource : public content::URLDataSource { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; std::string GetMimeType(const std::string&) override { return "text/html"; } bool ShouldAddContentSecurityPolicy() override { return false; } bool AllowCaching() override { @@ -271,7 +270,7 @@ std::string MobileSetupUIHTMLSource::GetSource() { void MobileSetupUIHTMLSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { const std::string path = content::URLDataSource::URLToRequestPath(url); // Sanity checks that activation was requested for an appropriate network. const NetworkState* network = @@ -279,13 +278,13 @@ void MobileSetupUIHTMLSource::StartDataRequest( if (!network) { NET_LOG(ERROR) << "Network for mobile setup not found: " << path; - DataRequestFailed(path, callback); + DataRequestFailed(path, std::move(callback)); return; } if (!network->Matches(NetworkTypePattern::Cellular())) { NET_LOG(ERROR) << "Mobile setup attempt for non cellular network: " << path; - DataRequestFailed(path, callback); + DataRequestFailed(path, std::move(callback)); return; } @@ -294,7 +293,7 @@ void MobileSetupUIHTMLSource::StartDataRequest( NET_LOG(ERROR) << "Mobile setup network in unexpected state: " << path << " payment_url: " << network->payment_url() << " activation_state: " << network->activation_state(); - DataRequestFailed(path, callback); + DataRequestFailed(path, std::move(callback)); return; } @@ -304,7 +303,7 @@ void MobileSetupUIHTMLSource::StartDataRequest( if (!device) { NET_LOG(ERROR) << "Network device for mobile setup not found: " << network->device_path(); - DataRequestFailed(path, callback); + DataRequestFailed(path, std::move(callback)); return; } @@ -354,7 +353,7 @@ void MobileSetupUIHTMLSource::StartDataRequest( full_html = webui::GetI18nTemplateHtml(html_for_non_activated, &strings); } - callback.Run(base::RefCountedString::TakeString(&full_html)); + std::move(callback).Run(base::RefCountedString::TakeString(&full_html)); } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/ui/webui/chromeos/image_source.cc b/chrome/browser/ui/webui/chromeos/image_source.cc index 3110ff00f3932..2ad02f4ce3e3f 100644 --- a/chrome/browser/ui/webui/chromeos/image_source.cc +++ b/chrome/browser/ui/webui/chromeos/image_source.cc @@ -29,13 +29,12 @@ namespace { const char* const kWhitelistedDirectories[] = {"regulatory_labels"}; // Callback for user_manager::UserImageLoader. -void ImageLoaded( - const content::URLDataSource::GotDataCallback& got_data_callback, - std::unique_ptr<user_manager::UserImage> user_image) { +void ImageLoaded(content::URLDataSource::GotDataCallback got_data_callback, + std::unique_ptr<user_manager::UserImage> user_image) { if (user_image->has_image_bytes()) - got_data_callback.Run(user_image->image_bytes()); + std::move(got_data_callback).Run(user_image->image_bytes()); else - got_data_callback.Run(nullptr); + std::move(got_data_callback).Run(nullptr); } } // namespace @@ -56,10 +55,10 @@ std::string ImageSource::GetSource() { void ImageSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& got_data_callback) { + content::URLDataSource::GotDataCallback got_data_callback) { const std::string path = content::URLDataSource::URLToRequestPath(url); if (!IsWhitelisted(path)) { - got_data_callback.Run(nullptr); + std::move(got_data_callback).Run(nullptr); return; } @@ -68,24 +67,23 @@ void ImageSource::StartDataRequest( base::PostTaskAndReplyWithResult( FROM_HERE, {base::ThreadPool(), base::MayBlock(), base::TaskPriority::USER_VISIBLE}, - base::Bind(&base::PathExists, image_path), - base::Bind(&ImageSource::StartDataRequestAfterPathExists, - weak_factory_.GetWeakPtr(), image_path, got_data_callback)); + base::BindOnce(&base::PathExists, image_path), + base::BindOnce(&ImageSource::StartDataRequestAfterPathExists, + weak_factory_.GetWeakPtr(), image_path, + std::move(got_data_callback))); } void ImageSource::StartDataRequestAfterPathExists( const base::FilePath& image_path, - const content::URLDataSource::GotDataCallback& got_data_callback, + content::URLDataSource::GotDataCallback got_data_callback, bool path_exists) { if (path_exists) { user_image_loader::StartWithFilePath( - task_runner_, - image_path, - ImageDecoder::DEFAULT_CODEC, + task_runner_, image_path, ImageDecoder::DEFAULT_CODEC, 0, // Do not crop. - base::Bind(&ImageLoaded, got_data_callback)); + base::BindOnce(&ImageLoaded, std::move(got_data_callback))); } else { - got_data_callback.Run(nullptr); + std::move(got_data_callback).Run(nullptr); } } diff --git a/chrome/browser/ui/webui/chromeos/image_source.h b/chrome/browser/ui/webui/chromeos/image_source.h index 6848d0aa08611..a36c544e74102 100644 --- a/chrome/browser/ui/webui/chromeos/image_source.h +++ b/chrome/browser/ui/webui/chromeos/image_source.h @@ -27,10 +27,10 @@ class ImageSource : public content::URLDataSource { // content::URLDataSource implementation. std::string GetSource() override; - void StartDataRequest(const GURL& url, - const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& - got_data_callback) override; + void StartDataRequest( + const GURL& url, + const content::WebContents::Getter& wc_getter, + content::URLDataSource::GotDataCallback got_data_callback) override; std::string GetMimeType(const std::string& path) override; @@ -38,7 +38,7 @@ class ImageSource : public content::URLDataSource { // Continuation from StartDataRequest(). void StartDataRequestAfterPathExists( const base::FilePath& image_path, - const content::URLDataSource::GotDataCallback& got_data_callback, + content::URLDataSource::GotDataCallback got_data_callback, bool path_exists); // Checks whether we have allowed the image to be loaded. diff --git a/chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.cc b/chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.cc index 2d4544f222da2..19b15236e1e7d 100644 --- a/chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.cc +++ b/chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.cc @@ -36,9 +36,9 @@ std::string ScreenlockIconSource::GetSource() const { void ScreenlockIconSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { if (!icon_provider_) { - callback.Run(GetDefaultIcon().As1xPNGBytes().get()); + std::move(callback).Run(GetDefaultIcon().As1xPNGBytes().get()); return; } @@ -49,11 +49,11 @@ void ScreenlockIconSource::StartDataRequest( gfx::Image image = icon_provider_->GetIcon(username); if (image.IsEmpty()) { - callback.Run(GetDefaultIcon().As1xPNGBytes().get()); + std::move(callback).Run(GetDefaultIcon().As1xPNGBytes().get()); return; } - callback.Run(image.As1xPNGBytes().get()); + std::move(callback).Run(image.As1xPNGBytes().get()); } std::string ScreenlockIconSource::GetMimeType(const std::string&) const { diff --git a/chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.h b/chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.h index 02933006fc185..b0a8d437f9139 100644 --- a/chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.h +++ b/chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.h @@ -25,7 +25,7 @@ class ScreenlockIconSource : public content::URLDataSource { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; std::string GetMimeType(const std::string& path) const override; diff --git a/chrome/browser/ui/webui/chromeos/slow_trace_ui.cc b/chrome/browser/ui/webui/chromeos/slow_trace_ui.cc index 0919e41148537..96c237d88e3cc 100644 --- a/chrome/browser/ui/webui/chromeos/slow_trace_ui.cc +++ b/chrome/browser/ui/webui/chromeos/slow_trace_ui.cc @@ -35,7 +35,7 @@ std::string SlowTraceSource::GetSource() { void SlowTraceSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { int trace_id = 0; // TODO(crbug/1009127): Simplify usages of |path| since |url| is available. const std::string path = content::URLDataSource::URLToRequestPath(url); @@ -44,13 +44,12 @@ void SlowTraceSource::StartDataRequest( if (!manager || pos == std::string::npos || !base::StringToInt(path.substr(pos + 1), &trace_id)) { - callback.Run(nullptr); + std::move(callback).Run(nullptr); return; } - manager->GetTraceData(trace_id, - base::Bind(&SlowTraceSource::OnGetTraceData, - base::Unretained(this), - callback)); + manager->GetTraceData( + trace_id, base::BindOnce(&SlowTraceSource::OnGetTraceData, + base::Unretained(this), std::move(callback))); } std::string SlowTraceSource::GetMimeType(const std::string& path) { @@ -60,9 +59,9 @@ std::string SlowTraceSource::GetMimeType(const std::string& path) { SlowTraceSource::~SlowTraceSource() {} void SlowTraceSource::OnGetTraceData( - const content::URLDataSource::GotDataCallback& callback, + content::URLDataSource::GotDataCallback callback, scoped_refptr<base::RefCountedString> trace_data) { - callback.Run(trace_data.get()); + std::move(callback).Run(trace_data.get()); } bool SlowTraceSource::AllowCaching() { diff --git a/chrome/browser/ui/webui/chromeos/slow_trace_ui.h b/chrome/browser/ui/webui/chromeos/slow_trace_ui.h index 78ebae81882c0..aa719c2f58bb7 100644 --- a/chrome/browser/ui/webui/chromeos/slow_trace_ui.h +++ b/chrome/browser/ui/webui/chromeos/slow_trace_ui.h @@ -33,12 +33,12 @@ class SlowTraceSource : public content::URLDataSource { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; std::string GetMimeType(const std::string& path) override; bool AllowCaching() override; private: - void OnGetTraceData(const content::URLDataSource::GotDataCallback& callback, + void OnGetTraceData(content::URLDataSource::GotDataCallback callback, scoped_refptr<base::RefCountedString> trace_data); DISALLOW_COPY_AND_ASSIGN(SlowTraceSource); diff --git a/chrome/browser/ui/webui/chromeos/terminal/terminal_source.cc b/chrome/browser/ui/webui/chromeos/terminal/terminal_source.cc index c63f034f13d76..a89867c8901b4 100644 --- a/chrome/browser/ui/webui/chromeos/terminal/terminal_source.cc +++ b/chrome/browser/ui/webui/chromeos/terminal/terminal_source.cc @@ -25,7 +25,7 @@ constexpr base::FilePath::CharType kDefaultFile[] = constexpr char kDefaultMime[] = "text/html"; void ReadFile(const base::FilePath& path, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { std::string content; // First look for uncompressed resource, then try for gzipped file. bool result = base::ReadFileToString(path, &content); @@ -43,7 +43,7 @@ void ReadFile(const base::FilePath& path, << path; scoped_refptr<base::RefCountedString> response = base::RefCountedString::TakeString(&content); - callback.Run(response.get()); + std::move(callback).Run(response.get()); } } // namespace @@ -60,7 +60,7 @@ bool TerminalSource::AllowCaching() { void TerminalSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { // TODO(crbug/1009127): Simplify usages of |path| since |url| is available. const std::string path = content::URLDataSource::URLToRequestPath(url); // Reparse path to strip any query or fragment, skip first '/' in path. @@ -72,7 +72,7 @@ void TerminalSource::StartDataRequest( base::PostTask( FROM_HERE, {base::ThreadPool(), base::MayBlock(), base::TaskPriority::USER_BLOCKING}, - base::BindOnce(&ReadFile, file_path, callback)); + base::BindOnce(&ReadFile, file_path, std::move(callback))); } std::string TerminalSource::GetMimeType(const std::string& path) { diff --git a/chrome/browser/ui/webui/chromeos/terminal/terminal_source.h b/chrome/browser/ui/webui/chromeos/terminal/terminal_source.h index 10f3d0d5b5970..119ca1bd5ba4d 100644 --- a/chrome/browser/ui/webui/chromeos/terminal/terminal_source.h +++ b/chrome/browser/ui/webui/chromeos/terminal/terminal_source.h @@ -27,7 +27,7 @@ class TerminalSource : public content::URLDataSource { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; std::string GetMimeType(const std::string& path) override; diff --git a/chrome/browser/ui/webui/chromeos/user_image_source.cc b/chrome/browser/ui/webui/chromeos/user_image_source.cc index 50d6e7ad866bd..18aaf98521ccc 100644 --- a/chrome/browser/ui/webui/chromeos/user_image_source.cc +++ b/chrome/browser/ui/webui/chromeos/user_image_source.cc @@ -180,7 +180,7 @@ std::string UserImageSource::GetSource() { void UserImageSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { // TODO(crbug/1009127): Make sure |url| matches // |chrome::kChromeUIUserImageURL| now that |url| is available. const std::string path = content::URLDataSource::URLToRequestPath(url); @@ -188,7 +188,7 @@ void UserImageSource::StartDataRequest( int frame = -1; ParseRequest(url, &email, &frame); const AccountId account_id(AccountId::FromUserEmail(email)); - callback.Run(GetUserImageInternal(account_id, frame)); + std::move(callback).Run(GetUserImageInternal(account_id, frame)); } std::string UserImageSource::GetMimeType(const std::string& path) { diff --git a/chrome/browser/ui/webui/chromeos/user_image_source.h b/chrome/browser/ui/webui/chromeos/user_image_source.h index 85c68ad302e49..4e6374d5b691b 100644 --- a/chrome/browser/ui/webui/chromeos/user_image_source.h +++ b/chrome/browser/ui/webui/chromeos/user_image_source.h @@ -34,7 +34,7 @@ class UserImageSource : public content::URLDataSource { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; std::string GetMimeType(const std::string& path) override; // Returns PNG encoded image for user with specified |account_id|. If there's diff --git a/chrome/browser/ui/webui/chromeos/video_source.cc b/chrome/browser/ui/webui/chromeos/video_source.cc index e8d526224f615..f3b5379aa2b8c 100644 --- a/chrome/browser/ui/webui/chromeos/video_source.cc +++ b/chrome/browser/ui/webui/chromeos/video_source.cc @@ -39,16 +39,16 @@ bool IsWhitelisted(const std::string& path) { } // Callback for user_manager::UserImageLoader. -void VideoLoaded( - const content::URLDataSource::GotDataCallback& got_data_callback, - std::unique_ptr<std::string> video_data, - bool did_load_file) { +void VideoLoaded(content::URLDataSource::GotDataCallback got_data_callback, + std::unique_ptr<std::string> video_data, + bool did_load_file) { if (video_data->size() && did_load_file) { - got_data_callback.Run(new base::RefCountedBytes( - reinterpret_cast<const unsigned char*>(video_data->data()), - video_data->size())); + std::move(got_data_callback) + .Run(new base::RefCountedBytes( + reinterpret_cast<const unsigned char*>(video_data->data()), + video_data->size())); } else { - got_data_callback.Run(nullptr); + std::move(got_data_callback).Run(nullptr); } } @@ -69,10 +69,10 @@ std::string VideoSource::GetSource() { void VideoSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& got_data_callback) { + content::URLDataSource::GotDataCallback got_data_callback) { const std::string path = content::URLDataSource::URLToRequestPath(url); if (!IsWhitelisted(path)) { - got_data_callback.Run(nullptr); + std::move(got_data_callback).Run(nullptr); return; } @@ -84,7 +84,7 @@ void VideoSource::StartDataRequest( base::BindOnce(&base::PathExists, video_path), base::BindOnce(&VideoSource::StartDataRequestAfterPathExists, weak_factory_.GetWeakPtr(), video_path, - got_data_callback)); + std::move(got_data_callback))); } std::string VideoSource::GetMimeType(const std::string& path) { @@ -97,7 +97,7 @@ std::string VideoSource::GetMimeType(const std::string& path) { void VideoSource::StartDataRequestAfterPathExists( const base::FilePath& video_path, - const content::URLDataSource::GotDataCallback& got_data_callback, + content::URLDataSource::GotDataCallback got_data_callback, bool path_exists) { if (path_exists) { auto video_data = std::make_unique<std::string>(); @@ -105,10 +105,11 @@ void VideoSource::StartDataRequestAfterPathExists( base::PostTaskAndReplyWithResult( task_runner_.get(), FROM_HERE, base::BindOnce(&base::ReadFileToString, video_path, data), - base::BindOnce(&VideoLoaded, got_data_callback, std::move(video_data))); + base::BindOnce(&VideoLoaded, std::move(got_data_callback), + std::move(video_data))); } else { - got_data_callback.Run(nullptr); + std::move(got_data_callback).Run(nullptr); } } diff --git a/chrome/browser/ui/webui/chromeos/video_source.h b/chrome/browser/ui/webui/chromeos/video_source.h index e113f3f9d2486..5ac0abd79b40e 100644 --- a/chrome/browser/ui/webui/chromeos/video_source.h +++ b/chrome/browser/ui/webui/chromeos/video_source.h @@ -29,17 +29,17 @@ class VideoSource : public content::URLDataSource { // content::URLDataSource: std::string GetSource() override; - void StartDataRequest(const GURL& url, - const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& - got_data_callback) override; + void StartDataRequest( + const GURL& url, + const content::WebContents::Getter& wc_getter, + content::URLDataSource::GotDataCallback got_data_callback) override; std::string GetMimeType(const std::string& path) override; private: // Continuation from StartDataRequest(). void StartDataRequestAfterPathExists( const base::FilePath& video_path, - const content::URLDataSource::GotDataCallback& got_data_callback, + content::URLDataSource::GotDataCallback got_data_callback, bool path_exists); // The background task runner on which file I/O is performed. diff --git a/chrome/browser/ui/webui/devtools_ui_data_source.cc b/chrome/browser/ui/webui/devtools_ui_data_source.cc index da69f1a6e6467..d718f14760552 100644 --- a/chrome/browser/ui/webui/devtools_ui_data_source.cc +++ b/chrome/browser/ui/webui/devtools_ui_data_source.cc @@ -97,7 +97,7 @@ GURL GetCustomDevToolsFrontendURL() { void DevToolsDataSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const GotDataCallback& callback) { + GotDataCallback callback) { // Serve request to devtools://bundled/ from local bundle. // TODO(crbug/1009127): Simplify usages of |path| since |url| is available. const std::string path = content::URLDataSource::URLToRequestPath(url); @@ -114,12 +114,12 @@ void DevToolsDataSource::StartDataRequest( #if !BUILDFLAG(DEBUG_DEVTOOLS) if (!GetCustomDevToolsFrontendURL().SchemeIsFile()) { // Fetch from packaged resources. - StartBundledDataRequest(path_under_bundled, callback); + StartBundledDataRequest(path_under_bundled, std::move(callback)); return; } #endif // Fetch from file system. - StartFileRequest(path_under_bundled, callback); + StartFileRequest(path_under_bundled, std::move(callback)); return; } @@ -127,7 +127,7 @@ void DevToolsDataSource::StartDataRequest( std::string empty_path_prefix(chrome::kChromeUIDevToolsBlankPath); if (base::StartsWith(path, empty_path_prefix, base::CompareCase::INSENSITIVE_ASCII)) { - callback.Run(new base::RefCountedStaticMemory()); + std::move(callback).Run(new base::RefCountedStaticMemory()); return; } @@ -140,10 +140,10 @@ void DevToolsDataSource::StartDataRequest( CHECK_EQ(url.host(), kRemoteFrontendDomain); if (url.is_valid() && DevToolsUIBindings::IsValidRemoteFrontendURL(url)) { - StartRemoteDataRequest(url, callback); + StartRemoteDataRequest(url, std::move(callback)); } else { DLOG(ERROR) << "Refusing to load invalid remote front-end URL"; - callback.Run(CreateNotFoundResponse()); + std::move(callback).Run(CreateNotFoundResponse()); } return; } @@ -158,12 +158,12 @@ void DevToolsDataSource::StartDataRequest( GURL url = GURL(custom_devtools_frontend.spec() + path.substr(custom_path_prefix.length())); DCHECK(url.is_valid()); - StartCustomDataRequest(url, callback); + StartCustomDataRequest(url, std::move(callback)); return; } } - callback.Run(CreateNotFoundResponse()); + std::move(callback).Run(CreateNotFoundResponse()); } std::string DevToolsDataSource::GetMimeType(const std::string& path) { @@ -184,7 +184,7 @@ bool DevToolsDataSource::ShouldServeMimeTypeAsContentTypeHeader() { void DevToolsDataSource::StartBundledDataRequest( const std::string& path, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { scoped_refptr<base::RefCountedMemory> bytes = content::DevToolsFrontendHost::GetFrontendResourceBytes(path); @@ -192,12 +192,12 @@ void DevToolsDataSource::StartBundledDataRequest( << "Unable to find dev tool resource: " << path << ". If you compiled with debug_devtools=1, try running with " "--debug-devtools."; - callback.Run(bytes); + std::move(callback).Run(bytes); } void DevToolsDataSource::StartRemoteDataRequest( const GURL& url, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { CHECK(url.is_valid()); net::NetworkTrafficAnnotationTag traffic_annotation = net::DefineNetworkTrafficAnnotation("devtools_hard_coded_data_source", @@ -224,14 +224,15 @@ void DevToolsDataSource::StartRemoteDataRequest( } })"); - StartNetworkRequest(url, traffic_annotation, net::LOAD_NORMAL, callback); + StartNetworkRequest(url, traffic_annotation, net::LOAD_NORMAL, + std::move(callback)); } void DevToolsDataSource::StartCustomDataRequest( const GURL& url, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { if (!url.is_valid()) { - callback.Run(CreateNotFoundResponse()); + std::move(callback).Run(CreateNotFoundResponse()); return; } net::NetworkTrafficAnnotationTag traffic_annotation = @@ -264,20 +265,20 @@ void DevToolsDataSource::StartCustomDataRequest( })"); StartNetworkRequest(url, traffic_annotation, net::LOAD_DISABLE_CACHE, - callback); + std::move(callback)); } void DevToolsDataSource::StartNetworkRequest( const GURL& url, const net::NetworkTrafficAnnotationTag& traffic_annotation, int load_flags, - const GotDataCallback& callback) { + GotDataCallback callback) { auto request = std::make_unique<network::ResourceRequest>(); request->url = url; request->load_flags = load_flags; auto request_iter = pending_requests_.emplace(pending_requests_.begin()); - request_iter->callback = callback; + request_iter->callback = std::move(callback); request_iter->loader = network::SimpleURLLoader::Create(std::move(request), traffic_annotation); request_iter->loader->DownloadToStringOfUnboundedSizeUntilCrashAndDie( @@ -297,7 +298,7 @@ scoped_refptr<base::RefCountedMemory> ReadFileForDevTools( } void DevToolsDataSource::StartFileRequest(const std::string& path, - const GotDataCallback& callback) { + GotDataCallback callback) { base::FilePath base_path; GURL custom_devtools_frontend = GetCustomDevToolsFrontendURL(); if (custom_devtools_frontend.SchemeIsFile()) { @@ -306,7 +307,7 @@ void DevToolsDataSource::StartFileRequest(const std::string& path, #if BUILDFLAG(DEBUG_DEVTOOLS) // Use default path for unbundled files when debug_devtools=true if (!base::PathService::Get(chrome::DIR_INSPECTOR_DEBUG, &base_path)) { - callback.Run(CreateNotFoundResponse()); + std::move(callback).Run(CreateNotFoundResponse()); return; } #else @@ -322,10 +323,8 @@ void DevToolsDataSource::StartFileRequest(const std::string& path, {base::MayBlock(), base::ThreadPool(), base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN, base::TaskPriority::USER_VISIBLE}, - // The usage of BindRepeating below is only because the type of - // task callback needs to match that of response callback, which - // is currently a repeating callback. - base::BindRepeating(ReadFileForDevTools, std::move(full_path)), callback); + base::BindOnce(ReadFileForDevTools, std::move(full_path)), + std::move(callback)); } void DevToolsDataSource::OnLoadComplete( @@ -345,5 +344,5 @@ DevToolsDataSource::PendingRequest::PendingRequest(PendingRequest&& other) = DevToolsDataSource::PendingRequest::~PendingRequest() { if (callback) - callback.Run(CreateNotFoundResponse()); + std::move(callback).Run(CreateNotFoundResponse()); } diff --git a/chrome/browser/ui/webui/devtools_ui_data_source.h b/chrome/browser/ui/webui/devtools_ui_data_source.h index 04a5c00d39364..a713ac19aec3f 100644 --- a/chrome/browser/ui/webui/devtools_ui_data_source.h +++ b/chrome/browser/ui/webui/devtools_ui_data_source.h @@ -41,7 +41,7 @@ class DevToolsDataSource : public content::URLDataSource { void StartDataRequest(const GURL& url, const content::WebContents::Getter& wc_getter, - const GotDataCallback& callback) override; + GotDataCallback callback) override; private: friend class DevToolsUIDataSourceTest; @@ -59,23 +59,23 @@ class DevToolsDataSource : public content::URLDataSource { // Serves bundled DevTools frontend from ResourceBundle. void StartBundledDataRequest(const std::string& path, - const GotDataCallback& callback); + GotDataCallback callback); // Serves remote DevTools frontend from hard-coded App Engine domain. - void StartRemoteDataRequest(const GURL& url, const GotDataCallback& callback); + void StartRemoteDataRequest(const GURL& url, GotDataCallback callback); // Serves remote DevTools frontend from any endpoint, passed through // command-line flag. - void StartCustomDataRequest(const GURL& url, const GotDataCallback& callback); + void StartCustomDataRequest(const GURL& url, GotDataCallback callback); virtual void StartNetworkRequest( const GURL& url, const net::NetworkTrafficAnnotationTag& traffic_annotation, int load_flags, - const GotDataCallback& callback); + GotDataCallback callback); virtual void StartFileRequest(const std::string& path, - const GotDataCallback& callback); + GotDataCallback callback); struct PendingRequest { PendingRequest(); diff --git a/chrome/browser/ui/webui/devtools_ui_data_source_unittest.cc b/chrome/browser/ui/webui/devtools_ui_data_source_unittest.cc index 07ccf1d07fe5c..64171abd143e5 100644 --- a/chrome/browser/ui/webui/devtools_ui_data_source_unittest.cc +++ b/chrome/browser/ui/webui/devtools_ui_data_source_unittest.cc @@ -49,15 +49,15 @@ class TestDevToolsDataSource : public DevToolsDataSource { const GURL& url, const net::NetworkTrafficAnnotationTag& traffic_annotation, int load_flags, - const GotDataCallback& callback) override { + GotDataCallback callback) override { std::string result = "url: " + url.spec(); - callback.Run(base::RefCountedString::TakeString(&result)); + std::move(callback).Run(base::RefCountedString::TakeString(&result)); } void StartFileRequest(const std::string& path, - const GotDataCallback& callback) override { + GotDataCallback callback) override { std::string result = "file: " + path; - callback.Run(base::RefCountedString::TakeString(&result)); + std::move(callback).Run(base::RefCountedString::TakeString(&result)); } }; diff --git a/chrome/browser/ui/webui/extensions/extension_icon_source.cc b/chrome/browser/ui/webui/extensions/extension_icon_source.cc index ee1b12ddf17ae..9d56d83ca971e 100644 --- a/chrome/browser/ui/webui/extensions/extension_icon_source.cc +++ b/chrome/browser/ui/webui/extensions/extension_icon_source.cc @@ -115,17 +115,17 @@ std::string ExtensionIconSource::GetMimeType(const std::string&) { void ExtensionIconSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { const std::string path = content::URLDataSource::URLToRequestPath(url); // This is where everything gets started. First, parse the request and make // the request data available for later. static int next_id = 0; - if (!ParseData(path, ++next_id, callback)) { + if (!ParseData(path, ++next_id, &callback)) { // If the request data cannot be parsed, request parameters will not be // added to |request_map_|. // Send back the default application icon (not resized or desaturated) as // the default response. - callback.Run(BitmapToMemory(GetDefaultAppImage()).get()); + std::move(callback).Run(BitmapToMemory(GetDefaultAppImage()).get()); return; } @@ -174,7 +174,7 @@ void ExtensionIconSource::FinalizeImage(const SkBitmap* image, else bitmap = *image; - request->callback.Run(BitmapToMemory(&bitmap).get()); + std::move(request->callback).Run(BitmapToMemory(&bitmap).get()); ClearData(request_id); } @@ -243,7 +243,7 @@ void ExtensionIconSource::OnFaviconDataAvailable( if (!request->grayscale) { // If we don't need a grayscale image, then we can bypass FinalizeImage // to avoid unnecessary conversions. - request->callback.Run(bitmap_result.bitmap_data.get()); + std::move(request->callback).Run(bitmap_result.bitmap_data.get()); ClearData(request_id); } else { FinalizeImage(ToBitmap(bitmap_result.bitmap_data->front(), @@ -273,7 +273,7 @@ void ExtensionIconSource::LoadIconFailed(int request_id) { bool ExtensionIconSource::ParseData( const std::string& path, int request_id, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback* callback) { // Extract the parameters from the path by lower casing and splitting. std::string path_lower = base::ToLowerASCII(path); std::vector<std::string> path_parts = base::SplitString( @@ -309,21 +309,22 @@ bool ExtensionIconSource::ParseData( bool grayscale = path_lower.find("grayscale=true") != std::string::npos; - SetData(request_id, callback, extension, grayscale, size, match_type); + SetData(request_id, std::move(*callback), extension, grayscale, size, + match_type); return true; } void ExtensionIconSource::SetData( int request_id, - const content::URLDataSource::GotDataCallback& callback, + content::URLDataSource::GotDataCallback callback, const Extension* extension, bool grayscale, int size, ExtensionIconSet::MatchType match) { std::unique_ptr<ExtensionIconRequest> request = std::make_unique<ExtensionIconRequest>(); - request->callback = callback; + request->callback = std::move(callback); request->extension = extension; request->grayscale = grayscale; request->size = size; diff --git a/chrome/browser/ui/webui/extensions/extension_icon_source.h b/chrome/browser/ui/webui/extensions/extension_icon_source.h index c3e1d6613b1a9..324b27fd39f90 100644 --- a/chrome/browser/ui/webui/extensions/extension_icon_source.h +++ b/chrome/browser/ui/webui/extensions/extension_icon_source.h @@ -73,7 +73,7 @@ class ExtensionIconSource : public content::URLDataSource, void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; bool AllowCaching() override; private: @@ -120,15 +120,15 @@ class ExtensionIconSource : public content::URLDataSource, void LoadIconFailed(int request_id); // Parses and saves an ExtensionIconRequest for the URL |path| for the - // specified |request_id|. + // specified |request_id|. Takes the |callback| if it returns true. bool ParseData(const std::string& path, int request_id, - const content::URLDataSource::GotDataCallback& callback); + content::URLDataSource::GotDataCallback* callback); // Stores the parameters associated with the |request_id|, making them // as an ExtensionIconRequest via GetData. void SetData(int request_id, - const content::URLDataSource::GotDataCallback& callback, + content::URLDataSource::GotDataCallback callback, const Extension* extension, bool grayscale, int size, diff --git a/chrome/browser/ui/webui/extensions/extensions_internals_source.cc b/chrome/browser/ui/webui/extensions/extensions_internals_source.cc index d957a3e4e4ccb..c60227d822612 100644 --- a/chrome/browser/ui/webui/extensions/extensions_internals_source.cc +++ b/chrome/browser/ui/webui/extensions/extensions_internals_source.cc @@ -436,9 +436,9 @@ std::string ExtensionsInternalsSource::GetMimeType(const std::string& path) { void ExtensionsInternalsSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { std::string json = WriteToString(); - callback.Run(base::RefCountedString::TakeString(&json)); + std::move(callback).Run(base::RefCountedString::TakeString(&json)); } std::string ExtensionsInternalsSource::WriteToString() const { diff --git a/chrome/browser/ui/webui/extensions/extensions_internals_source.h b/chrome/browser/ui/webui/extensions/extensions_internals_source.h index ca3121c8d9aa0..31e4952fc2d1b 100644 --- a/chrome/browser/ui/webui/extensions/extensions_internals_source.h +++ b/chrome/browser/ui/webui/extensions/extensions_internals_source.h @@ -23,7 +23,7 @@ class ExtensionsInternalsSource : public content::URLDataSource { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; // Simpler interface to generate string output, without needing to // call StartDataRequest. diff --git a/chrome/browser/ui/webui/favicon_source.cc b/chrome/browser/ui/webui/favicon_source.cc index d62e7ae4d1741..f53b02a65e76e 100644 --- a/chrome/browser/ui/webui/favicon_source.cc +++ b/chrome/browser/ui/webui/favicon_source.cc @@ -77,27 +77,27 @@ std::string FaviconSource::GetSource() { void FaviconSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { const std::string path = content::URLDataSource::URLToRequestPath(url); favicon::FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(profile_, ServiceAccessType::EXPLICIT_ACCESS); if (!favicon_service) { - SendDefaultResponse(callback); + SendDefaultResponse(std::move(callback)); return; } chrome::ParsedFaviconPath parsed; bool success = chrome::ParseFaviconPath(path, url_format_, &parsed); if (!success) { - SendDefaultResponse(callback); + SendDefaultResponse(std::move(callback)); return; } GURL page_url(parsed.page_url); GURL icon_url(parsed.icon_url); if (!page_url.is_valid() && !icon_url.is_valid()) { - SendDefaultResponse(callback); + SendDefaultResponse(std::move(callback)); return; } @@ -111,9 +111,9 @@ void FaviconSource::StartDataRequest( // IconType. favicon_service->GetRawFavicon( icon_url, favicon_base::IconType::kFavicon, desired_size_in_pixel, - base::BindRepeating(&FaviconSource::OnFaviconDataAvailable, - base::Unretained(this), callback, - parsed.size_in_dip, parsed.device_scale_factor), + base::BindOnce(&FaviconSource::OnFaviconDataAvailable, + base::Unretained(this), std::move(callback), + parsed.size_in_dip, parsed.device_scale_factor), &cancelable_task_tracker_); } else { // Intercept requests for prepopulated pages if TopSites exists. @@ -124,7 +124,7 @@ void FaviconSource::StartDataRequest( if (page_url == prepopulated_page.most_visited.url) { ui::ScaleFactor resource_scale_factor = ui::GetSupportedScaleFactor(parsed.device_scale_factor); - callback.Run( + std::move(callback).Run( ui::ResourceBundle::GetSharedInstance() .LoadDataResourceBytesForScale(prepopulated_page.favicon_id, resource_scale_factor)); @@ -144,9 +144,9 @@ void FaviconSource::StartDataRequest( favicon_service->GetRawFaviconForPageURL( page_url, {favicon_base::IconType::kFavicon}, desired_size_in_pixel, fallback_to_host, - base::Bind(&FaviconSource::OnFaviconDataAvailable, - base::Unretained(this), callback, parsed.size_in_dip, - parsed.device_scale_factor), + base::BindOnce(&FaviconSource::OnFaviconDataAvailable, + base::Unretained(this), std::move(callback), + parsed.size_in_dip, parsed.device_scale_factor), &cancelable_task_tracker_); return; } @@ -158,14 +158,14 @@ void FaviconSource::StartDataRequest( HistoryUiFaviconRequestHandlerFactory::GetForBrowserContext( profile_); if (!history_ui_favicon_request_handler) { - SendDefaultResponse(callback); + SendDefaultResponse(std::move(callback)); return; } history_ui_favicon_request_handler->GetRawFaviconForPageURL( page_url, desired_size_in_pixel, base::BindOnce(&FaviconSource::OnFaviconDataAvailable, - base::Unretained(this), callback, parsed.size_in_dip, - parsed.device_scale_factor), + base::Unretained(this), std::move(callback), + parsed.size_in_dip, parsed.device_scale_factor), favicon::FaviconRequestPlatform::kDesktop, parsed_history_ui_origin, /*icon_url_for_uma=*/ GURL(parsed.icon_url), &cancelable_task_tracker_); @@ -205,25 +205,25 @@ ui::NativeTheme* FaviconSource::GetNativeTheme() { } void FaviconSource::OnFaviconDataAvailable( - const content::URLDataSource::GotDataCallback& callback, + content::URLDataSource::GotDataCallback callback, int size_in_dip, float scale_factor, const favicon_base::FaviconRawBitmapResult& bitmap_result) { if (bitmap_result.is_valid()) { // Forward the data along to the networking system. - callback.Run(bitmap_result.bitmap_data.get()); + std::move(callback).Run(bitmap_result.bitmap_data.get()); } else { - SendDefaultResponse(callback, size_in_dip, scale_factor); + SendDefaultResponse(std::move(callback), size_in_dip, scale_factor); } } void FaviconSource::SendDefaultResponse( - const content::URLDataSource::GotDataCallback& callback) { - SendDefaultResponse(callback, 16, 1.0f); + content::URLDataSource::GotDataCallback callback) { + SendDefaultResponse(std::move(callback), 16, 1.0f); } void FaviconSource::SendDefaultResponse( - const content::URLDataSource::GotDataCallback& callback, + content::URLDataSource::GotDataCallback callback, int size_in_dip, float scale_factor) { const bool dark = GetNativeTheme()->ShouldUseDarkColors(); @@ -239,7 +239,7 @@ void FaviconSource::SendDefaultResponse( resource_id = dark ? IDR_DEFAULT_FAVICON_DARK : IDR_DEFAULT_FAVICON; break; } - callback.Run(LoadIconBytes(scale_factor, resource_id)); + std::move(callback).Run(LoadIconBytes(scale_factor, resource_id)); } base::RefCountedMemory* FaviconSource::LoadIconBytes(float scale_factor, diff --git a/chrome/browser/ui/webui/favicon_source.h b/chrome/browser/ui/webui/favicon_source.h index 5e419abf5c7a3..7b21b8ac2b9b0 100644 --- a/chrome/browser/ui/webui/favicon_source.h +++ b/chrome/browser/ui/webui/favicon_source.h @@ -46,7 +46,7 @@ class FaviconSource : public content::URLDataSource { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; std::string GetMimeType(const std::string&) override; bool AllowCaching() override; bool ShouldReplaceExistingSource() override; @@ -75,20 +75,18 @@ class FaviconSource : public content::URLDataSource { // |bitmap_result| is valid, returns it to caller using |callback|. Otherwise // will send appropriate default icon for |size_in_dip| and |scale_factor|. void OnFaviconDataAvailable( - const content::URLDataSource::GotDataCallback& callback, + content::URLDataSource::GotDataCallback callback, int size_in_dip, float scale_factor, const favicon_base::FaviconRawBitmapResult& bitmap_result); // Sends the 16x16 DIP 1x default favicon. - void SendDefaultResponse( - const content::URLDataSource::GotDataCallback& callback); + void SendDefaultResponse(content::URLDataSource::GotDataCallback callback); // Sends the default favicon. - void SendDefaultResponse( - const content::URLDataSource::GotDataCallback& callback, - int size_in_dip, - float scale_factor); + void SendDefaultResponse(content::URLDataSource::GotDataCallback callback, + int size_in_dip, + float scale_factor); chrome::FaviconUrlFormat url_format_; diff --git a/chrome/browser/ui/webui/fileicon_source.cc b/chrome/browser/ui/webui/fileicon_source.cc index f6ddc1453e77a..5a0a51e1161c4 100644 --- a/chrome/browser/ui/webui/fileicon_source.cc +++ b/chrome/browser/ui/webui/fileicon_source.cc @@ -65,24 +65,21 @@ void ParseQueryParams(const std::string& path, } // namespace -FileIconSource::IconRequestDetails::IconRequestDetails() : scale_factor(1.0f) { -} - +FileIconSource::IconRequestDetails::IconRequestDetails() = default; FileIconSource::IconRequestDetails::IconRequestDetails( - const IconRequestDetails& other) = default; + IconRequestDetails&& other) = default; +FileIconSource::IconRequestDetails& FileIconSource::IconRequestDetails:: +operator=(IconRequestDetails&& other) = default; +FileIconSource::IconRequestDetails::~IconRequestDetails() = default; -FileIconSource::IconRequestDetails::~IconRequestDetails() { -} - -FileIconSource::FileIconSource() {} - -FileIconSource::~FileIconSource() {} +FileIconSource::FileIconSource() = default; +FileIconSource::~FileIconSource() = default; void FileIconSource::FetchFileIcon( const base::FilePath& path, float scale_factor, IconLoader::IconSize icon_size, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { IconManager* im = g_browser_process->icon_manager(); gfx::Image* icon = im->LookupIconFromFilepath(path, icon_size); @@ -92,18 +89,17 @@ void FileIconSource::FetchFileIcon( icon->ToImageSkia()->GetRepresentation(scale_factor).GetBitmap(), false, &icon_data->data()); - callback.Run(icon_data.get()); + std::move(callback).Run(icon_data.get()); } else { // Attach the ChromeURLDataManager request ID to the history request. IconRequestDetails details; - details.callback = callback; + details.callback = std::move(callback); details.scale_factor = scale_factor; // Icon was not in cache, go fetch it slowly. - im->LoadIcon(path, - icon_size, - base::Bind(&FileIconSource::OnFileIconDataAvailable, - base::Unretained(this), details), + im->LoadIcon(path, icon_size, + base::BindOnce(&FileIconSource::OnFileIconDataAvailable, + base::Unretained(this), std::move(details)), &cancelable_task_tracker_); } } @@ -115,14 +111,14 @@ std::string FileIconSource::GetSource() { void FileIconSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { const std::string path = content::URLDataSource::URLToRequestPath(url); base::FilePath file_path; IconLoader::IconSize icon_size = IconLoader::NORMAL; float scale_factor = 1.0f; // TODO(crbug/1009127): Make ParseQueryParams take GURL. ParseQueryParams(path, &file_path, &scale_factor, &icon_size); - FetchFileIcon(file_path, scale_factor, icon_size, callback); + FetchFileIcon(file_path, scale_factor, icon_size, std::move(callback)); } std::string FileIconSource::GetMimeType(const std::string&) { @@ -134,7 +130,7 @@ bool FileIconSource::AllowCaching() { return false; } -void FileIconSource::OnFileIconDataAvailable(const IconRequestDetails& details, +void FileIconSource::OnFileIconDataAvailable(IconRequestDetails details, gfx::Image icon) { if (!icon.IsEmpty()) { scoped_refptr<base::RefCountedBytes> icon_data(new base::RefCountedBytes); @@ -142,9 +138,9 @@ void FileIconSource::OnFileIconDataAvailable(const IconRequestDetails& details, icon.ToImageSkia()->GetRepresentation(details.scale_factor).GetBitmap(), false, &icon_data->data()); - details.callback.Run(icon_data.get()); + std::move(details.callback).Run(icon_data.get()); } else { // TODO(glen): send a dummy icon. - details.callback.Run(nullptr); + std::move(details.callback).Run(nullptr); } } diff --git a/chrome/browser/ui/webui/fileicon_source.h b/chrome/browser/ui/webui/fileicon_source.h index c7599d7ce61e5..89cc0d1b7fbe1 100644 --- a/chrome/browser/ui/webui/fileicon_source.h +++ b/chrome/browser/ui/webui/fileicon_source.h @@ -29,7 +29,7 @@ class FileIconSource : public content::URLDataSource { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; std::string GetMimeType(const std::string&) override; bool AllowCaching() override; @@ -37,29 +37,30 @@ class FileIconSource : public content::URLDataSource { // Once the |path| and |icon_size| has been determined from the request, this // function is called to perform the actual fetch. Declared as virtual for // testing. - virtual void FetchFileIcon( - const base::FilePath& path, - float scale_factor, - IconLoader::IconSize icon_size, - const content::URLDataSource::GotDataCallback& callback); + virtual void FetchFileIcon(const base::FilePath& path, + float scale_factor, + IconLoader::IconSize icon_size, + content::URLDataSource::GotDataCallback callback); private: // Contains the necessary information for completing an icon fetch request. struct IconRequestDetails { IconRequestDetails(); - IconRequestDetails(const IconRequestDetails& other); + + IconRequestDetails(IconRequestDetails&& other); + IconRequestDetails& operator=(IconRequestDetails&& other); + ~IconRequestDetails(); // The callback to run with the response. content::URLDataSource::GotDataCallback callback; // The requested scale factor to respond with. - float scale_factor; + float scale_factor = 1; }; // Called when favicon data is available from the history backend. - void OnFileIconDataAvailable(const IconRequestDetails& details, - gfx::Image icon); + void OnFileIconDataAvailable(IconRequestDetails details, gfx::Image icon); // Tracks tasks requesting file icons. base::CancelableTaskTracker cancelable_task_tracker_; diff --git a/chrome/browser/ui/webui/fileicon_source_unittest.cc b/chrome/browser/ui/webui/fileicon_source_unittest.cc index f56d2b654e5ce..c2b59c0bbb389 100644 --- a/chrome/browser/ui/webui/fileicon_source_unittest.cc +++ b/chrome/browser/ui/webui/fileicon_source_unittest.cc @@ -22,11 +22,18 @@ class TestFileIconSource : public FileIconSource { public: TestFileIconSource() {} - MOCK_METHOD4(FetchFileIcon, + void FetchFileIcon( + const base::FilePath& path, + float scale_factor, + IconLoader::IconSize icon_size, + content::URLDataSource::GotDataCallback callback) override { + FetchFileIcon_(path, scale_factor, icon_size, callback); + } + MOCK_METHOD4(FetchFileIcon_, void(const base::FilePath& path, float scale_factor, IconLoader::IconSize icon_size, - const content::URLDataSource::GotDataCallback& callback)); + content::URLDataSource::GotDataCallback& callback)); ~TestFileIconSource() override {} }; @@ -115,14 +122,14 @@ TEST_F(FileIconSourceTest, FileIconSource_Parse) { for (unsigned i = 0; i < base::size(kBasicExpectations); i++) { auto source = std::make_unique<TestFileIconSource>(); content::URLDataSource::GotDataCallback callback; - EXPECT_CALL(*source.get(), - FetchFileIcon( - base::FilePath(kBasicExpectations[i].unescaped_path), - kBasicExpectations[i].scale_factor, - kBasicExpectations[i].size, CallbackIsNull())); + EXPECT_CALL( + *source.get(), + FetchFileIcon_(base::FilePath(kBasicExpectations[i].unescaped_path), + kBasicExpectations[i].scale_factor, + kBasicExpectations[i].size, CallbackIsNull())); source->StartDataRequest( GURL(base::StrCat( {"chrome://any-host/", kBasicExpectations[i].request_path})), - content::WebContents::Getter(), callback); + content::WebContents::Getter(), std::move(callback)); } } diff --git a/chrome/browser/ui/webui/interstitials/interstitial_ui.cc b/chrome/browser/ui/webui/interstitials/interstitial_ui.cc index caafe2226d54e..0535200ce1567 100644 --- a/chrome/browser/ui/webui/interstitials/interstitial_ui.cc +++ b/chrome/browser/ui/webui/interstitials/interstitial_ui.cc @@ -97,7 +97,7 @@ class InterstitialHTMLSource : public content::URLDataSource { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; private: #if BUILDFLAG(ENABLE_SUPERVISED_USERS) @@ -479,7 +479,7 @@ std::string InterstitialHTMLSource::GetContentSecurityPolicyImgSrc() { void InterstitialHTMLSource::StartDataRequest( const GURL& request_url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { // TODO(crbug/1009127): Simplify usages of |path| since |request_url| is // available. const std::string path = @@ -536,7 +536,7 @@ void InterstitialHTMLSource::StartDataRequest( } scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; html_bytes->data().assign(html.begin(), html.end()); - callback.Run(html_bytes.get()); + std::move(callback).Run(html_bytes.get()); } #if BUILDFLAG(ENABLE_SUPERVISED_USERS) diff --git a/chrome/browser/ui/webui/ntp/new_tab_ui.cc b/chrome/browser/ui/webui/ntp/new_tab_ui.cc index aaa9615fb9f74..f979ed1fae0c9 100644 --- a/chrome/browser/ui/webui/ntp/new_tab_ui.cc +++ b/chrome/browser/ui/webui/ntp/new_tab_ui.cc @@ -154,7 +154,7 @@ std::string NewTabUI::NewTabHTMLSource::GetSource() { void NewTabUI::NewTabHTMLSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); // TODO(crbug/1009127): Simplify usages of |path| since |url| is available. const std::string path = content::URLDataSource::URLToRequestPath(url); @@ -162,7 +162,7 @@ void NewTabUI::NewTabHTMLSource::StartDataRequest( // A path under new-tab was requested; it's likely a bad relative // URL from the new tab page, but in any case it's an error. NOTREACHED() << path << " should not have been requested on the NTP"; - callback.Run(nullptr); + std::move(callback).Run(nullptr); return; } @@ -175,7 +175,7 @@ void NewTabUI::NewTabHTMLSource::StartDataRequest( NTPResourceCacheFactory::GetForProfile(profile_)-> GetNewTabHTML(win_type)); - callback.Run(html_bytes.get()); + std::move(callback).Run(html_bytes.get()); } std::string NewTabUI::NewTabHTMLSource::GetMimeType( diff --git a/chrome/browser/ui/webui/ntp/new_tab_ui.h b/chrome/browser/ui/webui/ntp/new_tab_ui.h index 66f6c4d7569ac..acaf5cc2d67a9 100644 --- a/chrome/browser/ui/webui/ntp/new_tab_ui.h +++ b/chrome/browser/ui/webui/ntp/new_tab_ui.h @@ -58,7 +58,7 @@ class NewTabUI : public content::WebUIController { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; std::string GetMimeType(const std::string&) override; bool ShouldReplaceExistingSource() override; std::string GetContentSecurityPolicyScriptSrc() override; diff --git a/chrome/browser/ui/webui/prefs_internals_source.cc b/chrome/browser/ui/webui/prefs_internals_source.cc index d4ba24aa413a0..28854766b7df9 100644 --- a/chrome/browser/ui/webui/prefs_internals_source.cc +++ b/chrome/browser/ui/webui/prefs_internals_source.cc @@ -30,7 +30,7 @@ std::string PrefsInternalsSource::GetMimeType(const std::string& path) { void PrefsInternalsSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); std::string json; std::unique_ptr<base::DictionaryValue> prefs = @@ -38,5 +38,5 @@ void PrefsInternalsSource::StartDataRequest( DCHECK(prefs); CHECK(base::JSONWriter::WriteWithOptions( *prefs, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json)); - callback.Run(base::RefCountedString::TakeString(&json)); + std::move(callback).Run(base::RefCountedString::TakeString(&json)); } diff --git a/chrome/browser/ui/webui/prefs_internals_source.h b/chrome/browser/ui/webui/prefs_internals_source.h index 8aad42faab34e..5fc4058ba9ea9 100644 --- a/chrome/browser/ui/webui/prefs_internals_source.h +++ b/chrome/browser/ui/webui/prefs_internals_source.h @@ -22,7 +22,7 @@ class PrefsInternalsSource : public content::URLDataSource { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; private: Profile* profile_; diff --git a/chrome/browser/ui/webui/print_preview/print_preview_ui.cc b/chrome/browser/ui/webui/print_preview/print_preview_ui.cc index fa158a29c4db2..e3cf8ccbcdaf3 100644 --- a/chrome/browser/ui/webui/print_preview/print_preview_ui.cc +++ b/chrome/browser/ui/webui/print_preview/print_preview_ui.cc @@ -146,9 +146,8 @@ bool ShouldHandleRequestCallback(const std::string& path) { } // Get markup or other resources for the print preview page. -void HandleRequestCallback( - const std::string& path, - const content::WebUIDataSource::GotDataCallback& callback) { +void HandleRequestCallback(const std::string& path, + content::WebUIDataSource::GotDataCallback callback) { // ChromeWebUIDataSource handles most requests except for the print preview // data. int preview_ui_id; @@ -159,12 +158,12 @@ void HandleRequestCallback( PrintPreviewDataService::GetInstance()->GetDataEntry(preview_ui_id, page_index, &data); if (data.get()) { - callback.Run(data.get()); + std::move(callback).Run(data.get()); return; } // Invalid request. auto empty_bytes = base::MakeRefCounted<base::RefCountedBytes>(); - callback.Run(empty_bytes.get()); + std::move(callback).Run(empty_bytes.get()); } void AddPrintPreviewStrings(content::WebUIDataSource* source) { diff --git a/chrome/browser/ui/webui/test_data_source.cc b/chrome/browser/ui/webui/test_data_source.cc index 06a22e5da5a55..aa03e09612c9e 100644 --- a/chrome/browser/ui/webui/test_data_source.cc +++ b/chrome/browser/ui/webui/test_data_source.cc @@ -45,13 +45,13 @@ std::string TestDataSource::GetSource() { void TestDataSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { const std::string path = content::URLDataSource::URLToRequestPath(url); base::PostTask( FROM_HERE, {base::ThreadPool(), base::MayBlock(), base::TaskPriority::USER_BLOCKING}, base::BindOnce(&TestDataSource::ReadFile, base::Unretained(this), path, - callback)); + std::move(callback))); } std::string TestDataSource::GetMimeType(const std::string& path) { @@ -87,7 +87,7 @@ GURL TestDataSource::GetURLForPath(const std::string& path) { void TestDataSource::ReadFile( const std::string& path, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { std::string content; GURL url = GetURLForPath(path); @@ -125,5 +125,5 @@ void TestDataSource::ReadFile( scoped_refptr<base::RefCountedString> response = base::RefCountedString::TakeString(&content); - callback.Run(response.get()); + std::move(callback).Run(response.get()); } diff --git a/chrome/browser/ui/webui/test_data_source.h b/chrome/browser/ui/webui/test_data_source.h index b34e8808a7e40..f65809dd9c0ea 100644 --- a/chrome/browser/ui/webui/test_data_source.h +++ b/chrome/browser/ui/webui/test_data_source.h @@ -22,7 +22,7 @@ class TestDataSource : public content::URLDataSource { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; std::string GetMimeType(const std::string& path) override; @@ -37,7 +37,7 @@ class TestDataSource : public content::URLDataSource { GURL GetURLForPath(const std::string& path); void ReadFile(const std::string& path, - const content::URLDataSource::GotDataCallback& callback); + content::URLDataSource::GotDataCallback callback); base::FilePath src_root_; base::FilePath gen_root_; diff --git a/chrome/browser/ui/webui/test_files_request_filter.cc b/chrome/browser/ui/webui/test_files_request_filter.cc index 8255db505db11..7b971f56cf178 100644 --- a/chrome/browser/ui/webui/test_files_request_filter.cc +++ b/chrome/browser/ui/webui/test_files_request_filter.cc @@ -29,7 +29,7 @@ bool ShouldHandleTestFileRequestCallback(const std::string& path) { void HandleTestFileRequestCallback( const std::string& path, - const content::WebUIDataSource::GotDataCallback& callback) { + content::WebUIDataSource::GotDataCallback callback) { DCHECK(ShouldHandleTestFileRequestCallback(path)); base::ScopedAllowBlockingForTesting allow_blocking; @@ -44,7 +44,7 @@ void HandleTestFileRequestCallback( base::RefCountedString* ref_contents = new base::RefCountedString(); ref_contents->data() = contents; - callback.Run(ref_contents); + std::move(callback).Run(ref_contents); } } // namespace diff --git a/chrome/browser/ui/webui/theme_source.cc b/chrome/browser/ui/webui/theme_source.cc index 31b07bc966afe..536f075a8352a 100644 --- a/chrome/browser/ui/webui/theme_source.cc +++ b/chrome/browser/ui/webui/theme_source.cc @@ -84,7 +84,7 @@ std::string ThemeSource::GetSource() { void ThemeSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { // TODO(crbug/1009127): Simplify usages of |path| since |url| is available. const std::string path = content::URLDataSource::URLToRequestPath(url); // Default scale factor if not specified. @@ -99,7 +99,7 @@ void ThemeSource::StartDataRequest( NTPResourceCache::WindowType type = NTPResourceCache::GetWindowType(profile_, /*render_host=*/nullptr); NTPResourceCache* cache = NTPResourceCacheFactory::GetForProfile(profile_); - callback.Run(cache->GetNewTabCSS(type)); + std::move(callback).Run(cache->GetNewTabCSS(type)); return; } @@ -150,16 +150,16 @@ void ThemeSource::StartDataRequest( // URLs are only used by WebUI pages and component extensions. However, the // user can also enter these into the omnibox, so we need to fail // gracefully. - callback.Run(nullptr); + std::move(callback).Run(nullptr); } else if ((GetMimeType(path) == "image/png") && ((scale > max_scale) || (frame != -1))) { // This will extract and scale frame 0 of animated images. // TODO(reveman): Support scaling of animated images and avoid scaling and // re-encode when specific frame is specified (crbug.com/750064). DCHECK_LE(frame, 0); - SendThemeImage(callback, resource_id, scale); + SendThemeImage(std::move(callback), resource_id, scale); } else { - SendThemeBitmap(callback, resource_id, scale); + SendThemeBitmap(std::move(callback), resource_id, scale); } } @@ -206,7 +206,7 @@ bool ThemeSource::ShouldServiceRequest( // ThemeSource, private: void ThemeSource::SendThemeBitmap( - const content::URLDataSource::GotDataCallback& callback, + content::URLDataSource::GotDataCallback callback, int resource_id, float scale) { ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactor(scale); @@ -215,16 +215,17 @@ void ThemeSource::SendThemeBitmap( scoped_refptr<base::RefCountedMemory> image_data( ThemeService::GetThemeProviderForProfile(profile_->GetOriginalProfile()) .GetRawData(resource_id, scale_factor)); - callback.Run(image_data.get()); + std::move(callback).Run(image_data.get()); } else { DCHECK_CURRENTLY_ON(content::BrowserThread::IO); const ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - callback.Run(rb.LoadDataResourceBytesForScale(resource_id, scale_factor)); + std::move(callback).Run( + rb.LoadDataResourceBytesForScale(resource_id, scale_factor)); } } void ThemeSource::SendThemeImage( - const content::URLDataSource::GotDataCallback& callback, + content::URLDataSource::GotDataCallback callback, int resource_id, float scale) { scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); @@ -233,7 +234,7 @@ void ThemeSource::SendThemeImage( const ui::ThemeProvider& tp = ThemeService::GetThemeProviderForProfile( profile_->GetOriginalProfile()); ProcessImageOnUiThread(*tp.GetImageSkiaNamed(resource_id), scale, data); - callback.Run(data.get()); + std::move(callback).Run(data.get()); } else { DCHECK_CURRENTLY_ON(content::BrowserThread::IO); // Fetching image data in ResourceBundle should happen on the UI thread. See @@ -241,7 +242,7 @@ void ThemeSource::SendThemeImage( base::PostTaskAndReply( FROM_HERE, {content::BrowserThread::UI}, base::BindOnce(&ProcessResourceOnUiThread, resource_id, scale, data), - base::BindOnce(callback, data)); + base::BindOnce(std::move(callback), data)); } } diff --git a/chrome/browser/ui/webui/theme_source.h b/chrome/browser/ui/webui/theme_source.h index b862455c22bcc..33849c5cd8a34 100644 --- a/chrome/browser/ui/webui/theme_source.h +++ b/chrome/browser/ui/webui/theme_source.h @@ -25,7 +25,7 @@ class ThemeSource : public content::URLDataSource { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; std::string GetMimeType(const std::string& path) override; scoped_refptr<base::SingleThreadTaskRunner> TaskRunnerForRequestPath( const std::string& path) override; @@ -38,14 +38,14 @@ class ThemeSource : public content::URLDataSource { private: // Fetches and sends the theme bitmap. - void SendThemeBitmap(const content::URLDataSource::GotDataCallback& callback, + void SendThemeBitmap(content::URLDataSource::GotDataCallback callback, int resource_id, float scale); // Used in place of SendThemeBitmap when the desired scale is larger than // what the resource bundle supports. This can rescale the provided bitmap up // to the desired size. - void SendThemeImage(const content::URLDataSource::GotDataCallback& callback, + void SendThemeImage(content::URLDataSource::GotDataCallback callback, int resource_id, float scale); diff --git a/chrome/browser/ui/webui/theme_source_unittest.cc b/chrome/browser/ui/webui/theme_source_unittest.cc index 489540a192b93..d4cc3e8e41af0 100644 --- a/chrome/browser/ui/webui/theme_source_unittest.cc +++ b/chrome/browser/ui/webui/theme_source_unittest.cc @@ -28,7 +28,9 @@ class WebUISourcesTest : public testing::Test { theme_source()->StartDataRequest( GURL(base::StrCat({content::kChromeUIScheme, "://", chrome::kChromeUIThemeHost, "/", source})), - content::WebContents::Getter(), callback_); + content::WebContents::Getter(), + base::BindOnce(&WebUISourcesTest::SendResponse, + base::Unretained(this))); } size_t result_data_size_; @@ -37,8 +39,6 @@ class WebUISourcesTest : public testing::Test { void SetUp() override { profile_ = std::make_unique<TestingProfile>(); theme_source_ = std::make_unique<ThemeSource>(profile_.get()); - callback_ = base::Bind(&WebUISourcesTest::SendResponse, - base::Unretained(this)); } void TearDown() override { @@ -50,8 +50,6 @@ class WebUISourcesTest : public testing::Test { result_data_size_ = data ? data->size() : 0; } - content::URLDataSource::GotDataCallback callback_; - content::BrowserTaskEnvironment task_environment_; std::unique_ptr<TestingProfile> profile_; diff --git a/chrome/browser/ui/webui/welcome/ntp_background_fetcher.cc b/chrome/browser/ui/webui/welcome/ntp_background_fetcher.cc index 9a5026c9601e2..87153288b36bd 100644 --- a/chrome/browser/ui/webui/welcome/ntp_background_fetcher.cc +++ b/chrome/browser/ui/webui/welcome/ntp_background_fetcher.cc @@ -21,9 +21,9 @@ namespace welcome { NtpBackgroundFetcher::NtpBackgroundFetcher( size_t index, - const content::WebUIDataSource::GotDataCallback& callback) - : index_(index), callback_(callback) { - DCHECK(callback_ && !callback_.is_null()); + content::WebUIDataSource::GotDataCallback callback) + : index_(index), callback_(std::move(callback)) { + DCHECK(callback_); net::NetworkTrafficAnnotationTag traffic_annotation = net::DefineNetworkTrafficAnnotation("nux_ntp_background_preview", R"( semantics { @@ -74,9 +74,10 @@ NtpBackgroundFetcher::~NtpBackgroundFetcher() = default; void NtpBackgroundFetcher::OnFetchCompleted( std::unique_ptr<std::string> response_body) { if (response_body) { - callback_.Run(base::RefCountedString::TakeString(response_body.release())); + std::move(callback_).Run( + base::RefCountedString::TakeString(response_body.release())); } else { - callback_.Run(base::MakeRefCounted<base::RefCountedBytes>()); + std::move(callback_).Run(base::MakeRefCounted<base::RefCountedBytes>()); } } diff --git a/chrome/browser/ui/webui/welcome/ntp_background_fetcher.h b/chrome/browser/ui/webui/welcome/ntp_background_fetcher.h index bfd25a376a84e..f7ec424d63893 100644 --- a/chrome/browser/ui/webui/welcome/ntp_background_fetcher.h +++ b/chrome/browser/ui/webui/welcome/ntp_background_fetcher.h @@ -20,9 +20,8 @@ namespace welcome { class NtpBackgroundFetcher { public: - NtpBackgroundFetcher( - size_t index, - const content::WebUIDataSource::GotDataCallback& callback); + NtpBackgroundFetcher(size_t index, + content::WebUIDataSource::GotDataCallback callback); ~NtpBackgroundFetcher(); private: diff --git a/chrome/browser/ui/webui/welcome/welcome_ui.cc b/chrome/browser/ui/webui/welcome/welcome_ui.cc index bff9f47aea83d..a6209d2e71581 100644 --- a/chrome/browser/ui/webui/welcome/welcome_ui.cc +++ b/chrome/browser/ui/webui/welcome/welcome_ui.cc @@ -54,10 +54,9 @@ bool ShouldHandleRequestCallback(base::WeakPtr<WelcomeUI> weak_ptr, return !!weak_ptr; } -void HandleRequestCallback( - base::WeakPtr<WelcomeUI> weak_ptr, - const std::string& path, - const content::WebUIDataSource::GotDataCallback& callback) { +void HandleRequestCallback(base::WeakPtr<WelcomeUI> weak_ptr, + const std::string& path, + content::WebUIDataSource::GotDataCallback callback) { DCHECK(ShouldHandleRequestCallback(weak_ptr, path)); std::string index_param = path.substr(path.find_first_of("?") + 1); @@ -66,7 +65,7 @@ void HandleRequestCallback( background_index < 0); DCHECK(weak_ptr); - weak_ptr->CreateBackgroundFetcher(background_index, callback); + weak_ptr->CreateBackgroundFetcher(background_index, std::move(callback)); } void AddStrings(content::WebUIDataSource* html_source) { @@ -204,9 +203,9 @@ WelcomeUI::~WelcomeUI() {} void WelcomeUI::CreateBackgroundFetcher( size_t background_index, - const content::WebUIDataSource::GotDataCallback& callback) { + content::WebUIDataSource::GotDataCallback callback) { background_fetcher_ = std::make_unique<welcome::NtpBackgroundFetcher>( - background_index, callback); + background_index, std::move(callback)); } void WelcomeUI::StorePageSeen(Profile* profile) { diff --git a/chrome/browser/ui/webui/welcome/welcome_ui.h b/chrome/browser/ui/webui/welcome/welcome_ui.h index 3f0be1af968e3..4b5194737f9af 100644 --- a/chrome/browser/ui/webui/welcome/welcome_ui.h +++ b/chrome/browser/ui/webui/welcome/welcome_ui.h @@ -26,7 +26,7 @@ class WelcomeUI : public content::WebUIController { void CreateBackgroundFetcher( size_t background_index, - const content::WebUIDataSource::GotDataCallback& callback); + content::WebUIDataSource::GotDataCallback callback); protected: // Visible for testing. diff --git a/chrome/browser/web_applications/extensions/system_web_app_manager_browsertest.cc b/chrome/browser/web_applications/extensions/system_web_app_manager_browsertest.cc index f8399a6331dff..fce490a43a574 100644 --- a/chrome/browser/web_applications/extensions/system_web_app_manager_browsertest.cc +++ b/chrome/browser/web_applications/extensions/system_web_app_manager_browsertest.cc @@ -82,7 +82,7 @@ class TestWebUIController : public content::WebUIController { }), base::BindRepeating( [](const std::string& id, - const content::WebUIDataSource::GotDataCallback& callback) { + content::WebUIDataSource::GotDataCallback callback) { scoped_refptr<base::RefCountedString> ref_contents( new base::RefCountedString); if (id == "manifest.json") @@ -92,7 +92,7 @@ class TestWebUIController : public content::WebUIController { else NOTREACHED(); - callback.Run(ref_contents); + std::move(callback).Run(ref_contents); })); content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(), data_source); diff --git a/chrome/test/base/web_ui_browser_test.cc b/chrome/test/base/web_ui_browser_test.cc index e404704c20bd9..0341a0d7549ab 100644 --- a/chrome/test/base/web_ui_browser_test.cc +++ b/chrome/test/base/web_ui_browser_test.cc @@ -347,9 +347,6 @@ void BaseWebUIBrowserTest::BrowsePrintPreload(const GURL& browse_to) { #endif } -const std::string BaseWebUIBrowserTest::kDummyURL = - content::GetWebUIURLString("DummyURL"); - BaseWebUIBrowserTest::BaseWebUIBrowserTest() : libraries_preloaded_(false), override_selected_web_ui_(nullptr) {} @@ -369,6 +366,11 @@ void BaseWebUIBrowserTest::set_webui_host(const std::string& webui_host) { namespace { +const GURL& DummyUrl() { + static GURL url(content::GetWebUIURLString("DummyURL")); + return url; +} + // DataSource for the dummy URL. If no data source is provided then an error // page is shown. While this doesn't matter for most tests, without it, // navigation to different anchors cannot be listened to (via the hashchange @@ -384,11 +386,11 @@ class MockWebUIDataSource : public content::URLDataSource { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override { + content::URLDataSource::GotDataCallback callback) override { std::string dummy_html = "<html><body>Dummy</body></html>"; scoped_refptr<base::RefCountedString> response = base::RefCountedString::TakeString(&dummy_html); - callback.Run(response.get()); + std::move(callback).Run(response.get()); } std::string GetMimeType(const std::string& path) override { @@ -450,7 +452,7 @@ void BaseWebUIBrowserTest::SetUpOnMainThread() { content::WebUIControllerFactory::RegisterFactory(test_factory_.get()); - test_factory_->AddFactoryOverride(GURL(kDummyURL).host(), + test_factory_->AddFactoryOverride(DummyUrl().host(), mock_provider_.Pointer()); test_factory_->AddFactoryOverride(content::kChromeUIResourcesHost, mock_provider_.Pointer()); @@ -459,7 +461,7 @@ void BaseWebUIBrowserTest::SetUpOnMainThread() { void BaseWebUIBrowserTest::TearDownOnMainThread() { logging::SetLogMessageHandler(nullptr); - test_factory_->RemoveFactoryOverride(GURL(kDummyURL).host()); + test_factory_->RemoveFactoryOverride(DummyUrl().host()); content::WebUIControllerFactory::UnregisterFactoryForTesting( test_factory_.get()); diff --git a/chrome/test/base/web_ui_browser_test_browsertest.cc b/chrome/test/base/web_ui_browser_test_browsertest.cc index dcbcfc101404f..b1a7abf03ac00 100644 --- a/chrome/test/base/web_ui_browser_test_browsertest.cc +++ b/chrome/test/base/web_ui_browser_test_browsertest.cc @@ -21,6 +21,13 @@ using content::WebUIMessageHandler; +namespace { +const GURL& DummyUrl() { + static GURL url(content::GetWebUIURLString("DummyURL")); + return url; +} +} // namespace + // According to the interface for EXPECT_FATAL_FAILURE // (https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#catching-failures) // the statement must be statically available. Therefore, we make a static @@ -79,7 +86,7 @@ IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, MAYBE_TestFailsFast) { IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, MAYBE_TestRuntimeErrorFailsFast) { AddLibrary(base::FilePath(FILE_PATH_LITERAL("runtime_error.js"))); - ui_test_utils::NavigateToURL(browser(), GURL(kDummyURL)); + ui_test_utils::NavigateToURL(browser(), DummyUrl()); EXPECT_FATAL_FAILURE(RunJavascriptTestNoReturn("TestRuntimeErrorFailsFast"), "GetAsBoolean(&run_test_succeeded_)"); } @@ -170,11 +177,11 @@ class WebUIBrowserAsyncTest : public WebUIBrowserTest { return &message_handler_; } - // Set up and browse to kDummyURL for all tests. + // Set up and browse to DummyUrl() for all tests. void SetUpOnMainThread() override { WebUIBrowserTest::SetUpOnMainThread(); AddLibrary(base::FilePath(FILE_PATH_LITERAL("async.js"))); - ui_test_utils::NavigateToURL(browser(), GURL(kDummyURL)); + ui_test_utils::NavigateToURL(browser(), DummyUrl()); } DISALLOW_COPY_AND_ASSIGN(WebUIBrowserAsyncTest); diff --git a/components/dom_distiller/content/browser/dom_distiller_viewer_source.cc b/components/dom_distiller/content/browser/dom_distiller_viewer_source.cc index 6f57f7b40d696..f82ccdb92f44b 100644 --- a/components/dom_distiller/content/browser/dom_distiller_viewer_source.cc +++ b/components/dom_distiller/content/browser/dom_distiller_viewer_source.cc @@ -206,7 +206,7 @@ std::string DomDistillerViewerSource::GetSource() { void DomDistillerViewerSource::StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) { + content::URLDataSource::GotDataCallback callback) { // TODO(crbug/1009127): simplify path matching. const std::string path = URLDataSource::URLToRequestPath(url); content::WebContents* web_contents = wc_getter.Run(); @@ -214,12 +214,12 @@ void DomDistillerViewerSource::StartDataRequest( return; if (kViewerCssPath == path) { std::string css = viewer::GetCss(); - callback.Run(base::RefCountedString::TakeString(&css)); + std::move(callback).Run(base::RefCountedString::TakeString(&css)); return; } if (kViewerLoadingImagePath == path) { std::string image = viewer::GetLoadingImage(); - callback.Run(base::RefCountedString::TakeString(&image)); + std::move(callback).Run(base::RefCountedString::TakeString(&image)); return; } if (base::StartsWith(path, kViewerSaveFontScalingPath, @@ -267,7 +267,8 @@ void DomDistillerViewerSource::StartDataRequest( } // Place template on the page. - callback.Run(base::RefCountedString::TakeString(&unsafe_page_html)); + std::move(callback).Run( + base::RefCountedString::TakeString(&unsafe_page_html)); } std::string DomDistillerViewerSource::GetMimeType(const std::string& path) { diff --git a/components/dom_distiller/content/browser/dom_distiller_viewer_source.h b/components/dom_distiller/content/browser/dom_distiller_viewer_source.h index f011c1827e9dc..0e1e660717459 100644 --- a/components/dom_distiller/content/browser/dom_distiller_viewer_source.h +++ b/components/dom_distiller/content/browser/dom_distiller_viewer_source.h @@ -32,7 +32,7 @@ class DomDistillerViewerSource : public content::URLDataSource { void StartDataRequest( const GURL& url, const content::WebContents::Getter& wc_getter, - const content::URLDataSource::GotDataCallback& callback) override; + content::URLDataSource::GotDataCallback callback) override; std::string GetMimeType(const std::string& path) override; bool ShouldServiceRequest(const GURL& url, content::ResourceContext* resource_context, diff --git a/components/feedback/tracing_manager.cc b/components/feedback/tracing_manager.cc index d440735896b99..eb5fba1c5f02b 100644 --- a/components/feedback/tracing_manager.cc +++ b/components/feedback/tracing_manager.cc @@ -48,13 +48,13 @@ int TracingManager::RequestTrace() { return current_trace_id_; } -bool TracingManager::GetTraceData(int id, const TraceDataCallback& callback) { +bool TracingManager::GetTraceData(int id, TraceDataCallback callback) { // If a trace is being collected currently, send it via callback when // complete. if (current_trace_id_) { // Only allow one trace data request at a time. - if (trace_callback_.is_null()) { - trace_callback_ = callback; + if (!trace_callback_) { + trace_callback_ = std::move(callback); return true; } else { return false; @@ -66,7 +66,7 @@ bool TracingManager::GetTraceData(int id, const TraceDataCallback& callback) { // Always return the data asychronously, so the behavior is consistant. base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::BindOnce(callback, data->second)); + FROM_HERE, base::BindOnce(std::move(callback), data->second)); return true; } } @@ -79,10 +79,8 @@ void TracingManager::DiscardTraceData(int id) { current_trace_id_ = 0; // If the trace has already been requested, provide an empty string. - if (!trace_callback_.is_null()) { - trace_callback_.Run(scoped_refptr<base::RefCountedString>()); - trace_callback_.Reset(); - } + if (trace_callback_) + std::move(trace_callback_).Run(scoped_refptr<base::RefCountedString>()); } } @@ -106,10 +104,8 @@ void TracingManager::OnTraceDataCollected( trace_data_[current_trace_id_] = output; - if (!trace_callback_.is_null()) { - trace_callback_.Run(output); - trace_callback_.Reset(); - } + if (trace_callback_) + std::move(trace_callback_).Run(output); current_trace_id_ = 0; diff --git a/components/feedback/tracing_manager.h b/components/feedback/tracing_manager.h index 10d9f41e65d9b..8238fc420c4d8 100644 --- a/components/feedback/tracing_manager.h +++ b/components/feedback/tracing_manager.h @@ -20,8 +20,8 @@ class RefCountedString; } // Callback used for getting the output of a trace. -typedef base::Callback<void(scoped_refptr<base::RefCountedString> trace_data)> - TraceDataCallback; +using TraceDataCallback = + base::OnceCallback<void(scoped_refptr<base::RefCountedString> trace_data)>; // This class is used to manage performance metrics that can be attached to // feedback reports. This class is a Singleton that is owned by the preference @@ -49,7 +49,7 @@ class TracingManager { // Get the trace data for |id|. On success, true is returned, and the data is // returned via |callback|. Returns false on failure. - bool GetTraceData(int id, const TraceDataCallback& callback); + bool GetTraceData(int id, TraceDataCallback callback); // Discard the data for trace |id|. void DiscardTraceData(int id); diff --git a/components/gcm_driver/fake_gcm_driver.cc b/components/gcm_driver/fake_gcm_driver.cc index a05cf96dbdd33..eab1b9f670351 100644 --- a/components/gcm_driver/fake_gcm_driver.cc +++ b/components/gcm_driver/fake_gcm_driver.cc @@ -34,9 +34,9 @@ void FakeGCMDriver::ValidateRegistration( const std::string& app_id, const std::vector<std::string>& sender_ids, const std::string& registration_id, - const ValidateRegistrationCallback& callback) { + ValidateRegistrationCallback callback) { base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::BindOnce(callback, true /* is_valid */)); + FROM_HERE, base::BindOnce(std::move(callback), true /* is_valid */)); } void FakeGCMDriver::OnSignedIn() { diff --git a/components/gcm_driver/fake_gcm_driver.h b/components/gcm_driver/fake_gcm_driver.h index cc1a9d90b1e08..e0108c10f226c 100644 --- a/components/gcm_driver/fake_gcm_driver.h +++ b/components/gcm_driver/fake_gcm_driver.h @@ -26,11 +26,10 @@ class FakeGCMDriver : public GCMDriver { ~FakeGCMDriver() override; // GCMDriver overrides: - void ValidateRegistration( - const std::string& app_id, - const std::vector<std::string>& sender_ids, - const std::string& registration_id, - const ValidateRegistrationCallback& callback) override; + void ValidateRegistration(const std::string& app_id, + const std::vector<std::string>& sender_ids, + const std::string& registration_id, + ValidateRegistrationCallback callback) override; void OnSignedIn() override; void OnSignedOut() override; void AddConnectionObserver(GCMConnectionObserver* observer) override; diff --git a/components/gcm_driver/gcm_driver.h b/components/gcm_driver/gcm_driver.h index d924670742917..8189cc187bd97 100644 --- a/components/gcm_driver/gcm_driver.h +++ b/components/gcm_driver/gcm_driver.h @@ -44,7 +44,7 @@ class InstanceIDHandler { public: using GetTokenCallback = base::OnceCallback<void(const std::string& token, GCMClient::Result result)>; - using ValidateTokenCallback = base::Callback<void(bool is_valid)>; + using ValidateTokenCallback = base::OnceCallback<void(bool is_valid)>; using DeleteTokenCallback = base::OnceCallback<void(GCMClient::Result result)>; using GetInstanceIDDataCallback = @@ -64,7 +64,7 @@ class InstanceIDHandler { const std::string& authorized_entity, const std::string& scope, const std::string& token, - const ValidateTokenCallback& callback) = 0; + ValidateTokenCallback callback) = 0; virtual void DeleteToken(const std::string& app_id, const std::string& authorized_entity, const std::string& scope, @@ -95,7 +95,7 @@ class GCMDriver { using RegisterCallback = base::OnceCallback<void(const std::string& registration_id, GCMClient::Result result)>; - using ValidateRegistrationCallback = base::Callback<void(bool is_valid)>; + using ValidateRegistrationCallback = base::OnceCallback<void(bool is_valid)>; using UnregisterCallback = base::OnceCallback<void(GCMClient::Result result)>; using SendCallback = base::Callback<void(const std::string& message_id, GCMClient::Result result)>; @@ -131,11 +131,10 @@ class GCMDriver { // Checks that the provided |sender_ids| and |registration_id| matches the // stored registration info for |app_id|. - virtual void ValidateRegistration( - const std::string& app_id, - const std::vector<std::string>& sender_ids, - const std::string& registration_id, - const ValidateRegistrationCallback& callback) = 0; + virtual void ValidateRegistration(const std::string& app_id, + const std::vector<std::string>& sender_ids, + const std::string& registration_id, + ValidateRegistrationCallback callback) = 0; // Unregisters all sender_ids for an app. Only works on non-Android. Will also // remove any encryption keys associated with the |app_id|. diff --git a/components/gcm_driver/gcm_driver_android.cc b/components/gcm_driver/gcm_driver_android.cc index 9738d1c97ac07..bdf23058fe9b3 100644 --- a/components/gcm_driver/gcm_driver_android.cc +++ b/components/gcm_driver/gcm_driver_android.cc @@ -119,10 +119,10 @@ void GCMDriverAndroid::ValidateRegistration( const std::string& app_id, const std::vector<std::string>& sender_ids, const std::string& registration_id, - const ValidateRegistrationCallback& callback) { + ValidateRegistrationCallback callback) { // gcm_driver doesn't store registration IDs on Android, so assume it's valid. base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::BindOnce(callback, true /* is_valid */)); + FROM_HERE, base::BindOnce(std::move(callback), true /* is_valid */)); } void GCMDriverAndroid::OnSignedIn() { diff --git a/components/gcm_driver/gcm_driver_android.h b/components/gcm_driver/gcm_driver_android.h index 99176b84e8cd1..b52baedf61046 100644 --- a/components/gcm_driver/gcm_driver_android.h +++ b/components/gcm_driver/gcm_driver_android.h @@ -58,11 +58,10 @@ class GCMDriverAndroid : public GCMDriver, const base::android::JavaParamRef<jobjectArray>& data_keys_and_values); // GCMDriver implementation: - void ValidateRegistration( - const std::string& app_id, - const std::vector<std::string>& sender_ids, - const std::string& registration_id, - const ValidateRegistrationCallback& callback) override; + void ValidateRegistration(const std::string& app_id, + const std::vector<std::string>& sender_ids, + const std::string& registration_id, + ValidateRegistrationCallback callback) override; void OnSignedIn() override; void OnSignedOut() override; void Enable() override; diff --git a/components/gcm_driver/gcm_driver_desktop.cc b/components/gcm_driver/gcm_driver_desktop.cc index 6061918cd9e50..f674e075371eb 100644 --- a/components/gcm_driver/gcm_driver_desktop.cc +++ b/components/gcm_driver/gcm_driver_desktop.cc @@ -563,7 +563,7 @@ void GCMDriverDesktop::ValidateRegistration( const std::string& app_id, const std::vector<std::string>& sender_ids, const std::string& registration_id, - const ValidateRegistrationCallback& callback) { + ValidateRegistrationCallback callback) { DCHECK(!app_id.empty()); DCHECK(!sender_ids.empty() && sender_ids.size() <= kMaxSenders); DCHECK(!registration_id.empty()); @@ -586,25 +586,27 @@ void GCMDriverDesktop::ValidateRegistration( std::sort(gcm_info->sender_ids.begin(), gcm_info->sender_ids.end()); if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { - delayed_task_controller_->AddTask(base::Bind( - &GCMDriverDesktop::DoValidateRegistration, - weak_ptr_factory_.GetWeakPtr(), gcm_info, registration_id, callback)); + delayed_task_controller_->AddTask( + base::BindOnce(&GCMDriverDesktop::DoValidateRegistration, + weak_ptr_factory_.GetWeakPtr(), gcm_info, + registration_id, std::move(callback))); return; } - DoValidateRegistration(std::move(gcm_info), registration_id, callback); + DoValidateRegistration(std::move(gcm_info), registration_id, + std::move(callback)); } void GCMDriverDesktop::DoValidateRegistration( scoped_refptr<RegistrationInfo> registration_info, const std::string& registration_id, - const ValidateRegistrationCallback& callback) { + ValidateRegistrationCallback callback) { base::PostTaskAndReplyWithResult( io_thread_.get(), FROM_HERE, - base::Bind(&GCMDriverDesktop::IOWorker::ValidateRegistration, - base::Unretained(io_worker_.get()), - std::move(registration_info), registration_id), - callback); + base::BindOnce(&GCMDriverDesktop::IOWorker::ValidateRegistration, + base::Unretained(io_worker_.get()), + std::move(registration_info), registration_id), + std::move(callback)); } void GCMDriverDesktop::Shutdown() { @@ -928,12 +930,12 @@ void GCMDriverDesktop::ValidateToken(const std::string& app_id, const std::string& authorized_entity, const std::string& scope, const std::string& token, - const ValidateTokenCallback& callback) { + ValidateTokenCallback callback) { DCHECK(!app_id.empty()); DCHECK(!authorized_entity.empty()); DCHECK(!scope.empty()); DCHECK(!token.empty()); - DCHECK(!callback.is_null()); + DCHECK(callback); DCHECK(ui_thread_->RunsTasksInCurrentSequence()); GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); @@ -953,13 +955,15 @@ void GCMDriverDesktop::ValidateToken(const std::string& app_id, instance_id_info->scope = scope; if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { - delayed_task_controller_->AddTask(base::Bind( - &GCMDriverDesktop::DoValidateRegistration, - weak_ptr_factory_.GetWeakPtr(), instance_id_info, token, callback)); + delayed_task_controller_->AddTask( + base::BindOnce(&GCMDriverDesktop::DoValidateRegistration, + weak_ptr_factory_.GetWeakPtr(), instance_id_info, token, + std::move(callback))); return; } - DoValidateRegistration(std::move(instance_id_info), token, callback); + DoValidateRegistration(std::move(instance_id_info), token, + std::move(callback)); } void GCMDriverDesktop::DeleteToken(const std::string& app_id, @@ -993,12 +997,9 @@ void GCMDriverDesktop::DeleteToken(const std::string& app_id, // Delay the DeleteToken operation until GCMClient is ready. if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { - delayed_task_controller_->AddTask( - base::Bind(&GCMDriverDesktop::DoDeleteToken, - weak_ptr_factory_.GetWeakPtr(), - app_id, - authorized_entity, - scope)); + delayed_task_controller_->AddTask(base::BindOnce( + &GCMDriverDesktop::DoDeleteToken, weak_ptr_factory_.GetWeakPtr(), + app_id, authorized_entity, scope)); return; } @@ -1031,12 +1032,9 @@ void GCMDriverDesktop::AddInstanceIDData( // Delay the operation until GCMClient is ready. if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { - delayed_task_controller_->AddTask( - base::Bind(&GCMDriverDesktop::DoAddInstanceIDData, - weak_ptr_factory_.GetWeakPtr(), - app_id, - instance_id, - extra_data)); + delayed_task_controller_->AddTask(base::BindOnce( + &GCMDriverDesktop::DoAddInstanceIDData, weak_ptr_factory_.GetWeakPtr(), + app_id, instance_id, extra_data)); return; } @@ -1066,9 +1064,8 @@ void GCMDriverDesktop::RemoveInstanceIDData(const std::string& app_id) { // Delay the operation until GCMClient is ready. if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { delayed_task_controller_->AddTask( - base::Bind(&GCMDriverDesktop::DoRemoveInstanceIDData, - weak_ptr_factory_.GetWeakPtr(), - app_id)); + base::BindOnce(&GCMDriverDesktop::DoRemoveInstanceIDData, + weak_ptr_factory_.GetWeakPtr(), app_id)); return; } @@ -1110,9 +1107,8 @@ void GCMDriverDesktop::GetInstanceIDData( // Delay the operation until GCMClient is ready. if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { delayed_task_controller_->AddTask( - base::Bind(&GCMDriverDesktop::DoGetInstanceIDData, - weak_ptr_factory_.GetWeakPtr(), - app_id)); + base::BindOnce(&GCMDriverDesktop::DoGetInstanceIDData, + weak_ptr_factory_.GetWeakPtr(), app_id)); return; } @@ -1178,10 +1174,9 @@ void GCMDriverDesktop::WakeFromSuspendForHeartbeat(bool wake) { if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { // The GCM service was initialized but has not started yet. - delayed_task_controller_->AddTask( - base::Bind(&GCMDriverDesktop::WakeFromSuspendForHeartbeat, - weak_ptr_factory_.GetWeakPtr(), - wake_from_suspend_enabled_)); + delayed_task_controller_->AddTask(base::BindOnce( + &GCMDriverDesktop::WakeFromSuspendForHeartbeat, + weak_ptr_factory_.GetWeakPtr(), wake_from_suspend_enabled_)); return; } @@ -1205,8 +1200,8 @@ void GCMDriverDesktop::AddHeartbeatInterval(const std::string& scope, if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { // The GCM service was initialized but has not started yet. delayed_task_controller_->AddTask( - base::Bind(&GCMDriverDesktop::AddHeartbeatInterval, - weak_ptr_factory_.GetWeakPtr(), scope, interval_ms)); + base::BindOnce(&GCMDriverDesktop::AddHeartbeatInterval, + weak_ptr_factory_.GetWeakPtr(), scope, interval_ms)); return; } @@ -1226,8 +1221,8 @@ void GCMDriverDesktop::RemoveHeartbeatInterval(const std::string& scope) { if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { // The GCM service was initialized but has not started yet. delayed_task_controller_->AddTask( - base::Bind(&GCMDriverDesktop::RemoveHeartbeatInterval, - weak_ptr_factory_.GetWeakPtr(), scope)); + base::BindOnce(&GCMDriverDesktop::RemoveHeartbeatInterval, + weak_ptr_factory_.GetWeakPtr(), scope)); return; } diff --git a/components/gcm_driver/gcm_driver_desktop.h b/components/gcm_driver/gcm_driver_desktop.h index ce3e46c69939a..6b8d6818e5a2d 100644 --- a/components/gcm_driver/gcm_driver_desktop.h +++ b/components/gcm_driver/gcm_driver_desktop.h @@ -67,11 +67,10 @@ class GCMDriverDesktop : public GCMDriver, ~GCMDriverDesktop() override; // GCMDriver implementation: - void ValidateRegistration( - const std::string& app_id, - const std::vector<std::string>& sender_ids, - const std::string& registration_id, - const ValidateRegistrationCallback& callback) override; + void ValidateRegistration(const std::string& app_id, + const std::vector<std::string>& sender_ids, + const std::string& registration_id, + ValidateRegistrationCallback callback) override; void Shutdown() override; void OnSignedIn() override; void OnSignedOut() override; @@ -128,7 +127,7 @@ class GCMDriverDesktop : public GCMDriver, const std::string& authorized_entity, const std::string& scope, const std::string& token, - const ValidateTokenCallback& callback) override; + ValidateTokenCallback callback) override; void DeleteToken(const std::string& app_id, const std::string& authorized_entity, const std::string& scope, @@ -150,7 +149,7 @@ class GCMDriverDesktop : public GCMDriver, void DoValidateRegistration(scoped_refptr<RegistrationInfo> registration_info, const std::string& registration_id, - const ValidateRegistrationCallback& callback); + ValidateRegistrationCallback callback); // Stops the GCM service. It can be restarted by calling EnsureStarted again. void Stop(); diff --git a/components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.cc b/components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.cc index f704b3e09b378..84fd2347ce997 100644 --- a/components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.cc +++ b/components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.cc @@ -85,9 +85,9 @@ void FakeGCMDriverForInstanceID::ValidateToken( const std::string& authorized_entity, const std::string& scope, const std::string& token, - const ValidateTokenCallback& callback) { + ValidateTokenCallback callback) { base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::BindOnce(callback, true /* is_valid */)); + FROM_HERE, base::BindOnce(std::move(callback), true /* is_valid */)); } void FakeGCMDriverForInstanceID::DeleteToken( diff --git a/components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h b/components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h index ff428511e1636..c9eb42141b51a 100644 --- a/components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h +++ b/components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h @@ -51,7 +51,7 @@ class FakeGCMDriverForInstanceID : public gcm::FakeGCMDriver, const std::string& authorized_entity, const std::string& scope, const std::string& token, - const ValidateTokenCallback& callback) override; + ValidateTokenCallback callback) override; void DeleteToken(const std::string& app_id, const std::string& authorized_entity, const std::string& scope, diff --git a/components/gcm_driver/instance_id/instance_id.h b/components/gcm_driver/instance_id/instance_id.h index e9e3be481e47b..628fe9ec7345a 100644 --- a/components/gcm_driver/instance_id/instance_id.h +++ b/components/gcm_driver/instance_id/instance_id.h @@ -71,7 +71,7 @@ class InstanceID { base::Callback<void(const base::Time& creation_time)>; using GetTokenCallback = base::OnceCallback<void(const std::string& token, Result result)>; - using ValidateTokenCallback = base::Callback<void(bool is_valid)>; + using ValidateTokenCallback = base::OnceCallback<void(bool is_valid)>; using GetEncryptionInfoCallback = base::OnceCallback<void(std::string p256dh, std::string auth_secret)>; using DeleteTokenCallback = base::OnceCallback<void(Result result)>; @@ -121,7 +121,7 @@ class InstanceID { virtual void ValidateToken(const std::string& authorized_entity, const std::string& scope, const std::string& token, - const ValidateTokenCallback& callback) = 0; + ValidateTokenCallback callback) = 0; // Get the public encryption key and authentication secret associated with a // GCM-scoped token. If encryption info is not yet associated, it will be diff --git a/components/gcm_driver/instance_id/instance_id_android.cc b/components/gcm_driver/instance_id/instance_id_android.cc index 065aa4f3cdd2f..ee25207abb32d 100644 --- a/components/gcm_driver/instance_id/instance_id_android.cc +++ b/components/gcm_driver/instance_id/instance_id_android.cc @@ -125,10 +125,10 @@ void InstanceIDAndroid::GetToken( void InstanceIDAndroid::ValidateToken(const std::string& authorized_entity, const std::string& scope, const std::string& token, - const ValidateTokenCallback& callback) { + ValidateTokenCallback callback) { // gcm_driver doesn't store tokens on Android, so assume it's valid. base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::BindOnce(callback, true /* is_valid */)); + FROM_HERE, base::BindOnce(std::move(callback), true /* is_valid */)); } void InstanceIDAndroid::DeleteTokenImpl(const std::string& authorized_entity, diff --git a/components/gcm_driver/instance_id/instance_id_android.h b/components/gcm_driver/instance_id/instance_id_android.h index ede64fd6f8e14..89d8a189c6d72 100644 --- a/components/gcm_driver/instance_id/instance_id_android.h +++ b/components/gcm_driver/instance_id/instance_id_android.h @@ -51,7 +51,7 @@ class InstanceIDAndroid : public InstanceID { void ValidateToken(const std::string& authorized_entity, const std::string& scope, const std::string& token, - const ValidateTokenCallback& callback) override; + ValidateTokenCallback callback) override; void DeleteTokenImpl(const std::string& audience, const std::string& scope, DeleteTokenCallback callback) override; diff --git a/components/gcm_driver/instance_id/instance_id_impl.cc b/components/gcm_driver/instance_id/instance_id_impl.cc index 6723fb0211589..b7f7e27c70bfb 100644 --- a/components/gcm_driver/instance_id/instance_id_impl.cc +++ b/components/gcm_driver/instance_id/instance_id_impl.cc @@ -118,26 +118,27 @@ void InstanceIDImpl::DoGetToken( void InstanceIDImpl::ValidateToken(const std::string& authorized_entity, const std::string& scope, const std::string& token, - const ValidateTokenCallback& callback) { + ValidateTokenCallback callback) { DCHECK(!authorized_entity.empty()); DCHECK(!scope.empty()); DCHECK(!token.empty()); RunWhenReady(base::BindOnce(&InstanceIDImpl::DoValidateToken, weak_ptr_factory_.GetWeakPtr(), authorized_entity, - scope, token, callback)); + scope, token, std::move(callback))); } void InstanceIDImpl::DoValidateToken(const std::string& authorized_entity, const std::string& scope, const std::string& token, - const ValidateTokenCallback& callback) { + ValidateTokenCallback callback) { if (id_.empty()) { - callback.Run(false /* is_valid */); + std::move(callback).Run(false /* is_valid */); return; } - Handler()->ValidateToken(app_id(), authorized_entity, scope, token, callback); + Handler()->ValidateToken(app_id(), authorized_entity, scope, token, + std::move(callback)); } void InstanceIDImpl::DeleteTokenImpl(const std::string& authorized_entity, diff --git a/components/gcm_driver/instance_id/instance_id_impl.h b/components/gcm_driver/instance_id/instance_id_impl.h index 5698718480b92..580d3a7849f31 100644 --- a/components/gcm_driver/instance_id/instance_id_impl.h +++ b/components/gcm_driver/instance_id/instance_id_impl.h @@ -41,7 +41,7 @@ class InstanceIDImpl : public InstanceID { void ValidateToken(const std::string& authorized_entity, const std::string& scope, const std::string& token, - const ValidateTokenCallback& callback) override; + ValidateTokenCallback callback) override; void DeleteTokenImpl(const std::string& authorized_entity, const std::string& scope, DeleteTokenCallback callback) override; @@ -69,7 +69,7 @@ class InstanceIDImpl : public InstanceID { void DoValidateToken(const std::string& authorized_entity, const std::string& scope, const std::string& token, - const ValidateTokenCallback& callback); + ValidateTokenCallback callback); void DoDeleteToken(const std::string& authorized_entity, const std::string& scope, DeleteTokenCallback callback); diff --git a/components/invalidation/impl/fcm_invalidation_service_unittest.cc b/components/invalidation/impl/fcm_invalidation_service_unittest.cc index 8d69b328f3098..f8047c006d201 100644 --- a/components/invalidation/impl/fcm_invalidation_service_unittest.cc +++ b/components/invalidation/impl/fcm_invalidation_service_unittest.cc @@ -103,11 +103,17 @@ class MockInstanceID : public InstanceID { const std::map<std::string, std::string>& options, std::set<Flags> flags, GetTokenCallback& callback)); - MOCK_METHOD4(ValidateToken, + void ValidateToken(const std::string& authorized_entity, + const std::string& scope, + const std::string& token, + ValidateTokenCallback callback) override { + ValidateToken_(authorized_entity, scope, token, callback); + } + MOCK_METHOD4(ValidateToken_, void(const std::string& authorized_entity, const std::string& scope, const std::string& token, - const ValidateTokenCallback& callback)); + ValidateTokenCallback& callback)); protected: void DeleteTokenImpl(const std::string& authorized_entity, diff --git a/components/invalidation/impl/fcm_network_handler_unittests.cc b/components/invalidation/impl/fcm_network_handler_unittests.cc index bcdb759237c13..784580929dc93 100644 --- a/components/invalidation/impl/fcm_network_handler_unittests.cc +++ b/components/invalidation/impl/fcm_network_handler_unittests.cc @@ -77,11 +77,17 @@ class MockInstanceID : public InstanceID { const std::map<std::string, std::string>& options, std::set<Flags> flags, GetTokenCallback& callback)); - MOCK_METHOD4(ValidateToken, + void ValidateToken(const std::string& authorized_entity, + const std::string& scope, + const std::string& token, + ValidateTokenCallback callback) override { + ValidateToken_(authorized_entity, scope, token, callback); + } + MOCK_METHOD4(ValidateToken_, void(const std::string& authorized_entity, const std::string& scope, const std::string& token, - const ValidateTokenCallback& callback)); + ValidateTokenCallback& callback)); protected: void DeleteTokenImpl(const std::string& authorized_entity, @@ -112,11 +118,17 @@ class MockGCMDriver : public gcm::GCMDriver { &test_url_loader_factory_)) {} ~MockGCMDriver() override = default; - MOCK_METHOD4(ValidateRegistration, + void ValidateRegistration(const std::string& app_id, + const std::vector<std::string>& sender_ids, + const std::string& registration_id, + ValidateRegistrationCallback callback) override { + ValidateRegistration_(app_id, sender_ids, registration_id, callback); + } + MOCK_METHOD4(ValidateRegistration_, void(const std::string& app_id, const std::vector<std::string>& sender_ids, const std::string& registration_id, - const ValidateRegistrationCallback& callback)); + ValidateRegistrationCallback& callback)); MOCK_METHOD0(OnSignedIn, void()); MOCK_METHOD0(OnSignedOut, void()); MOCK_METHOD1(AddConnectionObserver, @@ -438,7 +450,7 @@ TEST_F(FCMNetworkHandlerTest, ShouldScheduleTokenValidationAndActOnNewToken) { EXPECT_CALL(*mock_instance_id(), GetToken_(_, _, _, _, _)) .WillOnce( InvokeCallbackArgument<4>("token", InstanceID::Result::SUCCESS)); - EXPECT_CALL(*mock_instance_id(), ValidateToken(_, _, _, _)).Times(0); + EXPECT_CALL(*mock_instance_id(), ValidateToken_(_, _, _, _)).Times(0); EXPECT_CALL(mock_on_token_callback, Run("token")).Times(1); handler->StartListening(); testing::Mock::VerifyAndClearExpectations(mock_instance_id()); @@ -469,7 +481,7 @@ TEST_F(FCMNetworkHandlerTest, EXPECT_CALL(*mock_instance_id(), GetToken_(_, _, _, _, _)) .WillOnce( InvokeCallbackArgument<4>("token", InstanceID::Result::SUCCESS)); - EXPECT_CALL(*mock_instance_id(), ValidateToken(_, _, _, _)).Times(0); + EXPECT_CALL(*mock_instance_id(), ValidateToken_(_, _, _, _)).Times(0); EXPECT_CALL(mock_on_token_callback, Run("token")).Times(1); handler->StartListening(); testing::Mock::VerifyAndClearExpectations(mock_instance_id()); diff --git a/content/browser/indexed_db/indexed_db_blob_info.cc b/content/browser/indexed_db/indexed_db_blob_info.cc index 64d6ccbdd39bc..d96dd372f3c3b 100644 --- a/content/browser/indexed_db/indexed_db_blob_info.cc +++ b/content/browser/indexed_db/indexed_db_blob_info.cc @@ -105,15 +105,15 @@ void IndexedDBBlobInfo::set_key(int64_t key) { } void IndexedDBBlobInfo::set_mark_used_callback( - const base::Closure& mark_used_callback) { - DCHECK(mark_used_callback_.is_null()); - mark_used_callback_ = mark_used_callback; + base::RepeatingClosure mark_used_callback) { + DCHECK(!mark_used_callback_); + mark_used_callback_ = std::move(mark_used_callback); } void IndexedDBBlobInfo::set_release_callback( - const base::RepeatingClosure& release_callback) { - DCHECK(release_callback_.is_null()); - release_callback_ = release_callback; + base::RepeatingClosure release_callback) { + DCHECK(!release_callback_); + release_callback_ = std::move(release_callback); } } // namespace content diff --git a/content/browser/indexed_db/indexed_db_blob_info.h b/content/browser/indexed_db/indexed_db_blob_info.h index 126c1d591ecb2..64be7db47917a 100644 --- a/content/browser/indexed_db/indexed_db_blob_info.h +++ b/content/browser/indexed_db/indexed_db_blob_info.h @@ -68,8 +68,8 @@ class CONTENT_EXPORT IndexedDBBlobInfo { void set_file_path(const base::FilePath& file_path); void set_last_modified(const base::Time& time); void set_key(int64_t key); - void set_mark_used_callback(const base::RepeatingClosure& mark_used_callback); - void set_release_callback(const base::RepeatingClosure& release_callback); + void set_mark_used_callback(base::RepeatingClosure mark_used_callback); + void set_release_callback(base::RepeatingClosure release_callback); private: bool is_file_; diff --git a/content/browser/indexed_db/indexed_db_dispatcher_host_unittest.cc b/content/browser/indexed_db/indexed_db_dispatcher_host_unittest.cc index c255a68403129..674e2f8341547 100644 --- a/content/browser/indexed_db/indexed_db_dispatcher_host_unittest.cc +++ b/content/browser/indexed_db/indexed_db_dispatcher_host_unittest.cc @@ -14,6 +14,7 @@ #include "base/strings/utf_string_conversions.h" #include "base/task/post_task.h" #include "base/test/bind_test_util.h" +#include "base/test/gmock_callback_support.h" #include "base/test/mock_callback.h" #include "base/test/test_simple_task_runner.h" #include "base/threading/thread.h" @@ -43,6 +44,7 @@ #include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom.h" #include "url/origin.h" +using base::test::RunClosure; using blink::IndexedDBDatabaseMetadata; using blink::IndexedDBIndexKeys; using blink::IndexedDBKey; @@ -65,10 +67,6 @@ ACTION_TEMPLATE(MoveArg, *out = std::move(*::testing::get<k>(args)); } -ACTION_P(RunClosure, closure) { - closure.Run(); -} - ACTION_P(QuitLoop, run_loop) { run_loop->Quit(); } @@ -84,8 +82,6 @@ MATCHER_P(MatchesIDBKey, key, "") { return arg.Equals(key); } -typedef void (base::Closure::*ClosureRunFcn)() const &; - static const char kDatabaseName[] = "db"; static const char kOrigin[] = "https://www.example.com"; static const int kFakeProcessId = 2; @@ -141,11 +137,11 @@ struct TestDatabaseConnection { DISALLOW_COPY_AND_ASSIGN(TestDatabaseConnection); }; -void StatusCallback(const base::Closure& callback, +void StatusCallback(base::OnceClosure callback, blink::mojom::IDBStatus* status_out, blink::mojom::IDBStatus status) { *status_out = status; - callback.Run(); + std::move(callback).Run(); } class TestIndexedDBObserver : public IndexedDBContextImpl::Observer { @@ -1051,7 +1047,8 @@ TEST_F(IndexedDBDispatcherHostTest, DISABLED_NotifyIndexedDBListChanged) { { ::testing::InSequence dummy; base::RunLoop loop; - base::Closure quit_closure = base::BarrierClosure(2, loop.QuitClosure()); + base::RepeatingClosure quit_closure = + base::BarrierClosure(2, loop.QuitClosure()); EXPECT_CALL(*connection1.connection_callbacks, Complete(kTransactionId1)) .Times(1) @@ -1107,7 +1104,8 @@ TEST_F(IndexedDBDispatcherHostTest, DISABLED_NotifyIndexedDBListChanged) { { ::testing::InSequence dummy; base::RunLoop loop; - base::Closure quit_closure = base::BarrierClosure(2, loop.QuitClosure()); + base::RepeatingClosure quit_closure = + base::BarrierClosure(2, loop.QuitClosure()); EXPECT_CALL(*connection2.connection_callbacks, Complete(kTransactionId2)) .Times(1) @@ -1159,7 +1157,8 @@ TEST_F(IndexedDBDispatcherHostTest, DISABLED_NotifyIndexedDBListChanged) { { ::testing::InSequence dummy; base::RunLoop loop; - base::Closure quit_closure = base::BarrierClosure(2, loop.QuitClosure()); + base::RepeatingClosure quit_closure = + base::BarrierClosure(2, loop.QuitClosure()); EXPECT_CALL(*connection3.connection_callbacks, Complete(kTransactionId3)) .Times(1) diff --git a/content/browser/loader/loader_browsertest.cc b/content/browser/loader/loader_browsertest.cc index 363ce80402c6a..39e4516be0046 100644 --- a/content/browser/loader/loader_browsertest.cc +++ b/content/browser/loader/loader_browsertest.cc @@ -755,12 +755,12 @@ class RequestDataBrowserTest : public ContentBrowserTest { base::AutoLock auto_lock(requests_lock_); requests_.push_back(data); if (requests_closure_) - requests_closure_.Run(); + std::move(requests_closure_).Run(); } base::Lock requests_lock_; std::vector<RequestData> requests_; - base::Closure requests_closure_; + base::OnceClosure requests_closure_; std::unique_ptr<URLLoaderInterceptor> interceptor_; }; diff --git a/content/browser/loader/navigation_url_loader_impl.cc b/content/browser/loader/navigation_url_loader_impl.cc index f71df26ab04ae..3f50c7be684af 100644 --- a/content/browser/loader/navigation_url_loader_impl.cc +++ b/content/browser/loader/navigation_url_loader_impl.cc @@ -1137,7 +1137,7 @@ class NavigationURLLoaderImpl::URLLoaderRequestController GlobalRequestID global_request_id_; net::RedirectInfo redirect_info_; int redirect_limit_ = net::URLRequest::kMaxRedirects; - base::Callback<WebContents*()> web_contents_getter_; + base::RepeatingCallback<WebContents*()> web_contents_getter_; std::unique_ptr<NavigationUIData> navigation_ui_data_; scoped_refptr<network::SharedURLLoaderFactory> network_loader_factory_; diff --git a/content/browser/net/network_errors_listing_ui.cc b/content/browser/net/network_errors_listing_ui.cc index df437d50fb01c..9f731d86fbc36 100644 --- a/content/browser/net/network_errors_listing_ui.cc +++ b/content/browser/net/network_errors_listing_ui.cc @@ -61,17 +61,16 @@ bool ShouldHandleWebUIRequestCallback(const std::string& path) { return path == kNetworkErrorDataFile; } -void HandleWebUIRequestCallback( - BrowserContext* current_context, - const std::string& path, - const WebUIDataSource::GotDataCallback& callback) { +void HandleWebUIRequestCallback(BrowserContext* current_context, + const std::string& path, + WebUIDataSource::GotDataCallback callback) { DCHECK(ShouldHandleWebUIRequestCallback(path)); base::DictionaryValue data; data.Set(kErrorCodesDataName, GetNetworkErrorData()); std::string json_string; base::JSONWriter::Write(data, &json_string); - callback.Run(base::RefCountedString::TakeString(&json_string)); + std::move(callback).Run(base::RefCountedString::TakeString(&json_string)); } } // namespace diff --git a/content/browser/network_service_browsertest.cc b/content/browser/network_service_browsertest.cc index dddc6603cf915..edded2122f5eb 100644 --- a/content/browser/network_service_browsertest.cc +++ b/content/browser/network_service_browsertest.cc @@ -79,14 +79,13 @@ class TestWebUIDataSource : public URLDataSource { std::string GetSource() override { return "webui"; } - void StartDataRequest( - const GURL& url, - const WebContents::Getter& wc_getter, - const URLDataSource::GotDataCallback& callback) override { + void StartDataRequest(const GURL& url, + const WebContents::Getter& wc_getter, + URLDataSource::GotDataCallback callback) override { std::string dummy_html = "<html><body>Foo</body></html>"; scoped_refptr<base::RefCountedString> response = base::RefCountedString::TakeString(&dummy_html); - callback.Run(response.get()); + std::move(callback).Run(response.get()); } std::string GetMimeType(const std::string& path) override { diff --git a/content/browser/notifications/notification_storage_unittest.cc b/content/browser/notifications/notification_storage_unittest.cc index 6f3c14ec8d23c..2bdf7bd4c1525 100644 --- a/content/browser/notifications/notification_storage_unittest.cc +++ b/content/browser/notifications/notification_storage_unittest.cc @@ -118,7 +118,7 @@ class NotificationStorageTest : public ::testing::Test { void WriteNotificationDataSynchronous(const NotificationDatabaseData& data) { base::RunLoop run_loop; storage_->WriteNotificationData( - data, base::Bind( + data, base::BindOnce( &NotificationStorageTest::DidWriteNotificationDataSynchronous, base::Unretained(this), run_loop.QuitClosure())); run_loop.Run(); @@ -140,9 +140,10 @@ class NotificationStorageTest : public ::testing::Test { base::RunLoop run_loop; storage_->ReadNotificationDataAndRecordInteraction( service_worker_registration_id, notification_id, interaction, - base::Bind(&NotificationStorageTest:: - DidReadNotificationDataAndRecordInteractionSynchronous, - base::Unretained(this), run_loop.QuitClosure())); + base::BindOnce( + &NotificationStorageTest:: + DidReadNotificationDataAndRecordInteractionSynchronous, + base::Unretained(this), run_loop.QuitClosure())); run_loop.Run(); return out_data_; } diff --git a/content/browser/payments/payment_app_browsertest.cc b/content/browser/payments/payment_app_browsertest.cc index 1b9c703fe310c..d0c7e4576cd77 100644 --- a/content/browser/payments/payment_app_browsertest.cc +++ b/content/browser/payments/payment_app_browsertest.cc @@ -34,25 +34,25 @@ using ::payments::mojom::PaymentMethodData; using ::payments::mojom::PaymentRequestEventData; using ::payments::mojom::PaymentRequestEventDataPtr; -void GetAllPaymentAppsCallback(const base::Closure& done_callback, +void GetAllPaymentAppsCallback(base::OnceClosure done_callback, PaymentAppProvider::PaymentApps* out_apps, PaymentAppProvider::PaymentApps apps) { *out_apps = std::move(apps); - done_callback.Run(); + std::move(done_callback).Run(); } -void PaymentEventResultCallback(const base::Closure& done_callback, +void PaymentEventResultCallback(base::OnceClosure done_callback, bool* out_payment_event_result, bool payment_event_result) { *out_payment_event_result = payment_event_result; - done_callback.Run(); + std::move(done_callback).Run(); } -void InvokePaymentAppCallback(const base::Closure& done_callback, +void InvokePaymentAppCallback(base::OnceClosure done_callback, PaymentHandlerResponsePtr* out_response, PaymentHandlerResponsePtr response) { *out_response = std::move(response); - done_callback.Run(); + std::move(done_callback).Run(); } } // namespace diff --git a/content/browser/payments/payment_app_installer.cc b/content/browser/payments/payment_app_installer.cc index 7d5827eb9c9ca..0e4d4941024a7 100644 --- a/content/browser/payments/payment_app_installer.cc +++ b/content/browser/payments/payment_app_installer.cc @@ -64,9 +64,11 @@ class SelfDeleteInstaller ->GetServiceWorkerContext()); service_worker_watcher_ = new ServiceWorkerContextWatcher( service_worker_context, - base::Bind(&SelfDeleteInstaller::onServiceWorkerRegistration, this), - base::Bind(&SelfDeleteInstaller::onServiceWorkerVersionUpdate, this), - base::Bind(&SelfDeleteInstaller::onServiceWorkerError, this)); + base::BindRepeating(&SelfDeleteInstaller::OnServiceWorkerRegistration, + this), + base::BindRepeating(&SelfDeleteInstaller::OnServiceWorkerVersionUpdate, + this), + base::BindRepeating(&SelfDeleteInstaller::OnServiceWorkerError, this)); service_worker_watcher_->Start(); blink::mojom::ServiceWorkerRegistrationOptions option; @@ -81,7 +83,7 @@ class SelfDeleteInstaller this)); } - void onServiceWorkerRegistration( + void OnServiceWorkerRegistration( const std::vector<ServiceWorkerRegistrationInfo>& info) { DCHECK_CURRENTLY_ON(BrowserThread::UI); @@ -91,7 +93,7 @@ class SelfDeleteInstaller } } - void onServiceWorkerVersionUpdate( + void OnServiceWorkerVersionUpdate( const std::vector<ServiceWorkerVersionInfo>& info) { DCHECK_CURRENTLY_ON(BrowserThread::UI); @@ -104,7 +106,7 @@ class SelfDeleteInstaller } } - void onServiceWorkerError( + void OnServiceWorkerError( int64_t registration_id, int64_t version_id, const ServiceWorkerContextCoreObserver::ErrorInfo& error_info) { diff --git a/content/browser/permissions/permission_controller_impl_unittest.cc b/content/browser/permissions/permission_controller_impl_unittest.cc index 2685e74920e0d..571e4d8d6b671 100644 --- a/content/browser/permissions/permission_controller_impl_unittest.cc +++ b/content/browser/permissions/permission_controller_impl_unittest.cc @@ -300,7 +300,7 @@ TEST_F(PermissionControllerImplTest, TEST_F(PermissionControllerImplTest, NotifyChangedSubscriptionsCallsOnChangeOnly) { using PermissionStatusCallback = - base::Callback<void(blink::mojom::PermissionStatus)>; + base::RepeatingCallback<void(blink::mojom::PermissionStatus)>; GURL kUrl = GURL(kTestUrl); url::Origin kTestOrigin = url::Origin::Create(kUrl); diff --git a/content/browser/presentation/presentation_service_impl.cc b/content/browser/presentation/presentation_service_impl.cc index bb1200c3f673e..f8ffc4ca19f75 100644 --- a/content/browser/presentation/presentation_service_impl.cc +++ b/content/browser/presentation/presentation_service_impl.cc @@ -165,8 +165,9 @@ void PresentationServiceImpl::SetReceiver( presentation_receiver_remote_.set_disconnect_handler(base::BindOnce( &PresentationServiceImpl::OnConnectionError, base::Unretained(this))); receiver_delegate_->RegisterReceiverConnectionAvailableCallback( - base::Bind(&PresentationServiceImpl::OnReceiverConnectionAvailable, - weak_factory_.GetWeakPtr())); + base::BindRepeating( + &PresentationServiceImpl::OnReceiverConnectionAvailable, + weak_factory_.GetWeakPtr())); } void PresentationServiceImpl::ListenForScreenAvailability(const GURL& url) { @@ -292,8 +293,8 @@ void PresentationServiceImpl::ListenForConnectionStateChange( if (controller_delegate_) { controller_delegate_->ListenForConnectionStateChange( render_process_id_, render_frame_id_, connection, - base::Bind(&PresentationServiceImpl::OnConnectionStateChanged, - weak_factory_.GetWeakPtr(), connection)); + base::BindRepeating(&PresentationServiceImpl::OnConnectionStateChanged, + weak_factory_.GetWeakPtr(), connection)); } } @@ -373,9 +374,9 @@ void PresentationServiceImpl::SetDefaultPresentationUrls( presentation_urls, render_frame_host_->GetLastCommittedOrigin()); controller_delegate_->SetDefaultPresentationUrls( - request, - base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted, - weak_factory_.GetWeakPtr())); + request, base::BindRepeating( + &PresentationServiceImpl::OnDefaultPresentationStarted, + weak_factory_.GetWeakPtr())); } void PresentationServiceImpl::CloseConnection( diff --git a/content/browser/push_messaging/push_messaging_manager.cc b/content/browser/push_messaging/push_messaging_manager.cc index 6e63b19c05223..2be315afe7d43 100644 --- a/content/browser/push_messaging/push_messaging_manager.cc +++ b/content/browser/push_messaging/push_messaging_manager.cc @@ -462,10 +462,10 @@ void PushMessagingManager::Core::RegisterOnUI( ->RequestPermission( PermissionType::NOTIFICATIONS, render_frame_host, data.requesting_origin, data.user_gesture, - base::Bind(&PushMessagingManager::Core:: - DidRequestPermissionInIncognito, - weak_factory_ui_to_ui_.GetWeakPtr(), - base::Passed(&data))); + base::BindOnce(&PushMessagingManager::Core:: + DidRequestPermissionInIncognito, + weak_factory_ui_to_ui_.GetWeakPtr(), + base::Passed(&data))); } } } @@ -480,13 +480,13 @@ void PushMessagingManager::Core::RegisterOnUI( push_service->SubscribeFromDocument( requesting_origin, registration_id, render_process_id_, render_frame_id_, std::move(options), data.user_gesture, - base::Bind(&Core::DidRegister, weak_factory_ui_to_ui_.GetWeakPtr(), - base::Passed(&data))); + base::BindOnce(&Core::DidRegister, weak_factory_ui_to_ui_.GetWeakPtr(), + base::Passed(&data))); } else { push_service->SubscribeFromWorker( requesting_origin, registration_id, std::move(options), - base::Bind(&Core::DidRegister, weak_factory_ui_to_ui_.GetWeakPtr(), - base::Passed(&data))); + base::BindOnce(&Core::DidRegister, weak_factory_ui_to_ui_.GetWeakPtr(), + base::Passed(&data))); } } @@ -681,9 +681,9 @@ void PushMessagingManager::Core::UnregisterFromService( push_service->Unsubscribe( blink::mojom::PushUnregistrationReason::JAVASCRIPT_API, requesting_origin, service_worker_registration_id, sender_id, - base::Bind(&Core::DidUnregisterFromService, - weak_factory_ui_to_ui_.GetWeakPtr(), base::Passed(&callback), - service_worker_registration_id)); + base::BindOnce(&Core::DidUnregisterFromService, + weak_factory_ui_to_ui_.GetWeakPtr(), + base::Passed(&callback), service_worker_registration_id)); } void PushMessagingManager::Core::DidUnregisterFromService( @@ -787,14 +787,14 @@ void PushMessagingManager::DidGetSubscription( RunOrPostTaskOnThread( FROM_HERE, BrowserThread::UI, - base::BindOnce(&Core::GetSubscriptionInfoOnUI, - base::Unretained(ui_core_.get()), origin, - service_worker_registration_id, application_server_key, - push_subscription_id, - base::Bind(&Core::GetSubscriptionDidGetInfoOnUI, - ui_core_weak_ptr_, base::Passed(&callback), - origin, service_worker_registration_id, - application_server_key))); + base::BindOnce( + &Core::GetSubscriptionInfoOnUI, base::Unretained(ui_core_.get()), + origin, service_worker_registration_id, application_server_key, + push_subscription_id, + base::BindOnce(&Core::GetSubscriptionDidGetInfoOnUI, + ui_core_weak_ptr_, base::Passed(&callback), origin, + service_worker_registration_id, + application_server_key))); return; } @@ -888,13 +888,13 @@ void PushMessagingManager::Core::GetSubscriptionDidGetInfoOnUI( blink::mojom::PushGetRegistrationStatus status = blink::mojom::PushGetRegistrationStatus::STORAGE_CORRUPT; - push_service->Unsubscribe(blink::mojom::PushUnregistrationReason:: - GET_SUBSCRIPTION_STORAGE_CORRUPT, - origin, service_worker_registration_id, - application_server_key, - base::Bind(&Core::GetSubscriptionDidUnsubscribe, - weak_factory_ui_to_ui_.GetWeakPtr(), - base::Passed(&callback), status)); + push_service->Unsubscribe( + blink::mojom::PushUnregistrationReason:: + GET_SUBSCRIPTION_STORAGE_CORRUPT, + origin, service_worker_registration_id, application_server_key, + base::BindOnce(&Core::GetSubscriptionDidUnsubscribe, + weak_factory_ui_to_ui_.GetWeakPtr(), + base::Passed(&callback), status)); RecordGetRegistrationStatus(status); } diff --git a/content/browser/push_messaging/push_messaging_router.cc b/content/browser/push_messaging/push_messaging_router.cc index d77cf069da272..bb29237824de4 100644 --- a/content/browser/push_messaging/push_messaging_router.cc +++ b/content/browser/push_messaging/push_messaging_router.cc @@ -25,13 +25,14 @@ namespace content { namespace { void RunDeliverCallback( - const PushMessagingRouter::DeliverMessageCallback& deliver_message_callback, + PushMessagingRouter::DeliverMessageCallback deliver_message_callback, blink::mojom::PushDeliveryStatus delivery_status) { DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); // Use PostTask() instead of RunOrPostTaskOnThread() to ensure the callback // is called asynchronously. - base::PostTask(FROM_HERE, {BrowserThread::UI}, - base::BindOnce(deliver_message_callback, delivery_status)); + base::PostTask( + FROM_HERE, {BrowserThread::UI}, + base::BindOnce(std::move(deliver_message_callback), delivery_status)); } } // namespace @@ -43,7 +44,7 @@ void PushMessagingRouter::DeliverMessage( int64_t service_worker_registration_id, const std::string& message_id, base::Optional<std::string> payload, - const DeliverMessageCallback& deliver_message_callback) { + DeliverMessageCallback deliver_message_callback) { DCHECK_CURRENTLY_ON(BrowserThread::UI); StoragePartition* partition = BrowserContext::GetStoragePartitionForSite(browser_context, origin); @@ -60,7 +61,7 @@ void PushMessagingRouter::DeliverMessage( std::move(service_worker_context), std::move(devtools_context), origin, service_worker_registration_id, message_id, - std::move(payload), deliver_message_callback)); + std::move(payload), std::move(deliver_message_callback))); } // static @@ -71,7 +72,7 @@ void PushMessagingRouter::FindServiceWorkerRegistration( int64_t service_worker_registration_id, const std::string& message_id, base::Optional<std::string> payload, - const DeliverMessageCallback& deliver_message_callback) { + DeliverMessageCallback deliver_message_callback) { DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); // Try to acquire the registration from storage. If it's already live we'll // receive it right away. If not, it will be revived from storage. @@ -80,7 +81,7 @@ void PushMessagingRouter::FindServiceWorkerRegistration( base::BindOnce( &PushMessagingRouter::FindServiceWorkerRegistrationCallback, std::move(devtools_context), message_id, std::move(payload), - deliver_message_callback)); + std::move(deliver_message_callback))); } // static @@ -88,19 +89,19 @@ void PushMessagingRouter::FindServiceWorkerRegistrationCallback( scoped_refptr<DevToolsBackgroundServicesContextImpl> devtools_context, const std::string& message_id, base::Optional<std::string> payload, - const DeliverMessageCallback& deliver_message_callback, + DeliverMessageCallback deliver_message_callback, blink::ServiceWorkerStatusCode service_worker_status, scoped_refptr<ServiceWorkerRegistration> service_worker_registration) { DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); UMA_HISTOGRAM_ENUMERATION("PushMessaging.DeliveryStatus.FindServiceWorker", service_worker_status); if (service_worker_status == blink::ServiceWorkerStatusCode::kErrorNotFound) { - RunDeliverCallback(deliver_message_callback, + RunDeliverCallback(std::move(deliver_message_callback), blink::mojom::PushDeliveryStatus::NO_SERVICE_WORKER); return; } if (service_worker_status != blink::ServiceWorkerStatusCode::kOk) { - RunDeliverCallback(deliver_message_callback, + RunDeliverCallback(std::move(deliver_message_callback), blink::mojom::PushDeliveryStatus::SERVICE_WORKER_ERROR); return; } @@ -118,7 +119,7 @@ void PushMessagingRouter::FindServiceWorkerRegistrationCallback( base::WrapRefCounted(version), std::move(service_worker_registration), std::move(devtools_context), message_id, - std::move(payload), deliver_message_callback)); + std::move(payload), std::move(deliver_message_callback))); } // static @@ -128,14 +129,14 @@ void PushMessagingRouter::DeliverMessageToWorker( scoped_refptr<DevToolsBackgroundServicesContextImpl> devtools_context, const std::string& message_id, base::Optional<std::string> payload, - const DeliverMessageCallback& deliver_message_callback, + DeliverMessageCallback deliver_message_callback, blink::ServiceWorkerStatusCode start_worker_status) { DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); if (start_worker_status != blink::ServiceWorkerStatusCode::kOk) { DeliverMessageEnd(std::move(service_worker), std::move(service_worker_registration), std::move(devtools_context), message_id, - deliver_message_callback, start_worker_status); + std::move(deliver_message_callback), start_worker_status); return; } @@ -143,7 +144,7 @@ void PushMessagingRouter::DeliverMessageToWorker( ServiceWorkerMetrics::EventType::PUSH, base::BindOnce(&PushMessagingRouter::DeliverMessageEnd, service_worker, std::move(service_worker_registration), devtools_context, - message_id, deliver_message_callback), + message_id, std::move(deliver_message_callback)), base::TimeDelta::FromSeconds(blink::mojom::kPushEventTimeoutSeconds), ServiceWorkerVersion::KILL_ON_TIMEOUT); @@ -168,7 +169,7 @@ void PushMessagingRouter::DeliverMessageEnd( scoped_refptr<ServiceWorkerRegistration> service_worker_registration, scoped_refptr<DevToolsBackgroundServicesContextImpl> devtools_context, const std::string& message_id, - const DeliverMessageCallback& deliver_message_callback, + DeliverMessageCallback deliver_message_callback, blink::ServiceWorkerStatusCode service_worker_status) { DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); UMA_HISTOGRAM_ENUMERATION("PushMessaging.DeliveryStatus.ServiceWorkerEvent", @@ -215,7 +216,7 @@ void PushMessagingRouter::DeliverMessageEnd( delivery_status = blink::mojom::PushDeliveryStatus::SERVICE_WORKER_ERROR; break; } - RunDeliverCallback(deliver_message_callback, delivery_status); + RunDeliverCallback(std::move(deliver_message_callback), delivery_status); if (devtools_context->IsRecording( DevToolsBackgroundService::kPushMessaging) && diff --git a/content/browser/push_messaging/push_messaging_router.h b/content/browser/push_messaging/push_messaging_router.h index 13b1f106169be..9b34fda852562 100644 --- a/content/browser/push_messaging/push_messaging_router.h +++ b/content/browser/push_messaging/push_messaging_router.h @@ -31,18 +31,17 @@ class ServiceWorkerVersion; class PushMessagingRouter { public: using DeliverMessageCallback = - base::Callback<void(blink::mojom::PushDeliveryStatus)>; + base::OnceCallback<void(blink::mojom::PushDeliveryStatus)>; // Delivers a push message with |data| to the Service Worker identified by // |origin| and |service_worker_registration_id|. Must be called on the UI // thread. - static void DeliverMessage( - BrowserContext* browser_context, - const GURL& origin, - int64_t service_worker_registration_id, - const std::string& message_id, - base::Optional<std::string> payload, - const DeliverMessageCallback& deliver_message_callback); + static void DeliverMessage(BrowserContext* browser_context, + const GURL& origin, + int64_t service_worker_registration_id, + const std::string& message_id, + base::Optional<std::string> payload, + DeliverMessageCallback deliver_message_callback); private: // Attempts to find a Service Worker registration so that a push event can be @@ -54,7 +53,7 @@ class PushMessagingRouter { int64_t service_worker_registration_id, const std::string& message_id, base::Optional<std::string> payload, - const DeliverMessageCallback& deliver_message_callback); + DeliverMessageCallback deliver_message_callback); // If a registration was successfully retrieved, dispatches a push event with // |data| on the Service Worker identified by |service_worker_registration|. @@ -63,7 +62,7 @@ class PushMessagingRouter { scoped_refptr<DevToolsBackgroundServicesContextImpl> devtools_context, const std::string& message_id, base::Optional<std::string> payload, - const DeliverMessageCallback& deliver_message_callback, + DeliverMessageCallback deliver_message_callback, blink::ServiceWorkerStatusCode service_worker_status, scoped_refptr<ServiceWorkerRegistration> service_worker_registration); @@ -75,7 +74,7 @@ class PushMessagingRouter { scoped_refptr<DevToolsBackgroundServicesContextImpl> devtools_context, const std::string& message_id, base::Optional<std::string> payload, - const DeliverMessageCallback& deliver_message_callback, + DeliverMessageCallback deliver_message_callback, blink::ServiceWorkerStatusCode start_worker_status); // Gets called asynchronously after the Service Worker has dispatched the push @@ -85,7 +84,7 @@ class PushMessagingRouter { scoped_refptr<ServiceWorkerRegistration> service_worker_registration, scoped_refptr<DevToolsBackgroundServicesContextImpl> devtools_context, const std::string& message_id, - const DeliverMessageCallback& deliver_message_callback, + DeliverMessageCallback deliver_message_callback, blink::ServiceWorkerStatusCode service_worker_status); DISALLOW_IMPLICIT_CONSTRUCTORS(PushMessagingRouter); diff --git a/content/browser/tracing/tracing_ui.cc b/content/browser/tracing/tracing_ui.cc index 39806147437b0..5214880f9f67f 100644 --- a/content/browser/tracing/tracing_ui.cc +++ b/content/browser/tracing/tracing_ui.cc @@ -43,7 +43,7 @@ namespace content { namespace { -void OnGotCategories(const WebUIDataSource::GotDataCallback& callback, +void OnGotCategories(WebUIDataSource::GotDataCallback callback, const std::set<std::string>& categorySet) { base::ListValue category_list; for (auto it = categorySet.begin(); it != categorySet.end(); it++) { @@ -52,34 +52,35 @@ void OnGotCategories(const WebUIDataSource::GotDataCallback& callback, scoped_refptr<base::RefCountedString> res(new base::RefCountedString()); base::JSONWriter::Write(category_list, &res->data()); - callback.Run(res); + std::move(callback).Run(res); } -void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback); +void OnRecordingEnabledAck(WebUIDataSource::GotDataCallback callback); bool BeginRecording(const std::string& data64, - const WebUIDataSource::GotDataCallback& callback) { + WebUIDataSource::GotDataCallback callback) { base::trace_event::TraceConfig trace_config("", ""); if (!TracingUI::GetTracingOptions(data64, &trace_config)) return false; return TracingController::GetInstance()->StartTracing( - trace_config, base::BindOnce(&OnRecordingEnabledAck, callback)); + trace_config, + base::BindOnce(&OnRecordingEnabledAck, std::move(callback))); } -void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback) { - callback.Run( +void OnRecordingEnabledAck(WebUIDataSource::GotDataCallback callback) { + std::move(callback).Run( scoped_refptr<base::RefCountedMemory>(new base::RefCountedString())); } -void OnTraceBufferUsageResult(const WebUIDataSource::GotDataCallback& callback, +void OnTraceBufferUsageResult(WebUIDataSource::GotDataCallback callback, float percent_full, size_t approximate_event_count) { std::string str = base::NumberToString(percent_full); - callback.Run(base::RefCountedString::TakeString(&str)); + std::move(callback).Run(base::RefCountedString::TakeString(&str)); } -void OnTraceBufferStatusResult(const WebUIDataSource::GotDataCallback& callback, +void OnTraceBufferStatusResult(WebUIDataSource::GotDataCallback callback, float percent_full, size_t approximate_event_count) { base::DictionaryValue status; @@ -91,45 +92,44 @@ void OnTraceBufferStatusResult(const WebUIDataSource::GotDataCallback& callback, base::RefCountedString* status_base64 = new base::RefCountedString(); base::Base64Encode(status_json, &status_base64->data()); - callback.Run(status_base64); + std::move(callback).Run(status_base64); } -void TracingCallbackWrapperBase64( - const WebUIDataSource::GotDataCallback& callback, - std::unique_ptr<std::string> data) { +void TracingCallbackWrapperBase64(WebUIDataSource::GotDataCallback callback, + std::unique_ptr<std::string> data) { base::RefCountedString* data_base64 = new base::RefCountedString(); base::Base64Encode(*data, &data_base64->data()); - callback.Run(data_base64); + std::move(callback).Run(data_base64); } bool OnBeginJSONRequest(const std::string& path, - const WebUIDataSource::GotDataCallback& callback) { + WebUIDataSource::GotDataCallback* callback) { if (path == "json/categories") { return TracingController::GetInstance()->GetCategories( - base::BindOnce(OnGotCategories, callback)); + base::BindOnce(OnGotCategories, std::move(*callback))); } const char kBeginRecordingPath[] = "json/begin_recording?"; if (base::StartsWith(path, kBeginRecordingPath, base::CompareCase::SENSITIVE)) { std::string data = path.substr(strlen(kBeginRecordingPath)); - return BeginRecording(data, callback); + return BeginRecording(data, std::move(*callback)); } if (path == "json/get_buffer_percent_full") { return TracingController::GetInstance()->GetTraceBufferUsage( - base::BindOnce(OnTraceBufferUsageResult, callback)); + base::BindOnce(OnTraceBufferUsageResult, std::move(*callback))); } if (path == "json/get_buffer_status") { return TracingController::GetInstance()->GetTraceBufferUsage( - base::BindOnce(OnTraceBufferStatusResult, callback)); + base::BindOnce(OnTraceBufferStatusResult, std::move(*callback))); } if (path == "json/end_recording_compressed") { if (!TracingController::GetInstance()->IsTracing()) return false; scoped_refptr<TracingController::TraceDataEndpoint> data_endpoint = TracingControllerImpl::CreateCompressedStringEndpoint( - TracingControllerImpl::CreateCallbackEndpoint( - base::Bind(TracingCallbackWrapperBase64, callback)), + TracingControllerImpl::CreateCallbackEndpoint(base::BindOnce( + TracingCallbackWrapperBase64, std::move(*callback))), false /* compress_with_background_priority */); return TracingController::GetInstance()->StopTracing(data_endpoint); } @@ -143,11 +143,13 @@ bool OnShouldHandleRequest(const std::string& path) { } void OnTracingRequest(const std::string& path, - const WebUIDataSource::GotDataCallback& callback) { + WebUIDataSource::GotDataCallback callback) { DCHECK(OnShouldHandleRequest(path)); - if (!OnBeginJSONRequest(path, callback)) { + if (!OnBeginJSONRequest(path, &callback)) { + // OnBeginJSONRequest only consumes |callback| if it returns true. + DCHECK(callback); std::string error("##ERROR##"); - callback.Run(base::RefCountedString::TakeString(&error)); + std::move(callback).Run(base::RefCountedString::TakeString(&error)); } } diff --git a/content/browser/web_contents/web_contents_android.cc b/content/browser/web_contents/web_contents_android.cc index c767ebfb76c1e..e2754d8b0d92d 100644 --- a/content/browser/web_contents/web_contents_android.cc +++ b/content/browser/web_contents/web_contents_android.cc @@ -657,10 +657,10 @@ int WebContentsAndroid::DownloadImage( const uint32_t preferred_size = 0; return web_contents_->DownloadImage( url, is_fav_icon, preferred_size, max_bitmap_size, bypass_cache, - base::Bind(&WebContentsAndroid::OnFinishDownloadImage, - weak_factory_.GetWeakPtr(), - ScopedJavaGlobalRef<jobject>(env, obj), - ScopedJavaGlobalRef<jobject>(env, jcallback))); + base::BindOnce(&WebContentsAndroid::OnFinishDownloadImage, + weak_factory_.GetWeakPtr(), + ScopedJavaGlobalRef<jobject>(env, obj), + ScopedJavaGlobalRef<jobject>(env, jcallback))); } void WebContentsAndroid::SetHasPersistentVideo( diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index 6c06d0e6c0ca3..ff200c5d38b9c 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -607,9 +607,8 @@ WebContentsImpl::WebContentsImpl(BrowserContext* browser_context) showing_context_menu_(false), text_autosizer_page_info_({0, 0, 1.f}), had_inner_webcontents_(false) { - frame_tree_.SetFrameRemoveListener( - base::Bind(&WebContentsImpl::OnFrameRemoved, - base::Unretained(this))); + frame_tree_.SetFrameRemoveListener(base::BindRepeating( + &WebContentsImpl::OnFrameRemoved, base::Unretained(this))); #if BUILDFLAG(ENABLE_PLUGINS) pepper_playback_observer_.reset(new PepperPlaybackObserver(this)); #endif @@ -1218,14 +1217,14 @@ void WebContentsImpl::UpdateZoomIfNecessary(const std::string& scheme, } #endif // !defined(OS_ANDROID) -base::Closure WebContentsImpl::AddBindingSet( +base::OnceClosure WebContentsImpl::AddBindingSet( const std::string& interface_name, WebContentsBindingSet* binding_set) { auto result = binding_sets_.insert(std::make_pair(interface_name, binding_set)); DCHECK(result.second); - return base::Bind(&WebContentsImpl::RemoveBindingSet, - weak_factory_.GetWeakPtr(), interface_name); + return base::BindOnce(&WebContentsImpl::RemoveBindingSet, + weak_factory_.GetWeakPtr(), interface_name); } WebContentsBindingSet* WebContentsImpl::GetBindingSet( diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index 970ffc6a05bdf..4974e934d3561 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -271,8 +271,8 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, // // |binding_set| is not owned and must either outlive this WebContents or be // explicitly removed before being destroyed. - base::Closure AddBindingSet(const std::string& interface_name, - WebContentsBindingSet* binding_set); + base::OnceClosure AddBindingSet(const std::string& interface_name, + WebContentsBindingSet* binding_set); // Accesses a WebContentsBindingSet for a specific interface on this // WebContents. Returns null of there is no registered binder for the diff --git a/content/browser/web_contents/web_contents_impl_browsertest.cc b/content/browser/web_contents/web_contents_impl_browsertest.cc index 6494d6007c6e1..6c39c9eb3bc26 100644 --- a/content/browser/web_contents/web_contents_impl_browsertest.cc +++ b/content/browser/web_contents/web_contents_impl_browsertest.cc @@ -2015,7 +2015,7 @@ struct FirstVisuallyNonEmptyPaintObserver : public WebContentsObserver { void DidFirstVisuallyNonEmptyPaint() override { did_fist_visually_non_empty_paint_ = true; - on_did_first_visually_non_empty_paint_.Run(); + std::move(on_did_first_visually_non_empty_paint_).Run(); } void WaitForDidFirstVisuallyNonEmptyPaint() { @@ -2026,7 +2026,7 @@ struct FirstVisuallyNonEmptyPaintObserver : public WebContentsObserver { run_loop.Run(); } - base::Closure on_did_first_visually_non_empty_paint_; + base::OnceClosure on_did_first_visually_non_empty_paint_; bool did_fist_visually_non_empty_paint_; }; @@ -2127,10 +2127,10 @@ class MockPageScaleObserver : public WebContentsObserver { private: void GotPageScaleUpdate() { got_page_scale_update_ = true; - on_page_scale_update_.Run(); + std::move(on_page_scale_update_).Run(); } - base::Closure on_page_scale_update_; + base::OnceClosure on_page_scale_update_; bool got_page_scale_update_; }; @@ -2844,7 +2844,7 @@ void DownloadImageTestInternal(Shell* shell, loop_runner->Run(); } -void ExpectNoValidImageCallback(const base::Closure& quit_closure, +void ExpectNoValidImageCallback(base::OnceClosure quit_closure, int id, int status_code, const GURL& image_url, @@ -2853,7 +2853,7 @@ void ExpectNoValidImageCallback(const base::Closure& quit_closure, EXPECT_EQ(200, status_code); EXPECT_TRUE(bitmap.empty()); EXPECT_TRUE(sizes.empty()); - quit_closure.Run(); + std::move(quit_closure).Run(); } void ExpectSingleValidImageCallback(base::OnceClosure quit_closure, diff --git a/content/browser/web_package/mock_web_bundle_reader_factory.cc b/content/browser/web_package/mock_web_bundle_reader_factory.cc index 2a9692f402e1a..25f7add11dfc0 100644 --- a/content/browser/web_package/mock_web_bundle_reader_factory.cc +++ b/content/browser/web_package/mock_web_bundle_reader_factory.cc @@ -184,7 +184,7 @@ class MockWebBundleReaderFactoryImpl final : public MockWebBundleReaderFactory { base::RunLoop run_loop; reader->ReadMetadata(base::BindOnce( - [](base::Closure quit_closure, + [](base::OnceClosure quit_closure, WebBundleReader::MetadataCallback callback, data_decoder::mojom::BundleMetadataParseErrorPtr error) { std::move(callback).Run(std::move(error)); @@ -207,7 +207,7 @@ class MockWebBundleReaderFactoryImpl final : public MockWebBundleReaderFactory { base::RunLoop run_loop; reader->ReadResponse( url, base::BindOnce( - [](base::Closure quit_closure, + [](base::OnceClosure quit_closure, WebBundleReader::ResponseCallback callback, data_decoder::mojom::BundleResponsePtr response, data_decoder::mojom::BundleResponseParseErrorPtr error) { diff --git a/content/browser/web_package/web_bundle_reader_unittest.cc b/content/browser/web_package/web_bundle_reader_unittest.cc index 420f459e79292..2d2f410868599 100644 --- a/content/browser/web_package/web_bundle_reader_unittest.cc +++ b/content/browser/web_package/web_bundle_reader_unittest.cc @@ -177,7 +177,7 @@ TEST_F(WebBundleReaderTest, ReadResponseBody) { GetReader()->ReadResponseBody( std::move(response), std::move(producer), base::BindOnce( - [](base::Closure quit_closure, net::Error* callback_result, + [](base::OnceClosure quit_closure, net::Error* callback_result, net::Error result) { *callback_result = result; std::move(quit_closure).Run(); diff --git a/content/browser/web_package/web_bundle_url_loader_factory_unittest.cc b/content/browser/web_package/web_bundle_url_loader_factory_unittest.cc index c6c5ae3f5f223..64f77f59426db 100644 --- a/content/browser/web_package/web_bundle_url_loader_factory_unittest.cc +++ b/content/browser/web_package/web_bundle_url_loader_factory_unittest.cc @@ -54,7 +54,7 @@ class WebBundleURLLoaderFactoryTest : public testing::Test { mock_factory_->ReadAndFullfillMetadata( reader_, std::move(metadata), base::BindOnce( - [](base::Closure quit_closure, + [](base::OnceClosure quit_closure, data_decoder::mojom::BundleMetadataParseErrorPtr error) { std::move(quit_closure).Run(); }, diff --git a/content/browser/webui/shared_resources_data_source.cc b/content/browser/webui/shared_resources_data_source.cc index b8e8f5b6c5c51..4412ba642fbed 100644 --- a/content/browser/webui/shared_resources_data_source.cc +++ b/content/browser/webui/shared_resources_data_source.cc @@ -294,7 +294,7 @@ std::string SharedResourcesDataSource::GetSource() { void SharedResourcesDataSource::StartDataRequest( const GURL& url, const WebContents::Getter& wc_getter, - const URLDataSource::GotDataCallback& callback) { + URLDataSource::GotDataCallback callback) { const std::string path = URLDataSource::URLToRequestPath(url); std::string updated_path = path; #if defined(OS_CHROMEOS) @@ -321,7 +321,7 @@ void SharedResourcesDataSource::StartDataRequest( bytes = GetContentClient()->GetDataResourceBytes(idr); } - callback.Run(std::move(bytes)); + std::move(callback).Run(std::move(bytes)); } bool SharedResourcesDataSource::AllowCaching() { diff --git a/content/browser/webui/shared_resources_data_source.h b/content/browser/webui/shared_resources_data_source.h index 07a4fed22055f..8473cf734893e 100644 --- a/content/browser/webui/shared_resources_data_source.h +++ b/content/browser/webui/shared_resources_data_source.h @@ -21,10 +21,9 @@ class SharedResourcesDataSource : public URLDataSource { // URLDataSource implementation. std::string GetSource() override; - void StartDataRequest( - const GURL& url, - const WebContents::Getter& wc_getter, - const URLDataSource::GotDataCallback& callback) override; + void StartDataRequest(const GURL& url, + const WebContents::Getter& wc_getter, + URLDataSource::GotDataCallback callback) override; bool AllowCaching() override; std::string GetMimeType(const std::string& path) override; bool ShouldServeMimeTypeAsContentTypeHeader() override; diff --git a/content/browser/webui/web_ui_browsertest_util.cc b/content/browser/webui/web_ui_browsertest_util.cc index 27e6e4f547c8e..0b2a161660b3e 100644 --- a/content/browser/webui/web_ui_browsertest_util.cc +++ b/content/browser/webui/web_ui_browsertest_util.cc @@ -30,11 +30,11 @@ namespace content { namespace { void GetResource(const std::string& id, - const WebUIDataSource::GotDataCallback& callback) { + WebUIDataSource::GotDataCallback callback) { base::ScopedAllowBlockingForTesting allow_blocking; if (id == "error") { - callback.Run(nullptr); + std::move(callback).Run(nullptr); return; } @@ -46,7 +46,7 @@ void GetResource(const std::string& id, base::RefCountedString* ref_contents = new base::RefCountedString; ref_contents->data() = contents; - callback.Run(ref_contents); + std::move(callback).Run(ref_contents); } struct WebUIControllerConfig { diff --git a/content/browser/webui/web_ui_data_source_impl.cc b/content/browser/webui/web_ui_data_source_impl.cc index ca4eac89dff0e..ef62de675ee2f 100644 --- a/content/browser/webui/web_ui_data_source_impl.cc +++ b/content/browser/webui/web_ui_data_source_impl.cc @@ -67,11 +67,10 @@ class WebUIDataSourceImpl::InternalDataSource : public URLDataSource { std::string GetMimeType(const std::string& path) override { return parent_->GetMimeType(path); } - void StartDataRequest( - const GURL& url, - const WebContents::Getter& wc_getter, - const URLDataSource::GotDataCallback& callback) override { - return parent_->StartDataRequest(url, wc_getter, callback); + void StartDataRequest(const GURL& url, + const WebContents::Getter& wc_getter, + URLDataSource::GotDataCallback callback) override { + return parent_->StartDataRequest(url, wc_getter, std::move(callback)); } bool ShouldReplaceExistingSource() override { return parent_->replace_existing_source_; @@ -275,11 +274,11 @@ std::string WebUIDataSourceImpl::GetMimeType(const std::string& path) const { void WebUIDataSourceImpl::StartDataRequest( const GURL& url, const WebContents::Getter& wc_getter, - const URLDataSource::GotDataCallback& callback) { + URLDataSource::GotDataCallback callback) { const std::string path = URLDataSource::URLToRequestPath(url); if (!should_handle_request_callback_.is_null() && should_handle_request_callback_.Run(path)) { - filter_callback_.Run(path, callback); + filter_callback_.Run(path, std::move(callback)); return; } @@ -288,7 +287,7 @@ void WebUIDataSourceImpl::StartDataRequest( if (use_strings_js_) { bool from_js_module = path == "strings.m.js"; if (from_js_module || path == "strings.js") { - SendLocalizedStringsAsJSON(callback, from_js_module); + SendLocalizedStringsAsJSON(std::move(callback), from_js_module); return; } } @@ -297,15 +296,15 @@ void WebUIDataSourceImpl::StartDataRequest( DCHECK_NE(resource_id, -1) << " for " << path; scoped_refptr<base::RefCountedMemory> response( GetContentClient()->GetDataResourceBytes(resource_id)); - callback.Run(response.get()); + std::move(callback).Run(response.get()); } void WebUIDataSourceImpl::SendLocalizedStringsAsJSON( - const URLDataSource::GotDataCallback& callback, + URLDataSource::GotDataCallback callback, bool from_js_module) { std::string template_data; webui::AppendJsonJS(&localized_strings_, &template_data, from_js_module); - callback.Run(base::RefCountedString::TakeString(&template_data)); + std::move(callback).Run(base::RefCountedString::TakeString(&template_data)); } const base::DictionaryValue* WebUIDataSourceImpl::GetLocalizedStrings() const { diff --git a/content/browser/webui/web_ui_data_source_impl.h b/content/browser/webui/web_ui_data_source_impl.h index f64f9e56ea68a..4e2cfa6c71404 100644 --- a/content/browser/webui/web_ui_data_source_impl.h +++ b/content/browser/webui/web_ui_data_source_impl.h @@ -67,9 +67,8 @@ class CONTENT_EXPORT WebUIDataSourceImpl : public URLDataSourceImpl, ~WebUIDataSourceImpl() override; // Completes a request by sending our dictionary of localized strings. - void SendLocalizedStringsAsJSON( - const URLDataSource::GotDataCallback& callback, - bool from_js_module); + void SendLocalizedStringsAsJSON(URLDataSource::GotDataCallback callback, + bool from_js_module); // Protected for testing. virtual const base::DictionaryValue* GetLocalizedStrings() const; @@ -85,7 +84,7 @@ class CONTENT_EXPORT WebUIDataSourceImpl : public URLDataSourceImpl, std::string GetMimeType(const std::string& path) const; void StartDataRequest(const GURL& url, const WebContents::Getter& wc_getter, - const URLDataSource::GotDataCallback& callback); + URLDataSource::GotDataCallback callback); int PathToIdrOrDefault(const std::string& path) const; diff --git a/content/browser/webui/web_ui_data_source_unittest.cc b/content/browser/webui/web_ui_data_source_unittest.cc index d330d4e22cb43..795c73dfcd183 100644 --- a/content/browser/webui/web_ui_data_source_unittest.cc +++ b/content/browser/webui/web_ui_data_source_unittest.cc @@ -54,9 +54,9 @@ class WebUIDataSourceTest : public testing::Test { WebUIDataSourceImpl* source() { return source_.get(); } void StartDataRequest(const std::string& path, - const URLDataSource::GotDataCallback& callback) { + URLDataSource::GotDataCallback callback) { source_->StartDataRequest(GURL("https://any-host/" + path), - WebContents::Getter(), callback); + WebContents::Getter(), std::move(callback)); } std::string GetMimeType(const std::string& path) const { @@ -64,7 +64,7 @@ class WebUIDataSourceTest : public testing::Test { } void HandleRequest(const std::string& path, - const WebUIDataSourceImpl::GotDataCallback&) { + WebUIDataSourceImpl::GotDataCallback) { request_path_ = path; } @@ -100,12 +100,12 @@ void EmptyStringsCallback(bool from_js_module, TEST_F(WebUIDataSourceTest, EmptyStrings) { source()->UseStringsJs(); - StartDataRequest("strings.js", base::Bind(&EmptyStringsCallback, false)); + StartDataRequest("strings.js", base::BindOnce(&EmptyStringsCallback, false)); } TEST_F(WebUIDataSourceTest, EmptyModuleStrings) { source()->UseStringsJs(); - StartDataRequest("strings.m.js", base::Bind(&EmptyStringsCallback, true)); + StartDataRequest("strings.m.js", base::BindOnce(&EmptyStringsCallback, true)); } void SomeValuesCallback(scoped_refptr<base::RefCountedMemory> data) { @@ -124,7 +124,7 @@ TEST_F(WebUIDataSourceTest, SomeValues) { source()->AddInteger("debt", -456); source()->AddString("planet", base::ASCIIToUTF16("pluto")); source()->AddLocalizedString("button", kDummyStringId); - StartDataRequest("strings.js", base::Bind(&SomeValuesCallback)); + StartDataRequest("strings.js", base::BindOnce(&SomeValuesCallback)); } void DefaultResourceFoobarCallback(scoped_refptr<base::RefCountedMemory> data) { @@ -140,8 +140,9 @@ void DefaultResourceStringsCallback( TEST_F(WebUIDataSourceTest, DefaultResource) { source()->SetDefaultResource(kDummyDefaultResourceId); - StartDataRequest("foobar", base::Bind(&DefaultResourceFoobarCallback)); - StartDataRequest("strings.js", base::Bind(&DefaultResourceStringsCallback)); + StartDataRequest("foobar", base::BindOnce(&DefaultResourceFoobarCallback)); + StartDataRequest("strings.js", + base::BindOnce(&DefaultResourceStringsCallback)); } void NamedResourceFoobarCallback(scoped_refptr<base::RefCountedMemory> data) { @@ -157,8 +158,8 @@ void NamedResourceStringsCallback(scoped_refptr<base::RefCountedMemory> data) { TEST_F(WebUIDataSourceTest, NamedResource) { source()->SetDefaultResource(kDummyDefaultResourceId); source()->AddResourcePath("foobar", kDummyResourceId); - StartDataRequest("foobar", base::Bind(&NamedResourceFoobarCallback)); - StartDataRequest("strings.js", base::Bind(&NamedResourceStringsCallback)); + StartDataRequest("foobar", base::BindOnce(&NamedResourceFoobarCallback)); + StartDataRequest("strings.js", base::BindOnce(&NamedResourceStringsCallback)); } void NamedResourceWithQueryStringCallback( @@ -171,7 +172,7 @@ TEST_F(WebUIDataSourceTest, NamedResourceWithQueryString) { source()->SetDefaultResource(kDummyDefaultResourceId); source()->AddResourcePath("foobar", kDummyResourceId); StartDataRequest("foobar?query?string", - base::Bind(&NamedResourceWithQueryStringCallback)); + base::BindOnce(&NamedResourceWithQueryStringCallback)); } void WebUIDataSourceTest::RequestFilterQueryStringCallback( @@ -192,8 +193,8 @@ TEST_F(WebUIDataSourceTest, RequestFilterQueryString) { source()->AddResourcePath("foobar", kDummyResourceId); StartDataRequest( "foobar?query?string", - base::Bind(&WebUIDataSourceTest::RequestFilterQueryStringCallback, - base::Unretained(this))); + base::BindOnce(&WebUIDataSourceTest::RequestFilterQueryStringCallback, + base::Unretained(this))); } TEST_F(WebUIDataSourceTest, MimeType) { diff --git a/content/browser/webui/web_ui_mojo_browsertest.cc b/content/browser/webui/web_ui_mojo_browsertest.cc index 74a4aeca64b65..d86c13c6855b9 100644 --- a/content/browser/webui/web_ui_mojo_browsertest.cc +++ b/content/browser/webui/web_ui_mojo_browsertest.cc @@ -62,7 +62,7 @@ base::FilePath GetFilePathForJSResource(const std::string& path) { // The bindings for the page are generated from a .mojom file. This code looks // up the generated file from disk and returns it. void GetResource(const std::string& id, - const WebUIDataSource::GotDataCallback& callback) { + WebUIDataSource::GotDataCallback callback) { base::ScopedAllowBlockingForTesting allow_blocking; std::string contents; @@ -78,7 +78,7 @@ void GetResource(const std::string& id, base::RefCountedString* ref_contents = new base::RefCountedString; ref_contents->data() = contents; - callback.Run(ref_contents); + std::move(callback).Run(ref_contents); } class BrowserTargetImpl : public mojom::BrowserTarget { @@ -124,11 +124,10 @@ class TestWebUIController : public WebUIController { WebUIDataSource* data_source = WebUIDataSource::Create("dummy-web-ui"); data_source->SetRequestFilter( base::BindRepeating([](const std::string& path) { return true; }), - base::BindRepeating( - [](const std::string& id, - const WebUIDataSource::GotDataCallback& callback) { - callback.Run(new base::RefCountedString); - })); + base::BindRepeating([](const std::string& id, + WebUIDataSource::GotDataCallback callback) { + std::move(callback).Run(new base::RefCountedString); + })); WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(), data_source); } diff --git a/content/browser/webui/web_ui_url_loader_factory.cc b/content/browser/webui/web_ui_url_loader_factory.cc index 2f67766b2d920..42a6c932ecb00 100644 --- a/content/browser/webui/web_ui_url_loader_factory.cc +++ b/content/browser/webui/web_ui_url_loader_factory.cc @@ -184,7 +184,7 @@ void StartURLLoader( // request_start response_start WebContents::Getter wc_getter = - base::Bind(WebContents::FromFrameTreeNodeId, frame_tree_node_id); + base::BindRepeating(WebContents::FromFrameTreeNodeId, frame_tree_node_id); bool replace_in_js = source->source()->ShouldReplaceI18nInJS() && @@ -197,9 +197,9 @@ void StartURLLoader( // To keep the same behavior as the old WebUI code, we call the source to get // the value for |replacements| on the IO thread. Since |replacements| is // owned by |source| keep a reference to it in the callback. - auto data_available_callback = - base::Bind(DataAvailable, resource_response, replacements, replace_in_js, - base::RetainedRef(source), base::Passed(&client_remote)); + URLDataSource::GotDataCallback data_available_callback = base::BindOnce( + DataAvailable, resource_response, replacements, replace_in_js, + base::RetainedRef(source), base::Passed(&client_remote)); // TODO(jam): once we only have this code path for WebUI, and not the // URLLRequestJob one, then we should switch data sources to run on the UI diff --git a/content/public/browser/content_browser_client.cc b/content/public/browser/content_browser_client.cc index 06b8121bcb330..a9e1fd367ed02 100644 --- a/content/public/browser/content_browser_client.cc +++ b/content/public/browser/content_browser_client.cc @@ -899,7 +899,7 @@ std::unique_ptr<LoginDelegate> ContentBrowserClient::CreateLoginDelegate( bool ContentBrowserClient::HandleExternalProtocol( const GURL& url, - WebContents::Getter web_contents_getter, + WebContents::OnceGetter web_contents_getter, int child_id, NavigationUIData* navigation_data, bool is_main_frame, diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h index 958c5145bc15b..bc4e6588f1176 100644 --- a/content/public/browser/content_browser_client.h +++ b/content/public/browser/content_browser_client.h @@ -1570,7 +1570,7 @@ class CONTENT_EXPORT ContentBrowserClient { // decisions about whether to allow an external application to launch. virtual bool HandleExternalProtocol( const GURL& url, - base::Callback<WebContents*(void)> web_contents_getter, + base::OnceCallback<WebContents*()> web_contents_getter, int child_id, NavigationUIData* navigation_data, bool is_main_frame, diff --git a/content/public/browser/push_messaging_service.h b/content/public/browser/push_messaging_service.h index 74efe7453aa28..8a7586c6b8898 100644 --- a/content/public/browser/push_messaging_service.h +++ b/content/public/browser/push_messaging_service.h @@ -40,10 +40,10 @@ class CONTENT_EXPORT PushMessagingService { using UnregisterCallback = base::OnceCallback<void(blink::mojom::PushUnregistrationStatus)>; using SubscriptionInfoCallback = - base::Callback<void(bool is_valid, - const GURL& endpoint, - const std::vector<uint8_t>& p256dh, - const std::vector<uint8_t>& auth)>; + base::OnceCallback<void(bool is_valid, + const GURL& endpoint, + const std::vector<uint8_t>& p256dh, + const std::vector<uint8_t>& auth)>; using StringCallback = base::OnceCallback< void(const std::string& data, bool success, bool not_found)>; @@ -80,12 +80,11 @@ class CONTENT_EXPORT PushMessagingService { // information to the callback. |sender_id| is also required since an // InstanceID might have multiple tokens associated with different senders, // though in practice Push doesn't yet use that. - virtual void GetSubscriptionInfo( - const GURL& origin, - int64_t service_worker_registration_id, - const std::string& sender_id, - const std::string& subscription_id, - const SubscriptionInfoCallback& callback) = 0; + virtual void GetSubscriptionInfo(const GURL& origin, + int64_t service_worker_registration_id, + const std::string& sender_id, + const std::string& subscription_id, + SubscriptionInfoCallback callback) = 0; // Unsubscribe the given |sender_id| from the push messaging service. Locally // deactivates the subscription, then runs |callback|, then asynchronously diff --git a/content/public/browser/url_data_source.h b/content/public/browser/url_data_source.h index 9e9d1508d1fd0..9c40fc826fe2e 100644 --- a/content/public/browser/url_data_source.h +++ b/content/public/browser/url_data_source.h @@ -61,8 +61,8 @@ class CONTENT_EXPORT URLDataSource { // Used by StartDataRequest so that the child class can return the data when // it's available. - typedef base::Callback<void(scoped_refptr<base::RefCountedMemory>)> - GotDataCallback; + using GotDataCallback = + base::OnceCallback<void(scoped_refptr<base::RefCountedMemory>)>; // Must be called on the task runner specified by TaskRunnerForRequestPath, // or the IO thread if TaskRunnerForRequestPath returns nullptr. @@ -76,7 +76,7 @@ class CONTENT_EXPORT URLDataSource { // null. virtual void StartDataRequest(const GURL& url, const WebContents::Getter& wc_getter, - const GotDataCallback& callback) = 0; + GotDataCallback callback) = 0; // The following methods are all called on the IO thread. diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h index 01e2904b287f8..ecee31b744ed0 100644 --- a/content/public/browser/web_contents.h +++ b/content/public/browser/web_contents.h @@ -264,7 +264,10 @@ class WebContents : public PageNavigator, // nullptr will be returned instead. // The callback should only run on the UI thread and it should always be // non-null. - using Getter = base::Callback<WebContents*(void)>; + using Getter = base::RepeatingCallback<WebContents*(void)>; + // Use this variant for instances that will only run the callback a single + // time. + using OnceGetter = base::OnceCallback<WebContents*(void)>; // Sets delegate for platform specific screen orientation functionality. CONTENT_EXPORT static void SetScreenOrientationDelegate( diff --git a/content/public/browser/web_contents_binding_set.cc b/content/public/browser/web_contents_binding_set.cc index 455a5fea04ae9..dca30289f14e5 100644 --- a/content/public/browser/web_contents_binding_set.cc +++ b/content/public/browser/web_contents_binding_set.cc @@ -27,7 +27,7 @@ WebContentsBindingSet::WebContentsBindingSet(WebContents* web_contents, ->AddBindingSet(interface_name, this)) {} WebContentsBindingSet::~WebContentsBindingSet() { - remove_callback_.Run(); + std::move(remove_callback_).Run(); } // static diff --git a/content/public/browser/web_contents_binding_set.h b/content/public/browser/web_contents_binding_set.h index bfe6fcef0b319..5a269244c827e 100644 --- a/content/public/browser/web_contents_binding_set.h +++ b/content/public/browser/web_contents_binding_set.h @@ -60,7 +60,7 @@ class CONTENT_EXPORT WebContentsBindingSet { void OnRequestForFrame(RenderFrameHost* render_frame_host, mojo::ScopedInterfaceEndpointHandle handle); - const base::Closure remove_callback_; + base::OnceClosure remove_callback_; Binder* binder_ = nullptr; DISALLOW_COPY_AND_ASSIGN(WebContentsBindingSet); diff --git a/content/public/browser/web_ui_data_source.h b/content/public/browser/web_ui_data_source.h index d1058746438a3..a8b6147b3d775 100644 --- a/content/public/browser/web_ui_data_source.h +++ b/content/public/browser/web_ui_data_source.h @@ -80,8 +80,8 @@ class WebUIDataSource { // Used as a parameter to GotDataCallback. The caller has to run this callback // with the result for the path that they filtered, passing ownership of the // memory. - typedef base::Callback<void(scoped_refptr<base::RefCountedMemory>)> - GotDataCallback; + using GotDataCallback = + base::OnceCallback<void(scoped_refptr<base::RefCountedMemory>)>; // Used by SetRequestFilter. The string parameter is the path of the request. // The return value indicates if the callee wants to handle the request. Iff @@ -94,9 +94,8 @@ class WebUIDataSource { // This callback is only called if a prior call to ShouldHandleRequestCallback // returned true. GotDataCallback should be used to provide the response // bytes. - typedef base::RepeatingCallback<void(const std::string&, - const GotDataCallback&)> - HandleRequestCallback; + using HandleRequestCallback = + base::RepeatingCallback<void(const std::string&, GotDataCallback)>; // Allows a caller to add a filter for URL requests. virtual void SetRequestFilter( diff --git a/content/shell/browser/web_test/web_test_push_messaging_service.cc b/content/shell/browser/web_test/web_test_push_messaging_service.cc index b33e05a107309..762c0f9079acf 100644 --- a/content/shell/browser/web_test/web_test_push_messaging_service.cc +++ b/content/shell/browser/web_test/web_test_push_messaging_service.cc @@ -101,14 +101,14 @@ void WebTestPushMessagingService::GetSubscriptionInfo( int64_t service_worker_registration_id, const std::string& sender_id, const std::string& subscription_id, - const SubscriptionInfoCallback& callback) { + SubscriptionInfoCallback callback) { std::vector<uint8_t> p256dh(kTestP256Key, kTestP256Key + base::size(kTestP256Key)); std::vector<uint8_t> auth(kAuthentication, kAuthentication + base::size(kAuthentication)); const GURL endpoint = CreateEndpoint(subscription_id); - callback.Run(true /* is_valid */, endpoint, p256dh, auth); + std::move(callback).Run(true /* is_valid */, endpoint, p256dh, auth); } bool WebTestPushMessagingService::SupportNonVisibleMessages() { diff --git a/content/shell/browser/web_test/web_test_push_messaging_service.h b/content/shell/browser/web_test/web_test_push_messaging_service.h index 6988df08ae48a..32d3ab6497b30 100644 --- a/content/shell/browser/web_test/web_test_push_messaging_service.h +++ b/content/shell/browser/web_test/web_test_push_messaging_service.h @@ -37,7 +37,7 @@ class WebTestPushMessagingService : public PushMessagingService { int64_t service_worker_registration_id, const std::string& sender_id, const std::string& subscription_id, - const SubscriptionInfoCallback& callback) override; + SubscriptionInfoCallback callback) override; bool SupportNonVisibleMessages() override; void Unsubscribe(blink::mojom::PushUnregistrationReason reason, const GURL& requesting_origin, diff --git a/extensions/shell/browser/shell_content_browser_client.cc b/extensions/shell/browser/shell_content_browser_client.cc index 832998744a77b..7096b01d6065a 100644 --- a/extensions/shell/browser/shell_content_browser_client.cc +++ b/extensions/shell/browser/shell_content_browser_client.cc @@ -335,7 +335,7 @@ bool ShellContentBrowserClient::WillCreateURLLoaderFactory( bool ShellContentBrowserClient::HandleExternalProtocol( const GURL& url, - content::WebContents::Getter web_contents_getter, + content::WebContents::OnceGetter web_contents_getter, int child_id, content::NavigationUIData* navigation_data, bool is_main_frame, diff --git a/extensions/shell/browser/shell_content_browser_client.h b/extensions/shell/browser/shell_content_browser_client.h index 4b8519b125060..69f405f4545b0 100644 --- a/extensions/shell/browser/shell_content_browser_client.h +++ b/extensions/shell/browser/shell_content_browser_client.h @@ -95,7 +95,7 @@ class ShellContentBrowserClient : public content::ContentBrowserClient { bool* bypass_redirect_checks) override; bool HandleExternalProtocol( const GURL& url, - content::WebContents::Getter web_contents_getter, + content::WebContents::OnceGetter web_contents_getter, int child_id, content::NavigationUIData* navigation_data, bool is_main_frame, diff --git a/ios/chrome/browser/ui/webui/about_ui.cc b/ios/chrome/browser/ui/webui/about_ui.cc index b1c4a93960138..9ea5fc37c651f 100644 --- a/ios/chrome/browser/ui/webui/about_ui.cc +++ b/ios/chrome/browser/ui/webui/about_ui.cc @@ -38,14 +38,13 @@ class AboutUIHTMLSource : public web::URLDataSourceIOS { std::string GetSource() const override; void StartDataRequest( const std::string& path, - const web::URLDataSourceIOS::GotDataCallback& callback) override; + web::URLDataSourceIOS::GotDataCallback callback) override; std::string GetMimeType(const std::string& path) const override; bool ShouldDenyXFrameOptions() const override; // Send the response data. - void FinishDataRequest( - const std::string& html, - const web::URLDataSourceIOS::GotDataCallback& callback); + void FinishDataRequest(const std::string& html, + web::URLDataSourceIOS::GotDataCallback callback); private: ~AboutUIHTMLSource() override; @@ -112,7 +111,7 @@ std::string AboutUIHTMLSource::GetSource() const { void AboutUIHTMLSource::StartDataRequest( const std::string& path, - const web::URLDataSourceIOS::GotDataCallback& callback) { + web::URLDataSourceIOS::GotDataCallback callback) { std::string response; // Add your data source here, in alphabetical order. if (source_name_ == kChromeUIChromeURLsHost) { @@ -131,14 +130,14 @@ void AboutUIHTMLSource::StartDataRequest( base::StatisticsRecorder::WriteHTMLGraph("", &response); } - FinishDataRequest(response, callback); + FinishDataRequest(response, std::move(callback)); } void AboutUIHTMLSource::FinishDataRequest( const std::string& html, - const web::URLDataSourceIOS::GotDataCallback& callback) { + web::URLDataSourceIOS::GotDataCallback callback) { std::string html_copy(html); - callback.Run(base::RefCountedString::TakeString(&html_copy)); + std::move(callback).Run(base::RefCountedString::TakeString(&html_copy)); } std::string AboutUIHTMLSource::GetMimeType(const std::string& path) const { diff --git a/ios/chrome/browser/ui/webui/prefs_internals_ui.cc b/ios/chrome/browser/ui/webui/prefs_internals_ui.cc index 052e86119fbca..fe65ffbc487cd 100644 --- a/ios/chrome/browser/ui/webui/prefs_internals_ui.cc +++ b/ios/chrome/browser/ui/webui/prefs_internals_ui.cc @@ -35,11 +35,11 @@ class PrefsInternalsSource : public web::URLDataSourceIOS { void StartDataRequest( const std::string& path, - const web::URLDataSourceIOS::GotDataCallback& callback) override { + web::URLDataSourceIOS::GotDataCallback callback) override { // TODO(crbug.com/1006711): Properly disable this webui provider for // incognito browser states. if (browser_state_->IsOffTheRecord()) { - callback.Run(nullptr); + std::move(callback).Run(nullptr); return; } @@ -51,7 +51,7 @@ class PrefsInternalsSource : public web::URLDataSourceIOS { DCHECK(prefs); CHECK(base::JSONWriter::WriteWithOptions( *prefs, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json)); - callback.Run(base::RefCountedString::TakeString(&json)); + std::move(callback).Run(base::RefCountedString::TakeString(&json)); } private: diff --git a/ios/chrome/browser/ui/webui/suggestions_ui.cc b/ios/chrome/browser/ui/webui/suggestions_ui.cc index 16beb1bba24b9..1c43c53241313 100644 --- a/ios/chrome/browser/ui/webui/suggestions_ui.cc +++ b/ios/chrome/browser/ui/webui/suggestions_ui.cc @@ -26,7 +26,7 @@ class SuggestionsSourceWrapper : public web::URLDataSourceIOS { std::string GetSource() const override; void StartDataRequest( const std::string& path, - const web::URLDataSourceIOS::GotDataCallback& callback) override; + web::URLDataSourceIOS::GotDataCallback callback) override; std::string GetMimeType(const std::string& path) const override; private: @@ -49,8 +49,8 @@ std::string SuggestionsSourceWrapper::GetSource() const { void SuggestionsSourceWrapper::StartDataRequest( const std::string& path, - const web::URLDataSourceIOS::GotDataCallback& callback) { - suggestions_source_.StartDataRequest(path, callback); + web::URLDataSourceIOS::GotDataCallback callback) { + suggestions_source_.StartDataRequest(path, std::move(callback)); } std::string SuggestionsSourceWrapper::GetMimeType( diff --git a/ios/chrome/browser/ui/webui/terms_ui.mm b/ios/chrome/browser/ui/webui/terms_ui.mm index 8ff629bfa33f2..7c360e27806f9 100644 --- a/ios/chrome/browser/ui/webui/terms_ui.mm +++ b/ios/chrome/browser/ui/webui/terms_ui.mm @@ -29,14 +29,13 @@ class TermsUIHTMLSource : public web::URLDataSourceIOS { std::string GetSource() const override; void StartDataRequest( const std::string& path, - const web::URLDataSourceIOS::GotDataCallback& callback) override; + web::URLDataSourceIOS::GotDataCallback callback) override; std::string GetMimeType(const std::string& path) const override; bool ShouldDenyXFrameOptions() const override; // Send the response data. - void FinishDataRequest( - const std::string& html, - const web::URLDataSourceIOS::GotDataCallback& callback); + void FinishDataRequest(const std::string& html, + web::URLDataSourceIOS::GotDataCallback callback); private: ~TermsUIHTMLSource() override; @@ -59,7 +58,7 @@ std::string TermsUIHTMLSource::GetSource() const { void TermsUIHTMLSource::StartDataRequest( const std::string& path, - const web::URLDataSourceIOS::GotDataCallback& callback) { + web::URLDataSourceIOS::GotDataCallback callback) { NSString* terms_of_service_path = base::SysUTF8ToNSString(GetTermsOfServicePath()); NSString* bundle_path = [base::mac::FrameworkBundle() bundlePath]; @@ -72,14 +71,14 @@ void TermsUIHTMLSource::StartDataRequest( encoding:NSUTF8StringEncoding error:&error]; DCHECK(!error && [content length]); - FinishDataRequest(base::SysNSStringToUTF8(content), callback); + FinishDataRequest(base::SysNSStringToUTF8(content), std::move(callback)); } void TermsUIHTMLSource::FinishDataRequest( const std::string& html, - const web::URLDataSourceIOS::GotDataCallback& callback) { + web::URLDataSourceIOS::GotDataCallback callback) { std::string html_copy(html); - callback.Run(base::RefCountedString::TakeString(&html_copy)); + std::move(callback).Run(base::RefCountedString::TakeString(&html_copy)); } std::string TermsUIHTMLSource::GetMimeType(const std::string& path) const { diff --git a/ios/web/public/webui/url_data_source_ios.h b/ios/web/public/webui/url_data_source_ios.h index 43e49fb00405b..28d70ed440704 100644 --- a/ios/web/public/webui/url_data_source_ios.h +++ b/ios/web/public/webui/url_data_source_ios.h @@ -50,7 +50,7 @@ class URLDataSourceIOS { // data is available or if the request could not be satisfied. This can be // called either in this callback or asynchronously with the response. virtual void StartDataRequest(const std::string& path, - const GotDataCallback& callback) = 0; + GotDataCallback callback) = 0; // Return the mimetype that should be sent with this response, or empty // string to specify no mime type. diff --git a/ios/web/webui/shared_resources_data_source_ios.h b/ios/web/webui/shared_resources_data_source_ios.h index 82bddd453666e..134ff8171923b 100644 --- a/ios/web/webui/shared_resources_data_source_ios.h +++ b/ios/web/webui/shared_resources_data_source_ios.h @@ -18,9 +18,8 @@ class SharedResourcesDataSourceIOS : public URLDataSourceIOS { // web::URLDataSourceIOS implementation. std::string GetSource() const override; - void StartDataRequest( - const std::string& path, - const URLDataSourceIOS::GotDataCallback& callback) override; + void StartDataRequest(const std::string& path, + URLDataSourceIOS::GotDataCallback callback) override; std::string GetMimeType(const std::string& path) const override; private: diff --git a/ios/web/webui/shared_resources_data_source_ios.mm b/ios/web/webui/shared_resources_data_source_ios.mm index 9578687e69687..53484b6dfff91 100644 --- a/ios/web/webui/shared_resources_data_source_ios.mm +++ b/ios/web/webui/shared_resources_data_source_ios.mm @@ -49,7 +49,7 @@ std::string SharedResourcesDataSourceIOS::GetSource() const { void SharedResourcesDataSourceIOS::StartDataRequest( const std::string& path, - const URLDataSourceIOS::GotDataCallback& callback) { + URLDataSourceIOS::GotDataCallback callback) { const GritResourceMap* resource = PathToResource(path); DCHECK(resource) << " path: " << path; scoped_refptr<base::RefCountedMemory> bytes; @@ -64,7 +64,7 @@ void SharedResourcesDataSourceIOS::StartDataRequest( bytes = web_client->GetDataResourceBytes(idr); } - callback.Run(bytes.get()); + std::move(callback).Run(bytes.get()); } std::string SharedResourcesDataSourceIOS::GetMimeType( diff --git a/ios/web/webui/web_ui_ios_data_source_impl.h b/ios/web/webui/web_ui_ios_data_source_impl.h index 9335e647d012e..405b566cc6800 100644 --- a/ios/web/webui/web_ui_ios_data_source_impl.h +++ b/ios/web/webui/web_ui_ios_data_source_impl.h @@ -40,9 +40,8 @@ class WebUIIOSDataSourceImpl : public URLDataSourceIOSImpl, ~WebUIIOSDataSourceImpl() override; // Completes a request by sending our dictionary of localized strings. - void SendLocalizedStringsAsJSON( - const URLDataSourceIOS::GotDataCallback& callback, - bool from_js_module); + void SendLocalizedStringsAsJSON(URLDataSourceIOS::GotDataCallback callback, + bool from_js_module); private: class InternalDataSource; @@ -60,7 +59,7 @@ class WebUIIOSDataSourceImpl : public URLDataSourceIOSImpl, std::string GetSource() const; std::string GetMimeType(const std::string& path) const; void StartDataRequest(const std::string& path, - const URLDataSourceIOS::GotDataCallback& callback); + URLDataSourceIOS::GotDataCallback callback); int PathToIdrOrDefault(const std::string& path) const; diff --git a/ios/web/webui/web_ui_ios_data_source_impl.mm b/ios/web/webui/web_ui_ios_data_source_impl.mm index ad488858e4219..edd2f97ea50d4 100644 --- a/ios/web/webui/web_ui_ios_data_source_impl.mm +++ b/ios/web/webui/web_ui_ios_data_source_impl.mm @@ -44,10 +44,9 @@ class WebUIIOSDataSourceImpl::InternalDataSource : public URLDataSourceIOS { std::string GetMimeType(const std::string& path) const override { return parent_->GetMimeType(path); } - void StartDataRequest( - const std::string& path, - const URLDataSourceIOS::GotDataCallback& callback) override { - return parent_->StartDataRequest(path, callback); + void StartDataRequest(const std::string& path, + URLDataSourceIOS::GotDataCallback callback) override { + return parent_->StartDataRequest(path, std::move(callback)); } bool ShouldReplaceExistingSource() const override { return parent_->replace_existing_source_; @@ -159,13 +158,13 @@ void WebUIIOSDataSourceImpl::EnsureLoadTimeDataDefaultsAdded() { void WebUIIOSDataSourceImpl::StartDataRequest( const std::string& path, - const URLDataSourceIOS::GotDataCallback& callback) { + URLDataSourceIOS::GotDataCallback callback) { EnsureLoadTimeDataDefaultsAdded(); if (use_strings_js_) { bool from_js_module = path == "strings.m.js"; if (from_js_module || path == "strings.js") { - SendLocalizedStringsAsJSON(callback, from_js_module); + SendLocalizedStringsAsJSON(std::move(callback), from_js_module); return; } } @@ -174,15 +173,15 @@ void WebUIIOSDataSourceImpl::StartDataRequest( DCHECK_NE(resource_id, -1); scoped_refptr<base::RefCountedMemory> response( GetWebClient()->GetDataResourceBytes(resource_id)); - callback.Run(response); + std::move(callback).Run(response); } void WebUIIOSDataSourceImpl::SendLocalizedStringsAsJSON( - const URLDataSourceIOS::GotDataCallback& callback, + URLDataSourceIOS::GotDataCallback callback, bool from_js_module) { std::string template_data; webui::AppendJsonJS(&localized_strings_, &template_data, from_js_module); - callback.Run(base::RefCountedString::TakeString(&template_data)); + std::move(callback).Run(base::RefCountedString::TakeString(&template_data)); } int WebUIIOSDataSourceImpl::PathToIdrOrDefault(const std::string& path) const {