update_engine: libchrome deprecated Bind/Callback APIs .. as uprev'ed libchrome does not support this. Currently CrOS libchrome maintains a patch to support code that still utilizes the deprecated Bind/Callbacks. BUG=b:272116782 TEST=FEATURES=test emerge-$B update_engine Change-Id: I3d462abc054556458157ee79684170a677ad5694 Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/4315196 Auto-Submit: Jae Hoon Kim <kimjae@chromium.org> Reviewed-by: Yuanpeng Ni <yuanpengni@chromium.org> Tested-by: Jae Hoon Kim <kimjae@chromium.org> Reviewed-by: Qijiang Yūki Ishii <fqj@google.com> Commit-Queue: Yuanpeng Ni <yuanpengni@chromium.org>
diff --git a/client_library/client_dbus.cc b/client_library/client_dbus.cc index b3b4287..18b2693 100644 --- a/client_library/client_dbus.cc +++ b/client_library/client_dbus.cc
@@ -231,10 +231,10 @@ } proxy_->RegisterStatusUpdateAdvancedSignalHandler( - base::Bind(&DBusUpdateEngineClient::RunStatusUpdateHandlers, - base::Unretained(this)), - base::Bind(&DBusUpdateEngineClient::DBusStatusHandlersRegistered, - base::Unretained(this))); + base::BindRepeating(&DBusUpdateEngineClient::RunStatusUpdateHandlers, + base::Unretained(this)), + base::BindOnce(&DBusUpdateEngineClient::DBusStatusHandlersRegistered, + base::Unretained(this))); dbus_handler_registered_ = true;
diff --git a/common/cpu_limiter.cc b/common/cpu_limiter.cc index b67107c..d2ab0d0 100644 --- a/common/cpu_limiter.cc +++ b/common/cpu_limiter.cc
@@ -47,7 +47,7 @@ } manage_shares_id_ = brillo::MessageLoop::current()->PostDelayedTask( FROM_HERE, - base::Bind(&CPULimiter::StopLimiterCallback, base::Unretained(this)), + base::BindOnce(&CPULimiter::StopLimiterCallback, base::Unretained(this)), base::Hours(2)); SetCpuShares(CpuShares::kLow); }
diff --git a/common/file_fetcher.cc b/common/file_fetcher.cc index 96d0d91..140f293 100644 --- a/common/file_fetcher.cc +++ b/common/file_fetcher.cc
@@ -127,8 +127,8 @@ ongoing_read_ = stream_->ReadAsync( buffer_.data(), bytes_to_read, - base::Bind(&FileFetcher::OnReadDoneCallback, base::Unretained(this)), - base::Bind(&FileFetcher::OnReadErrorCallback, base::Unretained(this)), + base::BindOnce(&FileFetcher::OnReadDoneCallback, base::Unretained(this)), + base::BindOnce(&FileFetcher::OnReadErrorCallback, base::Unretained(this)), nullptr); if (!ongoing_read_) {
diff --git a/common/mock_http_fetcher.cc b/common/mock_http_fetcher.cc index 41d95c8..9b91a9f 100644 --- a/common/mock_http_fetcher.cc +++ b/common/mock_http_fetcher.cc
@@ -65,7 +65,8 @@ CHECK(MessageLoop::current()); timeout_id_ = MessageLoop::current()->PostDelayedTask( FROM_HERE, - base::Bind(&MockHttpFetcher::TimeoutCallback, base::Unretained(this)), + base::BindOnce(&MockHttpFetcher::TimeoutCallback, + base::Unretained(this)), base::Milliseconds(10)); }
diff --git a/common/subprocess.cc b/common/subprocess.cc index 89d5b3a..bf8c5b5 100644 --- a/common/subprocess.cc +++ b/common/subprocess.cc
@@ -98,7 +98,7 @@ } proc->SetCloseUnusedFileDescriptors(true); proc->RedirectUsingPipe(STDOUT_FILENO, false); - proc->SetPreExecCallback(base::Bind(&SetupChild, env, flags)); + proc->SetPreExecCallback(base::BindOnce(&SetupChild, env, flags)); LOG(INFO) << "Running \"" << base::JoinString(cmd, " ") << "\""; return proc->Start(); @@ -193,7 +193,8 @@ CHECK(process_reaper_.WatchForChild( FROM_HERE, pid, - base::Bind(&Subprocess::ChildExitedCallback, base::Unretained(this)))); + base::BindOnce(&Subprocess::ChildExitedCallback, + base::Unretained(this)))); record->stdout_fd = record->proc.GetPipe(STDOUT_FILENO); // Capture the subprocess output. Make our end of the pipe non-blocking.
diff --git a/cros/daemon_chromeos.cc b/cros/daemon_chromeos.cc index d37fda5..51bed34 100644 --- a/cros/daemon_chromeos.cc +++ b/cros/daemon_chromeos.cc
@@ -52,8 +52,8 @@ dbus_adaptor_.reset(new UpdateEngineAdaptor()); SystemState::Get()->update_attempter()->AddObserver(dbus_adaptor_.get()); - dbus_adaptor_->RegisterAsync( - base::Bind(&DaemonChromeOS::OnDBusRegistered, base::Unretained(this))); + dbus_adaptor_->RegisterAsync(base::BindOnce(&DaemonChromeOS::OnDBusRegistered, + base::Unretained(this))); LOG(INFO) << "Waiting for DBus object to be registered."; return EX_OK; }
diff --git a/cros/dbus_service.cc b/cros/dbus_service.cc index 668ba3a..28e1088 100644 --- a/cros/dbus_service.cc +++ b/cros/dbus_service.cc
@@ -17,6 +17,7 @@ #include "update_engine/cros/dbus_service.h" #include <string> +#include <utility> #include <vector> #include <update_engine/dbus-constants.h> @@ -231,9 +232,9 @@ dbus::ObjectPath(update_engine::kUpdateEngineServicePath)) {} void UpdateEngineAdaptor::RegisterAsync( - const base::Callback<void(bool)>& completion_callback) { + base::OnceCallback<void(bool)> completion_callback) { RegisterWithDBusObject(&dbus_object_); - dbus_object_.RegisterAsync(completion_callback); + dbus_object_.RegisterAsync(std::move(completion_callback)); } bool UpdateEngineAdaptor::RequestOwnership() {
diff --git a/cros/dbus_service.h b/cros/dbus_service.h index 73b6a88..c2023d9 100644 --- a/cros/dbus_service.h +++ b/cros/dbus_service.h
@@ -191,7 +191,7 @@ // Register the DBus object with the update engine service asynchronously. // Calls |copmletion_callback| when done passing a boolean indicating if the // registration succeeded. - void RegisterAsync(const base::Callback<void(bool)>& completion_callback); + void RegisterAsync(base::OnceCallback<void(bool)> completion_callback); // Takes ownership of the well-known DBus name and returns whether it // succeeded.
diff --git a/cros/dbus_test_utils.h b/cros/dbus_test_utils.h index a6abbf9..06657c5 100644 --- a/cros/dbus_test_utils.h +++ b/cros/dbus_test_utils.h
@@ -50,19 +50,21 @@ // Returns whether the signal handler is registered. bool IsHandlerRegistered() const { return signal_callback_ != nullptr; } - const base::Callback<T>& signal_callback() { return *signal_callback_.get(); } + const base::RepeatingCallback<T>& signal_callback() { + return *signal_callback_.get(); + } void GrabCallbacks( - const base::Callback<T>& signal_callback, + const base::RepeatingCallback<T>& signal_callback, dbus::ObjectProxy::OnConnectedCallback* on_connected_callback) { - signal_callback_.reset(new base::Callback<T>(signal_callback)); + signal_callback_.reset(new base::RepeatingCallback<T>(signal_callback)); on_connected_callback_.reset(new dbus::ObjectProxy::OnConnectedCallback( std::move(*on_connected_callback))); // Notify from the main loop that the callback was connected. callback_connected_task_ = brillo::MessageLoop::current()->PostTask( FROM_HERE, - base::Bind(&MockSignalHandler<T>::OnCallbackConnected, - base::Unretained(this))); + base::BindOnce(&MockSignalHandler<T>::OnCallbackConnected, + base::Unretained(this))); } private: @@ -74,7 +76,7 @@ brillo::MessageLoop::TaskId callback_connected_task_{ brillo::MessageLoop::kTaskIdNull}; - std::unique_ptr<base::Callback<T>> signal_callback_; + std::unique_ptr<base::RepeatingCallback<T>> signal_callback_; std::unique_ptr<dbus::ObjectProxy::OnConnectedCallback> on_connected_callback_; };
diff --git a/cros/download_action_chromeos_unittest.cc b/cros/download_action_chromeos_unittest.cc index c56f306..052f1a1 100644 --- a/cros/download_action_chromeos_unittest.cc +++ b/cros/download_action_chromeos_unittest.cc
@@ -199,7 +199,7 @@ loop.PostTask( FROM_HERE, - base::Bind(&StartProcessorInRunLoop, &processor, http_fetcher_ptr)); + base::BindOnce(&StartProcessorInRunLoop, &processor, http_fetcher_ptr)); loop.Run(); EXPECT_FALSE(loop.PendingTasks()); @@ -330,7 +330,7 @@ loop.PostTask( FROM_HERE, - base::Bind( + base::BindOnce( [](ActionProcessor* processor) { processor->StartProcessing(); }, base::Unretained(&processor))); loop.Run(); @@ -387,7 +387,7 @@ processor.EnqueueAction(std::move(download_action)); loop.PostTask(FROM_HERE, - base::Bind(&TerminateEarlyTestStarter, &processor)); + base::BindOnce(&TerminateEarlyTestStarter, &processor)); loop.Run(); EXPECT_FALSE(loop.PendingTasks()); } @@ -497,7 +497,7 @@ loop.PostTask( FROM_HERE, - base::Bind( + base::BindOnce( [](ActionProcessor* processor) { processor->StartProcessing(); }, base::Unretained(&processor))); loop.Run(); @@ -577,7 +577,7 @@ loop_.PostTask( FROM_HERE, - base::Bind( + base::BindOnce( [](P2PDownloadActionTest* action_test, HttpFetcher* http_fetcher) { action_test->processor_.StartProcessing(); http_fetcher->SetOffset(action_test->start_at_offset_); @@ -742,7 +742,7 @@ loop_.PostTask( FROM_HERE, - base::Bind( + base::BindOnce( [](ActionProcessor* processor) { processor->StartProcessing(); }, base::Unretained(&processor_))); loop_.Run();
diff --git a/cros/fake_p2p_manager.h b/cros/fake_p2p_manager.h index e8399d0..38d0df9 100644 --- a/cros/fake_p2p_manager.h +++ b/cros/fake_p2p_manager.h
@@ -18,6 +18,7 @@ #define UPDATE_ENGINE_CROS_FAKE_P2P_MANAGER_H_ #include <string> +#include <utility> #include "update_engine/cros/p2p_manager.h" @@ -50,7 +51,7 @@ size_t minimum_size, base::TimeDelta max_time_to_wait, LookupCallback callback) override { - callback.Run(lookup_url_for_file_result_); + std::move(callback).Run(lookup_url_for_file_result_); } bool FileShare(const std::string& file_id, size_t expected_size) override {
diff --git a/cros/install_action_test.cc b/cros/install_action_test.cc index 58d3985..1ec9940 100644 --- a/cros/install_action_test.cc +++ b/cros/install_action_test.cc
@@ -155,7 +155,7 @@ loop_.PostTask( FROM_HERE, - base::Bind( + base::BindOnce( [](ActionProcessor* processor) { processor->StartProcessing(); }, base::Unretained(&processor_))); loop_.Run(); @@ -186,7 +186,7 @@ loop_.PostTask( FROM_HERE, - base::Bind( + base::BindOnce( [](ActionProcessor* processor) { processor->StartProcessing(); }, base::Unretained(&processor_))); loop_.Run(); @@ -217,7 +217,7 @@ loop_.PostTask( FROM_HERE, - base::Bind( + base::BindOnce( [](ActionProcessor* processor) { processor->StartProcessing(); }, base::Unretained(&processor_))); loop_.Run(); @@ -251,7 +251,7 @@ loop_.PostTask( FROM_HERE, - base::Bind( + base::BindOnce( [](ActionProcessor* processor) { processor->StartProcessing(); }, base::Unretained(&processor_))); loop_.Run();
diff --git a/cros/omaha_request_action.cc b/cros/omaha_request_action.cc index cc42934..a97408b 100644 --- a/cros/omaha_request_action.cc +++ b/cros/omaha_request_action.cc
@@ -906,8 +906,8 @@ file_id, minimum_size, kMaxP2PNetworkWaitTime, - base::Bind(&OmahaRequestAction::OnLookupPayloadViaP2PCompleted, - base::Unretained(this))); + base::BindOnce(&OmahaRequestAction::OnLookupPayloadViaP2PCompleted, + base::Unretained(this))); } }
diff --git a/cros/omaha_request_action_unittest.cc b/cros/omaha_request_action_unittest.cc index c57066b..2007cab 100644 --- a/cros/omaha_request_action_unittest.cc +++ b/cros/omaha_request_action_unittest.cc
@@ -590,7 +590,7 @@ tuc_params_.expected_download_error_code)) .Times(tuc_params_.ping_only ? 0 : 1); - loop_.PostTask(base::Bind( + loop_.PostTask(base::BindOnce( [](ActionProcessor* processor) { processor->StartProcessing(); }, base::Unretained(&processor))); loop_.Run(); @@ -616,7 +616,7 @@ processor.set_delegate(&delegate_); processor.EnqueueAction(std::move(action)); - loop_.PostTask(base::Bind( + loop_.PostTask(base::BindOnce( [](ActionProcessor* processor) { processor->StartProcessing(); }, base::Unretained(&processor))); loop_.Run(); @@ -1588,7 +1588,7 @@ processor.set_delegate(&delegate_); processor.EnqueueAction(std::move(action)); - loop_.PostTask(base::Bind( + loop_.PostTask(base::BindOnce( [](ActionProcessor* processor) { processor->StartProcessing(); }, base::Unretained(&processor))); loop_.Run(); @@ -1721,7 +1721,7 @@ processor.set_delegate(&delegate); processor.EnqueueAction(std::move(action)); - loop_.PostTask(base::Bind(&TerminateTransferTestStarter, &processor)); + loop_.PostTask(base::BindOnce(&TerminateTransferTestStarter, &processor)); loop_.Run(); EXPECT_FALSE(loop_.PendingTasks()); }
diff --git a/cros/p2p_manager.cc b/cros/p2p_manager.cc index aaa72cc..76a2cd8 100644 --- a/cros/p2p_manager.cc +++ b/cros/p2p_manager.cc
@@ -57,7 +57,6 @@ #include "update_engine/update_manager/p2p_enabled_policy.h" #include "update_engine/update_manager/update_manager.h" -using base::Bind; using base::FilePath; using base::StringPrintf; using base::Time; @@ -374,7 +373,7 @@ class LookupData { public: explicit LookupData(P2PManager::LookupCallback callback) - : callback_(callback) {} + : callback_(std::move(callback)) {} ~LookupData() { if (timeout_task_ != MessageLoop::kTaskIdNull) @@ -405,7 +404,7 @@ if (timeout > TimeDelta()) { timeout_task_ = MessageLoop::current()->PostDelayedTask( FROM_HERE, - Bind(&LookupData::OnTimeout, base::Unretained(this)), + base::BindOnce(&LookupData::OnTimeout, base::Unretained(this)), timeout); } } @@ -414,8 +413,8 @@ void ReportErrorAndDeleteInIdle() { MessageLoop::current()->PostTask( FROM_HERE, - Bind(&LookupData::OnIdleForReportErrorAndDelete, - base::Unretained(this))); + base::BindOnce(&LookupData::OnIdleForReportErrorAndDelete, + base::Unretained(this))); } void OnIdleForReportErrorAndDelete() { @@ -425,7 +424,7 @@ void IssueCallback(const string& url) { if (!callback_.is_null()) - callback_.Run(url); + std::move(callback_).Run(url); } void ReportError() { @@ -488,7 +487,7 @@ size_t minimum_size, TimeDelta max_time_to_wait, LookupCallback callback) { - LookupData* lookup_data = new LookupData(callback); + LookupData* lookup_data = new LookupData(std::move(callback)); string file_id_with_ext = file_id + "." + file_extension_; vector<string> args = configuration_->GetP2PClientArgs(file_id_with_ext, minimum_size); @@ -695,7 +694,8 @@ update_manager_->PolicyRequest( std::make_unique<P2PEnabledChangedPolicy>(), policy_data_, - Bind(&P2PManagerImpl::OnEnabledStatusChange, base::Unretained(this))); + base::BindOnce(&P2PManagerImpl::OnEnabledStatusChange, + base::Unretained(this))); waiting_for_enabled_status_change_ = true; }
diff --git a/cros/p2p_manager.h b/cros/p2p_manager.h index 889731d..14e4ca4 100644 --- a/cros/p2p_manager.h +++ b/cros/p2p_manager.h
@@ -59,7 +59,7 @@ // The type for the callback used in LookupUrlForFile(). // If the lookup failed, |url| is empty. - typedef base::Callback<void(const std::string& url)> LookupCallback; + typedef base::OnceCallback<void(const std::string& url)> LookupCallback; // Use the device policy specified by |device_policy|. If this is // null, then no device policy is used.
diff --git a/cros/p2p_manager_unittest.cc b/cros/p2p_manager_unittest.cc index bd275a6..dc99471 100644 --- a/cros/p2p_manager_unittest.cc +++ b/cros/p2p_manager_unittest.cc
@@ -505,31 +505,31 @@ "fooX", 42, TimeDelta(), - base::Bind(ExpectUrl, "http://1.2.3.4/fooX.cros_au_42")); + base::BindOnce(ExpectUrl, "http://1.2.3.4/fooX.cros_au_42")); loop_.Run(); // Emulate p2p-client returning invalid URL. test_conf_->SetP2PClientCommand({"echo", "not_a_valid_url"}); manager_->LookupUrlForFile( - "foobar", 42, TimeDelta(), base::Bind(ExpectUrl, "")); + "foobar", 42, TimeDelta(), base::BindOnce(ExpectUrl, "")); loop_.Run(); // Emulate p2p-client conveying failure. test_conf_->SetP2PClientCommand({"false"}); manager_->LookupUrlForFile( - "foobar", 42, TimeDelta(), base::Bind(ExpectUrl, "")); + "foobar", 42, TimeDelta(), base::BindOnce(ExpectUrl, "")); loop_.Run(); // Emulate p2p-client not existing. test_conf_->SetP2PClientCommand({"/path/to/non/existent/helper/program"}); manager_->LookupUrlForFile( - "foobar", 42, TimeDelta(), base::Bind(ExpectUrl, "")); + "foobar", 42, TimeDelta(), base::BindOnce(ExpectUrl, "")); loop_.Run(); // Emulate p2p-client crashing. test_conf_->SetP2PClientCommand({"sh", "-c", "kill -SEGV $$"}); manager_->LookupUrlForFile( - "foobar", 42, TimeDelta(), base::Bind(ExpectUrl, "")); + "foobar", 42, TimeDelta(), base::BindOnce(ExpectUrl, "")); loop_.Run(); // Emulate p2p-client exceeding its timeout. @@ -547,7 +547,7 @@ "echo http://1.2.3.4/; " "wait"}); manager_->LookupUrlForFile( - "foobar", 42, base::Milliseconds(500), base::Bind(ExpectUrl, "")); + "foobar", 42, base::Milliseconds(500), base::BindOnce(ExpectUrl, "")); loop_.Run(); }
diff --git a/cros/update_attempter.cc b/cros/update_attempter.cc index bfb410a..184f945 100644 --- a/cros/update_attempter.cc +++ b/cros/update_attempter.cc
@@ -72,8 +72,6 @@ #include "update_engine/update_manager/update_manager.h" #include "update_engine/update_status_utils.h" -using base::Bind; -using base::Callback; using base::FilePath; using base::Time; using base::TimeDelta; @@ -218,8 +216,8 @@ SystemState::Get()->update_manager()->PolicyRequest( std::make_unique<UpdateCheckAllowedPolicy>(), policy_data_, // Do not move because we don't want transfer of ownership. - base::Bind(&UpdateAttempter::OnUpdateScheduled, - weak_ptr_factory_.GetWeakPtr())); + base::BindOnce(&UpdateAttempter::OnUpdateScheduled, + weak_ptr_factory_.GetWeakPtr())); waiting_for_scheduled_check_ = true; return true; @@ -239,20 +237,21 @@ // Update boot flags after delay. MessageLoop::current()->PostDelayedTask( FROM_HERE, - base::Bind(&ActionProcessor::StartProcessing, - base::Unretained(&aux_processor_)), + base::BindOnce(&ActionProcessor::StartProcessing, + base::Unretained(&aux_processor_)), base::Seconds(60)); // Broadcast the update engine status on startup to ensure consistent system // state on crashes. - MessageLoop::current()->PostTask(FROM_HERE, - base::Bind(&UpdateAttempter::BroadcastStatus, - weak_ptr_factory_.GetWeakPtr())); + MessageLoop::current()->PostTask( + FROM_HERE, + base::BindOnce(&UpdateAttempter::BroadcastStatus, + weak_ptr_factory_.GetWeakPtr())); MessageLoop::current()->PostTask( FROM_HERE, - base::Bind(&UpdateAttempter::UpdateEngineStarted, - weak_ptr_factory_.GetWeakPtr())); + base::BindOnce(&UpdateAttempter::UpdateEngineStarted, + weak_ptr_factory_.GetWeakPtr())); return true; } @@ -2033,8 +2032,9 @@ LOG(INFO) << "Scheduling an action processor start."; MessageLoop::current()->PostTask( FROM_HERE, - Bind([](ActionProcessor* processor) { processor->StartProcessing(); }, - base::Unretained(processor_.get()))); + base::BindOnce( + [](ActionProcessor* processor) { processor->StartProcessing(); }, + base::Unretained(processor_.get()))); } void UpdateAttempter::DisableDeltaUpdateIfNeeded() {
diff --git a/cros/update_attempter.h b/cros/update_attempter.h index ef4c409..609804b 100644 --- a/cros/update_attempter.h +++ b/cros/update_attempter.h
@@ -267,7 +267,7 @@ // Note that only one callback can be set, so effectively at most one client // can be notified. virtual void set_forced_update_pending_callback( - base::Callback<void(bool, bool)>* callback) { + base::RepeatingCallback<void(bool, bool)>* callback) { forced_update_pending_callback_.reset(callback); } @@ -639,7 +639,7 @@ // cleared by an update attempt (false). The second argument indicates whether // this is an interactive update, and its value is significant iff the first // argument is true. - std::unique_ptr<base::Callback<void(bool, bool)>> + std::unique_ptr<base::RepeatingCallback<void(bool, bool)>> forced_update_pending_callback_; // The |app_version| and |omaha_url| parameters received during the latest
diff --git a/cros/update_attempter_unittest.cc b/cros/update_attempter_unittest.cc index b1c74d0..df3ee25 100644 --- a/cros/update_attempter_unittest.cc +++ b/cros/update_attempter_unittest.cc
@@ -27,6 +27,7 @@ #include <base/files/file_util.h> #include <base/files/scoped_temp_dir.h> +#include <base/functional/callback_helpers.h> #include <base/logging.h> #include <base/task/single_thread_task_executor.h> #include <brillo/message_loops/base_message_loop.h> @@ -239,7 +240,7 @@ certificate_checker_->Init(); attempter_.set_forced_update_pending_callback( - new base::Callback<void(bool, bool)>(base::Bind([](bool, bool) {}))); + new base::RepeatingCallback<void(bool, bool)>(base::DoNothing())); // Finish initializing the attempter. attempter_.Init(); @@ -408,8 +409,8 @@ void UpdateAttempterTest::ScheduleQuitMainLoop() { loop_.PostTask( FROM_HERE, - base::Bind([](brillo::BaseMessageLoop* loop) { loop->BreakLoop(); }, - base::Unretained(&loop_))); + base::BindOnce([](brillo::BaseMessageLoop* loop) { loop->BreakLoop(); }, + base::Unretained(&loop_))); } void UpdateAttempterTest::SessionIdTestChange() { @@ -422,8 +423,8 @@ TEST_F(UpdateAttempterTest, SessionIdTestChange) { loop_.PostTask(FROM_HERE, - base::Bind(&UpdateAttempterTest::SessionIdTestChange, - base::Unretained(this))); + base::BindOnce(&UpdateAttempterTest::SessionIdTestChange, + base::Unretained(this))); loop_.Run(); } @@ -451,8 +452,9 @@ TEST_F(UpdateAttempterTest, SessionIdTestEnforceEmptyStrPingOmaha) { loop_.PostTask( FROM_HERE, - base::Bind(&UpdateAttempterTest::SessionIdTestEnforceEmptyStrPingOmaha, - base::Unretained(this))); + base::BindOnce( + &UpdateAttempterTest::SessionIdTestEnforceEmptyStrPingOmaha, + base::Unretained(this))); loop_.Run(); } @@ -478,8 +480,8 @@ TEST_F(UpdateAttempterTest, SessionIdTestConsistencyInUpdateFlow) { loop_.PostTask( FROM_HERE, - base::Bind(&UpdateAttempterTest::SessionIdTestConsistencyInUpdateFlow, - base::Unretained(this))); + base::BindOnce(&UpdateAttempterTest::SessionIdTestConsistencyInUpdateFlow, + base::Unretained(this))); loop_.Run(); } @@ -505,9 +507,10 @@ } TEST_F(UpdateAttempterTest, SessionIdTestInDownloadAction) { - loop_.PostTask(FROM_HERE, - base::Bind(&UpdateAttempterTest::SessionIdTestInDownloadAction, - base::Unretained(this))); + loop_.PostTask( + FROM_HERE, + base::BindOnce(&UpdateAttempterTest::SessionIdTestInDownloadAction, + base::Unretained(this))); loop_.Run(); } @@ -812,8 +815,8 @@ attempter_.Update({}); loop_.PostTask(FROM_HERE, - base::Bind(&UpdateAttempterTest::UpdateTestVerify, - base::Unretained(this))); + base::BindOnce(&UpdateAttempterTest::UpdateTestVerify, + base::Unretained(this))); } void UpdateAttempterTest::UpdateTestVerify() { @@ -870,8 +873,8 @@ EXPECT_TRUE(attempter_.Rollback(true)); loop_.PostTask(FROM_HERE, - base::Bind(&UpdateAttempterTest::RollbackTestVerify, - base::Unretained(this))); + base::BindOnce(&UpdateAttempterTest::RollbackTestVerify, + base::Unretained(this))); } else { EXPECT_FALSE(attempter_.Rollback(true)); loop_.BreakLoop(); @@ -894,28 +897,28 @@ TEST_F(UpdateAttempterTest, RollbackTest) { loop_.PostTask(FROM_HERE, - base::Bind(&UpdateAttempterTest::RollbackTestStart, - base::Unretained(this), - false, - true)); + base::BindOnce(&UpdateAttempterTest::RollbackTestStart, + base::Unretained(this), + false, + true)); loop_.Run(); } TEST_F(UpdateAttempterTest, InvalidSlotRollbackTest) { loop_.PostTask(FROM_HERE, - base::Bind(&UpdateAttempterTest::RollbackTestStart, - base::Unretained(this), - false, - false)); + base::BindOnce(&UpdateAttempterTest::RollbackTestStart, + base::Unretained(this), + false, + false)); loop_.Run(); } TEST_F(UpdateAttempterTest, EnterpriseRollbackTest) { loop_.PostTask(FROM_HERE, - base::Bind(&UpdateAttempterTest::RollbackTestStart, - base::Unretained(this), - true, - true)); + base::BindOnce(&UpdateAttempterTest::RollbackTestStart, + base::Unretained(this), + true, + true)); loop_.Run(); } @@ -935,8 +938,8 @@ // testing, which is more permissive than we want to handle here. attempter_.DisableScheduleUpdates(); loop_.PostTask(FROM_HERE, - base::Bind(&UpdateAttempterTest::PingOmahaTestStart, - base::Unretained(this))); + base::BindOnce(&UpdateAttempterTest::PingOmahaTestStart, + base::Unretained(this))); brillo::MessageLoopRunMaxIterations(&loop_, 100); EXPECT_EQ(UpdateStatus::UPDATED_NEED_REBOOT, attempter_.status()); EXPECT_TRUE(attempter_.WasScheduleUpdatesCalled()); @@ -998,8 +1001,8 @@ TEST_F(UpdateAttempterTest, P2PNotEnabled) { loop_.PostTask(FROM_HERE, - base::Bind(&UpdateAttempterTest::P2PNotEnabledStart, - base::Unretained(this))); + base::BindOnce(&UpdateAttempterTest::P2PNotEnabledStart, + base::Unretained(this))); loop_.Run(); } @@ -1017,9 +1020,10 @@ } TEST_F(UpdateAttempterTest, P2PEnabledStartingFails) { - loop_.PostTask(FROM_HERE, - base::Bind(&UpdateAttempterTest::P2PEnabledStartingFailsStart, - base::Unretained(this))); + loop_.PostTask( + FROM_HERE, + base::BindOnce(&UpdateAttempterTest::P2PEnabledStartingFailsStart, + base::Unretained(this))); loop_.Run(); } @@ -1041,8 +1045,8 @@ TEST_F(UpdateAttempterTest, P2PEnabledHousekeepingFails) { loop_.PostTask( FROM_HERE, - base::Bind(&UpdateAttempterTest::P2PEnabledHousekeepingFailsStart, - base::Unretained(this))); + base::BindOnce(&UpdateAttempterTest::P2PEnabledHousekeepingFailsStart, + base::Unretained(this))); loop_.Run(); } @@ -1063,8 +1067,8 @@ TEST_F(UpdateAttempterTest, P2PEnabled) { loop_.PostTask(FROM_HERE, - base::Bind(&UpdateAttempterTest::P2PEnabledStart, - base::Unretained(this))); + base::BindOnce(&UpdateAttempterTest::P2PEnabledStart, + base::Unretained(this))); loop_.Run(); } @@ -1084,9 +1088,10 @@ } TEST_F(UpdateAttempterTest, P2PEnabledInteractive) { - loop_.PostTask(FROM_HERE, - base::Bind(&UpdateAttempterTest::P2PEnabledInteractiveStart, - base::Unretained(this))); + loop_.PostTask( + FROM_HERE, + base::BindOnce(&UpdateAttempterTest::P2PEnabledInteractiveStart, + base::Unretained(this))); loop_.Run(); } @@ -1109,8 +1114,8 @@ TEST_F(UpdateAttempterTest, ReadScatterFactorFromPolicy) { loop_.PostTask( FROM_HERE, - base::Bind(&UpdateAttempterTest::ReadScatterFactorFromPolicyTestStart, - base::Unretained(this))); + base::BindOnce(&UpdateAttempterTest::ReadScatterFactorFromPolicyTestStart, + base::Unretained(this))); loop_.Run(); } @@ -1139,8 +1144,8 @@ TEST_F(UpdateAttempterTest, DecrementUpdateCheckCountTest) { loop_.PostTask( FROM_HERE, - base::Bind(&UpdateAttempterTest::DecrementUpdateCheckCountTestStart, - base::Unretained(this))); + base::BindOnce(&UpdateAttempterTest::DecrementUpdateCheckCountTestStart, + base::Unretained(this))); loop_.Run(); } @@ -1193,7 +1198,7 @@ TEST_F(UpdateAttempterTest, NoScatteringDoneDuringManualUpdateTestStart) { loop_.PostTask( FROM_HERE, - base::Bind( + base::BindOnce( &UpdateAttempterTest::NoScatteringDoneDuringManualUpdateTestStart, base::Unretained(this))); loop_.Run(); @@ -1262,7 +1267,7 @@ TEST_F(UpdateAttempterTest, StagingSetsPrefsAndTurnsOffScattering) { loop_.PostTask( FROM_HERE, - base::Bind( + base::BindOnce( &UpdateAttempterTest::StagingSetsPrefsAndTurnsOffScatteringStart, base::Unretained(this))); loop_.Run(); @@ -1319,9 +1324,10 @@ } TEST_F(UpdateAttempterTest, StagingOffIfInteractive) { - loop_.PostTask(FROM_HERE, - base::Bind(&UpdateAttempterTest::StagingOffIfInteractiveStart, - base::Unretained(this))); + loop_.PostTask( + FROM_HERE, + base::BindOnce(&UpdateAttempterTest::StagingOffIfInteractiveStart, + base::Unretained(this))); loop_.Run(); } @@ -1338,8 +1344,8 @@ TEST_F(UpdateAttempterTest, StagingOffIfOobe) { loop_.PostTask(FROM_HERE, - base::Bind(&UpdateAttempterTest::StagingOffIfOobeStart, - base::Unretained(this))); + base::BindOnce(&UpdateAttempterTest::StagingOffIfOobeStart, + base::Unretained(this))); loop_.Run(); } @@ -1823,32 +1829,35 @@ } TEST_F(UpdateAttempterTest, ResetRollbackHappenedOobe) { - loop_.PostTask(FROM_HERE, - base::Bind(&UpdateAttempterTest::ResetRollbackHappenedStart, - base::Unretained(this), - /*is_consumer=*/false, - /*is_policy_loaded=*/false, - /*expected_reset=*/false)); + loop_.PostTask( + FROM_HERE, + base::BindOnce(&UpdateAttempterTest::ResetRollbackHappenedStart, + base::Unretained(this), + /*is_consumer=*/false, + /*is_policy_loaded=*/false, + /*expected_reset=*/false)); loop_.Run(); } TEST_F(UpdateAttempterTest, ResetRollbackHappenedConsumer) { - loop_.PostTask(FROM_HERE, - base::Bind(&UpdateAttempterTest::ResetRollbackHappenedStart, - base::Unretained(this), - /*is_consumer=*/true, - /*is_policy_loaded=*/false, - /*expected_reset=*/true)); + loop_.PostTask( + FROM_HERE, + base::BindOnce(&UpdateAttempterTest::ResetRollbackHappenedStart, + base::Unretained(this), + /*is_consumer=*/true, + /*is_policy_loaded=*/false, + /*expected_reset=*/true)); loop_.Run(); } TEST_F(UpdateAttempterTest, ResetRollbackHappenedEnterprise) { - loop_.PostTask(FROM_HERE, - base::Bind(&UpdateAttempterTest::ResetRollbackHappenedStart, - base::Unretained(this), - /*is_consumer=*/false, - /*is_policy_loaded=*/true, - /*expected_reset=*/true)); + loop_.PostTask( + FROM_HERE, + base::BindOnce(&UpdateAttempterTest::ResetRollbackHappenedStart, + base::Unretained(this), + /*is_consumer=*/false, + /*is_policy_loaded=*/true, + /*expected_reset=*/true)); loop_.Run(); }
diff --git a/cros/update_engine_client.cc b/cros/update_engine_client.cc index 7b10cf4..6f8b9a8 100644 --- a/cros/update_engine_client.cc +++ b/cros/update_engine_client.cc
@@ -91,8 +91,8 @@ // of the ProcessFlags method after the Daemon initialization is done. base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, - base::Bind(&UpdateEngineClient::ProcessFlagsAndExit, - base::Unretained(this))); + base::BindOnce(&UpdateEngineClient::ProcessFlagsAndExit, + base::Unretained(this))); return EX_OK; }
diff --git a/libcurl_http_fetcher.cc b/libcurl_http_fetcher.cc index 754739c..ab70712 100644 --- a/libcurl_http_fetcher.cc +++ b/libcurl_http_fetcher.cc
@@ -326,9 +326,9 @@ void LibcurlHttpFetcher::BeginTransfer(const string& url) { CHECK(!transfer_in_progress_); url_ = url; - auto closure = - base::Bind(&LibcurlHttpFetcher::ProxiesResolved, base::Unretained(this)); - ResolveProxiesForUrl(url_, closure); + ResolveProxiesForUrl(url_, + base::BindOnce(&LibcurlHttpFetcher::ProxiesResolved, + base::Unretained(this))); } void LibcurlHttpFetcher::ProxiesResolved() { @@ -457,8 +457,8 @@ #endif MessageLoop::current()->PostDelayedTask( FROM_HERE, - base::Bind(&LibcurlHttpFetcher::CurlPerformOnce, - base::Unretained(this)), + base::BindOnce(&LibcurlHttpFetcher::CurlPerformOnce, + base::Unretained(this)), base::Seconds(1)); return; } @@ -511,8 +511,8 @@ no_network_retry_count_++; retry_task_id_ = MessageLoop::current()->PostDelayedTask( FROM_HERE, - base::Bind(&LibcurlHttpFetcher::RetryTimeoutCallback, - base::Unretained(this)), + base::BindOnce(&LibcurlHttpFetcher::RetryTimeoutCallback, + base::Unretained(this)), kNoNetworkRetryTime); LOG(INFO) << "No HTTP response, retry " << no_network_retry_count_; } else if ((!sent_byte_ && !IsHttpResponseSuccess()) || @@ -537,8 +537,8 @@ LOG(INFO) << "Retrying with next proxy setting"; retry_task_id_ = MessageLoop::current()->PostTask( FROM_HERE, - base::Bind(&LibcurlHttpFetcher::RetryTimeoutCallback, - base::Unretained(this))); + base::BindOnce(&LibcurlHttpFetcher::RetryTimeoutCallback, + base::Unretained(this))); } else { // Out of proxies. Give up. LOG(INFO) << "No further proxies, indicating transfer complete"; @@ -577,8 +577,8 @@ LOG(INFO) << "Restarting transfer to download the remaining bytes"; retry_task_id_ = MessageLoop::current()->PostDelayedTask( FROM_HERE, - base::Bind(&LibcurlHttpFetcher::RetryTimeoutCallback, - base::Unretained(this)), + base::BindOnce(&LibcurlHttpFetcher::RetryTimeoutCallback, + base::Unretained(this)), retry_time_); } else { LOG(INFO) << "Transfer completed (" << http_response_code_ << "), " @@ -757,8 +757,8 @@ << " seconds."; timeout_id_ = MessageLoop::current()->PostDelayedTask( FROM_HERE, - base::Bind(&LibcurlHttpFetcher::TimeoutCallback, - base::Unretained(this)), + base::BindOnce(&LibcurlHttpFetcher::TimeoutCallback, + base::Unretained(this)), idle_time_); } } @@ -779,7 +779,8 @@ // be called back. timeout_id_ = MessageLoop::current()->PostDelayedTask( FROM_HERE, - base::Bind(&LibcurlHttpFetcher::TimeoutCallback, base::Unretained(this)), + base::BindOnce(&LibcurlHttpFetcher::TimeoutCallback, + base::Unretained(this)), idle_time_); // CurlPerformOnce() may call CleanUp(), so we need to schedule our callback
diff --git a/payload_consumer/filesystem_verifier_action.cc b/payload_consumer/filesystem_verifier_action.cc index 418a09a..3e6ddf6 100644 --- a/payload_consumer/filesystem_verifier_action.cc +++ b/payload_consumer/filesystem_verifier_action.cc
@@ -194,10 +194,10 @@ bool read_async_ok = src_stream_->ReadAsync( buffer_.data(), bytes_to_read, - base::Bind(&FilesystemVerifierAction::OnReadDoneCallback, - base::Unretained(this)), - base::Bind(&FilesystemVerifierAction::OnReadErrorCallback, - base::Unretained(this)), + base::BindOnce(&FilesystemVerifierAction::OnReadDoneCallback, + base::Unretained(this)), + base::BindOnce(&FilesystemVerifierAction::OnReadErrorCallback, + base::Unretained(this)), nullptr); if (!read_async_ok) {
diff --git a/payload_consumer/filesystem_verifier_action_unittest.cc b/payload_consumer/filesystem_verifier_action_unittest.cc index 2304e4c..1589afe 100644 --- a/payload_consumer/filesystem_verifier_action_unittest.cc +++ b/payload_consumer/filesystem_verifier_action_unittest.cc
@@ -145,7 +145,7 @@ processor_.set_delegate(&delegate); loop_.PostTask(FROM_HERE, - base::Bind( + base::BindOnce( [](ActionProcessor* processor, bool terminate_early) { processor->StartProcessing(); if (terminate_early) { @@ -313,7 +313,7 @@ loop_.PostTask( FROM_HERE, - base::Bind( + base::BindOnce( [](ActionProcessor* processor) { processor->StartProcessing(); }, base::Unretained(&processor_))); loop_.Run();
diff --git a/payload_consumer/postinstall_runner_action_unittest.cc b/payload_consumer/postinstall_runner_action_unittest.cc index c1b0922..935cc06 100644 --- a/payload_consumer/postinstall_runner_action_unittest.cc +++ b/payload_consumer/postinstall_runner_action_unittest.cc
@@ -125,16 +125,16 @@ // is ready by redirecting its input to /dev/zero. loop_.PostDelayedTask( FROM_HERE, - base::Bind(&PostinstallRunnerActionTest::SuspendRunningAction, - base::Unretained(this)), + base::BindOnce(&PostinstallRunnerActionTest::SuspendRunningAction, + base::Unretained(this)), base::Milliseconds(100)); } else { postinstall_action_->SuspendAction(); // Schedule to be resumed in a little bit. loop_.PostDelayedTask( FROM_HERE, - base::Bind(&PostinstallRunnerActionTest::ResumeRunningAction, - base::Unretained(this)), + base::BindOnce(&PostinstallRunnerActionTest::ResumeRunningAction, + base::Unretained(this)), base::Milliseconds(100)); } } @@ -144,8 +144,8 @@ // Wait for the postinstall command to run. loop_.PostDelayedTask( FROM_HERE, - base::Bind(&PostinstallRunnerActionTest::CancelWhenStarted, - base::Unretained(this)), + base::BindOnce(&PostinstallRunnerActionTest::CancelWhenStarted, + base::Unretained(this)), base::Milliseconds(10)); } else { CHECK(processor_); @@ -153,7 +153,7 @@ // doesn't leak memory, do not directly call |StopProcessing()|. loop_.PostDelayedTask( FROM_HERE, - base::Bind( + base::BindOnce( [](ActionProcessor* processor) { processor->StopProcessing(); }, base::Unretained(processor_)), base::Milliseconds(100)); @@ -227,7 +227,7 @@ loop_.PostTask( FROM_HERE, - base::Bind( + base::BindOnce( [](ActionProcessor* processor) { processor->StartProcessing(); }, base::Unretained(&processor))); loop_.Run(); @@ -423,9 +423,10 @@ ScopedLoopbackDeviceBinder loop(postinstall_image_, false, nullptr); // We need to wait for the child to run and setup its signal handler. - loop_.PostTask(FROM_HERE, - base::Bind(&PostinstallRunnerActionTest::SuspendRunningAction, - base::Unretained(this))); + loop_.PostTask( + FROM_HERE, + base::BindOnce(&PostinstallRunnerActionTest::SuspendRunningAction, + base::Unretained(this))); RunPostinstallAction(loop.dev(), "bin/postinst_suspend", false, false, false); // postinst_suspend returns 0 only if it was suspended at some point. EXPECT_EQ(ErrorCode::kSuccess, processor_delegate_.code_);
diff --git a/update_manager/evaluation_context.cc b/update_manager/evaluation_context.cc index fa19161..ec0734c 100644 --- a/update_manager/evaluation_context.cc +++ b/update_manager/evaluation_context.cc
@@ -31,8 +31,6 @@ #include "update_engine/common/system_state.h" #include "update_engine/common/utils.h" -using base::Callback; -using base::Closure; using base::Time; using base::TimeDelta; using brillo::MessageLoop; @@ -79,7 +77,7 @@ RemoveObserversAndTimeout(); } -unique_ptr<Closure> EvaluationContext::RemoveObserversAndTimeout() { +unique_ptr<base::OnceClosure> EvaluationContext::RemoveObserversAndTimeout() { for (auto& it : value_cache_) { if (it.first->GetMode() == kVariableModeAsync) it.first->RemoveObserver(this); @@ -119,10 +117,10 @@ void EvaluationContext::OnValueChangedOrTimeout() { // Copy the callback handle locally, allowing it to be reassigned. - unique_ptr<Closure> callback = RemoveObserversAndTimeout(); + unique_ptr<base::OnceClosure> callback = RemoveObserversAndTimeout(); if (callback.get()) - callback->Run(); + std::move(*callback).Run(); } bool EvaluationContext::IsWallclockTimeGreaterThan(Time timestamp) { @@ -158,7 +156,7 @@ is_expired_ = false; } -bool EvaluationContext::RunOnValueChangeOrTimeout(Closure callback) { +bool EvaluationContext::RunOnValueChangeOrTimeout(base::OnceClosure callback) { // Check that the method was not called more than once. if (callback_.get()) { LOG(ERROR) << "RunOnValueChangeOrTimeout called more than once."; @@ -208,7 +206,7 @@ timeout = expiration; // Store the reevaluation callback. - callback_.reset(new Closure(std::move(callback))); + callback_.reset(new base::OnceClosure(std::move(callback))); // Schedule a timeout event, if one is set. if (!timeout.is_max()) { @@ -216,8 +214,8 @@ << chromeos_update_engine::utils::FormatTimeDelta(timeout); timeout_event_ = MessageLoop::current()->PostDelayedTask( FROM_HERE, - base::Bind(&EvaluationContext::OnTimeout, - weak_ptr_factory_.GetWeakPtr()), + base::BindOnce(&EvaluationContext::OnTimeout, + weak_ptr_factory_.GetWeakPtr()), timeout); }
diff --git a/update_manager/evaluation_context.h b/update_manager/evaluation_context.h index b8979ed..ff1f513 100644 --- a/update_manager/evaluation_context.h +++ b/update_manager/evaluation_context.h
@@ -102,14 +102,14 @@ // expiration occurred, prior to re-evaluating the policy. void ResetExpiration(); - // Schedules the passed |callback| closure to be called when a cached + // Schedules the passed `callback` closure to be called when a cached // variable changes its value, a polling interval passes, or the context // expiration occurs. If none of these events can happen, for example if // there's no cached variable, this method returns false. // // Right before the passed closure is called the EvaluationContext is // reset, removing all the non-const cached values. - bool RunOnValueChangeOrTimeout(base::Closure callback); + bool RunOnValueChangeOrTimeout(base::OnceClosure callback); // Returns a textual representation of the evaluation context, // including the variables and their values. This is intended only @@ -119,7 +119,7 @@ // Removes all the Observers callbacks and timeout events scheduled by // RunOnValueChangeOrTimeout(). Also releases and returns the closure // associated with these events. This method is idempotent. - std::unique_ptr<base::Closure> RemoveObserversAndTimeout(); + std::unique_ptr<base::OnceClosure> RemoveObserversAndTimeout(); private: friend class UmEvaluationContextTest; @@ -153,7 +153,7 @@ // timeout, or notifying about the evaluation context expiration. It is up to // the caller to determine whether or not expiration occurred via // is_expired(). - std::unique_ptr<base::Closure> callback_; + std::unique_ptr<base::OnceClosure> callback_; // The TaskId returned by the message loop identifying the timeout callback. // Used for canceling the timeout callback.
diff --git a/update_manager/evaluation_context_unittest.cc b/update_manager/evaluation_context_unittest.cc index d23ef26..8abcb7f 100644 --- a/update_manager/evaluation_context_unittest.cc +++ b/update_manager/evaluation_context_unittest.cc
@@ -31,8 +31,6 @@ #include "update_engine/update_manager/mock_variable.h" #include "update_engine/update_manager/umtest_utils.h" -using base::Bind; -using base::Closure; using base::Time; using base::TimeDelta; using brillo::MessageLoop; @@ -67,7 +65,7 @@ // Runs |evaluation|; if the value pointed by |count_p| is greater than zero, // decrement it and schedule a reevaluation; otherwise, writes true to |done_p|. -void EvaluateRepeatedly(Closure evaluation, +void EvaluateRepeatedly(base::RepeatingClosure evaluation, shared_ptr<EvaluationContext> ec, int* count_p, bool* done_p) { @@ -75,7 +73,8 @@ // Schedule reevaluation if needed. if (*count_p > 0) { - Closure closure = Bind(EvaluateRepeatedly, evaluation, ec, count_p, done_p); + base::RepeatingClosure closure = base::BindRepeating( + EvaluateRepeatedly, evaluation, ec, count_p, done_p); ASSERT_TRUE(ec->RunOnValueChangeOrTimeout(closure)) << "Failed to schedule reevaluation, count_p=" << *count_p; (*count_p)--; @@ -218,7 +217,8 @@ eval_ctx_->GetValue(&fake_async_var_); bool value = false; - EXPECT_TRUE(eval_ctx_->RunOnValueChangeOrTimeout(Bind(&SetTrue, &value))); + EXPECT_TRUE( + eval_ctx_->RunOnValueChangeOrTimeout(base::BindOnce(&SetTrue, &value))); // Check that the scheduled callback isn't run until we signal a ValueChaged. MessageLoopRunMaxIterations(MessageLoop::current(), 100); EXPECT_FALSE(value); @@ -237,8 +237,10 @@ eval_ctx_->GetValue(&fake_async_var_); bool value = false; - EXPECT_TRUE(eval_ctx_->RunOnValueChangeOrTimeout(Bind(&SetTrue, &value))); - EXPECT_FALSE(eval_ctx_->RunOnValueChangeOrTimeout(Bind(&SetTrue, &value))); + EXPECT_TRUE( + eval_ctx_->RunOnValueChangeOrTimeout(base::BindOnce(&SetTrue, &value))); + EXPECT_FALSE( + eval_ctx_->RunOnValueChangeOrTimeout(base::BindOnce(&SetTrue, &value))); // The scheduled event should still work. fake_async_var_.NotifyValueChanged(); @@ -252,12 +254,14 @@ eval_ctx_->GetValue(&fake_poll_var_); bool value = false; - EXPECT_TRUE(eval_ctx_->RunOnValueChangeOrTimeout(Bind(&SetTrue, &value))); + EXPECT_TRUE( + eval_ctx_->RunOnValueChangeOrTimeout(base::BindOnce(&SetTrue, &value))); // Check that the scheduled callback isn't run until the timeout occurs. MessageLoopRunMaxIterations(MessageLoop::current(), 10); EXPECT_FALSE(value); - MessageLoopRunUntil( - MessageLoop::current(), base::Seconds(10), Bind(&GetBoolean, &value)); + MessageLoopRunUntil(MessageLoop::current(), + base::Seconds(10), + base::BindRepeating(&GetBoolean, &value)); EXPECT_TRUE(value); } @@ -268,12 +272,14 @@ eval_ctx_->GetValue(&fake_async_var_); bool value = false; - EXPECT_TRUE(eval_ctx_->RunOnValueChangeOrTimeout(Bind(&SetTrue, &value))); + EXPECT_TRUE( + eval_ctx_->RunOnValueChangeOrTimeout(base::BindOnce(&SetTrue, &value))); // Check that the scheduled callback isn't run until the timeout occurs. MessageLoopRunMaxIterations(MessageLoop::current(), 10); EXPECT_FALSE(value); - MessageLoopRunUntil( - MessageLoop::current(), base::Seconds(10), Bind(&GetBoolean, &value)); + MessageLoopRunUntil(MessageLoop::current(), + base::Seconds(10), + base::BindRepeating(&GetBoolean, &value)); EXPECT_TRUE(value); // Ensure that we cannot reschedule an evaluation. @@ -290,7 +296,8 @@ eval_ctx_->GetValue(&fake_async_var_); bool value = false; - EXPECT_TRUE(eval_ctx_->RunOnValueChangeOrTimeout(Bind(&SetTrue, &value))); + EXPECT_TRUE( + eval_ctx_->RunOnValueChangeOrTimeout(base::BindOnce(&SetTrue, &value))); eval_ctx_ = nullptr; // This should not trigger the callback since the EvaluationContext waiting @@ -304,7 +311,8 @@ TEST_F(UmEvaluationContextTest, RunOnValueChangeOrTimeoutReevaluatesRepeatedly) { fake_poll_var_.reset(new string("Polled value")); - Closure evaluation = Bind(ReadVar<string>, eval_ctx_, &fake_poll_var_); + base::RepeatingClosure evaluation = + base::BindRepeating(ReadVar<string>, eval_ctx_, &fake_poll_var_); int num_reevaluations = 2; bool done = false; @@ -312,11 +320,12 @@ evaluation.Run(); // Schedule repeated reevaluations. - Closure closure = Bind( + base::RepeatingClosure closure = base::BindRepeating( EvaluateRepeatedly, evaluation, eval_ctx_, &num_reevaluations, &done); ASSERT_TRUE(eval_ctx_->RunOnValueChangeOrTimeout(closure)); - MessageLoopRunUntil( - MessageLoop::current(), base::Seconds(10), Bind(&GetBoolean, &done)); + MessageLoopRunUntil(MessageLoop::current(), + base::Seconds(10), + base::BindRepeating(&GetBoolean, &done)); EXPECT_EQ(0, num_reevaluations); } @@ -339,14 +348,16 @@ fake_short_poll_var.reset(new string("Polled value")); eval_ctx_->GetValue(&fake_short_poll_var); bool value = false; - EXPECT_TRUE(eval_ctx_->RunOnValueChangeOrTimeout(Bind(&SetTrue, &value))); + EXPECT_TRUE( + eval_ctx_->RunOnValueChangeOrTimeout(base::BindOnce(&SetTrue, &value))); // Remove the last reference to the EvaluationContext and run the loop for // 10 seconds to give time to the main loop to trigger the timeout Event (of 1 // second). Our callback should not be called because the EvaluationContext // was removed before the timeout event is attended. eval_ctx_ = nullptr; - MessageLoopRunUntil( - MessageLoop::current(), base::Seconds(10), Bind(&GetBoolean, &value)); + MessageLoopRunUntil(MessageLoop::current(), + base::Seconds(10), + base::BindRepeating(&GetBoolean, &value)); EXPECT_FALSE(value); }
diff --git a/update_manager/generic_variables.h b/update_manager/generic_variables.h index d09e89d..b25a790 100644 --- a/update_manager/generic_variables.h +++ b/update_manager/generic_variables.h
@@ -146,11 +146,12 @@ template <typename T> class CallCopyVariable : public Variable<T> { public: - CallCopyVariable(const std::string& name, base::Callback<T(void)> func) + CallCopyVariable(const std::string& name, + base::RepeatingCallback<T(void)> func) : Variable<T>(name, kVariableModePoll), func_(func) {} CallCopyVariable(const std::string& name, const base::TimeDelta poll_interval, - base::Callback<T(void)> func) + base::RepeatingCallback<T(void)> func) : Variable<T>(name, poll_interval), func_(func) {} CallCopyVariable(const CallCopyVariable&) = delete; CallCopyVariable& operator=(const CallCopyVariable&) = delete; @@ -168,7 +169,7 @@ FRIEND_TEST(UmCallCopyVariableTest, SimpleTest); // The function to be called, stored as a base::Callback. - base::Callback<T(void)> func_; + base::RepeatingCallback<T(void)> func_; }; // A Variable class to implement simple Async variables. It provides two methods
diff --git a/update_manager/generic_variables_unittest.cc b/update_manager/generic_variables_unittest.cc index bfdcf89..f7edad1 100644 --- a/update_manager/generic_variables_unittest.cc +++ b/update_manager/generic_variables_unittest.cc
@@ -121,8 +121,8 @@ ASSERT_FALSE(test_obj.copied_); test_obj.val_ = 5; - base::Callback<CopyConstructorTestClass(void)> cb = - base::Bind(test_func, &test_obj); + base::RepeatingCallback<CopyConstructorTestClass(void)> cb = + base::BindRepeating(test_func, &test_obj); CallCopyVariable<CopyConstructorTestClass> var("var", cb); unique_ptr<const CopyConstructorTestClass> copy( @@ -136,7 +136,7 @@ TEST_F(UmCallCopyVariableTest, NullTest) { // Ensures that the variable returns null when the callback is null. - base::Callback<bool(void)> cb; + base::RepeatingCallback<bool(void)> cb; CallCopyVariable<bool> var("var", cb); UmTestUtils::ExpectVariableNotSet(&var); }
diff --git a/update_manager/policy_evaluator.cc b/update_manager/policy_evaluator.cc index 62f6206..982d852 100644 --- a/update_manager/policy_evaluator.cc +++ b/update_manager/policy_evaluator.cc
@@ -68,29 +68,29 @@ } void PolicyEvaluator::ScheduleEvaluation( - base::Callback<void(EvalStatus)> callback) { - base::Closure eval_callback = - base::Bind(&PolicyEvaluator::OnPolicyReadyToEvaluate, - weak_ptr_factory_.GetWeakPtr(), - std::move(callback)); - brillo::MessageLoop::current()->PostTask(FROM_HERE, eval_callback); + base::OnceCallback<void(EvalStatus)> callback) { + brillo::MessageLoop::current()->PostTask( + FROM_HERE, + base::BindOnce(&PolicyEvaluator::OnPolicyReadyToEvaluate, + weak_ptr_factory_.GetWeakPtr(), + std::move(callback))); } void PolicyEvaluator::OnPolicyReadyToEvaluate( - base::Callback<void(EvalStatus)> callback) { + base::OnceCallback<void(EvalStatus)> callback) { // Evaluate the policy. EvalStatus status = Evaluate(); if (status != EvalStatus::kAskMeAgainLater) { - callback.Run(status); + std::move(callback).Run(status); Unregister(); return; } // Re-schedule the policy request based on used variables. if (ec_->RunOnValueChangeOrTimeout( - base::Bind(&PolicyEvaluator::OnPolicyReadyToEvaluate, - weak_ptr_factory_.GetWeakPtr(), - callback))) + base::BindOnce(&PolicyEvaluator::OnPolicyReadyToEvaluate, + weak_ptr_factory_.GetWeakPtr(), + std::move(callback)))) return; // Reevaluation scheduled successfully. // Scheduling a reevaluation can fail because policy method didn't use any @@ -99,7 +99,7 @@ // use of the scheduling interface. LOG(ERROR) << "Failed to schedule a reevaluation of policy" << "; this is a bug."; - callback.Run(status); + std::move(callback).Run(status); Unregister(); }
diff --git a/update_manager/policy_evaluator.h b/update_manager/policy_evaluator.h index 1bef2fe..dd4fd53 100644 --- a/update_manager/policy_evaluator.h +++ b/update_manager/policy_evaluator.h
@@ -61,11 +61,11 @@ // Same as the above function but the asyncronous version. A call to this // function returns immediately and an evalution is scheduled in the main // message loop. The passed |callback| is called when the policy is evaluated. - void ScheduleEvaluation(base::Callback<void(EvalStatus)> callback); + void ScheduleEvaluation(base::OnceCallback<void(EvalStatus)> callback); private: // Internal function to reschedule policy evaluation. - void OnPolicyReadyToEvaluate(base::Callback<void(EvalStatus)> callback); + void OnPolicyReadyToEvaluate(base::OnceCallback<void(EvalStatus)> callback); State* state_; std::unique_ptr<EvaluationContext> ec_; std::unique_ptr<PolicyInterface> policy_;
diff --git a/update_manager/real_device_policy_provider.cc b/update_manager/real_device_policy_provider.cc index 403aa52..62c3ae8 100644 --- a/update_manager/real_device_policy_provider.cc +++ b/update_manager/real_device_policy_provider.cc
@@ -62,10 +62,11 @@ // We also listen for signals from the session manager to force a device // policy refresh. session_manager_proxy_->RegisterPropertyChangeCompleteSignalHandler( - base::Bind(&RealDevicePolicyProvider::OnPropertyChangedCompletedSignal, - base::Unretained(this)), - base::Bind(&RealDevicePolicyProvider::OnSignalConnected, - base::Unretained(this))); + base::BindRepeating( + &RealDevicePolicyProvider::OnPropertyChangedCompletedSignal, + base::Unretained(this)), + base::BindOnce(&RealDevicePolicyProvider::OnSignalConnected, + base::Unretained(this))); return true; } @@ -100,8 +101,9 @@ RefreshDevicePolicy(); scheduled_refresh_ = MessageLoop::current()->PostDelayedTask( FROM_HERE, - base::Bind(&RealDevicePolicyProvider::RefreshDevicePolicyAndReschedule, - base::Unretained(this)), + base::BindOnce( + &RealDevicePolicyProvider::RefreshDevicePolicyAndReschedule, + base::Unretained(this)), kDevicePolicyRefreshRateTime); }
diff --git a/update_manager/real_shill_provider.cc b/update_manager/real_shill_provider.cc index 1c2640a..317671e 100644 --- a/update_manager/real_shill_provider.cc +++ b/update_manager/real_shill_provider.cc
@@ -39,10 +39,10 @@ // Subscribe to the manager's PropertyChanged signal. manager_proxy->RegisterPropertyChangedSignalHandler( - base::Bind(&RealShillProvider::OnManagerPropertyChanged, - base::Unretained(this)), - base::Bind(&RealShillProvider::OnSignalConnected, - base::Unretained(this))); + base::BindRepeating(&RealShillProvider::OnManagerPropertyChanged, + base::Unretained(this)), + base::BindOnce(&RealShillProvider::OnSignalConnected, + base::Unretained(this))); // Attempt to read initial connection status. Even if this fails because shill // is not responding (e.g. it is down) we'll be notified via "PropertyChanged"
diff --git a/update_manager/real_system_provider.cc b/update_manager/real_system_provider.cc index 45a317e..a0ceeda 100644 --- a/update_manager/real_system_provider.cc +++ b/update_manager/real_system_provider.cc
@@ -54,7 +54,7 @@ public: RetryPollVariable(const string& name, const base::TimeDelta poll_interval, - base::Callback<bool(T* res)> func) + base::RepeatingCallback<bool(T* res)> func) : Variable<T>(name, poll_interval), func_(func), base_interval_(poll_interval) { @@ -87,7 +87,7 @@ private: // The function to be called, stored as a base::Callback. - base::Callback<bool(T*)> func_; + base::RepeatingCallback<bool(T*)> func_; // The desired polling interval when |func_| works and returns true. base::TimeDelta base_interval_; @@ -108,9 +108,10 @@ var_is_oobe_complete_.reset(new CallCopyVariable<bool>( "is_oobe_complete", - base::Bind(&chromeos_update_engine::HardwareInterface::IsOOBEComplete, - base::Unretained(SystemState::Get()->hardware()), - nullptr))); + base::BindRepeating( + &chromeos_update_engine::HardwareInterface::IsOOBEComplete, + base::Unretained(SystemState::Get()->hardware()), + nullptr))); var_num_slots_.reset(new ConstCopyVariable<unsigned int>( "num_slots", SystemState::Get()->boot_control()->GetNumSlots())); @@ -118,8 +119,9 @@ var_kiosk_required_platform_version_.reset(new RetryPollVariable<string>( "kiosk_required_platform_version", base::Hours(5), // Same as Chrome's CWS poll. - base::Bind(&RealSystemProvider::GetKioskAppRequiredPlatformVersion, - base::Unretained(this)))); + base::BindRepeating( + &RealSystemProvider::GetKioskAppRequiredPlatformVersion, + base::Unretained(this)))); var_chromeos_version_.reset(new ConstCopyVariable<base::Version>( "chromeos_version", @@ -130,14 +132,16 @@ var_is_resuming_from_hibernate_.reset(new CallCopyVariable<bool>( "is_resuming_from_hibernate", - base::Bind(&chromeos_update_engine::HibernateInterface::IsResuming, - base::Unretained(SystemState::Get()->hibernate())))); + base::BindRepeating( + &chromeos_update_engine::HibernateInterface::IsResuming, + base::Unretained(SystemState::Get()->hibernate())))); var_abort_resume_from_hibernate_.reset(new CallCopyVariable<bool>( "abort_resume_from_hibernate", - base::Bind(&chromeos_update_engine::HibernateInterface::AbortResume, - base::Unretained(SystemState::Get()->hibernate()), - "System update pending for too long"))); + base::BindRepeating( + &chromeos_update_engine::HibernateInterface::AbortResume, + base::Unretained(SystemState::Get()->hibernate()), + "System update pending for too long"))); return true; }
diff --git a/update_manager/real_updater_provider.cc b/update_manager/real_updater_provider.cc index a2631b9..2794673 100644 --- a/update_manager/real_updater_provider.cc +++ b/update_manager/real_updater_provider.cc
@@ -384,9 +384,10 @@ : UpdaterVariableBase<UpdateRequestStatus>::UpdaterVariableBase( name, kVariableModeAsync) { SystemState::Get()->update_attempter()->set_forced_update_pending_callback( - new base::Callback<void(bool, bool)>( // NOLINT(readability/function) - base::Bind(&ForcedUpdateRequestedVariable::Reset, - base::Unretained(this)))); + new base::RepeatingCallback<void( + bool, bool)>( // NOLINT(readability/function) + base::BindRepeating(&ForcedUpdateRequestedVariable::Reset, + base::Unretained(this)))); } ForcedUpdateRequestedVariable(const ForcedUpdateRequestedVariable&) = delete; ForcedUpdateRequestedVariable& operator=(
diff --git a/update_manager/update_manager.cc b/update_manager/update_manager.cc index 166c58c..683975b 100644 --- a/update_manager/update_manager.cc +++ b/update_manager/update_manager.cc
@@ -43,9 +43,10 @@ .Evaluate(); } -void UpdateManager::PolicyRequest(std::unique_ptr<PolicyInterface> policy, - std::shared_ptr<PolicyDataInterface> data, - base::Callback<void(EvalStatus)> callback) { +void UpdateManager::PolicyRequest( + std::unique_ptr<PolicyInterface> policy, + std::shared_ptr<PolicyDataInterface> data, + base::OnceCallback<void(EvalStatus)> callback) { auto ec = std::make_unique<EvaluationContext>(evaluation_timeout_, expiration_timeout_); evaluators_.push_back(std::make_unique<PolicyEvaluator>(
diff --git a/update_manager/update_manager.h b/update_manager/update_manager.h index a5d1ecb..7f12955 100644 --- a/update_manager/update_manager.h +++ b/update_manager/update_manager.h
@@ -70,7 +70,7 @@ // with the EvalStatus::kAskMeAgainLater status (which indicates an error). void PolicyRequest(std::unique_ptr<PolicyInterface> policy, std::shared_ptr<PolicyDataInterface> data, - base::Callback<void(EvalStatus)> callback); + base::OnceCallback<void(EvalStatus)> callback); // Removes the |evaluator| from the internal list of |evaluators_|. void Unregister(PolicyEvaluator* evaluator);
diff --git a/update_manager/update_manager_unittest.cc b/update_manager/update_manager_unittest.cc index 16fe9bc..a2a04af 100644 --- a/update_manager/update_manager_unittest.cc +++ b/update_manager/update_manager_unittest.cc
@@ -38,8 +38,6 @@ #include "update_engine/update_manager/fake_state.h" #include "update_engine/update_manager/umtest_utils.h" -using base::Bind; -using base::Callback; using base::Time; using brillo::MessageLoop; using brillo::MessageLoopRunMaxIterations; @@ -213,11 +211,11 @@ // succeeds the first time, we ensure that the passed callback is called from // the main loop in both cases even when we could evaluate it right now. vector<EvalStatus> calls; - Callback<void(EvalStatus)> callback = Bind(AccumulateCallsCallback, &calls); + auto callback = base::BindOnce(AccumulateCallsCallback, &calls); umut_->PolicyRequest(std::make_unique<FailingPolicy>(), std::make_shared<PolicyDataInterface>(), - callback); + std::move(callback)); // The callback should wait until we run the main loop for it to be executed. EXPECT_EQ(0U, calls.size()); MessageLoopRunMaxIterations(MessageLoop::current(), 100); @@ -228,12 +226,12 @@ // Set up an async policy call to return immediately, then wait a little and // ensure that the timeout event does not fire. vector<EvalStatus> calls; - Callback<void(EvalStatus)> callback = Bind(AccumulateCallsCallback, &calls); + auto callback = base::BindOnce(AccumulateCallsCallback, &calls); int num_called = 0; umut_->PolicyRequest(std::make_unique<FailingPolicy>(&num_called), std::make_shared<PolicyDataInterface>(), - callback); + std::move(callback)); // Run the main loop, ensure that policy was attempted once before deferring // to the default. MessageLoopRunMaxIterations(MessageLoop::current(), 100); @@ -254,13 +252,14 @@ // that the default policy was not used (no callback) and that evaluation is // reattempted. vector<EvalStatus> calls; - Callback<void(EvalStatus)> callback = Bind(AccumulateCallsCallback, &calls); + auto callback = base::BindOnce(AccumulateCallsCallback, &calls); int num_called = 0; auto policy = std::make_unique<DelayPolicy>( 0, fake_clock->GetWallclockTime() + base::Seconds(3), &num_called); - umut_->PolicyRequest( - std::move(policy), std::make_shared<PolicyDataInterface>(), callback); + umut_->PolicyRequest(std::move(policy), + std::make_shared<PolicyDataInterface>(), + std::move(callback)); // Run the main loop, ensure that policy was attempted once but the callback // was not invoked. MessageLoopRunMaxIterations(MessageLoop::current(), 100); @@ -289,7 +288,7 @@ TEST_F(UmUpdateManagerTest, AsyncPolicyRequestIsAddedToList) { umut_->PolicyRequest(std::make_unique<SimplePolicy>(), std::make_shared<PolicyDataInterface>(), - base::Bind([](EvalStatus) {})); + base::BindOnce([](EvalStatus) {})); EXPECT_EQ(1, umut_->evaluators_.size()); MessageLoopRunMaxIterations(MessageLoop::current(), 10);
diff --git a/update_manager/update_time_restrictions_monitor.cc b/update_manager/update_time_restrictions_monitor.cc index e5c8e90..c8dc31c 100644 --- a/update_manager/update_time_restrictions_monitor.cc +++ b/update_manager/update_time_restrictions_monitor.cc
@@ -77,8 +77,8 @@ WaitForRestrictedIntervalStarts(*new_intervals); const bool is_registered = evaluation_context_.RunOnValueChangeOrTimeout( - base::Bind(&UpdateTimeRestrictionsMonitor::OnIntervalsChanged, - base::Unretained(this))); + base::BindOnce(&UpdateTimeRestrictionsMonitor::OnIntervalsChanged, + base::Unretained(this))); DCHECK(is_registered); } @@ -104,8 +104,9 @@ timeout_event_ = MessageLoop::current()->PostDelayedTask( FROM_HERE, - base::Bind(&UpdateTimeRestrictionsMonitor::HandleRestrictedIntervalStarts, - weak_ptr_factory_.GetWeakPtr()), + base::BindOnce( + &UpdateTimeRestrictionsMonitor::HandleRestrictedIntervalStarts, + weak_ptr_factory_.GetWeakPtr()), duration_till_start); }
diff --git a/update_manager/variable.h b/update_manager/variable.h index 313829d..bf4ec25 100644 --- a/update_manager/variable.h +++ b/update_manager/variable.h
@@ -131,8 +131,8 @@ if (!observer_list_.empty()) { brillo::MessageLoop::current()->PostTask( FROM_HERE, - base::Bind(&BaseVariable::OnValueChangedNotification, - base::Unretained(this))); + base::BindOnce(&BaseVariable::OnValueChangedNotification, + base::Unretained(this))); } }