Skip to content

Commit

Permalink
Migrate ios/chrome from base::Bind to BindOnce/Repeating
Browse files Browse the repository at this point in the history
This is part of the base::Callback migration.

Context: https://cs.chromium.org/chromium/src/docs/callback.md?rcl=9fcc3764aea8f97e9f6de4a9ee61d554e67edcda&l=40

Bug: 1007792
Change-Id: I16c66d31f3c95b179288d2586682d981d0b4f7a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2505946
Commit-Queue: Renjie Tang <renjietang@chromium.org>
Auto-Submit: Renjie Tang <renjietang@chromium.org>
Reviewed-by: David Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823378}
  • Loading branch information
Renjie Tang authored and Commit Bot committed Nov 3, 2020
1 parent ab8ec17 commit 208c819
Show file tree
Hide file tree
Showing 59 changed files with 218 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
// will store the memory pressure level sent to the callback in
// |memory_pressure_level_| so that tests can verify the level is correct.
memory_pressure_listener_.reset(new base::MemoryPressureListener(
FROM_HERE, base::Bind(&MemoryWarningHelperTest::OnMemoryPressure,
base::Unretained(this))));
FROM_HERE,
base::BindRepeating(&MemoryWarningHelperTest::OnMemoryPressure,
base::Unretained(this))));
memory_pressure_level_ =
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE;
}
Expand Down
13 changes: 7 additions & 6 deletions ios/chrome/app/spotlight/topsites_spotlight_manager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,10 @@ + (TopSitesSpotlightManager*)topSitesSpotlightManagerWithBrowserState:
_suggestionsBridge.reset(new SpotlightSuggestionsBridge(self));
_syncService = syncService;
_suggestionService = suggestionsService;
_suggestionsServiceResponseSubscription = _suggestionService->AddCallback(
base::Bind(&SpotlightSuggestionsBridge::OnSuggestionsProfileAvailable,
_suggestionsBridge->AsWeakPtr()));
_suggestionsServiceResponseSubscription =
_suggestionService->AddCallback(base::BindRepeating(
&SpotlightSuggestionsBridge::OnSuggestionsProfileAvailable,
_suggestionsBridge->AsWeakPtr()));
_syncObserverBridge.reset(new SyncObserverBridge(self, syncService));
}
}
Expand Down Expand Up @@ -218,9 +219,9 @@ - (void)addAllTopSitesSpotlightItems {
}

- (void)addAllLocalTopSitesItems {
_topSites->GetMostVisitedURLs(
base::Bind(&SpotlightTopSitesCallbackBridge::OnMostVisitedURLsAvailable,
_topSitesCallbackBridge->AsWeakPtr()));
_topSites->GetMostVisitedURLs(base::BindOnce(
&SpotlightTopSitesCallbackBridge::OnMostVisitedURLsAvailable,
_topSitesCallbackBridge->AsWeakPtr()));
}

- (void)addAllSuggestionsTopSitesItems {
Expand Down
4 changes: 2 additions & 2 deletions ios/chrome/browser/application_context_impl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ void BindNetworkChangeManagerReceiver(
(channel != version_info::Channel::STABLE &&
channel != version_info::Channel::BETA);
browser_policy_connector_ = std::make_unique<BrowserPolicyConnectorIOS>(
base::Bind(&BuildPolicyHandlerList,
enable_future_policies_without_allowlist));
base::BindRepeating(&BuildPolicyHandlerList,
enable_future_policies_without_allowlist));

// Install a mock platform policy provider, if running under EG2 and one
// is supplied.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
prefs_change_observer_->Init(browser_state_->GetPrefs());
prefs_change_observer_->Add(
prefs::kIosHandoffToOtherDevices,
base::Bind(&DeviceSharingManagerImpl::UpdateHandoffManager,
base::Unretained(this)));
base::BindRepeating(&DeviceSharingManagerImpl::UpdateHandoffManager,
base::Unretained(this)));
UpdateHandoffManager();
[handoff_manager_ updateActiveURL:GURL()];
}
Expand Down
7 changes: 4 additions & 3 deletions ios/chrome/browser/dom_distiller/distiller_viewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ DistillerViewer::DistillerViewer(
distiller_ = distiller_factory->CreateDistillerForUrl(url);
distiller_->DistillPage(
url, std::move(page),
base::Bind(&DistillerViewer::OnDistillerFinished, base::Unretained(this)),
base::Bind(&DistillerViewer::OnArticleDistillationUpdated,
base::Unretained(this)));
base::BindOnce(&DistillerViewer::OnDistillerFinished,
base::Unretained(this)),
base::BindRepeating(&DistillerViewer::OnArticleDistillationUpdated,
base::Unretained(this)));
}

