summaryrefslogtreecommitdiffstats
path: root/chrome/browser/profiles
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/profiles')
-rw-r--r--chrome/browser/profiles/profile_manager.cc13
-rw-r--r--chrome/browser/profiles/profile_manager.h10
-rw-r--r--chrome/browser/profiles/startup_task_runner_service.cc30
-rw-r--r--chrome/browser/profiles/startup_task_runner_service.h45
-rw-r--r--chrome/browser/profiles/startup_task_runner_service_factory.cc33
-rw-r--r--chrome/browser/profiles/startup_task_runner_service_factory.h39
6 files changed, 166 insertions, 4 deletions
diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc
index e157d1f..ce4ff02 100644
--- a/chrome/browser/profiles/profile_manager.cc
+++ b/chrome/browser/profiles/profile_manager.cc
@@ -8,6 +8,7 @@
#include "base/bind.h"
#include "base/command_line.h"
+#include "base/deferred_sequenced_task_runner.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/metrics/histogram.h"
@@ -25,6 +26,8 @@
#include "chrome/browser/profiles/profile_destroyer.h"
#include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/profiles/profile_metrics.h"
+#include "chrome/browser/profiles/startup_task_runner_service.h"
+#include "chrome/browser/profiles/startup_task_runner_service_factory.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/browser.h"
@@ -847,6 +850,9 @@ void ProfileManager::DoFinalInitForServices(Profile* profile,
// initializing the managed flag if necessary).
ManagedUserServiceFactory::GetForProfile(profile)->Init();
#endif
+ // Start the deferred task runners once the profile is loaded.
+ StartupTaskRunnerServiceFactory::GetForProfile(profile)->
+ StartDeferredTaskRunners();
}
void ProfileManager::DoFinalInitLogging(Profile* profile) {
@@ -1173,12 +1179,17 @@ ProfileManagerWithoutInit::ProfileManagerWithoutInit(
}
void ProfileManager::RegisterTestingProfile(Profile* profile,
- bool add_to_cache) {
+ bool add_to_cache,
+ bool start_deferred_task_runners) {
RegisterProfile(profile, true);
if (add_to_cache) {
InitProfileUserPrefs(profile);
AddProfileToCache(profile);
}
+ if (start_deferred_task_runners) {
+ StartupTaskRunnerServiceFactory::GetForProfile(profile)->
+ StartDeferredTaskRunners();
+ }
}
void ProfileManager::RunCallbacks(const std::vector<CreateCallback>& callbacks,
diff --git a/chrome/browser/profiles/profile_manager.h b/chrome/browser/profiles/profile_manager.h
index a93d457..6cee37b8 100644
--- a/chrome/browser/profiles/profile_manager.h
+++ b/chrome/browser/profiles/profile_manager.h
@@ -211,10 +211,14 @@ class ProfileManager : public base::NonThreadSafe,
// Autoloads profiles if they are running background apps.
void AutoloadProfiles();
- // Register and add testing profile to the ProfileManager. Use ONLY in tests.
+ // Registers and adds testing profile to the ProfileManager.
// This allows the creation of Profiles outside of the standard creation path
- // for testing. If |addToCache|, add to ProfileInfoCache as well.
- void RegisterTestingProfile(Profile* profile, bool addToCache);
+ // for testing. If |addToCache|, adds to ProfileInfoCache as well.
+ // If |start_deferred_task_runners|, starts the deferred task runners.
+ // Use ONLY in tests.
+ void RegisterTestingProfile(Profile* profile,
+ bool addToCache,
+ bool start_deferred_task_runners);
const base::FilePath& user_data_dir() const { return user_data_dir_; }
diff --git a/chrome/browser/profiles/startup_task_runner_service.cc b/chrome/browser/profiles/startup_task_runner_service.cc
new file mode 100644
index 0000000..60407e1
--- /dev/null
+++ b/chrome/browser/profiles/startup_task_runner_service.cc
@@ -0,0 +1,30 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/profiles/startup_task_runner_service.h"
+
+#include "base/deferred_sequenced_task_runner.h"
+#include "base/logging.h"
+#include "chrome/browser/profiles/profile.h"
+
+StartupTaskRunnerService::StartupTaskRunnerService(Profile* profile)
+ : profile_(profile) {
+}
+
+StartupTaskRunnerService::~StartupTaskRunnerService() {
+}
+
+scoped_refptr<base::DeferredSequencedTaskRunner>
+ StartupTaskRunnerService::GetBookmarkTaskRunner() {
+ DCHECK(CalledOnValidThread());
+ if (!bookmark_task_runner_) {
+ bookmark_task_runner_ =
+ new base::DeferredSequencedTaskRunner(profile_->GetIOTaskRunner());
+ }
+ return bookmark_task_runner_;
+}
+
+void StartupTaskRunnerService::StartDeferredTaskRunners() {
+ GetBookmarkTaskRunner()->Start();
+}
diff --git a/chrome/browser/profiles/startup_task_runner_service.h b/chrome/browser/profiles/startup_task_runner_service.h
new file mode 100644
index 0000000..f6298a3
--- /dev/null
+++ b/chrome/browser/profiles/startup_task_runner_service.h
@@ -0,0 +1,45 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_PROFILES_STARTUP_TASK_RUNNER_SERVICE_H_
+#define CHROME_BROWSER_PROFILES_STARTUP_TASK_RUNNER_SERVICE_H_
+
+#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
+#include "base/threading/non_thread_safe.h"
+#include "chrome/browser/profiles/profile_keyed_service.h"
+
+class Profile;
+
+namespace base {
+class DeferredSequencedTaskRunner;
+} // namespace base
+
+// This service manages the startup task runners.
+class StartupTaskRunnerService : public base::NonThreadSafe,
+ public ProfileKeyedService {
+ public:
+ explicit StartupTaskRunnerService(Profile* profile);
+ virtual ~StartupTaskRunnerService();
+
+ // Returns sequenced task runner where all bookmarks I/O operations are
+ // performed.
+ // This method should only be called from the UI thread.
+ // Note: Using a separate task runner per profile service gives a better
+ // management of the sequence in which the task are started in order to avoid
+ // congestion during start-up (e.g the caller may decide to start loading the
+ // bookmarks only after the history finished).
+ scoped_refptr<base::DeferredSequencedTaskRunner> GetBookmarkTaskRunner();
+
+ // Starts the task runners that are deferred during start-up.
+ void StartDeferredTaskRunners();
+
+ private:
+ Profile* profile_;
+ scoped_refptr<base::DeferredSequencedTaskRunner> bookmark_task_runner_;
+
+ DISALLOW_COPY_AND_ASSIGN(StartupTaskRunnerService);
+};
+
+#endif // CHROME_BROWSER_PROFILES_STARTUP_TASK_RUNNER_SERVICE_H_
diff --git a/chrome/browser/profiles/startup_task_runner_service_factory.cc b/chrome/browser/profiles/startup_task_runner_service_factory.cc
new file mode 100644
index 0000000..eaff6a8
--- /dev/null
+++ b/chrome/browser/profiles/startup_task_runner_service_factory.cc
@@ -0,0 +1,33 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/profiles/startup_task_runner_service_factory.h"
+
+#include "chrome/browser/profiles/profile_dependency_manager.h"
+#include "chrome/browser/profiles/startup_task_runner_service.h"
+
+StartupTaskRunnerServiceFactory::StartupTaskRunnerServiceFactory()
+ : ProfileKeyedServiceFactory("StartupTaskRunnerServiceFactory",
+ ProfileDependencyManager::GetInstance()) {
+}
+
+StartupTaskRunnerServiceFactory::~StartupTaskRunnerServiceFactory() {}
+
+// static
+StartupTaskRunnerService* StartupTaskRunnerServiceFactory::GetForProfile(
+ Profile* profile) {
+ return static_cast<StartupTaskRunnerService*>(
+ GetInstance()->GetServiceForProfile(profile, true));
+}
+
+// static
+StartupTaskRunnerServiceFactory*
+ StartupTaskRunnerServiceFactory::GetInstance() {
+ return Singleton<StartupTaskRunnerServiceFactory>::get();
+}
+
+ProfileKeyedService* StartupTaskRunnerServiceFactory::BuildServiceInstanceFor(
+ Profile* profile) const {
+ return new StartupTaskRunnerService(profile);
+}
diff --git a/chrome/browser/profiles/startup_task_runner_service_factory.h b/chrome/browser/profiles/startup_task_runner_service_factory.h
new file mode 100644
index 0000000..58bb4db
--- /dev/null
+++ b/chrome/browser/profiles/startup_task_runner_service_factory.h
@@ -0,0 +1,39 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_PROFILES_STARTUP_TASK_RUNNER_SERVICE_FACTORY_H_
+#define CHROME_BROWSER_PROFILES_STARTUP_TASK_RUNNER_SERVICE_FACTORY_H_
+
+#include "base/basictypes.h"
+#include "base/memory/singleton.h"
+#include "chrome/browser/profiles/profile_keyed_service_factory.h"
+
+class StartupTaskRunnerService;
+class PrefRegistrySyncable;
+class Profile;
+
+// Singleton that owns the start-up task runner service.
+class StartupTaskRunnerServiceFactory : public ProfileKeyedServiceFactory {
+ public:
+ // Returns the instance of StartupTaskRunnerService associated with this
+ // profile (creating one if none exists).
+ static StartupTaskRunnerService* GetForProfile(Profile* profile);
+
+ // Returns an instance of the StartupTaskRunnerServiceFactory singleton.
+ static StartupTaskRunnerServiceFactory* GetInstance();
+
+ private:
+ friend struct DefaultSingletonTraits<StartupTaskRunnerServiceFactory>;
+
+ StartupTaskRunnerServiceFactory();
+ virtual ~StartupTaskRunnerServiceFactory();
+
+ // ProfileKeyedServiceFactory:
+ virtual ProfileKeyedService* BuildServiceInstanceFor(
+ Profile* profile) const OVERRIDE;
+
+ DISALLOW_COPY_AND_ASSIGN(StartupTaskRunnerServiceFactory);
+};
+
+#endif // CHROME_BROWSER_PROFILES_STARTUP_TASK_RUNNER_SERVICE_FACTORY_H_