diff options
author | Kristian Monsen <kristianm@google.com> | 2011-06-09 11:47:42 +0100 |
---|---|---|
committer | Kristian Monsen <kristianm@google.com> | 2011-06-29 14:33:03 +0100 |
commit | dc0f95d653279beabeb9817299e2902918ba123e (patch) | |
tree | 32eb121cd532053a5b9cb0c390331349af8d6baa /chrome/common/service_process_util_win.cc | |
parent | ba160cd4054d13d0cb0b1b46e61c3bed67095811 (diff) | |
download | external_chromium-dc0f95d653279beabeb9817299e2902918ba123e.zip external_chromium-dc0f95d653279beabeb9817299e2902918ba123e.tar.gz external_chromium-dc0f95d653279beabeb9817299e2902918ba123e.tar.bz2 |
Merge Chromium at r11.0.696.0: Initial merge by git
Change-Id: I273dde2843af0839dfc08b419bb443fbd449532d
Diffstat (limited to 'chrome/common/service_process_util_win.cc')
-rw-r--r-- | chrome/common/service_process_util_win.cc | 55 |
1 files changed, 39 insertions, 16 deletions
diff --git a/chrome/common/service_process_util_win.cc b/chrome/common/service_process_util_win.cc index f9a1816..adc5a72 100644 --- a/chrome/common/service_process_util_win.cc +++ b/chrome/common/service_process_util_win.cc @@ -8,12 +8,14 @@ #include "base/file_util.h" #include "base/logging.h" #include "base/path_service.h" +#include "base/scoped_ptr.h" #include "base/string16.h" #include "base/task.h" #include "base/utf_string_conversions.h" #include "base/win/object_watcher.h" #include "base/win/scoped_handle.h" #include "base/win/win_util.h" +#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" namespace { @@ -28,6 +30,22 @@ string16 GetServiceProcessShutdownEventName() { GetServiceProcessScopedVersionedName("_service_shutdown_evt")); } +std::string GetServiceProcessAutoRunKey() { + return GetServiceProcessScopedName("_service_run"); +} + +// Returns the name of the autotun reg value that we used to use for older +// versions of Chrome. +std::string GetObsoleteServiceProcessAutoRunKey() { + FilePath user_data_dir; + PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); + std::string scoped_name = WideToUTF8(user_data_dir.value()); + std::replace(scoped_name.begin(), scoped_name.end(), '\\', '!'); + std::replace(scoped_name.begin(), scoped_name.end(), '/', '!'); + scoped_name.append("_service_run"); + return scoped_name; +} + class ServiceProcessShutdownMonitor : public base::win::ObjectWatcher::Delegate { public: @@ -85,8 +103,14 @@ struct ServiceProcessState::StateData { scoped_ptr<ServiceProcessShutdownMonitor> shutdown_monitor; }; -bool ServiceProcessState::TakeSingletonLock() { +bool ServiceProcessState::InitializeState() { DCHECK(!state_); + state_ = new StateData; + return true; +} + +bool ServiceProcessState::TakeSingletonLock() { + DCHECK(state_); string16 event_name = GetServiceProcessReadyEventName(); CHECK(event_name.length() <= MAX_PATH); base::win::ScopedHandle service_process_ready_event; @@ -96,7 +120,6 @@ bool ServiceProcessState::TakeSingletonLock() { if ((error == ERROR_ALREADY_EXISTS) || (error == ERROR_ACCESS_DENIED)) return false; DCHECK(service_process_ready_event.IsValid()); - state_ = new StateData; state_->ready_event.Set(service_process_ready_event.Take()); return true; } @@ -117,24 +140,24 @@ bool ServiceProcessState::SignalReady( } bool ServiceProcessState::AddToAutoRun() { - FilePath chrome_path; - if (PathService::Get(base::FILE_EXE, &chrome_path)) { - CommandLine cmd_line(chrome_path); - cmd_line.AppendSwitchASCII(switches::kProcessType, - switches::kServiceProcess); - // We need a unique name for the command per user-date-dir. Just use the - // channel name. - return base::win::AddCommandToAutoRun( - HKEY_CURRENT_USER, - UTF8ToWide(GetAutoRunKey()), - cmd_line.command_line_string()); - } - return false; + DCHECK(autorun_command_line_.get()); + // Remove the old autorun value first because we changed the naming scheme + // for the autorun value name. + base::win::RemoveCommandFromAutoRun( + HKEY_CURRENT_USER, UTF8ToWide(GetObsoleteServiceProcessAutoRunKey())); + return base::win::AddCommandToAutoRun( + HKEY_CURRENT_USER, + UTF8ToWide(GetServiceProcessAutoRunKey()), + autorun_command_line_->command_line_string()); } bool ServiceProcessState::RemoveFromAutoRun() { + // Remove the old autorun value first because we changed the naming scheme + // for the autorun value name. + base::win::RemoveCommandFromAutoRun( + HKEY_CURRENT_USER, UTF8ToWide(GetObsoleteServiceProcessAutoRunKey())); return base::win::RemoveCommandFromAutoRun( - HKEY_CURRENT_USER, UTF8ToWide(GetAutoRunKey())); + HKEY_CURRENT_USER, UTF8ToWide(GetServiceProcessAutoRunKey())); } void ServiceProcessState::TearDownState() { |