Chromium Code Reviews| Index: chrome/browser/profiles/profile_impl.cc |
| diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc |
| index 735cba8acb25dc9e8cff36bb2870cc7a987155a7..096e30bc656def0bce3e898885bcf035083ae95e 100644 |
| --- a/chrome/browser/profiles/profile_impl.cc |
| +++ b/chrome/browser/profiles/profile_impl.cc |
| @@ -16,6 +16,7 @@ |
| #include "base/string_tokenizer.h" |
| #include "base/string_util.h" |
| #include "base/stringprintf.h" |
| +#include "base/threading/sequenced_worker_pool.h" |
| #include "base/utf_string_conversions.h" |
| #include "base/version.h" |
| #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| @@ -75,6 +76,7 @@ |
| #include "chrome/common/chrome_paths_internal.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/chrome_version_info.h" |
| +#include "chrome/common/json_pref_store.h" |
| #include "chrome/common/pref_names.h" |
| #include "chrome/common/url_constants.h" |
| #include "content/public/browser/browser_thread.h" |
| @@ -208,12 +210,19 @@ std::string ExitTypeToSessionTypePrefValue(Profile::ExitType type) { |
| Profile* Profile::CreateProfile(const FilePath& path, |
| Delegate* delegate, |
| CreateMode create_mode) { |
| + // Get sequenced task runner for making sure that file operations of |
| + // this profile (defined by |path|) are executed in expected order |
| + // (what was previously assured by the FILE thread). |
| + scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner = |
| + JsonPrefStore::GetTaskRunnerForFile(path, |
| + BrowserThread::GetBlockingPool()); |
| if (create_mode == CREATE_MODE_ASYNCHRONOUS) { |
| DCHECK(delegate); |
| - // This is safe while all file operations are done on the FILE thread. |
| - BrowserThread::PostTask( |
| - BrowserThread::FILE, FROM_HERE, |
| - base::Bind(&CreateDirectoryNoResult, path)); |
| + // We need to make sure that profile directory is created on the same |
| + // blocking pool where we will run all its important file serialization |
| + // tasks (i.e. JsonPrefStore). |
| + sequenced_task_runner->PostTask(FROM_HERE, |
| + base::Bind(&CreateDirectoryNoResult, path)); |
|
Mattias Nissler (ping if slow)
2012/10/22 17:28:21
This is dangerous if other code that is still on t
zel
2012/10/24 02:20:11
Yes, I've tested this and adjusted such FILE depen
Mattias Nissler (ping if slow)
2012/10/24 13:36:16
Well, those were probably the easier ones :) I'm c
zel
2012/10/24 16:49:48
Yeah, that's a great idea. Done - PTAL.
|
| } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { |
| if (!file_util::PathExists(path)) { |
| // TODO(tc): http://b/1094718 Bad things happen if we can't write to the |
| @@ -226,7 +235,7 @@ Profile* Profile::CreateProfile(const FilePath& path, |
| NOTREACHED(); |
| } |
| - return new ProfileImpl(path, delegate, create_mode); |
| + return new ProfileImpl(path, delegate, create_mode, sequenced_task_runner); |
| } |
| // static |
| @@ -279,9 +288,11 @@ void ProfileImpl::RegisterUserPrefs(PrefService* prefs) { |
| PrefService::SYNCABLE_PREF); |
| } |
| -ProfileImpl::ProfileImpl(const FilePath& path, |
| - Delegate* delegate, |
| - CreateMode create_mode) |
| +ProfileImpl::ProfileImpl( |
| + const FilePath& path, |
| + Delegate* delegate, |
| + CreateMode create_mode, |
| + base::SequencedTaskRunner* sequenced_task_runner) |
| : path_(path), |
| ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( |
| new VisitedLinkEventListener(this))), |
| @@ -331,7 +342,8 @@ ProfileImpl::ProfileImpl(const FilePath& path, |
| policy_service_.get(), |
| new ExtensionPrefStore( |
| ExtensionPrefValueMapFactory::GetForProfile(this), false), |
| - true)); |
| + true, |
| + sequenced_task_runner)); |
| // Wait for the notification that prefs has been loaded (successfully or |
| // not). |
| registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, |
| @@ -343,7 +355,8 @@ ProfileImpl::ProfileImpl(const FilePath& path, |
| policy_service_.get(), |
| new ExtensionPrefStore( |
| ExtensionPrefValueMapFactory::GetForProfile(this), false), |
| - false)); |
| + false, |
| + sequenced_task_runner)); |
| OnPrefsLoaded(true); |
| } else { |
| NOTREACHED(); |