OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 CHROME_APP_CHROME_WATCHER_CLIENT_WIN_H_ | |
6 #define CHROME_APP_CHROME_WATCHER_CLIENT_WIN_H_ | |
7 | |
8 #include <windows.h> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/command_line.h" | |
12 #include "base/macros.h" | |
13 #include "base/process/process.h" | |
14 #include "base/win/scoped_handle.h" | |
15 | |
16 // Launches a Chrome watcher process and permits the client to wait until the | |
17 // process is fully initialized. | |
18 class ChromeWatcherClient { | |
19 public: | |
20 // A CommandLineGenerator generates command lines that will launch a separate | |
21 // process and pass the supplied HANDLEs to WatcherMain in that process. The | |
22 // first HANDLE is an event that should be signaled when the watcher process | |
23 // is fully initialized. The second HANDLE is the process that the watcher | |
Sigurður Ásgeirsson
2015/01/29 16:59:56
note that both handles must be inheritable?
Maybe
erikwright (departed)
2015/01/30 20:39:57
Given that the command-line generator is not respo
| |
24 // process should watch. | |
25 typedef base::Callback<base::CommandLine(HANDLE, HANDLE)> | |
26 CommandLineGenerator; | |
27 | |
28 // Constructs an instance that launches its watcher process using the command | |
29 // line generated by |command_line_generator|. | |
30 explicit ChromeWatcherClient( | |
31 const CommandLineGenerator& command_line_generator); | |
32 | |
33 ~ChromeWatcherClient(); | |
34 | |
35 // Launches the watcher process such that the child process is able to inherit | |
36 // a handle to the current process. Returns true if the process is | |
37 // successfully launched. | |
38 bool LaunchWatcher(); | |
39 | |
40 // Blocks until the process, previously launched by LaunchWatcher, is either | |
41 // fully initialized or terminates. Returns true if the process successfully | |
42 // initializes. | |
43 bool WaitForInitialization(); | |
44 | |
45 // Terminates the previously launched watcher process with |exit_code| if it | |
46 // has not already exited. Blocks until the process has exited and returns its | |
Sigurður Ásgeirsson
2015/01/29 16:59:57
This is hopefully for testing only?
erikwright (departed)
2015/01/30 20:39:57
Yes, although I can't think of a good reason to la
Sigurður Ásgeirsson
2015/02/02 16:59:20
Not the way it's currently implemented.
TerminateP
erikwright (departed)
2015/02/03 20:05:34
How about this? It's up to the client to ask the "
| |
47 // exit code. Note that the return value might differ from |exit_code| if, for | |
48 // example, it exits naturally before the forced termination takes place. The | |
49 // return value is undefined if LaunchWatcher has not been called or failed, | |
50 // or if invoked multiple times. | |
51 int TerminateWatcher(int exit_code); | |
52 | |
53 // Returns true if the process has previously been launched and | |
54 // TerminateWatcher has not yet been invoked. | |
55 bool launched() { return process_.IsValid(); } | |
56 | |
57 private: | |
58 CommandLineGenerator command_line_generator_; | |
59 base::win::ScopedHandle on_initialized_event_; | |
60 base::Process process_; | |
61 | |
62 DISALLOW_COPY_AND_ASSIGN(ChromeWatcherClient); | |
63 }; | |
64 | |
65 #endif // CHROME_APP_CHROME_WATCHER_CLIENT_WIN_H_ | |
OLD | NEW |