Don't schedule more invokeFunctors than necessary.
[chromium-blink-merge.git] / components / browser_watcher / watcher_client_win.h
blob11caed8da470c94a353c0d680fd2ceef81a6de40
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.h"
12 namespace browser_watcher {
14 // An interface class to take care of the details in launching a browser
15 // watch process.
16 class WatcherClient {
17 public:
18 // Constructs a watcher client with a |base_command_line|, which should be
19 // a command line sufficient to invoke the watcher process. This command
20 // line will be augmented with the value of the inherited handle.
21 explicit WatcherClient(const base::CommandLine& base_command_line);
23 // Launches the watcher process.
24 void LaunchWatcher();
26 // Accessors, exposed only for testing.
27 bool use_legacy_launch() const { return use_legacy_launch_; }
28 void set_use_legacy_launch(bool use_legacy_launch) {
29 use_legacy_launch_ = use_legacy_launch;
31 base::ProcessHandle process() const { return process_.Handle(); }
33 private:
34 // Launches |cmd_line| such that the child process is able to inherit
35 // |handle|. If |use_legacy_launch_| is true, this uses a non-threadsafe
36 // legacy launch mode that's compatible with Windows XP.
37 // Returns a handle to the child process.
38 void LaunchWatcherProcess(const base::CommandLine& cmd_line,
39 base::Process self);
41 // If true, the watcher process will be launched with XP legacy handle
42 // inheritance. This is not thread safe and can leak random handles into the
43 // child process, but it's the best we can do on XP.
44 bool use_legacy_launch_;
46 // The base command line passed to the constructor.
47 base::CommandLine base_command_line_;
49 // A handle to the launched watcher process. Valid after a successful
50 // LaunchWatcher() call.
51 base::Process process_;
53 DISALLOW_COPY_AND_ASSIGN(WatcherClient);
56 } // namespace browser_watcher
58 #endif // COMPONENTS_BROWSER_WATCHER_WATCHER_CLIENT_WIN_H_