update_engine: Replace googe::protobuf::Closure with base::Closure

In order to clean up libchromeos, remove chromeos/callback.h and
switch update_engine from using
googe::protobuf::Closure/NewPermanentCallback to base::Closure/Bind

BUG=chromium:406060
TEST=FEATURES=test emerge-link update_engine

Change-Id: I02d222c3f6c9a5bf5177d58e3a25a596348619bf
Reviewed-on: https://chromium-review.googlesource.com/213675
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: David Zeuthen <zeuthen@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/chrome_browser_proxy_resolver.cc b/chrome_browser_proxy_resolver.cc
index 6d489d8..4ee1679 100644
--- a/chrome_browser_proxy_resolver.cc
+++ b/chrome_browser_proxy_resolver.cc
@@ -9,11 +9,11 @@
 #include <string>
 #include <utility>
 
+#include <base/bind.h>
 #include <base/strings/string_tokenizer.h>
 #include <base/strings/string_util.h>
 #include <dbus/dbus-glib-lowlevel.h>
 #include <dbus/dbus-glib.h>
-#include <google/protobuf/stubs/common.h>
 
 #include "update_engine/dbus_constants.h"
 #include "update_engine/glib_utils.h"
@@ -22,8 +22,6 @@
 namespace chromeos_update_engine {
 
 using base::StringTokenizer;
-using google::protobuf::Closure;
-using google::protobuf::NewPermanentCallback;
 using std::deque;
 using std::make_pair;
 using std::multimap;
@@ -141,10 +139,10 @@
   }
 
   callbacks_.insert(make_pair(url, make_pair(callback, data)));
-  Closure* closure = NewPermanentCallback(
-      this,
+  base::Closure* closure = new base::Closure(base::Bind(
       &ChromeBrowserProxyResolver::HandleTimeout,
-      url);
+      base::Unretained(this),
+      url));
   GSource* timer = g_timeout_source_new_seconds(timeout);
   g_source_set_callback(
       timer, utils::GlibRunClosure, closure, utils::GlibDestroyClosure);
diff --git a/download_action.h b/download_action.h
index c99f14b..e53ee34 100644
--- a/download_action.h
+++ b/download_action.h
@@ -13,7 +13,6 @@
 
 #include <base/memory/scoped_ptr.h>
 #include <curl/curl.h>
-#include <google/protobuf/stubs/common.h>
 
 #include "update_engine/action.h"
 #include "update_engine/delta_performer.h"
diff --git a/http_fetcher.cc b/http_fetcher.cc
index 2dd6ec4..7fa2812 100644
--- a/http_fetcher.cc
+++ b/http_fetcher.cc
@@ -4,7 +4,7 @@
 
 #include "update_engine/http_fetcher.h"
 
-using google::protobuf::Closure;
+using base::Closure;
 using std::deque;
 using std::string;
 
diff --git a/http_fetcher.h b/http_fetcher.h
index fa26133..bab19d9 100644
--- a/http_fetcher.h
+++ b/http_fetcher.h
@@ -10,9 +10,9 @@
 #include <vector>
 
 #include <base/basictypes.h>
+#include <base/callback.h>
 #include <base/logging.h>
 #include <glib.h>
-#include <google/protobuf/stubs/common.h>
 
 #include "update_engine/http_common.h"
 #include "update_engine/proxy_resolver.h"
@@ -59,8 +59,7 @@
 
   // Proxy methods to set the proxies, then to pop them off.
   // Returns true on success.
