Commit 0e840ae8 authored by Alex Turner's avatar Alex Turner Committed by Commit Bot

Migrate chrome/browser/metrics from base::Bind/Closure to Once/Repeating

base::Bind and base::Closure are deprecated and should be replaced with
the more explicit base::Bind{Once,Repeating} and
base::{Once,Repeating}Closure.

Bug: 1140564
Change-Id: Ieccd1f263d452a574cb439ca17e093c0fc5a94ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2487708Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Reviewed-by: default avatarDirk Pranke <dpranke@google.com>
Commit-Queue: Alex Turner <alexmt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820036}
parent ba165573
......@@ -333,7 +333,6 @@ _NOT_CONVERTED_TO_MODERN_BIND_AND_CALLBACK = '|'.join((
'^chrome/browser/lifetime/',
'^chrome/browser/media_galleries/',
'^chrome/browser/media/',
'^chrome/browser/metrics/',
'^chrome/browser/net/',
'^chrome/browser/notifications/',
'^chrome/browser/ntp_tiles/ntp_tiles_browsertest.cc',
......
......@@ -921,8 +921,9 @@ bool ChromeMetricsServiceClient::RegisterForNotifications() {
omnibox_url_opened_subscription_ =
OmniboxEventGlobalTracker::GetInstance()->RegisterCallback(
base::Bind(&ChromeMetricsServiceClient::OnURLOpenedFromOmnibox,
base::Unretained(this)));
base::BindRepeating(
&ChromeMetricsServiceClient::OnURLOpenedFromOmnibox,
base::Unretained(this)));
#if !defined(OS_ANDROID)
browser_activity_watcher_ = std::make_unique<BrowserActivityWatcher>(
......
......@@ -245,7 +245,7 @@ bool ChromeMetricsServicesManagerClient::GetSamplingRatePerMille(int* rate) {
void ChromeMetricsServicesManagerClient::OnCrosSettingsCreated() {
reporting_setting_observer_ =
chromeos::StatsReportingController::Get()->AddObserver(
base::Bind(&OnCrosMetricsReportingSettingChange));
base::BindRepeating(&OnCrosMetricsReportingSettingChange));
// Invoke the callback once initially to set the metrics reporting state.
OnCrosMetricsReportingSettingChange();
}
......@@ -260,7 +260,7 @@ std::unique_ptr<rappor::RapporServiceImpl>
ChromeMetricsServicesManagerClient::CreateRapporServiceImpl() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
return std::make_unique<rappor::RapporServiceImpl>(
local_state_, base::Bind(&chrome::IsOffTheRecordSessionActive));
local_state_, base::BindRepeating(&chrome::IsOffTheRecordSessionActive));
}
std::unique_ptr<variations::VariationsService>
......@@ -285,8 +285,8 @@ ChromeMetricsServicesManagerClient::GetMetricsStateManager() {
if (!metrics_state_manager_) {
metrics_state_manager_ = metrics::MetricsStateManager::Create(
local_state_, enabled_state_provider_.get(), GetRegistryBackupKey(),
base::Bind(&PostStoreMetricsClientInfo),
base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo));
base::BindRepeating(&PostStoreMetricsClientInfo),
base::BindRepeating(&GoogleUpdateSettings::LoadMetricsClientInfo));
}
return metrics_state_manager_.get();
}
......
......@@ -134,7 +134,8 @@ TEST(ExtensionsMetricsProvider, SystemProtoEncoding) {
std::unique_ptr<metrics::MetricsStateManager> metrics_state_manager(
metrics::MetricsStateManager::Create(
&local_state, &enabled_state_provider, base::string16(),
base::Bind(&StoreNoClientInfoBackup), base::Bind(&ReturnNoBackup)));
base::BindRepeating(&StoreNoClientInfoBackup),
base::BindRepeating(&ReturnNoBackup)));
TestExtensionsMetricsProvider extension_metrics(metrics_state_manager.get());
extension_metrics.ProvideSystemProfileMetrics(&system_profile);
ASSERT_EQ(2, system_profile.occupied_extension_bucket_size());
......
......@@ -651,16 +651,16 @@ void ProcessMemoryMetricsEmitter::FetchAndEmitProcessMemoryMetrics() {
// The callback keeps this object alive until the callback is invoked.
auto callback =
base::Bind(&ProcessMemoryMetricsEmitter::ReceivedMemoryDump, this);
base::BindOnce(&ProcessMemoryMetricsEmitter::ReceivedMemoryDump, this);
std::vector<std::string> mad_list;
for (const auto& metric : kAllocatorDumpNamesForMetrics)
mad_list.push_back(metric.dump_name);
if (pid_scope_ != base::kNullProcessId) {
memory_instrumentation::MemoryInstrumentation::GetInstance()
->RequestGlobalDumpForPid(pid_scope_, mad_list, callback);
->RequestGlobalDumpForPid(pid_scope_, mad_list, std::move(callback));
} else {
memory_instrumentation::MemoryInstrumentation::GetInstance()
->RequestGlobalDump(mad_list, callback);
->RequestGlobalDump(mad_list, std::move(callback));
}
// Use a lambda adapter to post the results back to this sequence.
......
......@@ -113,8 +113,8 @@ ThreadWatcherObserver::ThreadWatcherObserver(
content::NotificationService::AllSources());
omnibox_url_opened_subscription_ =
OmniboxEventGlobalTracker::GetInstance()->RegisterCallback(
base::Bind(&ThreadWatcherObserver::OnURLOpenedFromOmnibox,
base::Unretained(this)));
base::BindRepeating(&ThreadWatcherObserver::OnURLOpenedFromOmnibox,
base::Unretained(this)));
}
ThreadWatcherObserver::~ThreadWatcherObserver() {
......@@ -152,7 +152,7 @@ void ThreadWatcherObserver::OnUserActivityDetected() {
return;
last_wakeup_time_ = now;
WatchDogThread::PostTask(FROM_HERE,
base::Bind(&ThreadWatcherList::WakeUpAll));
base::BindOnce(&ThreadWatcherList::WakeUpAll));
}
} // namespace
......@@ -191,8 +191,7 @@ void ThreadWatcher::StartWatching(const WatchingParams& params) {
// WatchDogThread.
if (!WatchDogThread::CurrentlyOnWatchDogThread()) {
WatchDogThread::PostTask(
FROM_HERE,
base::Bind(&ThreadWatcher::StartWatching, params));
FROM_HERE, base::BindOnce(&ThreadWatcher::StartWatching, params));
return;
}
......@@ -262,12 +261,12 @@ void ThreadWatcher::PostPingMessage() {
// Send a ping message to the watched thread. Callback will be called on
// the WatchDogThread.
base::Closure callback(
base::Bind(&ThreadWatcher::OnPongMessage, weak_ptr_factory_.GetWeakPtr(),
ping_sequence_number_));
base::OnceClosure callback(base::BindOnce(&ThreadWatcher::OnPongMessage,
weak_ptr_factory_.GetWeakPtr(),
ping_sequence_number_));
if (watched_runner_->PostTask(
FROM_HERE, base::BindOnce(&ThreadWatcher::OnPingMessage, thread_id_,
callback))) {
std::move(callback)))) {
// Post a task to check the responsiveness of watched thread.
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
......@@ -386,10 +385,10 @@ void ThreadWatcher::Initialize() {
// static
void ThreadWatcher::OnPingMessage(const BrowserThread::ID& thread_id,
const base::Closure& callback_task) {
base::OnceClosure callback_task) {
// This method is called on watched thread.
DCHECK(BrowserThread::CurrentlyOn(thread_id));
WatchDogThread::PostTask(FROM_HERE, callback_task);
WatchDogThread::PostTask(FROM_HERE, std::move(callback_task));
}
void ThreadWatcher::ResetHangCounters() {
......@@ -502,13 +501,12 @@ void ThreadWatcherList::StartWatchingAll(
base::TimeDelta::FromSeconds(kSleepSeconds * unresponsive_threshold));
WatchDogThread::PostTask(
FROM_HERE,
base::Bind(&ThreadWatcherList::SetStopped, false));
FROM_HERE, base::BindOnce(&ThreadWatcherList::SetStopped, false));
WatchDogThread::PostDelayedTask(
FROM_HERE,
base::Bind(&ThreadWatcherList::InitializeAndStartWatching,
unresponsive_threshold, crash_on_hang_threads),
base::BindOnce(&ThreadWatcherList::InitializeAndStartWatching,
unresponsive_threshold, crash_on_hang_threads),
base::TimeDelta::FromSeconds(g_initialize_delay_seconds));
}
......@@ -706,9 +704,8 @@ void ThreadWatcherList::StartWatching(
// static
void ThreadWatcherList::DeleteAll() {
if (!WatchDogThread::CurrentlyOnWatchDogThread()) {
WatchDogThread::PostTask(
FROM_HERE,
base::Bind(&ThreadWatcherList::DeleteAll));
WatchDogThread::PostTask(FROM_HERE,
base::BindOnce(&ThreadWatcherList::DeleteAll));
return;
}
......@@ -784,20 +781,20 @@ bool WatchDogThread::CurrentlyOnWatchDogThread() {
// static
bool WatchDogThread::PostTask(const base::Location& from_here,
const base::Closure& task) {
return PostTaskHelper(from_here, task, base::TimeDelta());
base::OnceClosure task) {
return PostTaskHelper(from_here, std::move(task), base::TimeDelta());
}
// static
bool WatchDogThread::PostDelayedTask(const base::Location& from_here,
const base::Closure& task,
base::OnceClosure task,
base::TimeDelta delay) {
return PostTaskHelper(from_here, task, delay);
return PostTaskHelper(from_here, std::move(task), delay);
}
// static
bool WatchDogThread::PostTaskHelper(const base::Location& from_here,
const base::Closure& task,
base::OnceClosure task,
base::TimeDelta delay) {
{
base::AutoLock lock(g_watchdog_lock.Get());
......@@ -805,7 +802,7 @@ bool WatchDogThread::PostTaskHelper(const base::Location& from_here,
scoped_refptr<base::SingleThreadTaskRunner> task_runner =
g_watchdog_thread ? g_watchdog_thread->task_runner() : nullptr;
if (task_runner) {
task_runner->PostDelayedTask(from_here, task, delay);
task_runner->PostDelayedTask(from_here, std::move(task), delay);
return true;
}
}
......@@ -855,7 +852,7 @@ class StartupWatchDogThread : public base::Watchdog {
#if !defined(NDEBUG)
metrics::StartupHang();
#else
WatchDogThread::PostTask(FROM_HERE, base::Bind(&metrics::StartupHang));
WatchDogThread::PostTask(FROM_HERE, base::BindOnce(&metrics::StartupHang));
#endif
}
......
......@@ -193,7 +193,7 @@ class ThreadWatcher {
// Watched thread does nothing except post callback_task to the WATCHDOG
// Thread. This method is called on watched thread.
static void OnPingMessage(const content::BrowserThread::ID& thread_id,
const base::Closure& callback_task);
base::OnceClosure callback_task);
// This method resets |unresponsive_count_| to zero because watched thread is
// responding to the ping message with a pong message.
......@@ -474,10 +474,9 @@ class WatchDogThread : public base::Thread {
// They return true iff the watchdog thread existed and the task was posted.
// Note that even if the task is posted, there's no guarantee that it will
// run, since the target thread may already have a Quit message in its queue.
static bool PostTask(const base::Location& from_here,
const base::Closure& task);
static bool PostTask(const base::Location& from_here, base::OnceClosure task);
static bool PostDelayedTask(const base::Location& from_here,
const base::Closure& task,
base::OnceClosure task,
base::TimeDelta delay);
protected:
......@@ -489,7 +488,7 @@ class WatchDogThread : public base::Thread {
bool Started() const;
static bool PostTaskHelper(const base::Location& from_here,
const base::Closure& task,
base::OnceClosure task,
base::TimeDelta delay);
DISALLOW_COPY_AND_ASSIGN(WatchDogThread);
......
......@@ -18,10 +18,9 @@ void OnThreadWatcherTask(base::WaitableEvent* event) {
}
void PostAndWaitForWatchdogThread(base::WaitableEvent* event) {
WatchDogThread::PostDelayedTask(
FROM_HERE,
base::Bind(&OnThreadWatcherTask, event),
base::TimeDelta::FromSeconds(0));
WatchDogThread::PostDelayedTask(FROM_HERE,
base::BindOnce(&OnThreadWatcherTask, event),
base::TimeDelta::FromSeconds(0));
EXPECT_TRUE(event->TimedWait(base::TimeDelta::FromSeconds(1)));
}
......
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