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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 base::Thread::Options options; | 145 base::Thread::Options options; |
146 options.message_loop_type = MessageLoop::TYPE_IO; | 146 options.message_loop_type = MessageLoop::TYPE_IO; |
147 io_thread_.reset(new ServiceIOThread("ServiceProcess_IO")); | 147 io_thread_.reset(new ServiceIOThread("ServiceProcess_IO")); |
148 file_thread_.reset(new base::Thread("ServiceProcess_File")); | 148 file_thread_.reset(new base::Thread("ServiceProcess_File")); |
149 if (!io_thread_->StartWithOptions(options) || | 149 if (!io_thread_->StartWithOptions(options) || |
150 !file_thread_->StartWithOptions(options)) { | 150 !file_thread_->StartWithOptions(options)) { |
151 NOTREACHED(); | 151 NOTREACHED(); |
152 Teardown(); | 152 Teardown(); |
153 return false; | 153 return false; |
154 } | 154 } |
| 155 blocking_pool_ = new base::SequencedWorkerPool(3, "ServiceBlocking"); |
155 | 156 |
156 request_context_getter_ = new ServiceURLRequestContextGetter(); | 157 request_context_getter_ = new ServiceURLRequestContextGetter(); |
157 | 158 |
158 FilePath user_data_dir; | 159 FilePath user_data_dir; |
159 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 160 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
160 FilePath pref_path = user_data_dir.Append(chrome::kServiceStateFileName); | 161 FilePath pref_path = user_data_dir.Append(chrome::kServiceStateFileName); |
161 service_prefs_.reset( | 162 service_prefs_.reset( |
162 new ServiceProcessPrefs(pref_path, file_thread_->message_loop_proxy())); | 163 new ServiceProcessPrefs(pref_path, blocking_pool_)); |
163 service_prefs_->ReadPrefs(); | 164 service_prefs_->ReadPrefs(); |
164 | 165 |
165 // Check if a locale override has been specified on the command-line. | 166 // Check if a locale override has been specified on the command-line. |
166 std::string locale = command_line.GetSwitchValueASCII(switches::kLang); | 167 std::string locale = command_line.GetSwitchValueASCII(switches::kLang); |
167 if (!locale.empty()) { | 168 if (!locale.empty()) { |
168 service_prefs_->SetString(prefs::kApplicationLocale, locale); | 169 service_prefs_->SetString(prefs::kApplicationLocale, locale); |
169 service_prefs_->WritePrefs(); | 170 service_prefs_->WritePrefs(); |
170 } else { | 171 } else { |
171 // If no command-line value was specified, read the last used locale from | 172 // If no command-line value was specified, read the last used locale from |
172 // the prefs. | 173 // the prefs. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 bool ServiceProcess::Teardown() { | 212 bool ServiceProcess::Teardown() { |
212 service_prefs_.reset(); | 213 service_prefs_.reset(); |
213 cloud_print_proxy_.reset(); | 214 cloud_print_proxy_.reset(); |
214 | 215 |
215 ipc_server_.reset(); | 216 ipc_server_.reset(); |
216 // Signal this event before shutting down the service process. That way all | 217 // Signal this event before shutting down the service process. That way all |
217 // background threads can cleanup. | 218 // background threads can cleanup. |
218 shutdown_event_.Signal(); | 219 shutdown_event_.Signal(); |
219 io_thread_.reset(); | 220 io_thread_.reset(); |
220 file_thread_.reset(); | 221 file_thread_.reset(); |
| 222 |
| 223 if (blocking_pool_.get()) { |
| 224 blocking_pool_->Shutdown(); |
| 225 blocking_pool_ = NULL; |
| 226 } |
| 227 |
221 // The NetworkChangeNotifier must be destroyed after all other threads that | 228 // The NetworkChangeNotifier must be destroyed after all other threads that |
222 // might use it have been shut down. | 229 // might use it have been shut down. |
223 network_change_notifier_.reset(); | 230 network_change_notifier_.reset(); |
224 | 231 |
225 service_process_state_->SignalStopped(); | 232 service_process_state_->SignalStopped(); |
226 return true; | 233 return true; |
227 } | 234 } |
228 | 235 |
229 // 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 |
230 // or there was an error in the IPC channel. | 237 // or there was an error in the IPC channel. |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 if (enabled_services_ && !ipc_server_->is_client_connected()) { | 357 if (enabled_services_ && !ipc_server_->is_client_connected()) { |
351 GetCloudPrintProxy()->CheckCloudPrintProxyPolicy(); | 358 GetCloudPrintProxy()->CheckCloudPrintProxyPolicy(); |
352 } | 359 } |
353 ScheduleCloudPrintPolicyCheck(); | 360 ScheduleCloudPrintPolicyCheck(); |
354 } | 361 } |
355 | 362 |
356 ServiceProcess::~ServiceProcess() { | 363 ServiceProcess::~ServiceProcess() { |
357 Teardown(); | 364 Teardown(); |
358 g_service_process = NULL; | 365 g_service_process = NULL; |
359 } | 366 } |
OLD | NEW |