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 "app/app_switches.h" |
| 10 #include "app/resource_bundle.h" |
9 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 12 #include "base/command_line.h" |
11 #include "base/path_service.h" | 13 #include "base/path_service.h" |
12 #include "base/singleton.h" | 14 #include "base/singleton.h" |
13 #include "base/string16.h" | 15 #include "base/string16.h" |
14 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 17 #include "base/values.h" |
16 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
17 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
18 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
(...skipping 10 matching lines...) Expand all Loading... |
29 #endif // defined(ENABLED_REMOTING) | 31 #endif // defined(ENABLED_REMOTING) |
30 | 32 |
31 ServiceProcess* g_service_process = NULL; | 33 ServiceProcess* g_service_process = NULL; |
32 | 34 |
33 namespace { | 35 namespace { |
34 | 36 |
35 // Delay in millseconds after the last service is disabled before we attempt | 37 // Delay in millseconds after the last service is disabled before we attempt |
36 // a shutdown. | 38 // a shutdown. |
37 const int64 kShutdownDelay = 60000; | 39 const int64 kShutdownDelay = 60000; |
38 | 40 |
| 41 const char kDefaultServiceProcessLocale[] = "en-US"; |
| 42 |
39 class ServiceIOThread : public base::Thread { | 43 class ServiceIOThread : public base::Thread { |
40 public: | 44 public: |
41 explicit ServiceIOThread(const char* name); | 45 explicit ServiceIOThread(const char* name); |
42 virtual ~ServiceIOThread(); | 46 virtual ~ServiceIOThread(); |
43 | 47 |
44 protected: | 48 protected: |
45 virtual void CleanUp(); | 49 virtual void CleanUp(); |
46 | 50 |
47 private: | 51 private: |
48 DISALLOW_COPY_AND_ASSIGN(ServiceIOThread); | 52 DISALLOW_COPY_AND_ASSIGN(ServiceIOThread); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 std::string lsid = command_line.GetSwitchValueASCII( | 94 std::string lsid = command_line.GetSwitchValueASCII( |
91 switches::kServiceAccountLsid); | 95 switches::kServiceAccountLsid); |
92 | 96 |
93 FilePath user_data_dir; | 97 FilePath user_data_dir; |
94 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 98 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
95 FilePath pref_path = user_data_dir.Append(chrome::kServiceStateFileName); | 99 FilePath pref_path = user_data_dir.Append(chrome::kServiceStateFileName); |
96 service_prefs_.reset( | 100 service_prefs_.reset( |
97 new ServiceProcessPrefs(pref_path, file_thread_->message_loop_proxy())); | 101 new ServiceProcessPrefs(pref_path, file_thread_->message_loop_proxy())); |
98 service_prefs_->ReadPrefs(); | 102 service_prefs_->ReadPrefs(); |
99 | 103 |
| 104 // Check if a locale override has been specified on the command-line. |
| 105 std::string locale = command_line.GetSwitchValueASCII(switches::kLang); |
| 106 if (!locale.empty()) { |
| 107 service_prefs_->SetString(prefs::kApplicationLocale, locale); |
| 108 service_prefs_->WritePrefs(); |
| 109 } else { |
| 110 // If no command-line value was specified, read the last used locale from |
| 111 // the prefs. |
| 112 service_prefs_->GetString(prefs::kApplicationLocale, &locale); |
| 113 // If no locale was specified anywhere, use the default one. |
| 114 if (locale.empty()) |
| 115 locale = kDefaultServiceProcessLocale; |
| 116 } |
| 117 ResourceBundle::InitSharedInstance(locale); |
| 118 |
100 #if defined(ENABLE_REMOTING) | 119 #if defined(ENABLE_REMOTING) |
101 // Initialize chromoting host manager. | 120 // Initialize chromoting host manager. |
102 remoting_host_manager_ = new remoting::ChromotingHostManager(this); | 121 remoting_host_manager_ = new remoting::ChromotingHostManager(this); |
103 remoting_host_manager_->Initialize(file_thread_->message_loop_proxy()); | 122 remoting_host_manager_->Initialize(file_thread_->message_loop_proxy()); |
104 #endif | 123 #endif |
105 | 124 |
106 // Enable Cloud Print if needed. First check the command-line. | 125 // Enable Cloud Print if needed. First check the command-line. |
107 bool cloud_print_proxy_enabled = | 126 bool cloud_print_proxy_enabled = |
108 command_line.HasSwitch(switches::kEnableCloudPrintProxy); | 127 command_line.HasSwitch(switches::kEnableCloudPrintProxy); |
109 if (!cloud_print_proxy_enabled) { | 128 if (!cloud_print_proxy_enabled) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 } | 188 } |
170 | 189 |
171 CloudPrintProxy* ServiceProcess::GetCloudPrintProxy() { | 190 CloudPrintProxy* ServiceProcess::GetCloudPrintProxy() { |
172 if (!cloud_print_proxy_.get()) { | 191 if (!cloud_print_proxy_.get()) { |
173 cloud_print_proxy_.reset(new CloudPrintProxy()); | 192 cloud_print_proxy_.reset(new CloudPrintProxy()); |
174 cloud_print_proxy_->Initialize(service_prefs_.get(), this); | 193 cloud_print_proxy_->Initialize(service_prefs_.get(), this); |
175 } | 194 } |
176 return cloud_print_proxy_.get(); | 195 return cloud_print_proxy_.get(); |
177 } | 196 } |
178 | 197 |
179 void ServiceProcess::OnCloudPrintProxyEnabled() { | 198 void ServiceProcess::OnCloudPrintProxyEnabled(bool persist_state) { |
180 // Save the preference that we have enabled the cloud print proxy. | 199 if (persist_state) { |
181 service_prefs_->SetBoolean(prefs::kCloudPrintProxyEnabled, true); | 200 // Save the preference that we have enabled the cloud print proxy. |
182 service_prefs_->WritePrefs(); | 201 service_prefs_->SetBoolean(prefs::kCloudPrintProxyEnabled, true); |
| 202 service_prefs_->WritePrefs(); |
| 203 } |
183 OnServiceEnabled(); | 204 OnServiceEnabled(); |
184 } | 205 } |
185 | 206 |
186 void ServiceProcess::OnCloudPrintProxyDisabled() { | 207 void ServiceProcess::OnCloudPrintProxyDisabled(bool persist_state) { |
187 // Save the preference that we have disabled the cloud print proxy. | 208 if (persist_state) { |
188 service_prefs_->SetBoolean(prefs::kCloudPrintProxyEnabled, false); | 209 // Save the preference that we have disabled the cloud print proxy. |
189 service_prefs_->WritePrefs(); | 210 service_prefs_->SetBoolean(prefs::kCloudPrintProxyEnabled, false); |
| 211 service_prefs_->WritePrefs(); |
| 212 } |
190 OnServiceDisabled(); | 213 OnServiceDisabled(); |
191 } | 214 } |
192 | 215 |
193 void ServiceProcess::OnRemotingHostEnabled() { | 216 void ServiceProcess::OnRemotingHostEnabled() { |
194 OnServiceEnabled(); | 217 OnServiceEnabled(); |
195 } | 218 } |
196 | 219 |
197 void ServiceProcess::OnRemotingHostDisabled() { | 220 void ServiceProcess::OnRemotingHostDisabled() { |
198 OnServiceDisabled(); | 221 OnServiceDisabled(); |
199 } | 222 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 } | 260 } |
238 | 261 |
239 ServiceProcess::~ServiceProcess() { | 262 ServiceProcess::~ServiceProcess() { |
240 Teardown(); | 263 Teardown(); |
241 g_service_process = NULL; | 264 g_service_process = NULL; |
242 } | 265 } |
243 | 266 |
244 // Disable refcounting for runnable method because it is really not needed | 267 // Disable refcounting for runnable method because it is really not needed |
245 // when we post tasks on the main message loop. | 268 // when we post tasks on the main message loop. |
246 DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcess); | 269 DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcess); |
OLD | NEW |