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

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: Move to components 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 #include "components/browser_watcher/watcher_main_win.h"
19
20 namespace browser_watcher {
21
22 namespace {
23
24 base::win::ScopedHandle OpenOwnProcessInheritable() {
25 return base::win::ScopedHandle(
26 ::OpenProcess(SYNCHRONIZE | PROCESS_QUERY_INFORMATION,
27 TRUE, // Ineritable handle.
28 base::GetCurrentProcId()));
29 }
30
31 void AddHandleArgument(base::ProcessHandle handle,
32 base::CommandLine* cmd_line) {
33 DCHECK(cmd_line);
34
35 cmd_line->AppendSwitchASCII("parent-handle",
36 base::StringPrintf("%d", handle));
37 }
38
39 } // namespace
40
41 const base::FilePath::CharType kWatcherDll[] =
42 FILE_PATH_LITERAL("chrome_watcher.dll");
43 const char kWatcherDLLEntrypoint[] = "WatcherMain";
44
45 WatcherClient::WatcherClient(const base::CommandLine& base_command_line) :
46 use_legacy_launch_(base::win::GetVersion() < base::win::VERSION_VISTA),
47 base_command_line_(base_command_line),
48 process_(base::kNullProcessHandle) {
49 }
50
51 base::win::ScopedHandle WatcherClient::LaunchWatcherProcess(
52 const base::CommandLine& cmd_line, base::ProcessHandle handle) {
53 base::HandlesToInheritVector to_inherit;
54 base::LaunchOptions options;
55 options.start_hidden = true;
56 if (use_legacy_launch_) {
57 // Launch the child process inheriting all handles on XP.
58 options.inherit_handles = true;
59 } else {
60 // Launch the child process inheriting only |handle| on
61 // Vista and better.
62 to_inherit.push_back(handle);
63 options.handles_to_inherit = &to_inherit;
64 }
65
66 base::ProcessHandle process = base::kNullProcessHandle;
67 base::LaunchProcess(cmd_line, options, &process);
68 return base::win::ScopedHandle(process);
69 }
70
71 void WatcherClient::LaunchWatcher() {
72 DCHECK(!process_.IsValid());
73
74 // Build the command line for the watcher process.
75 base::win::ScopedHandle self(OpenOwnProcessInheritable());
76 DCHECK(self.IsValid());
77 base::CommandLine cmd_line(base_command_line_);
78 AddHandleArgument(self.Get(), &cmd_line);
79
80 // Launch it.
81 process_ = LaunchWatcherProcess(cmd_line, self.Get());
82 }
83
84 } // namespace browser_watcher
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698