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

Side by Side Diff: chrome/browser/profiles/profile_impl.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/browser/profiles/profile_impl.h" 5 #include "chrome/browser/profiles/profile_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/string_number_conversions.h" 15 #include "base/string_number_conversions.h"
16 #include "base/string_tokenizer.h" 16 #include "base/string_tokenizer.h"
17 #include "base/string_util.h" 17 #include "base/string_util.h"
18 #include "base/stringprintf.h" 18 #include "base/stringprintf.h"
19 #include "base/threading/sequenced_worker_pool.h"
19 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
20 #include "base/version.h" 21 #include "base/version.h"
21 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 22 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
22 #include "chrome/browser/background/background_contents_service_factory.h" 23 #include "chrome/browser/background/background_contents_service_factory.h"
23 #include "chrome/browser/background/background_mode_manager.h" 24 #include "chrome/browser/background/background_mode_manager.h"
24 #include "chrome/browser/browser_process.h" 25 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/chrome_plugin_service_filter.h" 26 #include "chrome/browser/chrome_plugin_service_filter.h"
26 #include "chrome/browser/content_settings/cookie_settings.h" 27 #include "chrome/browser/content_settings/cookie_settings.h"
27 #include "chrome/browser/content_settings/host_content_settings_map.h" 28 #include "chrome/browser/content_settings/host_content_settings_map.h"
28 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 29 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 NOTREACHED(); 202 NOTREACHED();
202 return std::string(); 203 return std::string();
203 } 204 }
204 205
205 } // namespace 206 } // namespace
206 207
207 // static 208 // static
208 Profile* Profile::CreateProfile(const FilePath& path, 209 Profile* Profile::CreateProfile(const FilePath& path,
209 Delegate* delegate, 210 Delegate* delegate,
210 CreateMode create_mode) { 211 CreateMode create_mode) {
212 // Get sequenced task runner for making sure that file operations of
213 // this profile (defined by |path|) are executed in expected order
214 // (what was previously assured by the FILE thread).
215 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner =
akalin 2012/10/19 02:00:51 use JsonPrefStore::CreateTaskRunnerForFile() here?
zel 2012/10/19 18:45:07 Done.
216 BrowserThread::GetBlockingPool()->
217 GetSequencedTaskRunnerWithShutdownBehavior(
218 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(
219 path.AsUTF8Unsafe()),
220 base::SequencedWorkerPool::BLOCK_SHUTDOWN);
211 if (create_mode == CREATE_MODE_ASYNCHRONOUS) { 221 if (create_mode == CREATE_MODE_ASYNCHRONOUS) {
212 DCHECK(delegate); 222 DCHECK(delegate);
213 // This is safe while all file operations are done on the FILE thread. 223 // We need to make sure that profile directory is created on the same
214 BrowserThread::PostTask( 224 // blocking pool where we will run all its important file serialization
215 BrowserThread::FILE, FROM_HERE, 225 // tasks (i.e. JsonPrefStore).
216 base::Bind(&CreateDirectoryNoResult, path)); 226 sequenced_task_runner->PostTask(FROM_HERE,
227 base::Bind(&CreateDirectoryNoResult, path));
217 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { 228 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) {
218 if (!file_util::PathExists(path)) { 229 if (!file_util::PathExists(path)) {
219 // TODO(tc): http://b/1094718 Bad things happen if we can't write to the 230 // TODO(tc): http://b/1094718 Bad things happen if we can't write to the
220 // profile directory. We should eventually be able to run in this 231 // profile directory. We should eventually be able to run in this
221 // situation. 232 // situation.
222 if (!file_util::CreateDirectory(path)) 233 if (!file_util::CreateDirectory(path))
223 return NULL; 234 return NULL;
224 } 235 }
225 } else { 236 } else {
226 NOTREACHED(); 237 NOTREACHED();
227 } 238 }
228 239
229 return new ProfileImpl(path, delegate, create_mode); 240 return new ProfileImpl(path, delegate, create_mode, sequenced_task_runner);
230 } 241 }
231 242
232 // static 243 // static
233 int ProfileImpl::create_readme_delay_ms = 60000; 244 int ProfileImpl::create_readme_delay_ms = 60000;
234 245
235 // static 246 // static
236 const char* const ProfileImpl::kPrefExitTypeNormal = "Normal"; 247 const char* const ProfileImpl::kPrefExitTypeNormal = "Normal";
237 248
238 // static 249 // static
239 void ProfileImpl::RegisterUserPrefs(PrefService* prefs) { 250 void ProfileImpl::RegisterUserPrefs(PrefService* prefs) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 prefs->RegisterIntegerPref(prefs::kMediaCacheSize, 283 prefs->RegisterIntegerPref(prefs::kMediaCacheSize,
273 0, 284 0,
274 PrefService::UNSYNCABLE_PREF); 285 PrefService::UNSYNCABLE_PREF);
275 286
276 // Deprecated. Kept around for migration. 287 // Deprecated. Kept around for migration.
277 prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit, 288 prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit,
278 false, 289 false,
279 PrefService::SYNCABLE_PREF); 290 PrefService::SYNCABLE_PREF);
280 } 291 }
281 292
282 ProfileImpl::ProfileImpl(const FilePath& path, 293 ProfileImpl::ProfileImpl(
283 Delegate* delegate, 294 const FilePath& path,
284 CreateMode create_mode) 295 Delegate* delegate,
296 CreateMode create_mode,
297 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner)
285 : path_(path), 298 : path_(path),
286 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( 299 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_(
287 new VisitedLinkEventListener(this))), 300 new VisitedLinkEventListener(this))),
288 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), 301 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)),
289 host_content_settings_map_(NULL), 302 host_content_settings_map_(NULL),
290 last_session_exit_type_(EXIT_NORMAL), 303 last_session_exit_type_(EXIT_NORMAL),
291 start_time_(Time::Now()), 304 start_time_(Time::Now()),
292 delegate_(delegate), 305 delegate_(delegate),
293 predictor_(NULL) { 306 predictor_(NULL) {
294 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << 307 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
(...skipping 29 matching lines...) Expand all
324 #else 337 #else
325 policy_service_.reset(new policy::PolicyServiceStub()); 338 policy_service_.reset(new policy::PolicyServiceStub());
326 #endif 339 #endif
327 340
328 if (create_mode == CREATE_MODE_ASYNCHRONOUS) { 341 if (create_mode == CREATE_MODE_ASYNCHRONOUS) {
329 prefs_.reset(PrefService::CreatePrefService( 342 prefs_.reset(PrefService::CreatePrefService(
330 GetPrefFilePath(), 343 GetPrefFilePath(),
331 policy_service_.get(), 344 policy_service_.get(),
332 new ExtensionPrefStore( 345 new ExtensionPrefStore(
333 ExtensionPrefValueMapFactory::GetForProfile(this), false), 346 ExtensionPrefValueMapFactory::GetForProfile(this), false),
334 true)); 347 true,
348 sequenced_task_runner));
335 // Wait for the notification that prefs has been loaded (successfully or 349 // Wait for the notification that prefs has been loaded (successfully or
336 // not). 350 // not).
337 registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, 351 registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED,
338 content::Source<PrefService>(prefs_.get())); 352 content::Source<PrefService>(prefs_.get()));
339 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { 353 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) {
340 // Load prefs synchronously. 354 // Load prefs synchronously.
341 prefs_.reset(PrefService::CreatePrefService( 355 prefs_.reset(PrefService::CreatePrefService(
342 GetPrefFilePath(), 356 GetPrefFilePath(),
343 policy_service_.get(), 357 policy_service_.get(),
344 new ExtensionPrefStore( 358 new ExtensionPrefStore(
345 ExtensionPrefValueMapFactory::GetForProfile(this), false), 359 ExtensionPrefValueMapFactory::GetForProfile(this), false),
346 false)); 360 false,
361 sequenced_task_runner));
347 OnPrefsLoaded(true); 362 OnPrefsLoaded(true);
348 } else { 363 } else {
349 NOTREACHED(); 364 NOTREACHED();
350 } 365 }
351 } 366 }
352 367
353 void ProfileImpl::DoFinalInit(bool is_new_profile) { 368 void ProfileImpl::DoFinalInit(bool is_new_profile) {
354 PrefService* prefs = GetPrefs(); 369 PrefService* prefs = GetPrefs();
355 pref_change_registrar_.Init(prefs); 370 pref_change_registrar_.Init(prefs);
356 pref_change_registrar_.Add(prefs::kGoogleServicesUsername, this); 371 pref_change_registrar_.Add(prefs::kGoogleServicesUsername, this);
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 if (!path.empty()) 1180 if (!path.empty())
1166 *cache_path = path; 1181 *cache_path = path;
1167 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : 1182 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) :
1168 prefs_->GetInteger(prefs::kDiskCacheSize); 1183 prefs_->GetInteger(prefs::kDiskCacheSize);
1169 } 1184 }
1170 1185
1171 base::Callback<ChromeURLDataManagerBackend*(void)> 1186 base::Callback<ChromeURLDataManagerBackend*(void)>
1172 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { 1187 ProfileImpl::GetChromeURLDataManagerBackendGetter() const {
1173 return io_data_.GetChromeURLDataManagerBackendGetter(); 1188 return io_data_.GetChromeURLDataManagerBackendGetter();
1174 } 1189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698