update_engine: Migrate time-based glib main loop calls to MessageLoop.

This patch replaces most calls to g_idle_add* and g_timeout_add* with
the equivalent MessageLoop::Post*Task(). To maintain compatibility with
unittests running the main loop and doing I/O we instantiate a
GlibMessageLoop for those tests.

BUG=chromium:499886
TEST=unittests still pass.

Change-Id: Ic87ba69bc47391ac3c36d1bfc3ca28d069666af1
Reviewed-on: https://chromium-review.googlesource.com/281197
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Trybot-Ready: Alex Deymo <deymo@chromium.org>
diff --git a/chrome_browser_proxy_resolver.h b/chrome_browser_proxy_resolver.h
index 8b47672..ab0a92c 100644
--- a/chrome_browser_proxy_resolver.h
+++ b/chrome_browser_proxy_resolver.h
@@ -14,6 +14,8 @@
 #include <dbus/dbus-glib-lowlevel.h>
 #include <gtest/gtest_prod.h>  // for FRIEND_TEST
 
+#include <chromeos/message_loops/message_loop.h>
+
 #include "update_engine/dbus_wrapper_interface.h"
 #include "update_engine/proxy_resolver.h"
 
@@ -52,7 +54,7 @@
   FRIEND_TEST(ChromeBrowserProxyResolverTest, SuccessTest);
   typedef std::multimap<std::string, std::pair<ProxiesResolvedFn, void*>>
       CallbacksMap;
-  typedef std::multimap<std::string, GSource*> TimeoutsMap;
+  typedef std::multimap<std::string, chromeos::MessageLoop::TaskId> TimeoutsMap;
 
   // Handle a reply from Chrome:
   void HandleReply(const std::string& source_url,
@@ -68,7 +70,7 @@
   static std::deque<std::string> ParseProxyString(const std::string& input);
 
   // Deletes internal state for the first instance of url in the state.
-  // If delete_timer is set, calls g_source_destroy on the timer source.
+  // If delete_timer is set, calls CancelTask on the timer id.
   // Returns the callback in an out parameter. Returns true on success.
   bool DeleteUrlState(const std::string& url,
                       bool delete_timer,
@@ -78,8 +80,8 @@
   void Shutdown();
 
   DBusWrapperInterface* dbus_;
-  DBusGProxy* proxy_;
-  DBusGProxy* peer_proxy_;
+  DBusGProxy* proxy_{nullptr};
+  DBusGProxy* peer_proxy_{nullptr};
   int timeout_;
   TimeoutsMap timers_;
   CallbacksMap callbacks_;