Commit ecb60945 authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Move the pref service from the IO thread to a task scheduler sequence.

Bug: 654988
Change-Id: I7f91eafc52aed40c8243e657b85c821605f9c76b
Reviewed-on: https://chromium-review.googlesource.com/526914Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#481028}
parent b74f9beb
...@@ -469,18 +469,14 @@ void BrowserProcessImpl::EndSession() { ...@@ -469,18 +469,14 @@ void BrowserProcessImpl::EndSession() {
ProfileManager* pm = profile_manager(); ProfileManager* pm = profile_manager();
std::vector<Profile*> profiles(pm->GetLoadedProfiles()); std::vector<Profile*> profiles(pm->GetLoadedProfiles());
scoped_refptr<RundownTaskCounter> rundown_counter(new RundownTaskCounter()); scoped_refptr<RundownTaskCounter> rundown_counter(new RundownTaskCounter());
const bool pref_service_enabled =
base::FeatureList::IsEnabled(features::kPrefService);
std::vector<scoped_refptr<base::SequencedTaskRunner>> profile_writer_runners; std::vector<scoped_refptr<base::SequencedTaskRunner>> profile_writer_runners;
for (size_t i = 0; i < profiles.size(); ++i) { for (size_t i = 0; i < profiles.size(); ++i) {
Profile* profile = profiles[i]; Profile* profile = profiles[i];
profile->SetExitType(Profile::EXIT_SESSION_ENDED); profile->SetExitType(Profile::EXIT_SESSION_ENDED);
if (profile->GetPrefs()) { if (profile->GetPrefs()) {
profile->GetPrefs()->CommitPendingWrite(); profile->GetPrefs()->CommitPendingWrite();
if (pref_service_enabled) { if (profile->GetPrefServiceTaskRunner()) {
rundown_counter->Post(content::BrowserThread::GetTaskRunnerForThread( rundown_counter->Post(profile->GetPrefServiceTaskRunner().get());
content::BrowserThread::IO)
.get());
profile_writer_runners.push_back(profile->GetIOTaskRunner()); profile_writer_runners.push_back(profile->GetIOTaskRunner());
} else { } else {
rundown_counter->Post(profile->GetIOTaskRunner().get()); rundown_counter->Post(profile->GetIOTaskRunner().get());
...@@ -527,7 +523,7 @@ void BrowserProcessImpl::EndSession() { ...@@ -527,7 +523,7 @@ void BrowserProcessImpl::EndSession() {
// http://crbug.com/318527. // http://crbug.com/318527.
const base::TimeTicks end_time = base::TimeTicks::Now() + kEndSessionTimeout; const base::TimeTicks end_time = base::TimeTicks::Now() + kEndSessionTimeout;
const bool timed_out = !rundown_counter->TimedWaitUntil(end_time); const bool timed_out = !rundown_counter->TimedWaitUntil(end_time);
if (timed_out || !pref_service_enabled) if (timed_out || !base::FeatureList::IsEnabled(features::kPrefService))
return; return;
scoped_refptr<RundownTaskCounter> profile_write_rundown_counter( scoped_refptr<RundownTaskCounter> profile_write_rundown_counter(
......
...@@ -387,8 +387,10 @@ void OffTheRecordProfileImpl::RegisterInProcessServices( ...@@ -387,8 +387,10 @@ void OffTheRecordProfileImpl::RegisterInProcessServices(
info.factory = base::Bind( info.factory = base::Bind(
&prefs::CreatePrefService, chrome::ExpectedPrefStores(), &prefs::CreatePrefService, chrome::ExpectedPrefStores(),
make_scoped_refptr(content::BrowserThread::GetBlockingPool())); make_scoped_refptr(content::BrowserThread::GetBlockingPool()));
info.task_runner = content::BrowserThread::GetTaskRunnerForThread( info.task_runner = base::CreateSequencedTaskRunnerWithTraits(
content::BrowserThread::IO); {base::TaskShutdownBehavior::BLOCK_SHUTDOWN,
base::TaskPriority::USER_VISIBLE});
pref_service_task_runner_ = info.task_runner;
services->insert(std::make_pair(prefs::mojom::kServiceName, info)); services->insert(std::make_pair(prefs::mojom::kServiceName, info));
} }
} }
...@@ -499,6 +501,11 @@ Profile::ExitType OffTheRecordProfileImpl::GetLastSessionExitType() { ...@@ -499,6 +501,11 @@ Profile::ExitType OffTheRecordProfileImpl::GetLastSessionExitType() {
return profile_->GetLastSessionExitType(); return profile_->GetLastSessionExitType();
} }
scoped_refptr<base::SequencedTaskRunner>
OffTheRecordProfileImpl::GetPrefServiceTaskRunner() {
return pref_service_task_runner_;
}
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
void OffTheRecordProfileImpl::ChangeAppLocale(const std::string& locale, void OffTheRecordProfileImpl::ChangeAppLocale(const std::string& locale,
AppLocaleChangedVia) { AppLocaleChangedVia) {
......
...@@ -80,6 +80,7 @@ class OffTheRecordProfileImpl : public Profile { ...@@ -80,6 +80,7 @@ class OffTheRecordProfileImpl : public Profile {
bool WasCreatedByVersionOrLater(const std::string& version) override; bool WasCreatedByVersionOrLater(const std::string& version) override;
void SetExitType(ExitType exit_type) override; void SetExitType(ExitType exit_type) override;
ExitType GetLastSessionExitType() override; ExitType GetLastSessionExitType() override;
scoped_refptr<base::SequencedTaskRunner> GetPrefServiceTaskRunner() override;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
void ChangeAppLocale(const std::string& locale, AppLocaleChangedVia) override; void ChangeAppLocale(const std::string& locale, AppLocaleChangedVia) override;
...@@ -139,6 +140,7 @@ class OffTheRecordProfileImpl : public Profile { ...@@ -139,6 +140,7 @@ class OffTheRecordProfileImpl : public Profile {
Profile* profile_; Profile* profile_;
std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs_; std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs_;
scoped_refptr<base::SequencedTaskRunner> pref_service_task_runner_;
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
std::unique_ptr<content::HostZoomMap::Subscription> track_zoom_subscription_; std::unique_ptr<content::HostZoomMap::Subscription> track_zoom_subscription_;
......
...@@ -303,6 +303,10 @@ class Profile : public content::BrowserContext { ...@@ -303,6 +303,10 @@ class Profile : public content::BrowserContext {
// Returns how the last session was shutdown. // Returns how the last session was shutdown.
virtual ExitType GetLastSessionExitType() = 0; virtual ExitType GetLastSessionExitType() = 0;
// Returns the SequencedTaskRunner the pref service runs on.
virtual scoped_refptr<base::SequencedTaskRunner>
GetPrefServiceTaskRunner() = 0;
// Stop sending accessibility events until ResumeAccessibilityEvents(). // Stop sending accessibility events until ResumeAccessibilityEvents().
// Calls to Pause nest; no events will be sent until the number of // Calls to Pause nest; no events will be sent until the number of
// Resume calls matches the number of Pause calls received. // Resume calls matches the number of Pause calls received.
......
...@@ -715,9 +715,7 @@ IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ...@@ -715,9 +715,7 @@ IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
profile->SetExitType(Profile::EXIT_CRASHED); profile->SetExitType(Profile::EXIT_CRASHED);
profile->GetPrefs()->CommitPendingWrite(); profile->GetPrefs()->CommitPendingWrite();
if (base::FeatureList::IsEnabled(features::kPrefService)) { if (base::FeatureList::IsEnabled(features::kPrefService)) {
FlushTaskRunner(content::BrowserThread::GetTaskRunnerForThread( FlushTaskRunner(profile->GetPrefServiceTaskRunner().get());
content::BrowserThread::IO)
.get());
} }
FlushTaskRunner(profile->GetIOTaskRunner().get()); FlushTaskRunner(profile->GetIOTaskRunner().get());
......
...@@ -979,6 +979,11 @@ Profile::ExitType ProfileImpl::GetLastSessionExitType() { ...@@ -979,6 +979,11 @@ Profile::ExitType ProfileImpl::GetLastSessionExitType() {
return last_session_exit_type_; return last_session_exit_type_;
} }
scoped_refptr<base::SequencedTaskRunner>
ProfileImpl::GetPrefServiceTaskRunner() {
return pref_service_task_runner_;
}
PrefService* ProfileImpl::GetPrefs() { PrefService* ProfileImpl::GetPrefs() {
return const_cast<PrefService*>( return const_cast<PrefService*>(
static_cast<const ProfileImpl*>(this)->GetPrefs()); static_cast<const ProfileImpl*>(this)->GetPrefs());
...@@ -1126,8 +1131,10 @@ void ProfileImpl::RegisterInProcessServices(StaticServiceMap* services) { ...@@ -1126,8 +1131,10 @@ void ProfileImpl::RegisterInProcessServices(StaticServiceMap* services) {
info.factory = base::Bind( info.factory = base::Bind(
&prefs::CreatePrefService, chrome::ExpectedPrefStores(), &prefs::CreatePrefService, chrome::ExpectedPrefStores(),
make_scoped_refptr(content::BrowserThread::GetBlockingPool())); make_scoped_refptr(content::BrowserThread::GetBlockingPool()));
info.task_runner = content::BrowserThread::GetTaskRunnerForThread( info.task_runner = base::CreateSequencedTaskRunnerWithTraits(
content::BrowserThread::IO); {base::TaskShutdownBehavior::BLOCK_SHUTDOWN,
base::TaskPriority::USER_VISIBLE});
pref_service_task_runner_ = info.task_runner;
services->insert(std::make_pair(prefs::mojom::kServiceName, info)); services->insert(std::make_pair(prefs::mojom::kServiceName, info));
} }
......
...@@ -145,6 +145,7 @@ class ProfileImpl : public Profile { ...@@ -145,6 +145,7 @@ class ProfileImpl : public Profile {
bool WasCreatedByVersionOrLater(const std::string& version) override; bool WasCreatedByVersionOrLater(const std::string& version) override;
void SetExitType(ExitType exit_type) override; void SetExitType(ExitType exit_type) override;
ExitType GetLastSessionExitType() override; ExitType GetLastSessionExitType() override;
scoped_refptr<base::SequencedTaskRunner> GetPrefServiceTaskRunner() override;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
void ChangeAppLocale(const std::string& locale, AppLocaleChangedVia) override; void ChangeAppLocale(const std::string& locale, AppLocaleChangedVia) override;
...@@ -233,6 +234,7 @@ class ProfileImpl : public Profile { ...@@ -233,6 +234,7 @@ class ProfileImpl : public Profile {
// first. // first.
scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_; scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_;
std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs_; std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs_;
scoped_refptr<base::SequencedTaskRunner> pref_service_task_runner_;
// See comment in GetOffTheRecordPrefs. Field exists so something owns the // See comment in GetOffTheRecordPrefs. Field exists so something owns the
// dummy. // dummy.
std::unique_ptr<sync_preferences::PrefServiceSyncable> dummy_otr_prefs_; std::unique_ptr<sync_preferences::PrefServiceSyncable> dummy_otr_prefs_;
......
...@@ -210,3 +210,9 @@ void FakeProfile::SetExitType(ExitType exit_type) { ...@@ -210,3 +210,9 @@ void FakeProfile::SetExitType(ExitType exit_type) {
Profile::ExitType FakeProfile::GetLastSessionExitType() { Profile::ExitType FakeProfile::GetLastSessionExitType() {
return EXIT_NORMAL; return EXIT_NORMAL;
} }
scoped_refptr<base::SequencedTaskRunner>
FakeProfile::GetPrefServiceTaskRunner() {
NOTIMPLEMENTED();
return nullptr;
}
...@@ -94,6 +94,7 @@ class FakeProfile : public Profile { ...@@ -94,6 +94,7 @@ class FakeProfile : public Profile {
bool WasCreatedByVersionOrLater(const std::string& version) override; bool WasCreatedByVersionOrLater(const std::string& version) override;
void SetExitType(ExitType exit_type) override; void SetExitType(ExitType exit_type) override;
ExitType GetLastSessionExitType() override; ExitType GetLastSessionExitType() override;
scoped_refptr<base::SequencedTaskRunner> GetPrefServiceTaskRunner() override;
private: private:
std::string name_; std::string name_;
......
...@@ -1050,6 +1050,12 @@ Profile::ExitType TestingProfile::GetLastSessionExitType() { ...@@ -1050,6 +1050,12 @@ Profile::ExitType TestingProfile::GetLastSessionExitType() {
return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED; return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED;
} }
scoped_refptr<base::SequencedTaskRunner>
TestingProfile::GetPrefServiceTaskRunner() {
NOTIMPLEMENTED();
return nullptr;
}
TestingProfile::Builder::Builder() TestingProfile::Builder::Builder()
: build_called_(false), : build_called_(false),
delegate_(NULL), delegate_(NULL),
......
...@@ -327,6 +327,7 @@ class TestingProfile : public Profile { ...@@ -327,6 +327,7 @@ class TestingProfile : public Profile {
bool IsGuestSession() const override; bool IsGuestSession() const override;
void SetExitType(ExitType exit_type) override {} void SetExitType(ExitType exit_type) override {}
ExitType GetLastSessionExitType() override; ExitType GetLastSessionExitType() override;
scoped_refptr<base::SequencedTaskRunner> GetPrefServiceTaskRunner() override;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
void ChangeAppLocale(const std::string&, AppLocaleChangedVia) override {} void ChangeAppLocale(const std::string&, AppLocaleChangedVia) override {}
void OnLogin() override {} void OnLogin() override {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment