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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 std::string scoped_name = WideToUTF8(user_data_dir.value()); | 44 std::string scoped_name = 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(Task* terminate_task) | 54 explicit ServiceProcessTerminateMonitor(const base::Closure& terminate_task) |
55 : terminate_task_(terminate_task) { | 55 : terminate_task_(terminate_task) { |
56 } | 56 } |
57 void Start() { | 57 void Start() { |
58 string16 event_name = GetServiceProcessTerminateEventName(); | 58 string16 event_name = GetServiceProcessTerminateEventName(); |
59 DCHECK(event_name.length() <= MAX_PATH); | 59 DCHECK(event_name.length() <= MAX_PATH); |
60 terminate_event_.Set(CreateEvent(NULL, TRUE, FALSE, event_name.c_str())); | 60 terminate_event_.Set(CreateEvent(NULL, TRUE, FALSE, event_name.c_str())); |
61 watcher_.StartWatching(terminate_event_.Get(), this); | 61 watcher_.StartWatching(terminate_event_.Get(), this); |
62 } | 62 } |
63 | 63 |
64 // base::ObjectWatcher::Delegate implementation. | 64 // base::ObjectWatcher::Delegate implementation. |
65 virtual void OnObjectSignaled(HANDLE object) { | 65 virtual void OnObjectSignaled(HANDLE object) { |
66 terminate_task_->Run(); | 66 if (!terminate_task_.is_null()) { |
67 terminate_task_.reset(); | 67 terminate_task_.Run(); |
| 68 terminate_task_.Reset(); |
| 69 } |
68 } | 70 } |
69 | 71 |
70 private: | 72 private: |
71 base::win::ScopedHandle terminate_event_; | 73 base::win::ScopedHandle terminate_event_; |
72 base::win::ObjectWatcher watcher_; | 74 base::win::ObjectWatcher watcher_; |
73 scoped_ptr<Task> terminate_task_; | 75 base::Closure terminate_task_; |
74 }; | 76 }; |
75 | 77 |
76 } // namespace | 78 } // namespace |
77 | 79 |
78 // Gets the name of the service process IPC channel. | 80 // Gets the name of the service process IPC channel. |
79 IPC::ChannelHandle GetServiceProcessChannel() { | 81 IPC::ChannelHandle GetServiceProcessChannel() { |
80 return GetServiceProcessScopedVersionedName("_service_ipc"); | 82 return GetServiceProcessScopedVersionedName("_service_ipc"); |
81 } | 83 } |
82 | 84 |
83 bool ForceServiceProcessShutdown(const std::string& version, | 85 bool ForceServiceProcessShutdown(const std::string& version, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 CreateEvent(NULL, TRUE, FALSE, event_name.c_str())); | 126 CreateEvent(NULL, TRUE, FALSE, event_name.c_str())); |
125 DWORD error = GetLastError(); | 127 DWORD error = GetLastError(); |
126 if ((error == ERROR_ALREADY_EXISTS) || (error == ERROR_ACCESS_DENIED)) | 128 if ((error == ERROR_ALREADY_EXISTS) || (error == ERROR_ACCESS_DENIED)) |
127 return false; | 129 return false; |
128 DCHECK(service_process_ready_event.IsValid()); | 130 DCHECK(service_process_ready_event.IsValid()); |
129 state_->ready_event.Set(service_process_ready_event.Take()); | 131 state_->ready_event.Set(service_process_ready_event.Take()); |
130 return true; | 132 return true; |
131 } | 133 } |
132 | 134 |
133 bool ServiceProcessState::SignalReady( | 135 bool ServiceProcessState::SignalReady( |
134 base::MessageLoopProxy* message_loop_proxy, Task* terminate_task) { | 136 base::MessageLoopProxy* message_loop_proxy, |
| 137 const base::Closure& terminate_task) { |
135 DCHECK(state_); | 138 DCHECK(state_); |
136 DCHECK(state_->ready_event.IsValid()); | 139 DCHECK(state_->ready_event.IsValid()); |
137 scoped_ptr<Task> scoped_terminate_task(terminate_task); | |
138 if (!SetEvent(state_->ready_event.Get())) { | 140 if (!SetEvent(state_->ready_event.Get())) { |
139 return false; | 141 return false; |
140 } | 142 } |
141 if (terminate_task) { | 143 if (!terminate_task.is_null()) { |
142 state_->terminate_monitor.reset( | 144 state_->terminate_monitor.reset( |
143 new ServiceProcessTerminateMonitor(scoped_terminate_task.release())); | 145 new ServiceProcessTerminateMonitor(terminate_task)); |
144 state_->terminate_monitor->Start(); | 146 state_->terminate_monitor->Start(); |
145 } | 147 } |
146 return true; | 148 return true; |
147 } | 149 } |
148 | 150 |
149 bool ServiceProcessState::AddToAutoRun() { | 151 bool ServiceProcessState::AddToAutoRun() { |
150 DCHECK(autorun_command_line_.get()); | 152 DCHECK(autorun_command_line_.get()); |
151 // 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 |
152 // for the autorun value name. | 154 // for the autorun value name. |
153 base::win::RemoveCommandFromAutoRun( | 155 base::win::RemoveCommandFromAutoRun( |
(...skipping 10 matching lines...) Expand all Loading... |
164 base::win::RemoveCommandFromAutoRun( | 166 base::win::RemoveCommandFromAutoRun( |
165 HKEY_CURRENT_USER, UTF8ToWide(GetObsoleteServiceProcessAutoRunKey())); | 167 HKEY_CURRENT_USER, UTF8ToWide(GetObsoleteServiceProcessAutoRunKey())); |
166 return base::win::RemoveCommandFromAutoRun( | 168 return base::win::RemoveCommandFromAutoRun( |
167 HKEY_CURRENT_USER, UTF8ToWide(GetServiceProcessAutoRunKey())); | 169 HKEY_CURRENT_USER, UTF8ToWide(GetServiceProcessAutoRunKey())); |
168 } | 170 } |
169 | 171 |
170 void ServiceProcessState::TearDownState() { | 172 void ServiceProcessState::TearDownState() { |
171 delete state_; | 173 delete state_; |
172 state_ = NULL; | 174 state_ = NULL; |
173 } | 175 } |
OLD | NEW |