Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / chrome / app / chrome_watcher_client_win.h
blob24c137ccb0ee0d9ef54b765ebfc0607b7bca21fa
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.
5 #ifndef CHROME_APP_CHROME_WATCHER_CLIENT_WIN_H_
6 #define CHROME_APP_CHROME_WATCHER_CLIENT_WIN_H_
8 #include <windows.h>
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/time/time.h"
15 #include "base/win/scoped_handle.h"
17 // Launches a Chrome watcher process and permits the client to wait until the
18 // process is fully initialized.
19 class ChromeWatcherClient {
20 public:
21 // A CommandLineGenerator generates command lines that will launch a separate
22 // process and pass the supplied values to WatcherMain in that process.
23 // |parent_process| is the process that the watcher process should watch;
24 // |main_thread_id| is the parent process' main thread ID.
25 // |on_initialized_event| should be signaled when the watcher process is fully
26 // initialized. The process will be launched such that the HANDLEs are
27 // inherited by the new process.
28 typedef base::Callback<base::CommandLine(HANDLE parent_process,
29 DWORD main_thread_id,
30 HANDLE on_initialized_event)>
31 CommandLineGenerator;
33 // Constructs an instance that launches its watcher process using the command
34 // line generated by |command_line_generator|.
35 explicit ChromeWatcherClient(
36 const CommandLineGenerator& command_line_generator);
38 ~ChromeWatcherClient();
40 // Launches the watcher process such that the child process is able to inherit
41 // a handle to the current process. Returns true if the process is
42 // successfully launched.
43 bool LaunchWatcher();
45 // Blocks until the process, previously launched by LaunchWatcher, is either
46 // fully initialized or has terminated. Returns true if the process
47 // successfully initializes. May be called multiple times.
48 bool EnsureInitialized();
50 // Waits for the process to exit. Returns true on success. It is up to the
51 // client to somehow signal the process to exit.
52 bool WaitForExit(int* exit_code);
54 // Same as WaitForExit() but only waits for up to |timeout|.
55 bool WaitForExitWithTimeout(base::TimeDelta timeout, int* exit_code);
57 private:
58 CommandLineGenerator command_line_generator_;
59 base::win::ScopedHandle on_initialized_event_;
60 base::Process process_;
62 DISALLOW_COPY_AND_ASSIGN(ChromeWatcherClient);
65 #endif // CHROME_APP_CHROME_WATCHER_CLIENT_WIN_H_