OLD | NEW |
---|---|
(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/process/launch.h" | |
10 #include "base/strings/stringprintf.h" | |
11 #include "base/win/scoped_handle.h" | |
erikwright (departed)
2014/11/18 20:00:05
dup from header
Sigurður Ásgeirsson
2014/11/18 21:18:56
Done.
| |
12 #include "base/win/windows_version.h" | |
13 #include "components/browser_watcher/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 DCHECK(cmd_line); | |
erikwright (departed)
2014/11/18 20:00:05
base/logging.h
Though it's probably overkill for
Sigurður Ásgeirsson
2014/11/18 21:18:56
Done.
| |
29 | |
30 cmd_line->AppendSwitchASCII(ExitCodeWatcher::kParenthHandleSwitch, | |
erikwright (departed)
2014/11/18 20:00:05
Wow. My bad. In your other CL, I should have point
Sigurður Ásgeirsson
2014/11/18 21:18:56
Done.
| |
31 base::StringPrintf("%d", handle)); | |
32 } | |
33 | |
34 } // namespace | |
35 | |
36 WatcherClient::WatcherClient(const base::CommandLine& base_command_line) : | |
37 use_legacy_launch_(base::win::GetVersion() < base::win::VERSION_VISTA), | |
38 base_command_line_(base_command_line), | |
39 process_(base::kNullProcessHandle) { | |
40 } | |
41 | |
42 base::win::ScopedHandle WatcherClient::LaunchWatcherProcess( | |
43 const base::CommandLine& cmd_line, base::ProcessHandle handle) { | |
44 base::HandlesToInheritVector to_inherit; | |
45 base::LaunchOptions options; | |
46 options.start_hidden = true; | |
47 if (use_legacy_launch_) { | |
48 // Launch the child process inheriting all handles on XP. | |
49 options.inherit_handles = true; | |
50 } else { | |
51 // Launch the child process inheriting only |handle| on | |
52 // Vista and better. | |
53 to_inherit.push_back(handle); | |
54 options.handles_to_inherit = &to_inherit; | |
55 } | |
56 | |
57 base::ProcessHandle process = base::kNullProcessHandle; | |
58 base::LaunchProcess(cmd_line, options, &process); | |
erikwright (departed)
2014/11/18 20:00:05
Would some logging be appropriate if this fails?
Sigurður Ásgeirsson
2014/11/18 21:18:57
Done, though in practice I don't think you'll get
| |
59 return base::win::ScopedHandle(process); | |
60 } | |
61 | |
62 void WatcherClient::LaunchWatcher() { | |
63 DCHECK(!process_.IsValid()); | |
erikwright (departed)
2014/11/18 20:00:05
base/logging.h
Sigurður Ásgeirsson
2014/11/18 21:18:56
Done.
| |
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()); | |
erikwright (departed)
2014/11/18 20:00:05
I wonder if the destructor of WatcherClient should
Sigurður Ásgeirsson
2014/11/18 21:18:56
This is baked into chrome.exe, there's no infrastr
| |
73 } | |
74 | |
75 } // namespace browser_watcher | |
OLD | NEW |