Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(598)

Side by Side Diff: chrome/service/service_process.cc

Issue 11027070: Moved JsonPrefStore to use SequencedWorkerPool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/environment.h" 12 #include "base/environment.h"
13 #include "base/i18n/rtl.h" 13 #include "base/i18n/rtl.h"
14 #include "base/memory/singleton.h" 14 #include "base/memory/singleton.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/string16.h" 16 #include "base/string16.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/common/chrome_constants.h" 19 #include "chrome/common/chrome_constants.h"
20 #include "chrome/common/chrome_paths.h" 20 #include "chrome/common/chrome_paths.h"
21 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/env_vars.h" 22 #include "chrome/common/env_vars.h"
23 #include "chrome/common/json_pref_store.h"
23 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
24 #include "chrome/common/service_process_util.h" 25 #include "chrome/common/service_process_util.h"
25 #include "chrome/service/cloud_print/cloud_print_proxy.h" 26 #include "chrome/service/cloud_print/cloud_print_proxy.h"
26 #include "chrome/service/net/service_url_request_context.h" 27 #include "chrome/service/net/service_url_request_context.h"
27 #include "chrome/service/service_ipc_server.h" 28 #include "chrome/service/service_ipc_server.h"
28 #include "chrome/service/service_process_prefs.h" 29 #include "chrome/service/service_process_prefs.h"
29 #include "grit/chromium_strings.h" 30 #include "grit/chromium_strings.h"
30 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
31 #include "net/base/network_change_notifier.h" 32 #include "net/base/network_change_notifier.h"
32 #include "net/url_request/url_fetcher.h" 33 #include "net/url_request/url_fetcher.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 base::Thread::Options options; 146 base::Thread::Options options;
146 options.message_loop_type = MessageLoop::TYPE_IO; 147 options.message_loop_type = MessageLoop::TYPE_IO;
147 io_thread_.reset(new ServiceIOThread("ServiceProcess_IO")); 148 io_thread_.reset(new ServiceIOThread("ServiceProcess_IO"));
148 file_thread_.reset(new base::Thread("ServiceProcess_File")); 149 file_thread_.reset(new base::Thread("ServiceProcess_File"));
149 if (!io_thread_->StartWithOptions(options) || 150 if (!io_thread_->StartWithOptions(options) ||
150 !file_thread_->StartWithOptions(options)) { 151 !file_thread_->StartWithOptions(options)) {
151 NOTREACHED(); 152 NOTREACHED();
152 Teardown(); 153 Teardown();
153 return false; 154 return false;
154 } 155 }
156 blocking_pool_ = new base::SequencedWorkerPool(3, "ServiceBlocking");
155 157
156 request_context_getter_ = new ServiceURLRequestContextGetter(); 158 request_context_getter_ = new ServiceURLRequestContextGetter();
157 159
158 FilePath user_data_dir; 160 FilePath user_data_dir;
159 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 161 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
160 FilePath pref_path = user_data_dir.Append(chrome::kServiceStateFileName); 162 FilePath pref_path = user_data_dir.Append(chrome::kServiceStateFileName);
161 service_prefs_.reset( 163 service_prefs_.reset(
162 new ServiceProcessPrefs(pref_path, file_thread_->message_loop_proxy())); 164 new ServiceProcessPrefs(
165 pref_path,
166 JsonPrefStore::GetTaskRunnerForFile(pref_path, blocking_pool_)));
163 service_prefs_->ReadPrefs(); 167 service_prefs_->ReadPrefs();
164 168
165 // Check if a locale override has been specified on the command-line. 169 // Check if a locale override has been specified on the command-line.
166 std::string locale = command_line.GetSwitchValueASCII(switches::kLang); 170 std::string locale = command_line.GetSwitchValueASCII(switches::kLang);
167 if (!locale.empty()) { 171 if (!locale.empty()) {
168 service_prefs_->SetString(prefs::kApplicationLocale, locale); 172 service_prefs_->SetString(prefs::kApplicationLocale, locale);
169 service_prefs_->WritePrefs(); 173 service_prefs_->WritePrefs();
170 } else { 174 } else {
171 // If no command-line value was specified, read the last used locale from 175 // If no command-line value was specified, read the last used locale from
172 // the prefs. 176 // the prefs.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 bool ServiceProcess::Teardown() { 215 bool ServiceProcess::Teardown() {
212 service_prefs_.reset(); 216 service_prefs_.reset();
213 cloud_print_proxy_.reset(); 217 cloud_print_proxy_.reset();
214 218
215 ipc_server_.reset(); 219 ipc_server_.reset();
216 // Signal this event before shutting down the service process. That way all 220 // Signal this event before shutting down the service process. That way all
217 // background threads can cleanup. 221 // background threads can cleanup.
218 shutdown_event_.Signal(); 222 shutdown_event_.Signal();
219 io_thread_.reset(); 223 io_thread_.reset();
220 file_thread_.reset(); 224 file_thread_.reset();
225
226 if (blocking_pool_.get()) {
227 blocking_pool_->Shutdown();
228 blocking_pool_ = NULL;
229 }
230
221 // The NetworkChangeNotifier must be destroyed after all other threads that 231 // The NetworkChangeNotifier must be destroyed after all other threads that
222 // might use it have been shut down. 232 // might use it have been shut down.
223 network_change_notifier_.reset(); 233 network_change_notifier_.reset();
224 234
225 service_process_state_->SignalStopped(); 235 service_process_state_->SignalStopped();
226 return true; 236 return true;
227 } 237 }
228 238
229 // This method is called when a shutdown command is received from IPC channel 239 // This method is called when a shutdown command is received from IPC channel
230 // or there was an error in the IPC channel. 240 // or there was an error in the IPC channel.
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 if (enabled_services_ && !ipc_server_->is_client_connected()) { 360 if (enabled_services_ && !ipc_server_->is_client_connected()) {
351 GetCloudPrintProxy()->CheckCloudPrintProxyPolicy(); 361 GetCloudPrintProxy()->CheckCloudPrintProxyPolicy();
352 } 362 }
353 ScheduleCloudPrintPolicyCheck(); 363 ScheduleCloudPrintPolicyCheck();
354 } 364 }
355 365
356 ServiceProcess::~ServiceProcess() { 366 ServiceProcess::~ServiceProcess() {
357 Teardown(); 367 Teardown();
358 g_service_process = NULL; 368 g_service_process = NULL;
359 } 369 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698