diff options
Diffstat (limited to 'chrome/browser')
13 files changed, 188 insertions, 12 deletions
diff --git a/chrome/browser/bookmarks/DEPS b/chrome/browser/bookmarks/DEPS index 104e900..4c3d5ac 100644 --- a/chrome/browser/bookmarks/DEPS +++ b/chrome/browser/bookmarks/DEPS @@ -22,6 +22,8 @@ include_rules = [ "!chrome/browser/profiles/profile_dependency_manager.h", "!chrome/browser/profiles/profile_keyed_service.h", "!chrome/browser/profiles/profile_keyed_service_factory.h", + "!chrome/browser/profiles/startup_task_runner_service.h", + "!chrome/browser/profiles/startup_task_runner_service_factory.h", # Do not add to the list of temporarily-allowed dependencies above, # and please do not introduce more #includes of these files. ] diff --git a/chrome/browser/bookmarks/bookmark_model.cc b/chrome/browser/bookmarks/bookmark_model.cc index 150afd4..d23f645 100644 --- a/chrome/browser/bookmarks/bookmark_model.cc +++ b/chrome/browser/bookmarks/bookmark_model.cc @@ -232,7 +232,8 @@ void BookmarkModel::Shutdown() { loaded_signal_.Signal(); } -void BookmarkModel::Load() { +void BookmarkModel::Load( + const scoped_refptr<base::SequencedTaskRunner>& task_runner) { if (store_.get()) { // If the store is non-null, it means Load was already invoked. Load should // only be invoked once. @@ -249,7 +250,7 @@ void BookmarkModel::Load() { content::Source<Profile>(profile_)); // Load the bookmarks. BookmarkStorage notifies us when done. - store_ = new BookmarkStorage(profile_, this, profile_->GetIOTaskRunner()); + store_ = new BookmarkStorage(profile_, this, task_runner); store_->LoadBookmarks(CreateLoadDetails()); } diff --git a/chrome/browser/bookmarks/bookmark_model.h b/chrome/browser/bookmarks/bookmark_model.h index 1d846d7..9853d38 100644 --- a/chrome/browser/bookmarks/bookmark_model.h +++ b/chrome/browser/bookmarks/bookmark_model.h @@ -33,6 +33,10 @@ class BookmarkModelObserver; class BookmarkStorage; class Profile; +namespace base { +class SequencedTaskRunner; +} + namespace bookmark_utils { struct TitleMatch; } @@ -236,7 +240,8 @@ class BookmarkModel : public content::NotificationObserver, // Loads the bookmarks. This is called upon creation of the // BookmarkModel. You need not invoke this directly. - void Load(); + // All load operations will be executed on |task_runner|. + void Load(const scoped_refptr<base::SequencedTaskRunner>& task_runner); // Returns true if the model finished loading. // This is virtual so it can be mocked. diff --git a/chrome/browser/bookmarks/bookmark_model_factory.cc b/chrome/browser/bookmarks/bookmark_model_factory.cc index 1f63b6d..73da8cb 100644 --- a/chrome/browser/bookmarks/bookmark_model_factory.cc +++ b/chrome/browser/bookmarks/bookmark_model_factory.cc @@ -4,11 +4,14 @@ #include "chrome/browser/bookmarks/bookmark_model_factory.h" +#include "base/deferred_sequenced_task_runner.h" #include "base/memory/singleton.h" #include "base/values.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_dependency_manager.h" +#include "chrome/browser/profiles/startup_task_runner_service.h" +#include "chrome/browser/profiles/startup_task_runner_service_factory.h" #include "chrome/common/pref_names.h" #include "components/user_prefs/pref_registry_syncable.h" @@ -38,7 +41,8 @@ BookmarkModelFactory::~BookmarkModelFactory() {} ProfileKeyedService* BookmarkModelFactory::BuildServiceInstanceFor( Profile* profile) const { BookmarkModel* bookmark_model = new BookmarkModel(profile); - bookmark_model->Load(); + bookmark_model->Load(StartupTaskRunnerServiceFactory::GetForProfile(profile)-> + GetBookmarkTaskRunner()); return bookmark_model; } 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_ diff --git a/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc b/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc index bfa351b..3f3e27b 100644 --- a/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc @@ -56,7 +56,7 @@ class HistoryMock : public HistoryService { ProfileKeyedService* BuildBookmarkModel(Profile* profile) { BookmarkModel* bookmark_model = new BookmarkModel(profile); - bookmark_model->Load(); + bookmark_model->Load(profile->GetIOTaskRunner()); return bookmark_model; } @@ -177,7 +177,7 @@ TEST_F(SyncBookmarkDataTypeControllerTest, StartBookmarkModelNotReady) { base::Unretained(&model_load_callback_))); EXPECT_EQ(DataTypeController::MODEL_STARTING, bookmark_dtc_->state()); - bookmark_model_->Load(); + bookmark_model_->Load(profile_.GetIOTaskRunner()); ui_test_utils::WaitForBookmarkModelToLoad(bookmark_model_); EXPECT_EQ(DataTypeController::MODEL_LOADED, bookmark_dtc_->state()); diff --git a/chrome/browser/sync/test/integration/sync_test.cc b/chrome/browser/sync/test/integration/sync_test.cc index fbe9500..d2facba 100644 --- a/chrome/browser/sync/test/integration/sync_test.cc +++ b/chrome/browser/sync/test/integration/sync_test.cc @@ -231,7 +231,9 @@ Profile* SyncTest::MakeProfile(const base::FilePath::StringType name) { Profile* profile = Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); - g_browser_process->profile_manager()->RegisterTestingProfile(profile, true); + g_browser_process->profile_manager()->RegisterTestingProfile(profile, + true, + true); return profile; } diff --git a/chrome/browser/ui/views/avatar_menu_button_browsertest.cc b/chrome/browser/ui/views/avatar_menu_button_browsertest.cc index ca14d6e..498919c 100644 --- a/chrome/browser/ui/views/avatar_menu_button_browsertest.cc +++ b/chrome/browser/ui/views/avatar_menu_button_browsertest.cc @@ -25,7 +25,7 @@ void CreateTestingProfile() { CHECK(file_util::CreateDirectory(path)); Profile* profile = Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); - profile_manager->RegisterTestingProfile(profile, true); + profile_manager->RegisterTestingProfile(profile, true, false); EXPECT_EQ(2u, profile_manager->GetNumberOfProfiles()); } |