Commit 7e559a5e authored by Yannic Bonenberger's avatar Yannic Bonenberger Committed by Commit Bot

Apply base_bind_rewriters to //content

This CL removes calls to base::AdaptCallbackForRepeating when the
returned base::RepeatingCallback is immediately converted
to a base::OnceCallback.
It also fixes a bug in //tools/clang/base_bind_rewriters which
caused commas to be wrongfully removed if base::AdaptCallbackForRepeating
is not the first parameter.

Change-Id: Ic90bfcef4496fa0a22a083e2c8506066cffd5b95
Reviewed-on: https://chromium-review.googlesource.com/1123819
Commit-Queue: Yannic Bonenberger <contact@yannic-bonenberger.com>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#573490}
parent 514bc3e3
...@@ -111,9 +111,8 @@ void RegistrationPendingOnIOThread( ...@@ -111,9 +111,8 @@ void RegistrationPendingOnIOThread(
const GURL& url, const GURL& url,
base::OnceCallback<void(bool)> callback) { base::OnceCallback<void(bool)> callback) {
sw_context->FindReadyRegistrationForDocument( sw_context->FindReadyRegistrationForDocument(
url, base::AdaptCallbackForRepeating( url, base::BindOnce(&RegistrationPendingDidGetSWRegistration,
base::BindOnce(&RegistrationPendingDidGetSWRegistration, sync_context, tag, std::move(callback)));
sync_context, tag, std::move(callback))));
} }
void SetMaxSyncAttemptsOnIOThread( void SetMaxSyncAttemptsOnIOThread(
......
...@@ -368,10 +368,10 @@ void BackgroundSyncManager::InitDidGetControllerParameters( ...@@ -368,10 +368,10 @@ void BackgroundSyncManager::InitDidGetControllerParameters(
return; return;
} }
GetDataFromBackend(kBackgroundSyncUserDataKey, GetDataFromBackend(
base::AdaptCallbackForRepeating(base::BindOnce( kBackgroundSyncUserDataKey,
&BackgroundSyncManager::InitDidGetDataFromBackend, base::BindOnce(&BackgroundSyncManager::InitDidGetDataFromBackend,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)))); weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
} }
void BackgroundSyncManager::InitDidGetDataFromBackend( void BackgroundSyncManager::InitDidGetDataFromBackend(
...@@ -599,9 +599,8 @@ void BackgroundSyncManager::DisableAndClearManager(base::OnceClosure callback) { ...@@ -599,9 +599,8 @@ void BackgroundSyncManager::DisableAndClearManager(base::OnceClosure callback) {
// loading from storage), so reload the registrations from storage again. // loading from storage), so reload the registrations from storage again.
GetDataFromBackend( GetDataFromBackend(
kBackgroundSyncUserDataKey, kBackgroundSyncUserDataKey,
base::AdaptCallbackForRepeating(base::BindOnce( base::BindOnce(&BackgroundSyncManager::DisableAndClearDidGetRegistrations,
&BackgroundSyncManager::DisableAndClearDidGetRegistrations, weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
weak_ptr_factory_.GetWeakPtr(), std::move(callback))));
} }
void BackgroundSyncManager::DisableAndClearDidGetRegistrations( void BackgroundSyncManager::DisableAndClearDidGetRegistrations(
...@@ -622,9 +621,8 @@ void BackgroundSyncManager::DisableAndClearDidGetRegistrations( ...@@ -622,9 +621,8 @@ void BackgroundSyncManager::DisableAndClearDidGetRegistrations(
for (const auto& sw_id_and_regs : user_data) { for (const auto& sw_id_and_regs : user_data) {
service_worker_context_->ClearRegistrationUserData( service_worker_context_->ClearRegistrationUserData(
sw_id_and_regs.first, {kBackgroundSyncUserDataKey}, sw_id_and_regs.first, {kBackgroundSyncUserDataKey},
base::AdaptCallbackForRepeating(base::BindOnce( base::BindOnce(&BackgroundSyncManager::DisableAndClearManagerClearedOne,
&BackgroundSyncManager::DisableAndClearManagerClearedOne, weak_ptr_factory_.GetWeakPtr(), barrier_closure));
weak_ptr_factory_.GetWeakPtr(), barrier_closure)));
} }
} }
...@@ -769,8 +767,7 @@ void BackgroundSyncManager::StoreDataInBackend( ...@@ -769,8 +767,7 @@ void BackgroundSyncManager::StoreDataInBackend(
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
service_worker_context_->StoreRegistrationUserData( service_worker_context_->StoreRegistrationUserData(
sw_registration_id, origin, {{backend_key, data}}, sw_registration_id, origin, {{backend_key, data}}, std::move(callback));
base::AdaptCallbackForRepeating(std::move(callback)));
} }
void BackgroundSyncManager::GetDataFromBackend( void BackgroundSyncManager::GetDataFromBackend(
...@@ -823,8 +820,8 @@ void BackgroundSyncManager::ScheduleDelayedTask(base::OnceClosure callback, ...@@ -823,8 +820,8 @@ void BackgroundSyncManager::ScheduleDelayedTask(base::OnceClosure callback,
void BackgroundSyncManager::HasMainFrameProviderHost(const GURL& origin, void BackgroundSyncManager::HasMainFrameProviderHost(const GURL& origin,
BoolCallback callback) { BoolCallback callback) {
service_worker_context_->HasMainFrameProviderHost( service_worker_context_->HasMainFrameProviderHost(origin,
origin, base::AdaptCallbackForRepeating(std::move(callback))); std::move(callback));
} }
void BackgroundSyncManager::GetRegistrationsImpl( void BackgroundSyncManager::GetRegistrationsImpl(
......
...@@ -141,15 +141,13 @@ class BackgroundSyncManagerTest : public testing::Test { ...@@ -141,15 +141,13 @@ class BackgroundSyncManagerTest : public testing::Test {
options2.scope = GURL(kPattern2); options2.scope = GURL(kPattern2);
helper_->context()->RegisterServiceWorker( helper_->context()->RegisterServiceWorker(
GURL(kScript1), options1, GURL(kScript1), options1,
base::AdaptCallbackForRepeating( base::BindOnce(&RegisterServiceWorkerCallback, &called_1,
base::BindOnce(&RegisterServiceWorkerCallback, &called_1, &sw_registration_id_1_));
&sw_registration_id_1_)));
helper_->context()->RegisterServiceWorker( helper_->context()->RegisterServiceWorker(
GURL(kScript2), options2, GURL(kScript2), options2,
base::AdaptCallbackForRepeating( base::BindOnce(&RegisterServiceWorkerCallback, &called_2,
base::BindOnce(&RegisterServiceWorkerCallback, &called_2, &sw_registration_id_2_));
&sw_registration_id_2_)));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(called_1); EXPECT_TRUE(called_1);
EXPECT_TRUE(called_2); EXPECT_TRUE(called_2);
...@@ -158,13 +156,13 @@ class BackgroundSyncManagerTest : public testing::Test { ...@@ -158,13 +156,13 @@ class BackgroundSyncManagerTest : public testing::Test {
// calling BackgroundSyncManager::Register. // calling BackgroundSyncManager::Register.
helper_->context_wrapper()->FindReadyRegistrationForId( helper_->context_wrapper()->FindReadyRegistrationForId(
sw_registration_id_1_, GURL(kPattern1).GetOrigin(), sw_registration_id_1_, GURL(kPattern1).GetOrigin(),
base::AdaptCallbackForRepeating(base::BindOnce( base::BindOnce(FindServiceWorkerRegistrationCallback,
FindServiceWorkerRegistrationCallback, &sw_registration_1_))); &sw_registration_1_));
helper_->context_wrapper()->FindReadyRegistrationForId( helper_->context_wrapper()->FindReadyRegistrationForId(
sw_registration_id_2_, GURL(kPattern1).GetOrigin(), sw_registration_id_2_, GURL(kPattern1).GetOrigin(),
base::AdaptCallbackForRepeating(base::BindOnce( base::BindOnce(FindServiceWorkerRegistrationCallback,
FindServiceWorkerRegistrationCallback, &sw_registration_2_))); &sw_registration_2_));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(sw_registration_1_); EXPECT_TRUE(sw_registration_1_);
EXPECT_TRUE(sw_registration_2_); EXPECT_TRUE(sw_registration_2_);
...@@ -334,8 +332,7 @@ class BackgroundSyncManagerTest : public testing::Test { ...@@ -334,8 +332,7 @@ class BackgroundSyncManagerTest : public testing::Test {
bool called = false; bool called = false;
helper_->context()->UnregisterServiceWorker( helper_->context()->UnregisterServiceWorker(
PatternForSWId(sw_registration_id), PatternForSWId(sw_registration_id),
base::AdaptCallbackForRepeating( base::BindOnce(&UnregisterServiceWorkerCallback, &called));
base::BindOnce(&UnregisterServiceWorkerCallback, &called)));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(called); EXPECT_TRUE(called);
} }
...@@ -654,14 +651,12 @@ TEST_F(BackgroundSyncManagerTest, SequentialOperations) { ...@@ -654,14 +651,12 @@ TEST_F(BackgroundSyncManagerTest, SequentialOperations) {
bool get_registrations_called = false; bool get_registrations_called = false;
test_background_sync_manager_->Register( test_background_sync_manager_->Register(
sw_registration_id_1_, sync_options_1_, sw_registration_id_1_, sync_options_1_,
base::AdaptCallbackForRepeating(base::BindOnce( base::BindOnce(&BackgroundSyncManagerTest::StatusAndRegistrationCallback,
&BackgroundSyncManagerTest::StatusAndRegistrationCallback, base::Unretained(this), &register_called));
base::Unretained(this), &register_called)));
test_background_sync_manager_->GetRegistrations( test_background_sync_manager_->GetRegistrations(
sw_registration_id_1_, sw_registration_id_1_,
base::AdaptCallbackForRepeating(base::BindOnce( base::BindOnce(&BackgroundSyncManagerTest::StatusAndRegistrationsCallback,
&BackgroundSyncManagerTest::StatusAndRegistrationsCallback, base::Unretained(this), &get_registrations_called));
base::Unretained(this), &get_registrations_called)));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// Init should be blocked while loading from the backend. // Init should be blocked while loading from the backend.
...@@ -696,9 +691,8 @@ TEST_F(BackgroundSyncManagerTest, ...@@ -696,9 +691,8 @@ TEST_F(BackgroundSyncManagerTest,
bool callback_called = false; bool callback_called = false;
test_background_sync_manager_->Register( test_background_sync_manager_->Register(
sw_registration_id_1_, sync_options_2_, sw_registration_id_1_, sync_options_2_,
base::AdaptCallbackForRepeating(base::BindOnce( base::BindOnce(&BackgroundSyncManagerTest::StatusAndRegistrationCallback,
&BackgroundSyncManagerTest::StatusAndRegistrationCallback, base::Unretained(this), &callback_called));
base::Unretained(this), &callback_called)));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_FALSE(callback_called); EXPECT_FALSE(callback_called);
......
...@@ -169,15 +169,15 @@ class BackgroundSyncServiceImplTest : public testing::Test { ...@@ -169,15 +169,15 @@ class BackgroundSyncServiceImplTest : public testing::Test {
options.scope = GURL(kServiceWorkerPattern); options.scope = GURL(kServiceWorkerPattern);
embedded_worker_helper_->context()->RegisterServiceWorker( embedded_worker_helper_->context()->RegisterServiceWorker(
GURL(kServiceWorkerScript), options, GURL(kServiceWorkerScript), options,
base::AdaptCallbackForRepeating(base::BindOnce( base::BindOnce(&RegisterServiceWorkerCallback, &called,
&RegisterServiceWorkerCallback, &called, &sw_registration_id_))); &sw_registration_id_));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(called); EXPECT_TRUE(called);
embedded_worker_helper_->context_wrapper()->FindReadyRegistrationForId( embedded_worker_helper_->context_wrapper()->FindReadyRegistrationForId(
sw_registration_id_, GURL(kServiceWorkerPattern).GetOrigin(), sw_registration_id_, GURL(kServiceWorkerPattern).GetOrigin(),
base::AdaptCallbackForRepeating(base::BindOnce( base::BindOnce(FindServiceWorkerRegistrationCallback,
FindServiceWorkerRegistrationCallback, &sw_registration_))); &sw_registration_));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(sw_registration_); EXPECT_TRUE(sw_registration_);
} }
......
...@@ -522,10 +522,9 @@ void CacheStorageCache::WriteSideData(ErrorCallback callback, ...@@ -522,10 +522,9 @@ void CacheStorageCache::WriteSideData(ErrorCallback callback,
quota_manager_proxy_->GetUsageAndQuota( quota_manager_proxy_->GetUsageAndQuota(
base::ThreadTaskRunnerHandle::Get().get(), origin_, base::ThreadTaskRunnerHandle::Get().get(), origin_,
blink::mojom::StorageType::kTemporary, blink::mojom::StorageType::kTemporary,
base::AdaptCallbackForRepeating( base::BindOnce(&CacheStorageCache::WriteSideDataDidGetQuota,
base::BindOnce(&CacheStorageCache::WriteSideDataDidGetQuota, weak_ptr_factory_.GetWeakPtr(), std::move(callback), url,
weak_ptr_factory_.GetWeakPtr(), std::move(callback), expected_response_time, buffer, buf_len));
url, expected_response_time, buffer, buf_len)));
} }
void CacheStorageCache::BatchOperation( void CacheStorageCache::BatchOperation(
...@@ -568,11 +567,10 @@ void CacheStorageCache::BatchOperation( ...@@ -568,11 +567,10 @@ void CacheStorageCache::BatchOperation(
quota_manager_proxy_->GetUsageAndQuota( quota_manager_proxy_->GetUsageAndQuota(
base::ThreadTaskRunnerHandle::Get().get(), origin_, base::ThreadTaskRunnerHandle::Get().get(), origin_,
blink::mojom::StorageType::kTemporary, blink::mojom::StorageType::kTemporary,
base::AdaptCallbackForRepeating(base::BindOnce( base::BindOnce(&CacheStorageCache::BatchDidGetUsageAndQuota,
&CacheStorageCache::BatchDidGetUsageAndQuota, weak_ptr_factory_.GetWeakPtr(), std::move(operations),
weak_ptr_factory_.GetWeakPtr(), std::move(operations), std::move(callback), std::move(bad_message_callback),
std::move(callback), std::move(bad_message_callback), space_required, side_data_size));
space_required, side_data_size)));
return; return;
} }
......
...@@ -141,10 +141,10 @@ class BlinkNotificationServiceImplTest : public ::testing::Test { ...@@ -141,10 +141,10 @@ class BlinkNotificationServiceImplTest : public ::testing::Test {
base::RunLoop run_loop; base::RunLoop run_loop;
embedded_worker_helper_->context()->RegisterServiceWorker( embedded_worker_helper_->context()->RegisterServiceWorker(
GURL(kTestServiceWorkerUrl), options, GURL(kTestServiceWorkerUrl), options,
base::AdaptCallbackForRepeating(base::BindOnce( base::BindOnce(
&BlinkNotificationServiceImplTest::DidRegisterServiceWorker, &BlinkNotificationServiceImplTest::DidRegisterServiceWorker,
base::Unretained(this), &service_worker_registration_id, base::Unretained(this), &service_worker_registration_id,
run_loop.QuitClosure()))); run_loop.QuitClosure()));
run_loop.Run(); run_loop.Run();
} }
......
...@@ -623,11 +623,13 @@ class AdaptCallbackForRepeatingRewriter : public MatchFinder::MatchCallback, ...@@ -623,11 +623,13 @@ class AdaptCallbackForRepeatingRewriter : public MatchFinder::MatchCallback,
result.SourceManager->getSpellingLoc(target->getLocStart()), result.SourceManager->getSpellingLoc(target->getLocStart()),
result.SourceManager->getSpellingLoc(target->getArg(0)->getExprLoc()) result.SourceManager->getSpellingLoc(target->getArg(0)->getExprLoc())
.getLocWithOffset(-1)); .getLocWithOffset(-1));
replacements_->emplace_back(*result.SourceManager, left, "");
// We use " " as replacement to work around https://crbug.com/861886.
replacements_->emplace_back(*result.SourceManager, left, " ");
auto r_paren = clang::CharSourceRange::getTokenRange( auto r_paren = clang::CharSourceRange::getTokenRange(
result.SourceManager->getSpellingLoc(target->getRParenLoc()), result.SourceManager->getSpellingLoc(target->getRParenLoc()),
result.SourceManager->getSpellingLoc(target->getRParenLoc())); result.SourceManager->getSpellingLoc(target->getRParenLoc()));
replacements_->emplace_back(*result.SourceManager, r_paren, ""); replacements_->emplace_back(*result.SourceManager, r_paren, " ");
} }
private: private:
......
...@@ -6,14 +6,18 @@ ...@@ -6,14 +6,18 @@
void Foo(base::OnceClosure) {} void Foo(base::OnceClosure) {}
void Bar(int, base::OnceClosure, int) {}
void Test() { void Test() {
base::OnceClosure cb = base::BindOnce([] {}); base::OnceClosure cb = base::BindOnce([] {});
Foo(base::BindOnce([] {})); Foo(base::BindOnce([] {}));
Bar(1, base::BindOnce([] {}), 1);
using namespace base; using namespace base;
OnceClosure cb2 = BindOnce([] {}); OnceClosure cb2 = BindOnce([] {});
Foo(BindOnce([] {})); Foo(BindOnce([] {}));
Bar(1, BindOnce([] {}), 1);
OnceClosure cb3 = base::BindOnce([] {}); OnceClosure cb3 = BindOnce([] {});
} }
...@@ -6,14 +6,18 @@ ...@@ -6,14 +6,18 @@
void Foo(base::OnceClosure) {} void Foo(base::OnceClosure) {}
void Bar(int, base::OnceClosure, int) {}
void Test() { void Test() {
base::OnceClosure cb = base::AdaptCallbackForRepeating(base::BindOnce([] {})); base::OnceClosure cb = base::AdaptCallbackForRepeating(base::BindOnce([] {}));
Foo(base::AdaptCallbackForRepeating(base::BindOnce([] {}))); Foo(base::AdaptCallbackForRepeating(base::BindOnce([] {})));
Bar(1, base::AdaptCallbackForRepeating(base::BindOnce([] {})), 1);
using namespace base; using namespace base;
OnceClosure cb2 = AdaptCallbackForRepeating(BindOnce([] {})); OnceClosure cb2 = AdaptCallbackForRepeating(BindOnce([] {}));
Foo(AdaptCallbackForRepeating(BindOnce([] {}))); Foo(AdaptCallbackForRepeating(BindOnce([] {})));
Bar(1, AdaptCallbackForRepeating(BindOnce([] {})), 1);
OnceClosure cb3 = base::BindOnce([] {}); OnceClosure cb3 = BindOnce([] {});
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment