OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/base_switches.h" | 10 #include "base/base_switches.h" |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 230 |
231 return true; | 231 return true; |
232 } | 232 } |
233 | 233 |
234 bool ServiceProcess::Teardown() { | 234 bool ServiceProcess::Teardown() { |
235 service_prefs_.reset(); | 235 service_prefs_.reset(); |
236 cloud_print_proxy_.reset(); | 236 cloud_print_proxy_.reset(); |
237 | 237 |
238 mojo_ipc_support_.reset(); | 238 mojo_ipc_support_.reset(); |
239 ipc_server_.reset(); | 239 ipc_server_.reset(); |
240 | |
241 // On POSIX, this must be called before joining |io_thread_| because it posts | |
242 // a DeleteSoon() task to that thread. | |
243 service_process_state_->SignalStopped(); | |
244 | |
245 // Signal this event before shutting down the service process. That way all | 240 // Signal this event before shutting down the service process. That way all |
246 // background threads can cleanup. | 241 // background threads can cleanup. |
247 shutdown_event_.Signal(); | 242 shutdown_event_.Signal(); |
248 io_thread_.reset(); | 243 io_thread_.reset(); |
249 file_thread_.reset(); | 244 file_thread_.reset(); |
250 | 245 |
251 if (blocking_pool_.get()) { | 246 if (blocking_pool_.get()) { |
252 // The goal is to make it impossible for chrome to 'infinite loop' during | 247 // The goal is to make it impossible for chrome to 'infinite loop' during |
253 // shutdown, but to reasonably expect that all BLOCKING_SHUTDOWN tasks | 248 // shutdown, but to reasonably expect that all BLOCKING_SHUTDOWN tasks |
254 // queued during shutdown get run. There's nothing particularly scientific | 249 // queued during shutdown get run. There's nothing particularly scientific |
255 // about the number chosen. | 250 // about the number chosen. |
256 const int kMaxNewShutdownBlockingTasks = 1000; | 251 const int kMaxNewShutdownBlockingTasks = 1000; |
257 blocking_pool_->Shutdown(kMaxNewShutdownBlockingTasks); | 252 blocking_pool_->Shutdown(kMaxNewShutdownBlockingTasks); |
258 blocking_pool_ = NULL; | 253 blocking_pool_ = NULL; |
259 } | 254 } |
260 | 255 |
261 // The NetworkChangeNotifier must be destroyed after all other threads that | 256 // The NetworkChangeNotifier must be destroyed after all other threads that |
262 // might use it have been shut down. | 257 // might use it have been shut down. |
263 network_change_notifier_.reset(); | 258 network_change_notifier_.reset(); |
264 | 259 |
| 260 service_process_state_->SignalStopped(); |
265 return true; | 261 return true; |
266 } | 262 } |
267 | 263 |
268 // This method is called when a shutdown command is received from IPC channel | 264 // This method is called when a shutdown command is received from IPC channel |
269 // or there was an error in the IPC channel. | 265 // or there was an error in the IPC channel. |
270 void ServiceProcess::Shutdown() { | 266 void ServiceProcess::Shutdown() { |
271 #if defined(OS_MACOSX) | 267 #if defined(OS_MACOSX) |
272 // On MacOS X the service must be removed from the launchd job list. | 268 // On MacOS X the service must be removed from the launchd job list. |
273 // http://www.chromium.org/developers/design-documents/service-processes | 269 // http://www.chromium.org/developers/design-documents/service-processes |
274 // The best way to do that is to go through the ForceServiceProcessShutdown | 270 // The best way to do that is to go through the ForceServiceProcessShutdown |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 } else { | 408 } else { |
413 Shutdown(); | 409 Shutdown(); |
414 } | 410 } |
415 } | 411 } |
416 } | 412 } |
417 | 413 |
418 ServiceProcess::~ServiceProcess() { | 414 ServiceProcess::~ServiceProcess() { |
419 Teardown(); | 415 Teardown(); |
420 g_service_process = NULL; | 416 g_service_process = NULL; |
421 } | 417 } |
OLD | NEW |