siggi | 420541c | 2014-11-18 23:16:32 | [diff] [blame] | 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 | |
| 5 | #ifndef COMPONENTS_BROWSER_WATCHER_WATCHER_CLIENT_WIN_H_ |
| 6 | #define COMPONENTS_BROWSER_WATCHER_WATCHER_CLIENT_WIN_H_ |
| 7 | |
erikwright | 7c4a426 | 2015-01-09 18:32:33 | [diff] [blame] | 8 | #include "base/callback.h" |
siggi | 420541c | 2014-11-18 23:16:32 | [diff] [blame] | 9 | #include "base/macros.h" |
rvargas | 42ba469 | 2014-12-10 18:40:21 | [diff] [blame] | 10 | #include "base/process/process.h" |
siggi | 420541c | 2014-11-18 23:16:32 | [diff] [blame] | 11 | |
erikwright | 7c4a426 | 2015-01-09 18:32:33 | [diff] [blame] | 12 | namespace base { |
| 13 | class CommandLine; |
| 14 | } // namespace base |
| 15 | |
siggi | 420541c | 2014-11-18 23:16:32 | [diff] [blame] | 16 | namespace browser_watcher { |
| 17 | |
| 18 | // An interface class to take care of the details in launching a browser |
| 19 | // watch process. |
| 20 | class WatcherClient { |
| 21 | public: |
erikwright | 7c4a426 | 2015-01-09 18:32:33 | [diff] [blame] | 22 | // A CommandLineGenerator generates command lines that will launch a separate |
| 23 | // process and pass the supplied HANDLE to ExitCodeWatcher in that process. |
| 24 | typedef base::Callback<base::CommandLine(HANDLE)> CommandLineGenerator; |
siggi | 420541c | 2014-11-18 23:16:32 | [diff] [blame] | 25 | |
erikwright | 7c4a426 | 2015-01-09 18:32:33 | [diff] [blame] | 26 | // Constructs a watcher client that launches its watcher process using the |
| 27 | // command line generated by |command_line_generator|. |
| 28 | explicit WatcherClient(const CommandLineGenerator& command_line_generator); |
| 29 | |
thakis | 56e8586a | 2015-05-01 18:55:21 | [diff] [blame] | 30 | ~WatcherClient(); |
| 31 | |
erikwright | 7c4a426 | 2015-01-09 18:32:33 | [diff] [blame] | 32 | // Launches the watcher process such that the child process is able to inherit |
Bruce Dawson | cf669e9 | 2017-07-24 21:35:21 | [diff] [blame] | 33 | // a handle to the current process. |
siggi | 420541c | 2014-11-18 23:16:32 | [diff] [blame] | 34 | void LaunchWatcher(); |
| 35 | |
erikwright | c57091e | 2015-02-04 15:19:10 | [diff] [blame] | 36 | // Ensures that |handle| may be inherited by the watcher process. |handle| |
| 37 | // must still be inheritable, and it's the client's responsibility to |
| 38 | // communicate the value of |handle| to the launched process. |
| 39 | void AddInheritedHandle(HANDLE handle); |
| 40 | |
| 41 | // Returns the launched process. |
| 42 | const base::Process& process() const { return process_; } |
| 43 | |
siggi | 420541c | 2014-11-18 23:16:32 | [diff] [blame] | 44 | private: |
erikwright | 7c4a426 | 2015-01-09 18:32:33 | [diff] [blame] | 45 | // The CommandLineGenerator passed to the constructor. |
| 46 | CommandLineGenerator command_line_generator_; |
siggi | 420541c | 2014-11-18 23:16:32 | [diff] [blame] | 47 | |
| 48 | // A handle to the launched watcher process. Valid after a successful |
| 49 | // LaunchWatcher() call. |
rvargas | 42ba469 | 2014-12-10 18:40:21 | [diff] [blame] | 50 | base::Process process_; |
siggi | 420541c | 2014-11-18 23:16:32 | [diff] [blame] | 51 | |
erikwright | c57091e | 2015-02-04 15:19:10 | [diff] [blame] | 52 | std::vector<HANDLE> inherited_handles_; |
| 53 | |
siggi | 420541c | 2014-11-18 23:16:32 | [diff] [blame] | 54 | DISALLOW_COPY_AND_ASSIGN(WatcherClient); |
| 55 | }; |
| 56 | |
| 57 | } // namespace browser_watcher |
| 58 | |
| 59 | #endif // COMPONENTS_BROWSER_WATCHER_WATCHER_CLIENT_WIN_H_ |