Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: components/browser_watcher/watcher_client_win.cc

Issue 743463002: Browser watcher, part deux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Address Erik's remaining comments. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "components/browser_watcher/watcher_client_win.h"
6
7 #include <windows.h>
8
9 #include "base/logging.h"
10 #include "base/process/launch.h"
11 #include "base/strings/stringprintf.h"
12 #include "base/win/windows_version.h"
13 #include "components/browser_watcher/exit_code_watcher_win.h"
14
15 namespace browser_watcher {
16
17 namespace {
18
19 base::win::ScopedHandle OpenOwnProcessInheritable() {
20 return base::win::ScopedHandle(
21 ::OpenProcess(SYNCHRONIZE | PROCESS_QUERY_INFORMATION,
22 TRUE, // Ineritable handle.
23 base::GetCurrentProcId()));
24 }
25
26 void AddHandleArgument(base::ProcessHandle handle,
27 base::CommandLine* cmd_line) {
28 cmd_line->AppendSwitchASCII(ExitCodeWatcher::kParenthHandleSwitch,
29 base::StringPrintf("%d", handle));
30 }
31
32 } // namespace
33
34 WatcherClient::WatcherClient(const base::CommandLine& base_command_line) :
35 use_legacy_launch_(base::win::GetVersion() < base::win::VERSION_VISTA),
36 base_command_line_(base_command_line),
37 process_(base::kNullProcessHandle) {
38 }
39
40 base::win::ScopedHandle WatcherClient::LaunchWatcherProcess(
41 const base::CommandLine& cmd_line, base::ProcessHandle handle) {
42 base::HandlesToInheritVector to_inherit;
43 base::LaunchOptions options;
44 options.start_hidden = true;
45 if (use_legacy_launch_) {
46 // Launch the child process inheriting all handles on XP.
47 options.inherit_handles = true;
48 } else {
49 // Launch the child process inheriting only |handle| on
50 // Vista and better.
51 to_inherit.push_back(handle);
52 options.handles_to_inherit = &to_inherit;
53 }
54
55 base::ProcessHandle process = base::kNullProcessHandle;
56 if (!base::LaunchProcess(cmd_line, options, &process))
57 LOG(ERROR) << "Failed to launch browser watcher.";
58
59 return base::win::ScopedHandle(process);
60 }
61
62 void WatcherClient::LaunchWatcher() {
63 DCHECK(!process_.IsValid());
64
65 // Build the command line for the watcher process.
66 base::win::ScopedHandle self(OpenOwnProcessInheritable());
67 DCHECK(self.IsValid());
68 base::CommandLine cmd_line(base_command_line_);
69 AddHandleArgument(self.Get(), &cmd_line);
70
71 // Launch it.
72 process_ = LaunchWatcherProcess(cmd_line, self.Get());
73 }
74
75 } // namespace browser_watcher
OLDNEW
« no previous file with comments | « components/browser_watcher/watcher_client_win.h ('k') | components/browser_watcher/watcher_client_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698