blob: 3964d8307d1d244ba98a9ea92f7e103160b8aa49 [file] [log] [blame]
siggi420541c2014-11-18 23:16:321// 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
erikwright7c4a4262015-01-09 18:32:338#include "base/callback.h"
siggi420541c2014-11-18 23:16:329#include "base/macros.h"
rvargas42ba4692014-12-10 18:40:2110#include "base/process/process.h"
siggi420541c2014-11-18 23:16:3211
erikwright7c4a4262015-01-09 18:32:3312namespace base {
13class CommandLine;
14} // namespace base
15
siggi420541c2014-11-18 23:16:3216namespace browser_watcher {
17
18// An interface class to take care of the details in launching a browser
19// watch process.
20class WatcherClient {
21 public:
erikwright7c4a4262015-01-09 18:32:3322 // 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;
siggi420541c2014-11-18 23:16:3225
erikwright7c4a4262015-01-09 18:32:3326 // 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
thakis56e8586a2015-05-01 18:55:2130 ~WatcherClient();
31
erikwright7c4a4262015-01-09 18:32:3332 // Launches the watcher process such that the child process is able to inherit
Bruce Dawsoncf669e92017-07-24 21:35:2133 // a handle to the current process.
siggi420541c2014-11-18 23:16:3234 void LaunchWatcher();
35
erikwrightc57091e2015-02-04 15:19:1036 // 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
siggi420541c2014-11-18 23:16:3244 private:
erikwright7c4a4262015-01-09 18:32:3345 // The CommandLineGenerator passed to the constructor.
46 CommandLineGenerator command_line_generator_;
siggi420541c2014-11-18 23:16:3247
48 // A handle to the launched watcher process. Valid after a successful
49 // LaunchWatcher() call.
rvargas42ba4692014-12-10 18:40:2150 base::Process process_;
siggi420541c2014-11-18 23:16:3251
erikwrightc57091e2015-02-04 15:19:1052 std::vector<HANDLE> inherited_handles_;
53
siggi420541c2014-11-18 23:16:3254 DISALLOW_COPY_AND_ASSIGN(WatcherClient);
55};
56
57} // namespace browser_watcher
58
59#endif // COMPONENTS_BROWSER_WATCHER_WATCHER_CLIENT_WIN_H_