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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/profiles/profile_impl.h ('k') | chrome/browser/sync/credential_cache_service_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/profiles/profile_impl.cc
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index 3d399049478a2f60a7dbf500f407b096ec3b8a7d..1298800415798a35c44c1cc0c37f9cf4c18436d5 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -12,10 +12,13 @@
#include "base/file_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/path_service.h"
+#include "base/prefs/json_pref_store.h"
#include "base/string_number_conversions.h"
#include "base/string_tokenizer.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
+#include "base/synchronization/waitable_event.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"
@@ -155,8 +158,33 @@ const char* const kPrefExitTypeSessionEnded = "SessionEnded";
// Helper method needed because PostTask cannot currently take a Callback
// function with non-void return type.
// TODO(jhawkins): Remove once IgnoreResult is fixed.
-void CreateDirectoryNoResult(const FilePath& path) {
+void CreateDirectoryNoResult(const FilePath& path,
Mattias Nissler (ping if slow) 2012/10/24 17:07:49 nit: Rename to CreateDirectoryAndSignal or somesuc
zel 2012/10/24 17:23:14 Done.
+ base::WaitableEvent* done_creating) {
file_util::CreateDirectory(path);
+ done_creating->Signal();
+}
+
+// Task that blocks the FILE thread until CreateDirectoryNoResult() finishes on
+// blocking I/O pool.
+void BlockFileThreadOnDirectoryCreate(base::WaitableEvent* done_creating) {
+ done_creating->Wait();
+}
+
+// Initiates creation of profile directory on |sequenced_task_runner| and
+// ensures that FILE thread is blocked until that operation finishes.
+void CreateProfileDirectory(base::SequencedTaskRunner* sequenced_task_runner,
+ const FilePath& path) {
+ base::WaitableEvent* done_creating = new base::WaitableEvent(false, false);
+ sequenced_task_runner->PostTask(FROM_HERE,
+ base::Bind(&CreateDirectoryNoResult,
+ path,
+ done_creating));
+ // Block the FILE thread until directory is created on I/O pool to make sure
+ // that we don't attempt any operation until that part completes.
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
Mattias Nissler (ping if slow) 2012/10/24 17:07:49 nit: indentation
zel 2012/10/24 17:23:14 Done.
+ base::Bind(&BlockFileThreadOnDirectoryCreate,
+ base::Owned(done_creating)));
}
FilePath GetCachePath(const FilePath& base) {
@@ -205,16 +233,20 @@ std::string ExitTypeToSessionTypePrefValue(Profile::ExitType type) {
} // namespace
+
Mattias Nissler (ping if slow) 2012/10/24 17:07:49 remove extra newline
zel 2012/10/24 17:23:14 Done.
// static
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));
+ CreateProfileDirectory(sequenced_task_runner, path);
} 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
@@ -227,7 +259,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
@@ -280,9 +312,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))),
@@ -329,6 +363,7 @@ ProfileImpl::ProfileImpl(const FilePath& path,
if (create_mode == CREATE_MODE_ASYNCHRONOUS) {
prefs_.reset(PrefService::CreatePrefService(
GetPrefFilePath(),
+ sequenced_task_runner,
policy_service_.get(),
new ExtensionPrefStore(
ExtensionPrefValueMapFactory::GetForProfile(this), false),
@@ -341,6 +376,7 @@ ProfileImpl::ProfileImpl(const FilePath& path,
// Load prefs synchronously.
prefs_.reset(PrefService::CreatePrefService(
GetPrefFilePath(),
+ sequenced_task_runner,
policy_service_.get(),
new ExtensionPrefStore(
ExtensionPrefValueMapFactory::GetForProfile(this), false),
@@ -364,9 +400,10 @@ void ProfileImpl::DoFinalInit(bool is_new_profile) {
// to PathService.
chrome::GetUserCacheDirectory(path_, &base_cache_path_);
// Always create the cache directory asynchronously.
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- base::Bind(&CreateDirectoryNoResult, base_cache_path_));
+ scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner =
+ JsonPrefStore::GetTaskRunnerForFile(base_cache_path_,
+ BrowserThread::GetBlockingPool());
+ CreateProfileDirectory(sequenced_task_runner, base_cache_path_);
// Now that the profile is hooked up to receive pref change notifications to
// kGoogleServicesUsername, initialize components that depend on it to reflect
« no previous file with comments | « chrome/browser/profiles/profile_impl.h ('k') | chrome/browser/sync/credential_cache_service_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698