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

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

Issue 717223002: Browser watcher end-end-to-end . (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/lkgr
Patch Set: Address Erik's 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/path_service.h"
10 #include "base/process/launch.h"
11 #include "base/strings/string16.h"
12 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "base/win/scoped_handle.h"
15 #include "base/win/scoped_process_information.h"
16 #include "base/win/startup_information.h"
17 #include "base/win/windows_version.h"
18
19 namespace browser_watcher {
20
21 namespace {
22
23 base::win::ScopedHandle OpenOwnProcessInheritable() {
24 return base::win::ScopedHandle(
25 ::OpenProcess(SYNCHRONIZE | PROCESS_QUERY_INFORMATION,
26 TRUE, // Ineritable handle.
27 base::GetCurrentProcId()));
28 }
29
30 void AddHandleArgument(base::ProcessHandle handle,
31 base::CommandLine* cmd_line) {
32 DCHECK(cmd_line);
33
34 cmd_line->AppendSwitchASCII("parent-handle",
35 base::StringPrintf("%d", handle));
36 }
37
38 } // namespace
39
40 WatcherClient::WatcherClient(const base::CommandLine& base_command_line) :
41 use_legacy_launch_(base::win::GetVersion() < base::win::VERSION_VISTA),
42 base_command_line_(base_command_line),
43 process_(base::kNullProcessHandle) {
44 }
45
46 base::win::ScopedHandle WatcherClient::LaunchWatcherProcess(
47 const base::CommandLine& cmd_line, base::ProcessHandle handle) {
48 base::HandlesToInheritVector to_inherit;
49 base::LaunchOptions options;
50 options.start_hidden = true;
51 if (use_legacy_launch_) {
52 // Launch the child process inheriting all handles on XP.
53 options.inherit_handles = true;
54 } else {
55 // Launch the child process inheriting only |handle| on
56 // Vista and better.
57 to_inherit.push_back(handle);
58 options.handles_to_inherit = &to_inherit;
59 }
60
61 base::ProcessHandle process = base::kNullProcessHandle;
62 base::LaunchProcess(cmd_line, options, &process);
63 return base::win::ScopedHandle(process);
64 }
65
66 void WatcherClient::LaunchWatcher() {
67 DCHECK(!process_.IsValid());
68
69 // Build the command line for the watcher process.
70 base::win::ScopedHandle self(OpenOwnProcessInheritable());
71 DCHECK(self.IsValid());
72 base::CommandLine cmd_line(base_command_line_);
73 AddHandleArgument(self.Get(), &cmd_line);
74
75 // Launch it.
76 process_ = LaunchWatcherProcess(cmd_line, self.Get());
77 }
78
79 } // 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