Refactor parsing of the Chrome Watcher command line to make the parent handle accessible outside ExitCodeWatcher.

This CL changes the API between chrome/app and chrome/chrome_watcher. Previously, chrome_watcher was responsible for choosing and interpreting a command-line for launching the Watcher. Now the watcher API is a typical typed C++ API and chrome/app is responsible for all command-line handling.

BUG=

Review URL: https://codereview.chromium.org/841553003

Cr-Commit-Position: refs/heads/master@{#310802}
diff --git a/components/browser_watcher/exit_code_watcher_win.cc b/components/browser_watcher/exit_code_watcher_win.cc
index 0c9e7df7..218978c 100644
--- a/components/browser_watcher/exit_code_watcher_win.cc
+++ b/components/browser_watcher/exit_code_watcher_win.cc
@@ -4,10 +4,8 @@
 
 #include "components/browser_watcher/exit_code_watcher_win.h"
 
-#include "base/command_line.h"
 #include "base/logging.h"
 #include "base/process/kill.h"
-#include "base/strings/string_number_conversions.h"
 #include "base/strings/stringprintf.h"
 #include "base/win/registry.h"
 
@@ -24,8 +22,6 @@
 
 }  // namespace
 
-const char ExitCodeWatcher::kParenthHandleSwitch[] = "parent-handle";
-
 ExitCodeWatcher::ExitCodeWatcher(const base::char16* registry_path) :
     registry_path_(registry_path), exit_code_(STILL_ACTIVE) {
 }
@@ -33,36 +29,23 @@
 ExitCodeWatcher::~ExitCodeWatcher() {
 }
 
-bool ExitCodeWatcher::ParseArguments(const base::CommandLine& cmd_line) {
-  std::string process_handle_str =
-      cmd_line.GetSwitchValueASCII(kParenthHandleSwitch);
-  unsigned process_handle_uint = 0;
-  if (process_handle_str.empty() ||
-      !base::StringToUint(process_handle_str, &process_handle_uint)) {
-    LOG(ERROR) << "Missing or invalid parent-handle argument.";
-    return false;
-  }
-
-  HANDLE process_handle = reinterpret_cast<HANDLE>(process_handle_uint);
-  // Initial test of the handle, a zero PID indicates invalid handle, or not
-  // a process handle. In this case, bail immediately and avoid closing the
-  // handle.
-  DWORD process_pid = ::GetProcessId(process_handle);
+bool ExitCodeWatcher::Initialize(base::Process process) {
+  DWORD process_pid = process.pid();
   if (process_pid == 0) {
-    LOG(ERROR) << "Invalid parent-handle, can't get parent PID.";
+    LOG(ERROR) << "Invalid parent handle, can't get parent process ID.";
     return false;
   }
 
   FILETIME creation_time = {};
   FILETIME dummy = {};
-  if (!::GetProcessTimes(process_handle, &creation_time,
-                         &dummy, &dummy, &dummy)) {
-    LOG(ERROR) << "Invalid parent handle, can't get parent process times.";
+  if (!::GetProcessTimes(process.Handle(), &creation_time, &dummy, &dummy,
+                         &dummy)) {
+    PLOG(ERROR) << "Invalid parent handle, can't get parent process times.";
     return false;
   }
 
   // Success, take ownership of the process handle.
-  process_ = base::Process(process_handle);
+  process_ = process.Pass();
   process_creation_time_ = base::Time::FromFileTime(creation_time);
 
   // Start by writing the value STILL_ACTIVE to registry, to allow detection