| 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/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "net/base/network_change_notifier.h" | 32 #include "net/base/network_change_notifier.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 34 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
| 35 #include "ui/base/ui_base_switches.h" | 35 #include "ui/base/ui_base_switches.h" |
| 36 | 36 |
| 37 #if defined(TOOLKIT_USES_GTK) | 37 #if defined(TOOLKIT_USES_GTK) |
| 38 #include "ui/gfx/gtk_util.h" | 38 #include "ui/gfx/gtk_util.h" |
| 39 #include <gtk/gtk.h> | 39 #include <gtk/gtk.h> |
| 40 #endif | 40 #endif |
| 41 | 41 |
| 42 #if defined(ENABLE_REMOTING) | |
| 43 #include "chrome/service/remoting/chromoting_host_manager.h" | |
| 44 #if defined(OS_MACOSX) | |
| 45 #include "base/mac/mac_util.h" | |
| 46 #endif // defined(OS_MACOSX) | |
| 47 #endif // defined(ENABLED_REMOTING) | |
| 48 | |
| 49 ServiceProcess* g_service_process = NULL; | 42 ServiceProcess* g_service_process = NULL; |
| 50 | 43 |
| 51 namespace { | 44 namespace { |
| 52 | 45 |
| 53 // Delay in millseconds after the last service is disabled before we attempt | 46 // Delay in millseconds after the last service is disabled before we attempt |
| 54 // a shutdown. | 47 // a shutdown. |
| 55 const int64 kShutdownDelay = 60000; | 48 const int64 kShutdownDelay = 60000; |
| 56 | 49 |
| 57 const char kDefaultServiceProcessLocale[] = "en-US"; | 50 const char kDefaultServiceProcessLocale[] = "en-US"; |
| 58 | 51 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 // the prefs. | 174 // the prefs. |
| 182 service_prefs_->GetString(prefs::kApplicationLocale, &locale); | 175 service_prefs_->GetString(prefs::kApplicationLocale, &locale); |
| 183 // If no locale was specified anywhere, use the default one. | 176 // If no locale was specified anywhere, use the default one. |
| 184 if (locale.empty()) | 177 if (locale.empty()) |
| 185 locale = kDefaultServiceProcessLocale; | 178 locale = kDefaultServiceProcessLocale; |
| 186 } | 179 } |
| 187 ResourceBundle::InitSharedInstance(locale); | 180 ResourceBundle::InitSharedInstance(locale); |
| 188 | 181 |
| 189 PrepareRestartOnCrashEnviroment(command_line); | 182 PrepareRestartOnCrashEnviroment(command_line); |
| 190 | 183 |
| 191 #if defined(ENABLE_REMOTING) | |
| 192 // Load media codecs, required by the Chromoting host | |
| 193 FilePath module_path; | |
| 194 if (PathService::Get(chrome::DIR_MEDIA_LIBS, &module_path) && | |
| 195 media::InitializeMediaLibrary(module_path)) { | |
| 196 // Initialize chromoting host manager. | |
| 197 remoting_host_manager_ = new remoting::ChromotingHostManager(this); | |
| 198 remoting_host_manager_->Initialize(message_loop, | |
| 199 file_thread_->message_loop_proxy()); | |
| 200 } | |
| 201 #endif // ENABLE_REMOTING | |
| 202 | |
| 203 // Enable Cloud Print if needed. First check the command-line. | 184 // Enable Cloud Print if needed. First check the command-line. |
| 204 bool cloud_print_proxy_enabled = | 185 bool cloud_print_proxy_enabled = |
| 205 command_line.HasSwitch(switches::kEnableCloudPrintProxy); | 186 command_line.HasSwitch(switches::kEnableCloudPrintProxy); |
| 206 if (!cloud_print_proxy_enabled) { | 187 if (!cloud_print_proxy_enabled) { |
| 207 // Then check if the cloud print proxy was previously enabled. | 188 // Then check if the cloud print proxy was previously enabled. |
| 208 service_prefs_->GetBoolean(prefs::kCloudPrintProxyEnabled, | 189 service_prefs_->GetBoolean(prefs::kCloudPrintProxyEnabled, |
| 209 &cloud_print_proxy_enabled); | 190 &cloud_print_proxy_enabled); |
| 210 } | 191 } |
| 211 | 192 |
| 212 if (cloud_print_proxy_enabled) { | 193 if (cloud_print_proxy_enabled) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 241 io_thread_.reset(); | 222 io_thread_.reset(); |
| 242 file_thread_.reset(); | 223 file_thread_.reset(); |
| 243 // The NetworkChangeNotifier must be destroyed after all other threads that | 224 // The NetworkChangeNotifier must be destroyed after all other threads that |
| 244 // might use it have been shut down. | 225 // might use it have been shut down. |
| 245 network_change_notifier_.reset(); | 226 network_change_notifier_.reset(); |
| 246 | 227 |
| 247 service_process_state_->SignalStopped(); | 228 service_process_state_->SignalStopped(); |
| 248 return true; | 229 return true; |
| 249 } | 230 } |
| 250 | 231 |
| 251 #if defined(ENABLE_REMOTING) | |
| 252 static void QuitMessageLoop(MessageLoop* message_loop) { | |
| 253 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | |
| 254 } | |
| 255 #endif | |
| 256 | |
| 257 // This method is called when a shutdown command is received from IPC channel | 232 // This method is called when a shutdown command is received from IPC channel |
| 258 // or there was an error in the IPC channel. | 233 // or there was an error in the IPC channel. |
| 259 void ServiceProcess::Shutdown() { | 234 void ServiceProcess::Shutdown() { |
| 260 #if defined(ENABLE_REMOTING) | |
| 261 // During shutdown of remoting host it has some left over operations on | |
| 262 // the UI thread. So we let the teardown to proceed asynchronously | |
| 263 if (remoting_host_manager_.get()) { | |
| 264 remoting_host_manager_->Teardown( | |
| 265 NewRunnableFunction(&QuitMessageLoop, main_message_loop_)); | |
| 266 } | |
| 267 #else | |
| 268 // Quit the main message loop. | 235 // Quit the main message loop. |
| 269 main_message_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 236 main_message_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 270 #endif | |
| 271 } | 237 } |
| 272 | 238 |
| 273 bool ServiceProcess::HandleClientDisconnect() { | 239 bool ServiceProcess::HandleClientDisconnect() { |
| 274 // If there are no enabled services or if there is an update available | 240 // If there are no enabled services or if there is an update available |
| 275 // we want to shutdown right away. Else we want to keep listening for | 241 // we want to shutdown right away. Else we want to keep listening for |
| 276 // new connections. | 242 // new connections. |
| 277 if (!enabled_services_ || update_available()) { | 243 if (!enabled_services_ || update_available()) { |
| 278 Shutdown(); | 244 Shutdown(); |
| 279 return false; | 245 return false; |
| 280 } | 246 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 300 | 266 |
| 301 void ServiceProcess::OnCloudPrintProxyDisabled(bool persist_state) { | 267 void ServiceProcess::OnCloudPrintProxyDisabled(bool persist_state) { |
| 302 if (persist_state) { | 268 if (persist_state) { |
| 303 // Save the preference that we have disabled the cloud print proxy. | 269 // Save the preference that we have disabled the cloud print proxy. |
| 304 service_prefs_->SetBoolean(prefs::kCloudPrintProxyEnabled, false); | 270 service_prefs_->SetBoolean(prefs::kCloudPrintProxyEnabled, false); |
| 305 service_prefs_->WritePrefs(); | 271 service_prefs_->WritePrefs(); |
| 306 } | 272 } |
| 307 OnServiceDisabled(); | 273 OnServiceDisabled(); |
| 308 } | 274 } |
| 309 | 275 |
| 310 void ServiceProcess::OnChromotingHostEnabled() { | |
| 311 OnServiceEnabled(); | |
| 312 } | |
| 313 | |
| 314 void ServiceProcess::OnChromotingHostDisabled() { | |
| 315 OnServiceDisabled(); | |
| 316 } | |
| 317 | |
| 318 ServiceURLRequestContextGetter* | 276 ServiceURLRequestContextGetter* |
| 319 ServiceProcess::GetServiceURLRequestContextGetter() { | 277 ServiceProcess::GetServiceURLRequestContextGetter() { |
| 320 DCHECK(request_context_getter_.get()); | 278 DCHECK(request_context_getter_.get()); |
| 321 return request_context_getter_.get(); | 279 return request_context_getter_.get(); |
| 322 } | 280 } |
| 323 | 281 |
| 324 void ServiceProcess::OnServiceEnabled() { | 282 void ServiceProcess::OnServiceEnabled() { |
| 325 enabled_services_++; | 283 enabled_services_++; |
| 326 if ((1 == enabled_services_) && | 284 if ((1 == enabled_services_) && |
| 327 !CommandLine::ForCurrentProcess()->HasSwitch( | 285 !CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 } else { | 322 } else { |
| 365 Shutdown(); | 323 Shutdown(); |
| 366 } | 324 } |
| 367 } | 325 } |
| 368 } | 326 } |
| 369 | 327 |
| 370 ServiceProcess::~ServiceProcess() { | 328 ServiceProcess::~ServiceProcess() { |
| 371 Teardown(); | 329 Teardown(); |
| 372 g_service_process = NULL; | 330 g_service_process = NULL; |
| 373 } | 331 } |
| OLD | NEW |