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" |
(...skipping 29 matching lines...) Expand all Loading... |
40 #endif | 40 #endif |
41 | 41 |
42 ServiceProcess* g_service_process = NULL; | 42 ServiceProcess* g_service_process = NULL; |
43 | 43 |
44 namespace { | 44 namespace { |
45 | 45 |
46 // Delay in seconds after the last service is disabled before we attempt | 46 // Delay in seconds after the last service is disabled before we attempt |
47 // a shutdown. | 47 // a shutdown. |
48 const int kShutdownDelaySeconds = 60; | 48 const int kShutdownDelaySeconds = 60; |
49 | 49 |
50 // Delay in hours between launching a browser process to check the | |
51 // policy for us. | |
52 const int64 kPolicyCheckDelayHours = 8; | |
53 | |
54 const char kDefaultServiceProcessLocale[] = "en-US"; | 50 const char kDefaultServiceProcessLocale[] = "en-US"; |
55 | 51 |
56 class ServiceIOThread : public base::Thread { | 52 class ServiceIOThread : public base::Thread { |
57 public: | 53 public: |
58 explicit ServiceIOThread(const char* name); | 54 explicit ServiceIOThread(const char* name); |
59 ~ServiceIOThread() override; | 55 ~ServiceIOThread() override; |
60 | 56 |
61 protected: | 57 protected: |
62 void CleanUp() override; | 58 void CleanUp() override; |
63 | 59 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 // ready. | 194 // ready. |
199 if (!service_process_state_->SignalReady( | 195 if (!service_process_state_->SignalReady( |
200 io_thread_->message_loop_proxy().get(), | 196 io_thread_->message_loop_proxy().get(), |
201 base::Bind(&ServiceProcess::Terminate, base::Unretained(this)))) { | 197 base::Bind(&ServiceProcess::Terminate, base::Unretained(this)))) { |
202 return false; | 198 return false; |
203 } | 199 } |
204 | 200 |
205 // See if we need to stay running. | 201 // See if we need to stay running. |
206 ScheduleShutdownCheck(); | 202 ScheduleShutdownCheck(); |
207 | 203 |
208 // Occasionally check to see if we need to launch the browser to get the | |
209 // policy state information. | |
210 CloudPrintPolicyCheckIfNeeded(); | |
211 return true; | 204 return true; |
212 } | 205 } |
213 | 206 |
214 bool ServiceProcess::Teardown() { | 207 bool ServiceProcess::Teardown() { |
215 service_prefs_.reset(); | 208 service_prefs_.reset(); |
216 cloud_print_proxy_.reset(); | 209 cloud_print_proxy_.reset(); |
217 | 210 |
218 ipc_server_.reset(); | 211 ipc_server_.reset(); |
219 // Signal this event before shutting down the service process. That way all | 212 // Signal this event before shutting down the service process. That way all |
220 // background threads can cleanup. | 213 // background threads can cleanup. |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 // Note that there is still a timing window here because a client may | 338 // Note that there is still a timing window here because a client may |
346 // decide to connect at this point. | 339 // decide to connect at this point. |
347 // TODO(sanjeevr): Fix this timing window. | 340 // TODO(sanjeevr): Fix this timing window. |
348 ScheduleShutdownCheck(); | 341 ScheduleShutdownCheck(); |
349 } else { | 342 } else { |
350 Shutdown(); | 343 Shutdown(); |
351 } | 344 } |
352 } | 345 } |
353 } | 346 } |
354 | 347 |
355 void ServiceProcess::ScheduleCloudPrintPolicyCheck() { | |
356 base::MessageLoop::current()->PostDelayedTask( | |
357 FROM_HERE, | |
358 base::Bind(&ServiceProcess::CloudPrintPolicyCheckIfNeeded, | |
359 base::Unretained(this)), | |
360 base::TimeDelta::FromHours(kPolicyCheckDelayHours)); | |
361 } | |
362 | |
363 void ServiceProcess::CloudPrintPolicyCheckIfNeeded() { | |
364 if (enabled_services_ && !ipc_server_->is_client_connected()) { | |
365 GetCloudPrintProxy()->CheckCloudPrintProxyPolicy(); | |
366 } | |
367 ScheduleCloudPrintPolicyCheck(); | |
368 } | |
369 | |
370 ServiceProcess::~ServiceProcess() { | 348 ServiceProcess::~ServiceProcess() { |
371 Teardown(); | 349 Teardown(); |
372 g_service_process = NULL; | 350 g_service_process = NULL; |
373 } | 351 } |
OLD | NEW |