DistillerViewer::~DistillerViewer() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void RemoveFilesWithOptions(NSSet* files_to_keep, NSInteger age_in_days) {
base::ThreadPool::PostTaskAndReply(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
base::BindOnce(&RemoveFilesWithOptions, referenced_files, age_in_days),
base::Bind(&RunCallback, base::Passed(&closure_runner)));
base::BindOnce(&RunCallback, base::Passed(&closure_runner)));
}

NSSet* ExternalFileRemoverImpl::GetReferencedExternalFiles() {
Expand Down
2 changes: 1 addition & 1 deletion ios/chrome/browser/flags/about_flags.mm
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ void GetFlagFeatureEntries(flags_ui::FlagsStorage* flags_storage,
base::ListValue* unsupported_entries) {
GetGlobalFlagsState().GetFlagFeatureEntries(
flags_storage, access, supported_entries, unsupported_entries,
base::Bind(&SkipConditionalFeatureEntry));
base::BindRepeating(&SkipConditionalFeatureEntry));
}

void SetFeatureEntryEnabled(flags_ui::FlagsStorage* flags_storage,
Expand Down
8 changes: 4 additions & 4 deletions ios/chrome/browser/history/history_client_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ void HistoryClientImpl::OnHistoryServiceCreated(
history::HistoryService* history_service) {
if (bookmark_model_) {
on_bookmarks_removed_ =
base::Bind(&history::HistoryService::URLsNoLongerBookmarked,
base::Unretained(history_service));
base::BindRepeating(&history::HistoryService::URLsNoLongerBookmarked,
base::Unretained(history_service));
favicons_changed_subscription_ =
history_service->AddFaviconsChangedCallback(
base::Bind(&bookmarks::BookmarkModel::OnFaviconsChanged,
base::Unretained(bookmark_model_)));
base::BindRepeating(&bookmarks::BookmarkModel::OnFaviconsChanged,
base::Unretained(bookmark_model_)));
}
}

Expand Down
2 changes: 1 addition & 1 deletion ios/chrome/browser/history/history_client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class HistoryClientImpl : public history::HistoryClient,
bookmarks::BookmarkModel* bookmark_model_;

// Callback invoked when URLs are removed from BookmarkModel.
base::Callback<void(const std::set<GURL>&)> on_bookmarks_removed_;
base::RepeatingCallback<void(const std::set<GURL>&)> on_bookmarks_removed_;

