OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 #ifndef COMPONENTS_BROWSER_WATCHER_WATCHER_WIN_H_ |
| 5 #define COMPONENTS_BROWSER_WATCHER_WATCHER_WIN_H_ |
| 6 |
| 7 #include "base/macros.h" |
| 8 #include "base/process/process_handle.h" |
| 9 #include "base/strings/string16.h" |
| 10 #include "base/time/time.h" |
| 11 #include "base/win/scoped_handle.h" |
| 12 |
| 13 namespace base { |
| 14 class CommandLine; |
| 15 } |
| 16 |
| 17 namespace browser_watcher { |
| 18 |
| 19 // Watches for the exit code of a process and records it in a given registry |
| 20 // location. |
| 21 class ExitCodeWatcher { |
| 22 public: |
| 23 // Name of the switch used for the parent process handle. |
| 24 static const char kParenthHandleSwitch[]; |
| 25 |
| 26 // Initialize the watcher with a registry path. |
| 27 explicit ExitCodeWatcher(const base::char16* registry_path); |
| 28 ~ExitCodeWatcher(); |
| 29 |
| 30 // Initializes from arguments on |cmd_line|, returns true on success. |
| 31 // This function expects the process handle indicated by kParentHandleSwitch |
| 32 // in |cmd_line| to be open with sufficient privilege to wait and retrieve |
| 33 // the process exit code. |
| 34 // It checks the handle for validity and takes ownership of it. |
| 35 // The intent is for this handle to be inherited into the watcher process |
| 36 // hosting the instance of this class. |
| 37 bool ParseArguments(const base::CommandLine& cmd_line); |
| 38 |
| 39 // Waits for the process to exit and records its exit code in registry. |
| 40 // This is a blocking call. |
| 41 void WaitForExit(); |
| 42 |
| 43 base::ProcessHandle process() const { return process_.Get(); } |
| 44 |
| 45 private: |
| 46 // Writes |exit_code| to registry, returns true on success. |
| 47 bool WriteProcessExitCode(int exit_code); |
| 48 |
| 49 // The registry path the exit codes are written to. |
| 50 base::string16 registry_path_; |
| 51 |
| 52 // Handle, PID, and creation time of the watched process. |
| 53 base::win::ScopedHandle process_; |
| 54 base::ProcessId process_pid_; |
| 55 base::Time process_creation_time_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(ExitCodeWatcher); |
| 58 }; |
| 59 |
| 60 } // namespace browser_watcher |
| 61 |
| 62 #endif // COMPONENTS_BROWSER_WATCHER_WATCHER_WIN_H_ |
OLD | NEW |