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

Side by Side Diff: chrome/common/service_process_util_win.cc

Issue 8495039: NewRunnable* conversion to base::Bind for service process utils. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Could swear I build this on the Mac... Created 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/service_process_util_unittest.cc ('k') | chrome/service/service_process.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 }
OLDNEW
« no previous file with comments | « chrome/common/service_process_util_unittest.cc ('k') | chrome/service/service_process.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698