// Subscription for notifications of changes to favicons.
std::unique_ptr<
Expand Down
7 changes: 4 additions & 3 deletions ios/chrome/browser/history/top_sites_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ scoped_refptr<RefcountedKeyedService> TopSitesFactory::BuildServiceInstanceFor(
history::HistoryService* history_service =
ios::HistoryServiceFactory::GetForBrowserState(
browser_state, ServiceAccessType::EXPLICIT_ACCESS);
scoped_refptr<history::TopSitesImpl> top_sites(new history::TopSitesImpl(
browser_state->GetPrefs(), history_service,
history::PrepopulatedPageList(), base::Bind(CanAddURLToHistory)));
scoped_refptr<history::TopSitesImpl> top_sites(
new history::TopSitesImpl(browser_state->GetPrefs(), history_service,
history::PrepopulatedPageList(),
base::BindRepeating(CanAddURLToHistory)));
top_sites->Init(
browser_state->GetStatePath().Append(history::kTopSitesFilename));
return top_sites;
Expand Down
5 changes: 3 additions & 2 deletions ios/chrome/browser/metrics/first_user_action_recorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ FirstUserActionRecorder::FirstUserActionRecorder(
recorded_action_(false),
action_pending_(false),
background_duration_(background_duration),
action_callback_(base::Bind(&FirstUserActionRecorder::OnUserAction,
base::Unretained(this))) {
action_callback_(
base::BindRepeating(&FirstUserActionRecorder::OnUserAction,
base::Unretained(this))) {
base::AddActionCallback(action_callback_);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,13 @@ void GetNetworkConnectionTrackerAsync(
bool IOSChromeMetricsServiceClient::RegisterForNotifications() {
tab_parented_subscription_ =
TabParentingGlobalObserver::GetInstance()->RegisterCallback(
base::Bind(&IOSChromeMetricsServiceClient::OnTabParented,
base::Unretained(this)));
base::BindRepeating(&IOSChromeMetricsServiceClient::OnTabParented,
base::Unretained(this)));
omnibox_url_opened_subscription_ =
OmniboxEventGlobalTracker::GetInstance()->RegisterCallback(
base::Bind(&IOSChromeMetricsServiceClient::OnURLOpenedFromOmnibox,
base::Unretained(this)));
base::BindRepeating(
&IOSChromeMetricsServiceClient::OnURLOpenedFromOmnibox,
base::Unretained(this)));

std::vector<ChromeBrowserState*> loaded_browser_states =
GetApplicationContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ bool IsConsentGiven() const override {
DCHECK(thread_checker_.CalledOnValidThread());
return std::make_unique<rappor::RapporServiceImpl>(
local_state_,
base::Bind(
base::BindRepeating(
&IOSChromeMetricsServicesManagerClient::AreIncognitoTabsPresent));
}

Expand Down Expand Up @@ -100,8 +100,8 @@ bool IsConsentGiven() const override {
if (!metrics_state_manager_) {
metrics_state_manager_ = metrics::MetricsStateManager::Create(
local_state_, enabled_state_provider_.get(), base::string16(),
base::Bind(&PostStoreMetricsClientInfo),
base::Bind(&LoadMetricsClientInfo));
base::BindRepeating(&PostStoreMetricsClientInfo),
base::BindRepeating(&LoadMetricsClientInfo));
}
return metrics_state_manager_.get();
}
Expand Down
4 changes: 2 additions & 2 deletions ios/chrome/browser/omaha/omaha_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class OmahaService {

// Returns debug information about the omaha service.
static void GetDebugInformation(
const base::Callback<void(base::DictionaryValue*)> callback);
base::OnceCallback<void(base::DictionaryValue*)> callback);

private:
// For tests:
Expand Down Expand Up @@ -152,7 +152,7 @@ class OmahaService {

// Computes debugging information and fill |result|.
void GetDebugInformationOnIOThread(
const base::Callback<void(base::DictionaryValue*)> callback);
base::OnceCallback<void(base::DictionaryValue*)> callback);

// Returns whether the next ping to send must a an install/update ping. If
// |true|, the next ping must use |GetInstallRetryRequestId| as identifier
Expand Down
21 changes: 12 additions & 9 deletions ios/chrome/browser/omaha/omaha_service.mm
Original file line number Diff line number Diff line change
Expand Up @@ -469,18 +469,20 @@ - (void)parser:(NSXMLParser*)parser

// static
void OmahaService::GetDebugInformation(
const base::Callback<void(base::DictionaryValue*)> callback) {
base::OnceCallback<void(base::DictionaryValue*)> callback) {
if (OmahaService::IsEnabled()) {
OmahaService* service = GetInstance();
base::PostTask(FROM_HERE, {web::WebThread::IO},
base::BindOnce(&OmahaService::GetDebugInformationOnIOThread,
base::Unretained(service), callback));
base::PostTask(
FROM_HERE, {web::WebThread::IO},
base::BindOnce(&OmahaService::GetDebugInformationOnIOThread,
base::Unretained(service), std::move(callback)));

} else {
auto result = std::make_unique<base::DictionaryValue>();
// Invoke the callback with an empty response.
base::PostTask(FROM_HERE, {web::WebThread::UI},
base::BindOnce(callback, base::Owned(result.release())));
base::PostTask(
FROM_HERE, {web::WebThread::UI},
base::BindOnce(std::move(callback), base::Owned(result.release())));
}
}

Expand Down Expand Up @@ -773,7 +775,7 @@ GURL url(ios::GetChromeBrowserProvider()
}

void OmahaService::GetDebugInformationOnIOThread(
const base::Callback<void(base::DictionaryValue*)> callback) {
base::OnceCallback<void(base::DictionaryValue*)> callback) {
auto result = std::make_unique<base::DictionaryValue>();

result->SetString("message", GetCurrentPingContent());
Expand All @@ -797,8 +799,9 @@ GURL url(ios::GetChromeBrowserProvider()
(timer_.desired_run_time() - base::TimeTicks::Now())));

// Sending the value to the callback.
base::PostTask(FROM_HERE, {web::WebThread::UI},
base::BindOnce(callback, base::Owned(result.release())));
base::PostTask(
FROM_HERE, {web::WebThread::UI},
base::BindOnce(std::move(callback), base::Owned(result.release())));
}

bool OmahaService::IsNextPingInstallRetry() {
Expand Down
Loading

0 comments on commit 208c819

Please sign in to comment.