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/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/callback.h" |
10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
11 #include "base/environment.h" | 12 #include "base/environment.h" |
12 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
13 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
14 #include "base/path_service.h" | 15 #include "base/path_service.h" |
15 #include "base/string16.h" | 16 #include "base/string16.h" |
16 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "chrome/common/chrome_constants.h" | 19 #include "chrome/common/chrome_constants.h" |
19 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 204 |
204 VLOG(1) << "Starting Service Process IPC Server"; | 205 VLOG(1) << "Starting Service Process IPC Server"; |
205 ipc_server_.reset(new ServiceIPCServer( | 206 ipc_server_.reset(new ServiceIPCServer( |
206 service_process_state_->GetServiceProcessChannel())); | 207 service_process_state_->GetServiceProcessChannel())); |
207 ipc_server_->Init(); | 208 ipc_server_->Init(); |
208 | 209 |
209 // After the IPC server has started we signal that the service process is | 210 // After the IPC server has started we signal that the service process is |
210 // ready. | 211 // ready. |
211 if (!service_process_state_->SignalReady( | 212 if (!service_process_state_->SignalReady( |
212 io_thread_->message_loop_proxy(), | 213 io_thread_->message_loop_proxy(), |
213 NewRunnableMethod(this, &ServiceProcess::Terminate))) { | 214 base::Bind(&ServiceProcess::Terminate, base::Unretained(this)))) { |
214 return false; | 215 return false; |
215 } | 216 } |
216 | 217 |
217 // See if we need to stay running. | 218 // See if we need to stay running. |
218 ScheduleShutdownCheck(); | 219 ScheduleShutdownCheck(); |
219 return true; | 220 return true; |
220 } | 221 } |
221 | 222 |
222 bool ServiceProcess::Teardown() { | 223 bool ServiceProcess::Teardown() { |
223 service_prefs_.reset(); | 224 service_prefs_.reset(); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 LOG(ERROR) << "Unable to RemoveFromAutoRun"; | 339 LOG(ERROR) << "Unable to RemoveFromAutoRun"; |
339 } | 340 } |
340 // We will wait for some time to respond to IPCs before shutting down. | 341 // We will wait for some time to respond to IPCs before shutting down. |
341 ScheduleShutdownCheck(); | 342 ScheduleShutdownCheck(); |
342 } | 343 } |
343 } | 344 } |
344 | 345 |
345 void ServiceProcess::ScheduleShutdownCheck() { | 346 void ServiceProcess::ScheduleShutdownCheck() { |
346 MessageLoop::current()->PostDelayedTask( | 347 MessageLoop::current()->PostDelayedTask( |
347 FROM_HERE, | 348 FROM_HERE, |
348 NewRunnableMethod(this, &ServiceProcess::ShutdownIfNeeded), | 349 base::Bind(&ServiceProcess::ShutdownIfNeeded, base::Unretained(this)), |
349 kShutdownDelay); | 350 kShutdownDelay); |
350 } | 351 } |
351 | 352 |
352 void ServiceProcess::ShutdownIfNeeded() { | 353 void ServiceProcess::ShutdownIfNeeded() { |
353 if (0 == enabled_services_) { | 354 if (0 == enabled_services_) { |
354 if (ipc_server_->is_client_connected()) { | 355 if (ipc_server_->is_client_connected()) { |
355 // If there is a client connected, we need to try again later. | 356 // If there is a client connected, we need to try again later. |
356 // Note that there is still a timing window here because a client may | 357 // Note that there is still a timing window here because a client may |
357 // decide to connect at this point. | 358 // decide to connect at this point. |
358 // TODO(sanjeevr): Fix this timing window. | 359 // TODO(sanjeevr): Fix this timing window. |
359 ScheduleShutdownCheck(); | 360 ScheduleShutdownCheck(); |
360 } else { | 361 } else { |
361 Shutdown(); | 362 Shutdown(); |
362 } | 363 } |
363 } | 364 } |
364 } | 365 } |
365 | 366 |
366 ServiceProcess::~ServiceProcess() { | 367 ServiceProcess::~ServiceProcess() { |
367 Teardown(); | 368 Teardown(); |
368 g_service_process = NULL; | 369 g_service_process = NULL; |
369 } | 370 } |
OLD | NEW |