| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 if (cloud_print_proxy_enabled) { | 129 if (cloud_print_proxy_enabled) { |
| 130 GetCloudPrintProxy()->EnableForUser(lsid); | 130 GetCloudPrintProxy()->EnableForUser(lsid); |
| 131 } | 131 } |
| 132 | 132 |
| 133 VLOG(1) << "Starting Service Process IPC Server"; | 133 VLOG(1) << "Starting Service Process IPC Server"; |
| 134 ipc_server_.reset(new ServiceIPCServer(GetServiceProcessChannelName())); | 134 ipc_server_.reset(new ServiceIPCServer(GetServiceProcessChannelName())); |
| 135 ipc_server_->Init(); | 135 ipc_server_->Init(); |
| 136 | 136 |
| 137 // After the IPC server has started we signal that the service process is | 137 // After the IPC server has started we signal that the service process is |
| 138 // ready. | 138 // ready. |
| 139 Singleton<ServiceProcessState>::get()->SignalReady( | 139 ServiceProcessState::GetInstance()->SignalReady( |
| 140 NewRunnableMethod(this, &ServiceProcess::Shutdown)); | 140 NewRunnableMethod(this, &ServiceProcess::Shutdown)); |
| 141 | 141 |
| 142 // See if we need to stay running. | 142 // See if we need to stay running. |
| 143 ScheduleShutdownCheck(); | 143 ScheduleShutdownCheck(); |
| 144 return true; | 144 return true; |
| 145 } | 145 } |
| 146 | 146 |
| 147 bool ServiceProcess::Teardown() { | 147 bool ServiceProcess::Teardown() { |
| 148 service_prefs_.reset(); | 148 service_prefs_.reset(); |
| 149 cloud_print_proxy_.reset(); | 149 cloud_print_proxy_.reset(); |
| 150 | 150 |
| 151 #if defined(ENABLE_REMOTING) | 151 #if defined(ENABLE_REMOTING) |
| 152 ShutdownChromotingHost(); | 152 ShutdownChromotingHost(); |
| 153 #endif | 153 #endif |
| 154 | 154 |
| 155 ipc_server_.reset(); | 155 ipc_server_.reset(); |
| 156 // Signal this event before shutting down the service process. That way all | 156 // Signal this event before shutting down the service process. That way all |
| 157 // background threads can cleanup. | 157 // background threads can cleanup. |
| 158 shutdown_event_.Signal(); | 158 shutdown_event_.Signal(); |
| 159 io_thread_.reset(); | 159 io_thread_.reset(); |
| 160 file_thread_.reset(); | 160 file_thread_.reset(); |
| 161 // The NetworkChangeNotifier must be destroyed after all other threads that | 161 // The NetworkChangeNotifier must be destroyed after all other threads that |
| 162 // might use it have been shut down. | 162 // might use it have been shut down. |
| 163 network_change_notifier_.reset(); | 163 network_change_notifier_.reset(); |
| 164 | 164 |
| 165 Singleton<ServiceProcessState>::get()->SignalStopped(); | 165 ServiceProcessState::GetInstance()->SignalStopped(); |
| 166 return true; | 166 return true; |
| 167 } | 167 } |
| 168 | 168 |
| 169 void ServiceProcess::Shutdown() { | 169 void ServiceProcess::Shutdown() { |
| 170 // Quit the main message loop. | 170 // Quit the main message loop. |
| 171 main_message_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 171 main_message_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 172 } | 172 } |
| 173 | 173 |
| 174 bool ServiceProcess::HandleClientDisconnect() { | 174 bool ServiceProcess::HandleClientDisconnect() { |
| 175 // If there are no enabled services or if there is an update available | 175 // If there are no enabled services or if there is an update available |
| (...skipping 24 matching lines...) Expand all Loading... |
| 200 void ServiceProcess::OnCloudPrintProxyDisabled() { | 200 void ServiceProcess::OnCloudPrintProxyDisabled() { |
| 201 // Save the preference that we have disabled the cloud print proxy. | 201 // Save the preference that we have disabled the cloud print proxy. |
| 202 service_prefs_->prefs()->SetBoolean(prefs::kCloudPrintProxyEnabled, false); | 202 service_prefs_->prefs()->SetBoolean(prefs::kCloudPrintProxyEnabled, false); |
| 203 service_prefs_->WritePrefs(); | 203 service_prefs_->WritePrefs(); |
| 204 OnServiceDisabled(); | 204 OnServiceDisabled(); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void ServiceProcess::OnServiceEnabled() { | 207 void ServiceProcess::OnServiceEnabled() { |
| 208 enabled_services_++; | 208 enabled_services_++; |
| 209 if (1 == enabled_services_) { | 209 if (1 == enabled_services_) { |
| 210 Singleton<ServiceProcessState>::get()->AddToAutoRun(); | 210 ServiceProcessState::GetInstance()->AddToAutoRun(); |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 | 213 |
| 214 void ServiceProcess::OnServiceDisabled() { | 214 void ServiceProcess::OnServiceDisabled() { |
| 215 DCHECK_NE(enabled_services_, 0); | 215 DCHECK_NE(enabled_services_, 0); |
| 216 enabled_services_--; | 216 enabled_services_--; |
| 217 if (0 == enabled_services_) { | 217 if (0 == enabled_services_) { |
| 218 Singleton<ServiceProcessState>::get()->RemoveFromAutoRun(); | 218 ServiceProcessState::GetInstance()->RemoveFromAutoRun(); |
| 219 // We will wait for some time to respond to IPCs before shutting down. | 219 // We will wait for some time to respond to IPCs before shutting down. |
| 220 ScheduleShutdownCheck(); | 220 ScheduleShutdownCheck(); |
| 221 } | 221 } |
| 222 } | 222 } |
| 223 | 223 |
| 224 void ServiceProcess::ScheduleShutdownCheck() { | 224 void ServiceProcess::ScheduleShutdownCheck() { |
| 225 MessageLoop::current()->PostDelayedTask( | 225 MessageLoop::current()->PostDelayedTask( |
| 226 FROM_HERE, | 226 FROM_HERE, |
| 227 NewRunnableMethod(this, &ServiceProcess::ShutdownIfNeeded), | 227 NewRunnableMethod(this, &ServiceProcess::ShutdownIfNeeded), |
| 228 kShutdownDelay); | 228 kShutdownDelay); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 #endif | 388 #endif |
| 389 | 389 |
| 390 ServiceProcess::~ServiceProcess() { | 390 ServiceProcess::~ServiceProcess() { |
| 391 Teardown(); | 391 Teardown(); |
| 392 g_service_process = NULL; | 392 g_service_process = NULL; |
| 393 } | 393 } |
| 394 | 394 |
| 395 // Disable refcounting for runnable method because it is really not needed | 395 // Disable refcounting for runnable method because it is really not needed |
| 396 // when we post tasks on the main message loop. | 396 // when we post tasks on the main message loop. |
| 397 DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcess); | 397 DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcess); |
| OLD | NEW |