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.
5 #ifndef COMPONENTS_BROWSER_WATCHER_WATCHER_CLIENT_WIN_H_
6 #define COMPONENTS_BROWSER_WATCHER_WATCHER_CLIENT_WIN_H_
8 #include "base/command_line.h"
9 #include "base/macros.h"
10 #include "base/process/process_handle.h"
11 #include "base/win/scoped_handle.h"
13 namespace browser_watcher
{
15 // An interface class to take care of the details in launching a browser
19 // Constructs a watcher client with a |base_command_line|, which should be
20 // a command line sufficient to invoke the watcher process. This command
21 // line will be augmented with the value of the inherited handle.
22 explicit WatcherClient(const base::CommandLine
& base_command_line
);
24 // Launches the watcher process.
27 // Accessors, exposed only for testing.
28 bool use_legacy_launch() const { return use_legacy_launch_
; }
29 void set_use_legacy_launch(bool use_legacy_launch
) {
30 use_legacy_launch_
= use_legacy_launch
;
32 base::ProcessHandle
process() const { return process_
.Get(); }
35 // Launches |cmd_line| such that the child process is able to inherit
36 // |handle|. If |use_legacy_launch_| is true, this uses a non-threadsafe
37 // legacy launch mode that's compatible with Windows XP.
38 // Returns a handle to the child process.
39 base::win::ScopedHandle
LaunchWatcherProcess(
40 const base::CommandLine
& cmd_line
, base::ProcessHandle self_handle
);
42 // If true, the watcher process will be launched with XP legacy handle
43 // inheritance. This is not thread safe and can leak random handles into the
44 // child process, but it's the best we can do on XP.
45 bool use_legacy_launch_
;
47 // The base command line passed to the constructor.
48 base::CommandLine base_command_line_
;
50 // A handle to the launched watcher process. Valid after a successful
51 // LaunchWatcher() call.
52 base::win::ScopedHandle process_
;
54 DISALLOW_COPY_AND_ASSIGN(WatcherClient
);
57 } // namespace browser_watcher
59 #endif // COMPONENTS_BROWSER_WATCHER_WATCHER_CLIENT_WIN_H_