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

Unified Diff: chrome/app/chrome_watcher_command_line_win.cc

Issue 1538923004: [win] Change Chrome Watcher configuration API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added unittests. Created 5 years 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: chrome/app/chrome_watcher_command_line_win.cc
diff --git a/chrome/app/chrome_watcher_command_line_win.cc b/chrome/app/chrome_watcher_command_line_win.cc
index d5318a630248ca58ae01d54aa10051f5696e66c9..923a6b5099f3605305532ee7721312ab0c730656 100644
--- a/chrome/app/chrome_watcher_command_line_win.cc
+++ b/chrome/app/chrome_watcher_command_line_win.cc
@@ -17,9 +17,9 @@
namespace {
+const char kMainThreadIdSwitch[] = "main-thread-id";
const char kOnIninitializedEventHandleSwitch[] = "on-initialized-event-handle";
const char kParentHandleSwitch[] = "parent-handle";
-const char kMainThreadIdSwitch[] = "main-thread-id";
void AppendHandleSwitch(const std::string& switch_name,
HANDLE handle,
@@ -47,6 +47,87 @@ HANDLE ReadHandleFromSwitch(const base::CommandLine& command_line,
} // namespace
+ChromeWatcherCommandLineGenerator::ChromeWatcherCommandLineGenerator(
+ const base::FilePath& chrome_exe) : chrome_exe_(chrome_exe) {
+}
+
+bool ChromeWatcherCommandLineGenerator::SetOnInitializedEventHandle(
+ HANDLE on_initialized_event_handle) {
+ return SetHandle(on_initialized_event_handle, &on_initialized_event_handle_);
+}
+
+bool ChromeWatcherCommandLineGenerator::SetParentProcessHandle(
+ HANDLE parent_process_handle) {
+ return SetHandle(parent_process_handle, &parent_process_handle_);
+}
+
+// Generates a command-line representing this configuration.
+base::CommandLine ChromeWatcherCommandLineGenerator::GenerateCommandLine() {
+ // TODO(chrisha): Get rid of the following function and move the
+ // implementation here.
+ return GenerateChromeWatcherCommandLine(
+ chrome_exe_, parent_process_handle_.Get(), ::GetCurrentThreadId(),
+ on_initialized_event_handle_.Get());
+}
+
+void ChromeWatcherCommandLineGenerator::GetInheritedHandles(
+ std::vector<HANDLE>* inherited_handles) const {
+ inherited_handles->push_back(on_initialized_event_handle_.Get());
+ inherited_handles->push_back(parent_process_handle_.Get());
+}
+
+bool ChromeWatcherCommandLineGenerator::SetHandle(
+ HANDLE handle, base::win::ScopedHandle* scoped_handle) {
+ // Create a duplicate handle that is inheritable.
+ HANDLE proc = ::GetCurrentProcess();
+ HANDLE new_handle = 0;
+ if (!::DuplicateHandle(proc, handle, proc, &new_handle, 0, TRUE,
+ DUPLICATE_SAME_ACCESS)) {
+ return false;
+ }
+
+ scoped_handle->Set(new_handle);
+ return true;
+}
+
+ChromeWatcherCommandLineInterpreter::ChromeWatcherCommandLineInterpreter()
+ : main_thread_id_(0) {
+}
+
+ChromeWatcherCommandLineInterpreter::~ChromeWatcherCommandLineInterpreter() {
+ // If any handles were not taken then die violently.
+ if (on_initialized_event_handle_.Get() || parent_process_handle_.Get())
grt (UTC plus 2) 2015/12/21 20:19:06 nit: use IsValid() rather than .Get()
chrisha 2015/12/21 23:25:30 Done.
+ CHECK(false);
grt (UTC plus 2) 2015/12/21 20:19:06 can you make a death test (https://github.com/goog
chrisha 2015/12/21 23:25:30 Done.
+}
+
+bool ChromeWatcherCommandLineInterpreter::InterpretCommandLine(
+ const base::CommandLine& command_line) {
+ // TODO(chrisha): Get rid of the following function and move the
+ // implementation here.
+ return InterpretChromeWatcherCommandLine(
+ command_line, &parent_process_handle_, &main_thread_id_,
+ &on_initialized_event_handle_);
+}
+
+bool ChromeWatcherCommandLineInterpreter::TakeOnInitializedEventHandle(
+ base::win::ScopedHandle* on_initialized_event_handle) {
+ return TakeHandle(&on_initialized_event_handle_, on_initialized_event_handle);
grt (UTC plus 2) 2015/12/21 20:19:06 can this be: return std::move(on_initialized_eve
chrisha 2015/12/21 23:25:30 Changed to using move semantics and returning a ra
+}
+
+bool ChromeWatcherCommandLineInterpreter::TakeParentProcessHandle(
+ base::win::ScopedHandle* parent_process_handle) {
+ return TakeHandle(&parent_process_handle_, parent_process_handle);
+}
+
+bool ChromeWatcherCommandLineInterpreter::TakeHandle(
+ base::win::ScopedHandle* internal_handle,
+ base::win::ScopedHandle* external_handle) {
+ if (!internal_handle->Get())
+ return false;
+ external_handle->Set(internal_handle->Take());
+ return true;
+}
+
base::CommandLine GenerateChromeWatcherCommandLine(
const base::FilePath& chrome_exe,
HANDLE parent_process,
« chrome/app/chrome_watcher_command_line_win.h ('K') | « chrome/app/chrome_watcher_command_line_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698