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" |
11 #include "base/environment.h" | 11 #include "base/environment.h" |
12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/singleton.h" | 14 #include "base/singleton.h" |
15 #include "base/string16.h" | 15 #include "base/string16.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
19 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/env_vars.h" | 21 #include "chrome/common/env_vars.h" |
22 #include "chrome/common/net/url_fetcher.h" | 22 #include "chrome/common/net/url_fetcher.h" |
23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
24 #include "chrome/common/service_process_util.h" | 24 #include "chrome/common/service_process_util.h" |
25 #include "chrome/service/cloud_print/cloud_print_proxy.h" | 25 #include "chrome/service/cloud_print/cloud_print_proxy.h" |
26 #include "chrome/service/service_ipc_server.h" | 26 #include "chrome/service/service_ipc_server.h" |
27 #include "chrome/service/service_process_prefs.h" | 27 #include "chrome/service/service_process_prefs.h" |
28 #include "grit/chromium_strings.h" | 28 #include "grit/chromium_strings.h" |
29 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
30 #include "media/base/media.h" | |
30 #include "net/base/network_change_notifier.h" | 31 #include "net/base/network_change_notifier.h" |
31 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
32 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
33 #include "ui/base/ui_base_switches.h" | 34 #include "ui/base/ui_base_switches.h" |
34 | 35 |
35 #if defined(ENABLE_REMOTING) | 36 #if defined(ENABLE_REMOTING) |
36 #include "chrome/service/remoting/chromoting_host_manager.h" | 37 #include "chrome/service/remoting/chromoting_host_manager.h" |
37 #endif // defined(ENABLED_REMOTING) | 38 #endif // defined(ENABLED_REMOTING) |
38 | 39 |
39 ServiceProcess* g_service_process = NULL; | 40 ServiceProcess* g_service_process = NULL; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 service_prefs_->GetString(prefs::kApplicationLocale, &locale); | 154 service_prefs_->GetString(prefs::kApplicationLocale, &locale); |
154 // If no locale was specified anywhere, use the default one. | 155 // If no locale was specified anywhere, use the default one. |
155 if (locale.empty()) | 156 if (locale.empty()) |
156 locale = kDefaultServiceProcessLocale; | 157 locale = kDefaultServiceProcessLocale; |
157 } | 158 } |
158 ResourceBundle::InitSharedInstance(locale); | 159 ResourceBundle::InitSharedInstance(locale); |
159 | 160 |
160 PrepareRestartOnCrashEnviroment(command_line); | 161 PrepareRestartOnCrashEnviroment(command_line); |
161 | 162 |
162 #if defined(ENABLE_REMOTING) | 163 #if defined(ENABLE_REMOTING) |
164 // Load media codecs, required by the Chromoting host | |
165 bool initialized_media_library = false; | |
166 #if defined(OS_MACOSX) | |
167 FilePath bundle_path = base::mac::MainAppBundlePath(); | |
168 | |
169 initialized_media_library = | |
170 media::InitializeMediaLibrary(bundle_path.Append("Libraries")); | |
171 #else | |
172 FilePath module_path; | |
173 initialized_media_library = | |
174 PathService::Get(base::DIR_MODULE, &module_path) && | |
175 media::InitializeMediaLibrary(module_path); | |
176 #endif | |
177 | |
163 // Initialize chromoting host manager. | 178 // Initialize chromoting host manager. |
164 remoting_host_manager_ = new remoting::ChromotingHostManager(this); | 179 remoting_host_manager_ = new remoting::ChromotingHostManager(this); |
165 remoting_host_manager_->Initialize(message_loop, | 180 remoting_host_manager_->Initialize(message_loop, |
166 file_thread_->message_loop_proxy()); | 181 file_thread_->message_loop_proxy()); |
167 #endif | 182 #endif // ENABLE_REMOTING |
168 | 183 |
169 // Enable Cloud Print if needed. First check the command-line. | 184 // Enable Cloud Print if needed. First check the command-line. |
170 bool cloud_print_proxy_enabled = | 185 bool cloud_print_proxy_enabled = |
171 command_line.HasSwitch(switches::kEnableCloudPrintProxy); | 186 command_line.HasSwitch(switches::kEnableCloudPrintProxy); |
172 if (!cloud_print_proxy_enabled) { | 187 if (!cloud_print_proxy_enabled) { |
173 // Then check if the cloud print proxy was previously enabled. | 188 // Then check if the cloud print proxy was previously enabled. |
174 service_prefs_->GetBoolean(prefs::kCloudPrintProxyEnabled, | 189 service_prefs_->GetBoolean(prefs::kCloudPrintProxyEnabled, |
175 &cloud_print_proxy_enabled); | 190 &cloud_print_proxy_enabled); |
176 } | 191 } |
177 | 192 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 static void QuitMessageLoop(MessageLoop* message_loop) { | 232 static void QuitMessageLoop(MessageLoop* message_loop) { |
218 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 233 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
219 } | 234 } |
220 | 235 |
221 // This method is called when a shutdown command is received from IPC channel | 236 // This method is called when a shutdown command is received from IPC channel |
222 // or there was an error in the IPC channel. | 237 // or there was an error in the IPC channel. |
223 void ServiceProcess::Shutdown() { | 238 void ServiceProcess::Shutdown() { |
224 #if defined(ENABLE_REMOTING) | 239 #if defined(ENABLE_REMOTING) |
225 // During shutdown of remoting host it has some left over operations on | 240 // During shutdown of remoting host it has some left over operations on |
226 // the UI thread. So we let the teardown to proceed asynchronously | 241 // the UI thread. So we let the teardown to proceed asynchronously |
227 remoting_host_manager_->Teardown( | 242 if (remoting_host_manager_.get()) |
Alpha Left Google
2011/02/17 17:23:10
nit: since the following statement span across two
| |
243 remoting_host_manager_->Teardown( | |
228 NewRunnableFunction(&QuitMessageLoop, main_message_loop_)); | 244 NewRunnableFunction(&QuitMessageLoop, main_message_loop_)); |
Alpha Left Google
2011/02/17 17:23:10
nit: indent this by 4 spaces.
| |
229 #else | 245 #else |
230 // Quit the main message loop. | 246 // Quit the main message loop. |
231 main_message_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 247 main_message_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
232 #endif | 248 #endif |
233 } | 249 } |
234 | 250 |
235 bool ServiceProcess::HandleClientDisconnect() { | 251 bool ServiceProcess::HandleClientDisconnect() { |
236 // If there are no enabled services or if there is an update available | 252 // If there are no enabled services or if there is an update available |
237 // we want to shutdown right away. Else we want to keep listening for | 253 // we want to shutdown right away. Else we want to keep listening for |
238 // new connections. | 254 // new connections. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 } | 332 } |
317 | 333 |
318 ServiceProcess::~ServiceProcess() { | 334 ServiceProcess::~ServiceProcess() { |
319 Teardown(); | 335 Teardown(); |
320 g_service_process = NULL; | 336 g_service_process = NULL; |
321 } | 337 } |
322 | 338 |
323 // Disable refcounting for runnable method because it is really not needed | 339 // Disable refcounting for runnable method because it is really not needed |
324 // when we post tasks on the main message loop. | 340 // when we post tasks on the main message loop. |
325 DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcess); | 341 DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcess); |
OLD | NEW |