update_engine: Use libchromeos to launch subprocesses.

The Subprocess class handles the execution of suprocesses in the
update_engine such as the post-install script and bspatch operations.

This patch migrates this class from using glib functions to use
libchromeos classes with equivalent functionality.

Callsites and unittests were updated to match the new interface.

BUG=chromium:499886
TEST=Unittest still pass. Deployed on link and cros flash another image
using a delta payload.

Change-Id: Ia64d39734e220675113f393a6049e9a9b0fe8409
Reviewed-on: https://chromium-review.googlesource.com/288837
Trybot-Ready: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
diff --git a/p2p_manager.cc b/p2p_manager.cc
index c72a023..b1b4438 100644
--- a/p2p_manager.cc
+++ b/p2p_manager.cc
@@ -369,8 +369,8 @@
   ~LookupData() {
     if (timeout_task_ != MessageLoop::kTaskIdNull)
       MessageLoop::current()->CancelTask(timeout_task_);
-    if (child_tag_)
-      Subprocess::Get().KillExec(child_tag_);
+    if (child_pid_)
+      Subprocess::Get().KillExec(child_pid_);
   }
 
   void InitiateLookup(const vector<string>& cmd, TimeDelta timeout) {
@@ -380,11 +380,11 @@
     // guarantee is useful for testing).
 
     // We expect to run just "p2p-client" and find it in the path.
-    child_tag_ = Subprocess::Get().ExecFlags(
-        cmd, G_SPAWN_SEARCH_PATH, false /* redirect stderr */, OnLookupDone,
-        this);
+    child_pid_ = Subprocess::Get().ExecFlags(
+        cmd, Subprocess::kSearchPath,
+        Bind(&LookupData::OnLookupDone, base::Unretained(this)));
 
-    if (!child_tag_) {
+    if (!child_pid_) {
       LOG(ERROR) << "Error spawning " << utils::StringVectorToString(cmd);
       ReportErrorAndDeleteInIdle();
       return;
@@ -442,19 +442,16 @@
     reported_ = true;
   }
 
-  static void OnLookupDone(int return_code,
-                           const string& output,
-                           void *user_data) {
-    LookupData *lookup_data = reinterpret_cast<LookupData*>(user_data);
-    lookup_data->child_tag_ = 0;
+  void OnLookupDone(int return_code, const string& output) {
+    child_pid_ = 0;
     if (return_code != 0) {
       LOG(INFO) << "Child exited with non-zero exit code "
                 << return_code;
-      lookup_data->ReportError();
+      ReportError();
     } else {
-      lookup_data->ReportSuccess(output);
+      ReportSuccess(output);
     }
-    delete lookup_data;
+    delete this;
   }
 
   void OnTimeout() {
@@ -467,7 +464,7 @@
 
   // The Subprocess tag of the running process. A value of 0 means that the
   // process is not running.
-  uint32_t child_tag_{0};
+  pid_t child_pid_{0};
 
   // The timeout task_id we are waiting on, if any.
   MessageLoop::TaskId timeout_task_{MessageLoop::kTaskIdNull};