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

Side by Side Diff: chrome/service/service_process.cc

Issue 7736002: Make the mac service process handling code clean itself up properly as far as launchd is concerned. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add launchd test Created 9 years, 3 months 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/service/service_process.h ('k') | no next file » | 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/service/service_process.h" 5 #include "chrome/service/service_process.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 OnServiceEnabled(); 203 OnServiceEnabled();
204 } 204 }
205 205
206 VLOG(1) << "Starting Service Process IPC Server"; 206 VLOG(1) << "Starting Service Process IPC Server";
207 ipc_server_.reset(new ServiceIPCServer( 207 ipc_server_.reset(new ServiceIPCServer(
208 service_process_state_->GetServiceProcessChannel())); 208 service_process_state_->GetServiceProcessChannel()));
209 ipc_server_->Init(); 209 ipc_server_->Init();
210 210
211 // After the IPC server has started we signal that the service process is 211 // After the IPC server has started we signal that the service process is
212 // ready. 212 // ready.
213 if (!state->SignalReady(io_thread_->message_loop_proxy(), 213 if (!service_process_state_->SignalReady(
214 NewRunnableMethod(this, &ServiceProcess::Shutdown))) { 214 io_thread_->message_loop_proxy(),
215 NewRunnableMethod(this, &ServiceProcess::Terminate))) {
215 return false; 216 return false;
216 } 217 }
217 218
218 // See if we need to stay running. 219 // See if we need to stay running.
219 ScheduleShutdownCheck(); 220 ScheduleShutdownCheck();
220 return true; 221 return true;
221 } 222 }
222 223
223 bool ServiceProcess::Teardown() { 224 bool ServiceProcess::Teardown() {
224 service_prefs_.reset(); 225 service_prefs_.reset();
225 cloud_print_proxy_.reset(); 226 cloud_print_proxy_.reset();
226 227
227 ipc_server_.reset(); 228 ipc_server_.reset();
228 // Signal this event before shutting down the service process. That way all 229 // Signal this event before shutting down the service process. That way all
229 // background threads can cleanup. 230 // background threads can cleanup.
230 shutdown_event_.Signal(); 231 shutdown_event_.Signal();
231 io_thread_.reset(); 232 io_thread_.reset();
232 file_thread_.reset(); 233 file_thread_.reset();
233 // The NetworkChangeNotifier must be destroyed after all other threads that 234 // The NetworkChangeNotifier must be destroyed after all other threads that
234 // might use it have been shut down. 235 // might use it have been shut down.
235 network_change_notifier_.reset(); 236 network_change_notifier_.reset();
236 237
237 service_process_state_->SignalStopped(); 238 service_process_state_->SignalStopped();
238 return true; 239 return true;
239 } 240 }
240 241
241 // This method is called when a shutdown command is received from IPC channel 242 // This method is called when a shutdown command is received from IPC channel
242 // or there was an error in the IPC channel. 243 // or there was an error in the IPC channel.
243 void ServiceProcess::Shutdown() { 244 void ServiceProcess::Shutdown() {
244 // Quit the main message loop. 245 #if defined(OS_MACOSX)
246 // On MacOS X the service must be removed from the launchd job list.
247 // http://www.chromium.org/developers/design-documents/service-processes
248 // The best way to do that is to go through the ForceServiceProcessShutdown
249 // path. If it succeeds Terminate() will be called from the handler registered
250 // via service_process_state_->SignalReady().
251 // On failure call Terminate() directly to force the process to actually
252 // terminate.
253 if (!ForceServiceProcessShutdown("", 0)) {
254 Terminate();
255 }
256 #else
257 Terminate();
258 #endif
259 }
260
261 void ServiceProcess::Terminate() {
245 main_message_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); 262 main_message_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask());
246 } 263 }
247 264
248 bool ServiceProcess::HandleClientDisconnect() { 265 bool ServiceProcess::HandleClientDisconnect() {
249 // If there are no enabled services or if there is an update available 266 // If there are no enabled services or if there is an update available
250 // we want to shutdown right away. Else we want to keep listening for 267 // we want to shutdown right away. Else we want to keep listening for
251 // new connections. 268 // new connections.
252 if (!enabled_services_ || update_available()) { 269 if (!enabled_services_ || update_available()) {
253 Shutdown(); 270 Shutdown();
254 return false; 271 return false;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 } else { 362 } else {
346 Shutdown(); 363 Shutdown();
347 } 364 }
348 } 365 }
349 } 366 }
350 367
351 ServiceProcess::~ServiceProcess() { 368 ServiceProcess::~ServiceProcess() {
352 Teardown(); 369 Teardown();
353 g_service_process = NULL; 370 g_service_process = NULL;
354 } 371 }
OLDNEW
« no previous file with comments | « chrome/service/service_process.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698