Documents what ApplicationManager::Delegate do
[chromium-blink-merge.git] / chrome / app / chrome_watcher_client_win.h
blobaaa8d140d4a4e26b56b9f928f24b117feca0ca50
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 HANDLE values to WatcherMain in that process.
23 // The first HANDLE is the process that the watcher process should watch. The
24 // second HANDLE is an event that should be signaled when the watcher process
25 // is fully initialized. The process will be launched such that the HANDLEs
26 // are inherited by the new process.
27 typedef base::Callback<base::CommandLine(HANDLE, HANDLE)>
28 CommandLineGenerator;
30 // Constructs an instance that launches its watcher process using the command
31 // line generated by |command_line_generator|.
32 explicit ChromeWatcherClient(
33 const CommandLineGenerator& command_line_generator);
35 ~ChromeWatcherClient();
37 // Launches the watcher process such that the child process is able to inherit
38 // a handle to the current process. Returns true if the process is
39 // successfully launched.
40 bool LaunchWatcher();
42 // Blocks until the process, previously launched by LaunchWatcher, is either
43 // fully initialized or has terminated. Returns true if the process
44 // successfully initializes. May be called multiple times.
45 bool EnsureInitialized();
47 // Waits for the process to exit. Returns true on success. It is up to the
48 // client to somehow signal the process to exit.
49 bool WaitForExit(int* exit_code);
51 // Same as WaitForExit() but only waits for up to |timeout|.
52 bool WaitForExitWithTimeout(base::TimeDelta timeout, int* exit_code);
54 private:
55 CommandLineGenerator command_line_generator_;
56 base::win::ScopedHandle on_initialized_event_;
57 base::Process process_;
59 DISALLOW_COPY_AND_ASSIGN(ChromeWatcherClient);
62 #endif // CHROME_APP_CHROME_WATCHER_CLIENT_WIN_H_