OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_BROWSER_WATCHER_WATCHER_CLIENT_WIN_H_ | 5 #ifndef COMPONENTS_BROWSER_WATCHER_WATCHER_CLIENT_WIN_H_ |
6 #define COMPONENTS_BROWSER_WATCHER_WATCHER_CLIENT_WIN_H_ | 6 #define COMPONENTS_BROWSER_WATCHER_WATCHER_CLIENT_WIN_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/process/process.h" | 10 #include "base/process/process.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 // Constructs a watcher client that launches its watcher process using the | 26 // Constructs a watcher client that launches its watcher process using the |
27 // command line generated by |command_line_generator|. | 27 // command line generated by |command_line_generator|. |
28 explicit WatcherClient(const CommandLineGenerator& command_line_generator); | 28 explicit WatcherClient(const CommandLineGenerator& command_line_generator); |
29 | 29 |
30 // Launches the watcher process such that the child process is able to inherit | 30 // Launches the watcher process such that the child process is able to inherit |
31 // a handle to the current process. If use_legacy_launch() is true, this uses | 31 // a handle to the current process. If use_legacy_launch() is true, this uses |
32 // a non-threadsafe legacy launch mode that's compatible with Windows XP. | 32 // a non-threadsafe legacy launch mode that's compatible with Windows XP. |
33 void LaunchWatcher(); | 33 void LaunchWatcher(); |
34 | 34 |
| 35 // Ensures that |handle| may be inherited by the watcher process. |handle| |
| 36 // must still be inheritable, and it's the client's responsibility to |
| 37 // communicate the value of |handle| to the launched process. |
| 38 void AddInheritedHandle(HANDLE handle); |
| 39 |
| 40 // Returns the launched process. |
| 41 const base::Process& process() const { return process_; } |
| 42 |
35 // Accessors, exposed only for testing. | 43 // Accessors, exposed only for testing. |
36 bool use_legacy_launch() const { return use_legacy_launch_; } | 44 bool use_legacy_launch() const { return use_legacy_launch_; } |
37 void set_use_legacy_launch(bool use_legacy_launch) { | 45 void set_use_legacy_launch(bool use_legacy_launch) { |
38 use_legacy_launch_ = use_legacy_launch; | 46 use_legacy_launch_ = use_legacy_launch; |
39 } | 47 } |
40 base::ProcessHandle process() const { return process_.Handle(); } | |
41 | 48 |
42 private: | 49 private: |
43 // If true, the watcher process will be launched with XP legacy handle | 50 // If true, the watcher process will be launched with XP legacy handle |
44 // inheritance. This is not thread safe and can leak random handles into the | 51 // inheritance. This is not thread safe and can leak random handles into the |
45 // child process, but it's the best we can do on XP. | 52 // child process, but it's the best we can do on XP. |
46 bool use_legacy_launch_; | 53 bool use_legacy_launch_; |
47 | 54 |
48 // The CommandLineGenerator passed to the constructor. | 55 // The CommandLineGenerator passed to the constructor. |
49 CommandLineGenerator command_line_generator_; | 56 CommandLineGenerator command_line_generator_; |
50 | 57 |
51 // A handle to the launched watcher process. Valid after a successful | 58 // A handle to the launched watcher process. Valid after a successful |
52 // LaunchWatcher() call. | 59 // LaunchWatcher() call. |
53 base::Process process_; | 60 base::Process process_; |
54 | 61 |
| 62 std::vector<HANDLE> inherited_handles_; |
| 63 |
55 DISALLOW_COPY_AND_ASSIGN(WatcherClient); | 64 DISALLOW_COPY_AND_ASSIGN(WatcherClient); |
56 }; | 65 }; |
57 | 66 |
58 } // namespace browser_watcher | 67 } // namespace browser_watcher |
59 | 68 |
60 #endif // COMPONENTS_BROWSER_WATCHER_WATCHER_CLIENT_WIN_H_ | 69 #endif // COMPONENTS_BROWSER_WATCHER_WATCHER_CLIENT_WIN_H_ |
OLD | NEW |