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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/browser_watcher/watcher_client_win.cc
diff --git a/components/browser_watcher/watcher_client_win.cc b/components/browser_watcher/watcher_client_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..68d53fb29b62b9b317363bd9c6e15ae0adb4199e
--- /dev/null
+++ b/components/browser_watcher/watcher_client_win.cc
@@ -0,0 +1,84 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/browser_watcher/watcher_client_win.h"
+
+#include <windows.h>
+
+#include "base/path_service.h"
+#include "base/process/launch.h"
+#include "base/strings/string16.h"
+#include "base/strings/stringprintf.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/win/scoped_handle.h"
+#include "base/win/scoped_process_information.h"
+#include "base/win/startup_information.h"
+#include "base/win/windows_version.h"
+#include "components/browser_watcher/watcher_main_win.h"
+
+namespace browser_watcher {
+
+namespace {
+
+base::win::ScopedHandle OpenOwnProcessInheritable() {
+ return base::win::ScopedHandle(
+ ::OpenProcess(SYNCHRONIZE | PROCESS_QUERY_INFORMATION,
+ TRUE, // Ineritable handle.
+ base::GetCurrentProcId()));
+}
+
+void AddHandleArgument(base::ProcessHandle handle,
+ base::CommandLine* cmd_line) {
+ DCHECK(cmd_line);
+
+ cmd_line->AppendSwitchASCII("parent-handle",
+ base::StringPrintf("%d", handle));
+}
+
+} // namespace
+
+const base::FilePath::CharType kWatcherDll[] =
+ FILE_PATH_LITERAL("chrome_watcher.dll");
+const char kWatcherDLLEntrypoint[] = "WatcherMain";
+
+WatcherClient::WatcherClient(const base::CommandLine& base_command_line) :
+ use_legacy_launch_(base::win::GetVersion() < base::win::VERSION_VISTA),
+ base_command_line_(base_command_line),
+ process_(base::kNullProcessHandle) {
+}
+
+base::win::ScopedHandle WatcherClient::LaunchWatcherProcess(
+ const base::CommandLine& cmd_line, base::ProcessHandle handle) {
+ base::HandlesToInheritVector to_inherit;
+ base::LaunchOptions options;
+ options.start_hidden = true;
+ if (use_legacy_launch_) {
+ // Launch the child process inheriting all handles on XP.
+ options.inherit_handles = true;
+ } else {
+ // Launch the child process inheriting only |handle| on
+ // Vista and better.
+ to_inherit.push_back(handle);
+ options.handles_to_inherit = &to_inherit;
+ }
+
+ base::ProcessHandle process = base::kNullProcessHandle;
+ base::LaunchProcess(cmd_line, options, &process);
+ return base::win::ScopedHandle(process);
+}
+
+void WatcherClient::LaunchWatcher() {
+ DCHECK(!process_.IsValid());
+
+ // Build the command line for the watcher process.
+ base::win::ScopedHandle self(OpenOwnProcessInheritable());
+ DCHECK(self.IsValid());
+ base::CommandLine cmd_line(base_command_line_);
+ AddHandleArgument(self.Get(), &cmd_line);
+
+ // Launch it.
+ process_ = LaunchWatcherProcess(cmd_line, self.Get());
+}
+
+} // namespace browser_watcher

Powered by Google App Engine
This is Rietveld 408576698