Refactor update_client to use base::OnceCallback.

For correctness, change the type of callbacks which are invoked one time 
only from base::Callback to base::OnceCallback. Same for closures.

This is a mechanical change.
BUG=780524

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I29c9b2bab9e83695f0ac041a95a23545ef852a81
Reviewed-on: https://chromium-review.googlesource.com/741037
Reviewed-by: Devlin <[email protected]>
Reviewed-by: Julian Pastarmov <[email protected]>
Reviewed-by: Joshua Pawlicki <[email protected]>
Commit-Queue: Sorin Jianu <[email protected]>
Cr-Commit-Position: refs/heads/master@{#513520}
diff --git a/components/component_updater/component_updater_service.cc b/components/component_updater/component_updater_service.cc
index b99e5ed..cd03f5c 100644
--- a/components/component_updater/component_updater_service.cc
+++ b/components/component_updater/component_updater_service.cc
@@ -67,8 +67,8 @@
 CrxUpdateService::~CrxUpdateService() {
   DCHECK(thread_checker_.CalledOnValidThread());
 
-  for (const auto item : ready_callbacks_) {
-    item.second.Run();
+  for (auto& item : ready_callbacks_) {
+    std::move(item.second).Run();
   }
 
   RemoveObserver(this);
@@ -238,18 +238,19 @@
 }
 
 void CrxUpdateService::MaybeThrottle(const std::string& id,
-                                     const base::Closure& callback) {
+                                     base::OnceClosure callback) {
   DCHECK(thread_checker_.CalledOnValidThread());
-  auto it = components_.find(id);
+  const auto it = components_.find(id);
   if (it != components_.end()) {
     DCHECK_EQ(it->first, id);
     if (OnDemandUpdateWithCooldown(id)) {
-      ready_callbacks_.insert(std::make_pair(id, callback));
+      ready_callbacks_.insert(std::make_pair(id, std::move(callback)));
       return;
     }
   }
 
-  callback.Run();  // Unblock the request if the request can't be throttled.
+  // Unblock the request if the request can't be throttled.
+  std::move(callback).Run();
 }
 
 void CrxUpdateService::OnDemandUpdate(const std::string& id,
@@ -293,7 +294,7 @@
   UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.Calls", UPDATE_TYPE_MANUAL,
                             UPDATE_TYPE_COUNT);
   update_client_->Install(
-      id, base::Bind(&CrxUpdateService::OnUpdate, base::Unretained(this)),
+      id, base::BindOnce(&CrxUpdateService::OnUpdate, base::Unretained(this)),
       base::BindOnce(&CrxUpdateService::OnUpdateComplete,
                      base::Unretained(this), std::move(callback),
                      base::TimeTicks::Now()));
@@ -320,7 +321,7 @@
   if (!unsecure_ids.empty()) {
     update_client_->Update(
         unsecure_ids,
-        base::Bind(&CrxUpdateService::OnUpdate, base::Unretained(this)),
+        base::BindOnce(&CrxUpdateService::OnUpdate, base::Unretained(this)),
         base::BindOnce(&CrxUpdateService::OnUpdateComplete,
                        base::Unretained(this), Callback(),
                        base::TimeTicks::Now()));
@@ -329,7 +330,7 @@
   if (!secure_ids.empty()) {
     update_client_->Update(
         secure_ids,
-        base::Bind(&CrxUpdateService::OnUpdate, base::Unretained(this)),
+        base::BindOnce(&CrxUpdateService::OnUpdate, base::Unretained(this)),
         base::BindOnce(&CrxUpdateService::OnUpdateComplete,
                        base::Unretained(this), Callback(),
                        base::TimeTicks::Now()));
@@ -403,7 +404,7 @@
       event == Observer::Events::COMPONENT_NOT_UPDATED) {
     auto callbacks = ready_callbacks_.equal_range(id);
     for (auto it = callbacks.first; it != callbacks.second; ++it) {
-      it->second.Run();
+      std::move(it->second).Run();
     }
     ready_callbacks_.erase(id);
   }