update_engine: Convert update_manager to chromeos::MessageLoop.

The update_manager/event_loop.* files were basically an abstraction of
the glib main loop in order to make it easier to replace it later.
This patch removes those files and replaces their functions with the
chromeos::MessageLoop interface, backing it up with a FakeMessageLoop
during test, and a real GlibMessageLoop during normal execution. This
patch reduces the running time of the unittest considerably since there
is no need to wait for the timeouts.

BUG=chromium:419827,chromium:402066
TEST=Unittest still pass. Tested on a link device that the UM still runs.

Change-Id: Id572248ff4c9c8be7226ef8c653a5c94ab9c1677
Reviewed-on: https://chromium-review.googlesource.com/276892
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
diff --git a/p2p_manager_unittest.cc b/p2p_manager_unittest.cc
index 8b0c62e..990fb3e 100644
--- a/p2p_manager_unittest.cc
+++ b/p2p_manager_unittest.cc
@@ -16,6 +16,9 @@
 #include <base/bind.h>
 #include <base/callback.h>
 #include <base/strings/stringprintf.h>
+#include <chromeos/message_loops/fake_message_loop.h>
+#include <chromeos/message_loops/message_loop.h>
+#include <chromeos/message_loops/message_loop_utils.h>
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 #include <policy/libpolicy.h>
@@ -30,6 +33,7 @@
 #include "update_engine/utils.h"
 
 using base::TimeDelta;
+using chromeos::MessageLoop;
 using chromeos_update_engine::test_utils::System;
 using std::string;
 using std::unique_ptr;
@@ -50,6 +54,7 @@
 
   // Derived from testing::Test.
   void SetUp() override {
+    loop_.SetAsCurrent();
     test_conf_ = new FakeP2PManagerConfiguration();
 
     // Allocate and install a mock policy implementation in the fake Update
@@ -61,13 +66,17 @@
     // Construct the P2P manager under test.
     manager_.reset(P2PManager::Construct(test_conf_, &fake_clock_, &fake_um_,
                                          "cros_au", 3,
-                                         base::TimeDelta::FromDays(5)));
+                                         TimeDelta::FromDays(5)));
   }
-  void TearDown() override {}
+
+  void TearDown() override {
+    EXPECT_FALSE(loop_.PendingTasks());
+  }
 
   // The P2PManager::Configuration instance used for testing.
   FakeP2PManagerConfiguration *test_conf_;
 
+  chromeos::FakeMessageLoop loop_{nullptr};
   FakeClock fake_clock_;
   chromeos_update_manager::MockPolicy *mock_policy_ = nullptr;
   chromeos_update_manager::FakeUpdateManager fake_um_;
@@ -83,7 +92,7 @@
   EXPECT_CALL(*mock_policy_, P2PEnabledChanged(_, _, _, _, false));
 
   EXPECT_FALSE(manager_->IsP2PEnabled());
-  test_utils::RunGMainLoopMaxIterations(100);
+  chromeos::MessageLoopRunMaxIterations(MessageLoop::current(), 100);
   EXPECT_FALSE(manager_->IsP2PEnabled());
 }
 
@@ -98,7 +107,7 @@
   EXPECT_CALL(*mock_policy_, P2PEnabledChanged(_, _, _, _, false));
 
   EXPECT_TRUE(manager_->IsP2PEnabled());
-  test_utils::RunGMainLoopMaxIterations(100);
+  chromeos::MessageLoopRunMaxIterations(MessageLoop::current(), 100);
   EXPECT_FALSE(manager_->IsP2PEnabled());
 }
 
@@ -110,7 +119,7 @@
   test_conf_ = new FakeP2PManagerConfiguration();
   manager_.reset(P2PManager::Construct(
       test_conf_, &fake_clock_, &fake_um_, "cros_au", 3,
-      base::TimeDelta() /* max_file_age */));
+      TimeDelta() /* max_file_age */));
   EXPECT_EQ(manager_->CountSharedFiles(), 0);
 
   // Generate files with different timestamps matching our pattern and generate