update_engine: Replace FileWatcher.

base::MessageLoop::WatchFileDescriptor() is removed in the next uprev.
This CL replaces the uses (including indirect uses), by FileDescriptorWatcher.

BUG=chromium:909719
TEST=Built locally. Ran cros_run_unit_tests.

Change-Id: Ide9f94daf2be28696ec6bc1f82ab46a2bd2b6c6f
diff --git a/common/subprocess.cc b/common/subprocess.cc
index 0131f10..36655c7 100644
--- a/common/subprocess.cc
+++ b/common/subprocess.cc
@@ -127,8 +127,7 @@
     if (!ok || eof) {
       // There was either an error or an EOF condition, so we are done watching
       // the file descriptor.
-      MessageLoop::current()->CancelTask(record->stdout_task_id);
-      record->stdout_task_id = MessageLoop::kTaskIdNull;
+      record->stdout_controller.reset();
       return;
     }
   } while (bytes_read);
@@ -143,8 +142,7 @@
   // Make sure we read any remaining process output and then close the pipe.
   OnStdoutReady(record);
 
-  MessageLoop::current()->CancelTask(record->stdout_task_id);
-  record->stdout_task_id = MessageLoop::kTaskIdNull;
+  record->stdout_controller.reset();
 
   // Don't print any log if the subprocess exited with exit code 0.
   if (info.si_code != CLD_EXITED) {
@@ -199,12 +197,9 @@
                << record->stdout_fd << ".";
   }
 
-  record->stdout_task_id = MessageLoop::current()->WatchFileDescriptor(
-      FROM_HERE,
+  record->stdout_controller = base::FileDescriptorWatcher::WatchReadable(
       record->stdout_fd,
-      MessageLoop::WatchMode::kWatchRead,
-      true,
-      base::Bind(&Subprocess::OnStdoutReady, record.get()));
+      base::BindRepeating(&Subprocess::OnStdoutReady, record.get()));
 
   subprocess_records_[pid] = std::move(record);
   return pid;
diff --git a/common/subprocess.h b/common/subprocess.h
index bc19d16..bac9e48 100644
--- a/common/subprocess.h
+++ b/common/subprocess.h
@@ -25,6 +25,7 @@
 #include <vector>
 
 #include <base/callback.h>
+#include <base/files/file_descriptor_watcher_posix.h>
 #include <base/logging.h>
 #include <base/macros.h>
 #include <brillo/asynchronous_signal_handler_interface.h>
@@ -120,8 +121,7 @@
 
     // These are used to monitor the stdout of the running process, including
     // the stderr if it was redirected.
-    brillo::MessageLoop::TaskId stdout_task_id{
-        brillo::MessageLoop::kTaskIdNull};
+    std::unique_ptr<base::FileDescriptorWatcher::Controller> stdout_controller;
     int stdout_fd{-1};
     std::string stdout;
   };