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