-  bool ResolveProxiesForUrl(const std::string& url,
-                            google::protobuf::Closure* callback);
+  bool ResolveProxiesForUrl(const std::string& url, base::Closure* callback);
 
   void SetProxies(const std::deque<std::string>& proxies) {
     proxies_ = proxies;
@@ -150,7 +149,7 @@
   guint no_resolver_idle_id_;
 
   // Callback for when we are resolving proxies
-  google::protobuf::Closure* callback_;
+  base::Closure* callback_;
 
   // Global system context.
   SystemState* system_state_;
diff --git a/libcurl_http_fetcher.cc b/libcurl_http_fetcher.cc
index e2167cd..da643bf 100644
--- a/libcurl_http_fetcher.cc
+++ b/libcurl_http_fetcher.cc
@@ -7,6 +7,7 @@
 #include <algorithm>
 #include <string>
 
+#include <base/bind.h>
 #include <base/logging.h>
 #include <base/strings/string_util.h>
 #include <base/strings/stringprintf.h>
@@ -15,7 +16,6 @@
 #include "update_engine/hardware_interface.h"
 #include "update_engine/utils.h"
 
-using google::protobuf::NewPermanentCallback;
 using std::make_pair;
 using std::max;
 using std::string;
@@ -221,9 +221,9 @@
 void LibcurlHttpFetcher::BeginTransfer(const std::string& url) {
   CHECK(!transfer_in_progress_);
   url_ = url;
-  if (!ResolveProxiesForUrl(
-          url_,
-          NewPermanentCallback(this, &LibcurlHttpFetcher::ProxiesResolved))) {
+  auto closure = base::Bind(&LibcurlHttpFetcher::ProxiesResolved,
+                            base::Unretained(this));
+  if (!ResolveProxiesForUrl(url_, new base::Closure(closure))) {
     LOG(ERROR) << "Couldn't resolve proxies";
     if (delegate_)
       delegate_->TransferComplete(this, false);
diff --git a/proxy_resolver.cc b/proxy_resolver.cc
index f9905bb..fd233de 100644
--- a/proxy_resolver.cc
+++ b/proxy_resolver.cc
@@ -4,6 +4,8 @@
 
 #include "update_engine/proxy_resolver.h"
 
+#include <base/bind.h>
+
 using std::deque;
 using std::string;
 
@@ -21,11 +23,11 @@
 bool DirectProxyResolver::GetProxiesForUrl(const std::string& url,
                                            ProxiesResolvedFn callback,
                                            void* data) {
-  google::protobuf::Closure* closure = google::protobuf::NewPermanentCallback(
-      this,
+  base::Closure* closure = new base::Closure(base::Bind(
       &DirectProxyResolver::ReturnCallback,
+      base::Unretained(this),
       callback,
-      data);
+      data));
   idle_callback_id_ = g_idle_add_full(
       G_PRIORITY_DEFAULT,
       utils::GlibRunClosure,
diff --git a/proxy_resolver.h b/proxy_resolver.h
index 03bf731..1a924bd 100644
--- a/proxy_resolver.h
+++ b/proxy_resolver.h
@@ -10,7 +10,6 @@
 #include <string>
 
 #include <base/logging.h>
-#include <google/protobuf/stubs/common.h>
 
 #include "update_engine/utils.h"
 
diff --git a/update_attempter.cc b/update_attempter.cc
index 6768529..d0ef575 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -53,7 +53,6 @@
 using base::Time;
 using base::TimeDelta;
 using base::TimeTicks;
-using google::protobuf::NewPermanentCallback;
 using std::make_pair;
 using std::set;
 using std::shared_ptr;
diff --git a/utils.cc b/utils.cc
index 37d1c9a..2dcc8ca 100644
--- a/utils.cc
+++ b/utils.cc
@@ -25,6 +25,7 @@
 #include <utility>
 #include <vector>
 
+#include <base/callback.h>
 #include <base/file_util.h>
 #include <base/files/file_path.h>
 #include <base/files/scoped_file.h>
@@ -36,7 +37,6 @@
 #include <base/strings/string_util.h>
 #include <base/strings/stringprintf.h>
 #include <glib.h>
-#include <google/protobuf/stubs/common.h>
 
 #include "update_engine/clock_interface.h"
 #include "update_engine/constants.h"
@@ -828,14 +828,13 @@
 }
 
 gboolean GlibRunClosure(gpointer data) {
-  google::protobuf::Closure* callback =
-      reinterpret_cast<google::protobuf::Closure*>(data);
+  base::Closure* callback = reinterpret_cast<base::Closure*>(data);
   callback->Run();
   return FALSE;
 }
 
 void GlibDestroyClosure(gpointer data) {
-  delete reinterpret_cast<google::protobuf::Closure*>(data);
+  delete reinterpret_cast<base::Closure*>(data);
 }
 
 string FormatSecs(unsigned secs) {