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 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/environment.h" | 12 #include "base/environment.h" |
13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
| 14 #include "base/location.h" |
14 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
15 #include "base/path_service.h" | 16 #include "base/path_service.h" |
16 #include "base/prefs/json_pref_store.h" | 17 #include "base/prefs/json_pref_store.h" |
| 18 #include "base/single_thread_task_runner.h" |
17 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
18 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/thread_task_runner_handle.h" |
19 #include "base/values.h" | 22 #include "base/values.h" |
20 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
21 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
22 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
23 #include "chrome/common/env_vars.h" | 26 #include "chrome/common/env_vars.h" |
24 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
25 #include "chrome/common/service_process_util.h" | 28 #include "chrome/common/service_process_util.h" |
26 #include "chrome/grit/chromium_strings.h" | 29 #include "chrome/grit/chromium_strings.h" |
27 #include "chrome/grit/generated_resources.h" | 30 #include "chrome/grit/generated_resources.h" |
28 #include "chrome/service/cloud_print/cloud_print_proxy.h" | 31 #include "chrome/service/cloud_print/cloud_print_proxy.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 189 } |
187 | 190 |
188 VLOG(1) << "Starting Service Process IPC Server"; | 191 VLOG(1) << "Starting Service Process IPC Server"; |
189 ipc_server_.reset(new ServiceIPCServer( | 192 ipc_server_.reset(new ServiceIPCServer( |
190 service_process_state_->GetServiceProcessChannel())); | 193 service_process_state_->GetServiceProcessChannel())); |
191 ipc_server_->Init(); | 194 ipc_server_->Init(); |
192 | 195 |
193 // After the IPC server has started we signal that the service process is | 196 // After the IPC server has started we signal that the service process is |
194 // ready. | 197 // ready. |
195 if (!service_process_state_->SignalReady( | 198 if (!service_process_state_->SignalReady( |
196 io_thread_->message_loop_proxy().get(), | 199 io_thread_->task_runner().get(), |
197 base::Bind(&ServiceProcess::Terminate, base::Unretained(this)))) { | 200 base::Bind(&ServiceProcess::Terminate, base::Unretained(this)))) { |
198 return false; | 201 return false; |
199 } | 202 } |
200 | 203 |
201 // See if we need to stay running. | 204 // See if we need to stay running. |
202 ScheduleShutdownCheck(); | 205 ScheduleShutdownCheck(); |
203 | 206 |
204 return true; | 207 return true; |
205 } | 208 } |
206 | 209 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 // terminate. | 249 // terminate. |
247 if (!ForceServiceProcessShutdown("", 0)) { | 250 if (!ForceServiceProcessShutdown("", 0)) { |
248 Terminate(); | 251 Terminate(); |
249 } | 252 } |
250 #else | 253 #else |
251 Terminate(); | 254 Terminate(); |
252 #endif | 255 #endif |
253 } | 256 } |
254 | 257 |
255 void ServiceProcess::Terminate() { | 258 void ServiceProcess::Terminate() { |
256 main_message_loop_->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); | 259 main_message_loop_->task_runner()->PostTask(FROM_HERE, |
| 260 base::MessageLoop::QuitClosure()); |
257 } | 261 } |
258 | 262 |
259 bool ServiceProcess::HandleClientDisconnect() { | 263 bool ServiceProcess::HandleClientDisconnect() { |
260 // If there are no enabled services or if there is an update available | 264 // If there are no enabled services or if there is an update available |
261 // we want to shutdown right away. Else we want to keep listening for | 265 // we want to shutdown right away. Else we want to keep listening for |
262 // new connections. | 266 // new connections. |
263 if (!enabled_services_ || update_available()) { | 267 if (!enabled_services_ || update_available()) { |
264 Shutdown(); | 268 Shutdown(); |
265 return false; | 269 return false; |
266 } | 270 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 if (!service_process_state_->RemoveFromAutoRun()) { | 322 if (!service_process_state_->RemoveFromAutoRun()) { |
319 // TODO(scottbyer/sanjeevr/dmaclach): Handle error condition | 323 // TODO(scottbyer/sanjeevr/dmaclach): Handle error condition |
320 LOG(ERROR) << "Unable to RemoveFromAutoRun"; | 324 LOG(ERROR) << "Unable to RemoveFromAutoRun"; |
321 } | 325 } |
322 // We will wait for some time to respond to IPCs before shutting down. | 326 // We will wait for some time to respond to IPCs before shutting down. |
323 ScheduleShutdownCheck(); | 327 ScheduleShutdownCheck(); |
324 } | 328 } |
325 } | 329 } |
326 | 330 |
327 void ServiceProcess::ScheduleShutdownCheck() { | 331 void ServiceProcess::ScheduleShutdownCheck() { |
328 base::MessageLoop::current()->PostDelayedTask( | 332 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
329 FROM_HERE, | 333 FROM_HERE, |
330 base::Bind(&ServiceProcess::ShutdownIfNeeded, base::Unretained(this)), | 334 base::Bind(&ServiceProcess::ShutdownIfNeeded, base::Unretained(this)), |
331 base::TimeDelta::FromSeconds(kShutdownDelaySeconds)); | 335 base::TimeDelta::FromSeconds(kShutdownDelaySeconds)); |
332 } | 336 } |
333 | 337 |
334 void ServiceProcess::ShutdownIfNeeded() { | 338 void ServiceProcess::ShutdownIfNeeded() { |
335 if (0 == enabled_services_) { | 339 if (0 == enabled_services_) { |
336 if (ipc_server_->is_client_connected()) { | 340 if (ipc_server_->is_client_connected()) { |
337 // If there is a client connected, we need to try again later. | 341 // If there is a client connected, we need to try again later. |
338 // Note that there is still a timing window here because a client may | 342 // Note that there is still a timing window here because a client may |
339 // decide to connect at this point. | 343 // decide to connect at this point. |
340 // TODO(sanjeevr): Fix this timing window. | 344 // TODO(sanjeevr): Fix this timing window. |
341 ScheduleShutdownCheck(); | 345 ScheduleShutdownCheck(); |
342 } else { | 346 } else { |
343 Shutdown(); | 347 Shutdown(); |
344 } | 348 } |
345 } | 349 } |
346 } | 350 } |
347 | 351 |
348 ServiceProcess::~ServiceProcess() { | 352 ServiceProcess::~ServiceProcess() { |
349 Teardown(); | 353 Teardown(); |
350 g_service_process = NULL; | 354 g_service_process = NULL; |
351 } | 355 } |
OLD | NEW |