| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/common/service_process_util.h" | 5 #include "chrome/common/service_process_util.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/win/object_watcher.h" | 15 #include "base/win/object_watcher.h" |
| 16 #include "base/win/scoped_handle.h" | 16 #include "base/win/scoped_handle.h" |
| 17 #include "base/win/win_util.h" | 17 #include "base/win/win_util.h" |
| 18 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
| 19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 const char* kTerminateEventSuffix = "_service_terminate_evt"; | 23 const char* kTerminateEventSuffix = "_service_terminate_evt"; |
| 24 | 24 |
| 25 base::string16 GetServiceProcessReadyEventName() { | 25 base::string16 GetServiceProcessReadyEventName() { |
| 26 return UTF8ToWide( | 26 return base::UTF8ToWide( |
| 27 GetServiceProcessScopedVersionedName("_service_ready")); | 27 GetServiceProcessScopedVersionedName("_service_ready")); |
| 28 } | 28 } |
| 29 | 29 |
| 30 base::string16 GetServiceProcessTerminateEventName() { | 30 base::string16 GetServiceProcessTerminateEventName() { |
| 31 return UTF8ToWide( | 31 return base::UTF8ToWide( |
| 32 GetServiceProcessScopedVersionedName(kTerminateEventSuffix)); | 32 GetServiceProcessScopedVersionedName(kTerminateEventSuffix)); |
| 33 } | 33 } |
| 34 | 34 |
| 35 std::string GetServiceProcessAutoRunKey() { | 35 std::string GetServiceProcessAutoRunKey() { |
| 36 return GetServiceProcessScopedName("_service_run"); | 36 return GetServiceProcessScopedName("_service_run"); |
| 37 } | 37 } |
| 38 | 38 |
| 39 // Returns the name of the autotun reg value that we used to use for older | 39 // Returns the name of the autotun reg value that we used to use for older |
| 40 // versions of Chrome. | 40 // versions of Chrome. |
| 41 std::string GetObsoleteServiceProcessAutoRunKey() { | 41 std::string GetObsoleteServiceProcessAutoRunKey() { |
| 42 base::FilePath user_data_dir; | 42 base::FilePath user_data_dir; |
| 43 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 43 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 44 std::string scoped_name = WideToUTF8(user_data_dir.value()); | 44 std::string scoped_name = base::WideToUTF8(user_data_dir.value()); |
| 45 std::replace(scoped_name.begin(), scoped_name.end(), '\\', '!'); | 45 std::replace(scoped_name.begin(), scoped_name.end(), '\\', '!'); |
| 46 std::replace(scoped_name.begin(), scoped_name.end(), '/', '!'); | 46 std::replace(scoped_name.begin(), scoped_name.end(), '/', '!'); |
| 47 scoped_name.append("_service_run"); | 47 scoped_name.append("_service_run"); |
| 48 return scoped_name; | 48 return scoped_name; |
| 49 } | 49 } |
| 50 | 50 |
| 51 class ServiceProcessTerminateMonitor | 51 class ServiceProcessTerminateMonitor |
| 52 : public base::win::ObjectWatcher::Delegate { | 52 : public base::win::ObjectWatcher::Delegate { |
| 53 public: | 53 public: |
| 54 explicit ServiceProcessTerminateMonitor(const base::Closure& terminate_task) | 54 explicit ServiceProcessTerminateMonitor(const base::Closure& terminate_task) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 81 IPC::ChannelHandle GetServiceProcessChannel() { | 81 IPC::ChannelHandle GetServiceProcessChannel() { |
| 82 return GetServiceProcessScopedVersionedName("_service_ipc"); | 82 return GetServiceProcessScopedVersionedName("_service_ipc"); |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool ForceServiceProcessShutdown(const std::string& version, | 85 bool ForceServiceProcessShutdown(const std::string& version, |
| 86 base::ProcessId process_id) { | 86 base::ProcessId process_id) { |
| 87 base::win::ScopedHandle terminate_event; | 87 base::win::ScopedHandle terminate_event; |
| 88 std::string versioned_name = version; | 88 std::string versioned_name = version; |
| 89 versioned_name.append(kTerminateEventSuffix); | 89 versioned_name.append(kTerminateEventSuffix); |
| 90 base::string16 event_name = | 90 base::string16 event_name = |
| 91 UTF8ToWide(GetServiceProcessScopedName(versioned_name)); | 91 base::UTF8ToWide(GetServiceProcessScopedName(versioned_name)); |
| 92 terminate_event.Set(OpenEvent(EVENT_MODIFY_STATE, FALSE, event_name.c_str())); | 92 terminate_event.Set(OpenEvent(EVENT_MODIFY_STATE, FALSE, event_name.c_str())); |
| 93 if (!terminate_event.IsValid()) | 93 if (!terminate_event.IsValid()) |
| 94 return false; | 94 return false; |
| 95 SetEvent(terminate_event.Get()); | 95 SetEvent(terminate_event.Get()); |
| 96 return true; | 96 return true; |
| 97 } | 97 } |
| 98 | 98 |
| 99 bool CheckServiceProcessReady() { | 99 bool CheckServiceProcessReady() { |
| 100 base::string16 event_name = GetServiceProcessReadyEventName(); | 100 base::string16 event_name = GetServiceProcessReadyEventName(); |
| 101 base::win::ScopedHandle event( | 101 base::win::ScopedHandle event( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 state_->terminate_monitor->Start(); | 146 state_->terminate_monitor->Start(); |
| 147 } | 147 } |
| 148 return true; | 148 return true; |
| 149 } | 149 } |
| 150 | 150 |
| 151 bool ServiceProcessState::AddToAutoRun() { | 151 bool ServiceProcessState::AddToAutoRun() { |
| 152 DCHECK(autorun_command_line_.get()); | 152 DCHECK(autorun_command_line_.get()); |
| 153 // Remove the old autorun value first because we changed the naming scheme | 153 // Remove the old autorun value first because we changed the naming scheme |
| 154 // for the autorun value name. | 154 // for the autorun value name. |
| 155 base::win::RemoveCommandFromAutoRun( | 155 base::win::RemoveCommandFromAutoRun( |
| 156 HKEY_CURRENT_USER, UTF8ToWide(GetObsoleteServiceProcessAutoRunKey())); | 156 HKEY_CURRENT_USER, |
| 157 base::UTF8ToWide(GetObsoleteServiceProcessAutoRunKey())); |
| 157 return base::win::AddCommandToAutoRun( | 158 return base::win::AddCommandToAutoRun( |
| 158 HKEY_CURRENT_USER, | 159 HKEY_CURRENT_USER, |
| 159 UTF8ToWide(GetServiceProcessAutoRunKey()), | 160 base::UTF8ToWide(GetServiceProcessAutoRunKey()), |
| 160 autorun_command_line_->GetCommandLineString()); | 161 autorun_command_line_->GetCommandLineString()); |
| 161 } | 162 } |
| 162 | 163 |
| 163 bool ServiceProcessState::RemoveFromAutoRun() { | 164 bool ServiceProcessState::RemoveFromAutoRun() { |
| 164 // Remove the old autorun value first because we changed the naming scheme | 165 // Remove the old autorun value first because we changed the naming scheme |
| 165 // for the autorun value name. | 166 // for the autorun value name. |
| 166 base::win::RemoveCommandFromAutoRun( | 167 base::win::RemoveCommandFromAutoRun( |
| 167 HKEY_CURRENT_USER, UTF8ToWide(GetObsoleteServiceProcessAutoRunKey())); | 168 HKEY_CURRENT_USER, |
| 169 base::UTF8ToWide(GetObsoleteServiceProcessAutoRunKey())); |
| 168 return base::win::RemoveCommandFromAutoRun( | 170 return base::win::RemoveCommandFromAutoRun( |
| 169 HKEY_CURRENT_USER, UTF8ToWide(GetServiceProcessAutoRunKey())); | 171 HKEY_CURRENT_USER, base::UTF8ToWide(GetServiceProcessAutoRunKey())); |
| 170 } | 172 } |
| 171 | 173 |
| 172 void ServiceProcessState::TearDownState() { | 174 void ServiceProcessState::TearDownState() { |
| 173 delete state_; | 175 delete state_; |
| 174 state_ = NULL; | 176 state_ = NULL; |
| 175 } | 177 } |
| OLD | NEW |