Correctly track texture cleared state for sharing
[chromium-blink-merge.git] / components / browser_watcher / watcher_client_win.cc
blobe055278839034731404114449c422e0ef06efe98
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 #include "components/browser_watcher/watcher_client_win.h"
7 #include <windows.h>
9 #include "base/command_line.h"
10 #include "base/logging.h"
11 #include "base/process/launch.h"
12 #include "base/win/windows_version.h"
14 namespace browser_watcher {
16 namespace {
18 base::Process OpenOwnProcessInheritable() {
19 return base::Process(
20 ::OpenProcess(SYNCHRONIZE | PROCESS_QUERY_INFORMATION,
21 TRUE, // Ineritable handle.
22 base::GetCurrentProcId()));
25 } // namespace
27 WatcherClient::WatcherClient(const CommandLineGenerator& command_line_generator)
28 : use_legacy_launch_(base::win::GetVersion() < base::win::VERSION_VISTA),
29 command_line_generator_(command_line_generator),
30 process_(base::kNullProcessHandle) {
33 void WatcherClient::LaunchWatcher() {
34 DCHECK(!process_.IsValid());
36 // Build the command line for the watcher process.
37 base::Process self = OpenOwnProcessInheritable();
38 DCHECK(self.IsValid());
39 base::CommandLine cmd_line(command_line_generator_.Run(self.Handle()));
41 base::HandlesToInheritVector to_inherit;
42 base::LaunchOptions options;
43 options.start_hidden = true;
44 if (use_legacy_launch_) {
45 // Launch the child process inheriting all handles on XP.
46 options.inherit_handles = true;
47 } else {
48 // Launch the child process inheriting only |self| on
49 // Vista and better.
50 to_inherit.push_back(self.Handle());
51 options.handles_to_inherit = &to_inherit;
54 process_ = base::LaunchProcess(cmd_line, options);
55 if (!process_.IsValid())
56 LOG(ERROR) << "Failed to launch browser watcher.";
59 } // namespace browser_watcher