blob: aaa8d140d4a4e26b56b9f928f24b117feca0ca50 [file] [log] [blame]
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <windows.h>
#include "base/callback.h"
#include "base/command_line.h"
#include "base/macros.h"
#include "base/process/process.h"
#include "base/time/time.h"
#include "base/win/scoped_handle.h"
// Launches a Chrome watcher process and permits the client to wait until the
// process is fully initialized.
class ChromeWatcherClient {
// A CommandLineGenerator generates command lines that will launch a separate
// process and pass the supplied HANDLE values to WatcherMain in that process.
// The first HANDLE is the process that the watcher process should watch. The
// second HANDLE is an event that should be signaled when the watcher process
// is fully initialized. The process will be launched such that the HANDLEs
// are inherited by the new process.
typedef base::Callback<base::CommandLine(HANDLE, HANDLE)>
// Constructs an instance that launches its watcher process using the command
// line generated by |command_line_generator|.
explicit ChromeWatcherClient(
const CommandLineGenerator& command_line_generator);
// Launches the watcher process such that the child process is able to inherit
// a handle to the current process. Returns true if the process is
// successfully launched.
bool LaunchWatcher();
// Blocks until the process, previously launched by LaunchWatcher, is either
// fully initialized or has terminated. Returns true if the process
// successfully initializes. May be called multiple times.
bool EnsureInitialized();
// Waits for the process to exit. Returns true on success. It is up to the
// client to somehow signal the process to exit.
bool WaitForExit(int* exit_code);
// Same as WaitForExit() but only waits for up to |timeout|.
bool WaitForExitWithTimeout(base::TimeDelta timeout, int* exit_code);
CommandLineGenerator command_line_generator_;
base::win::ScopedHandle on_initialized_event_;
base::Process process_;