Index: chrome/browser/browser_process_impl.cc |
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc |
index be342085d4c81cde97e4375b29079b4685152651..8d3d31874381317eb4ceef46c32ca3412137f5b7 100644 |
--- a/chrome/browser/browser_process_impl.cc |
+++ b/chrome/browser/browser_process_impl.cc |
@@ -76,6 +76,7 @@ |
#include "chrome/browser/update_client/chrome_update_query_params_delegate.h" |
#include "chrome/common/channel_info.h" |
#include "chrome/common/chrome_constants.h" |
+#include "chrome/common/chrome_features.h" |
#include "chrome/common/chrome_paths.h" |
#include "chrome/common/chrome_switches.h" |
#include "chrome/common/crash_keys.h" |
@@ -139,6 +140,7 @@ |
#endif |
#if !defined(OS_ANDROID) |
+#include "chrome/browser/features.h" |
#include "chrome/browser/gcm/gcm_product_util.h" |
#include "chrome/browser/lifetime/keep_alive_registry.h" |
#include "chrome/browser/ui/user_manager.h" |
@@ -194,7 +196,8 @@ static const int kUpdateCheckIntervalHours = 6; |
// and Windows. We have a timeout here because we're unable to run the UI |
// messageloop and there's some deadlock risk. Our only option is to exit |
// anyway. |
-static const int kEndSessionTimeoutSeconds = 10; |
+static constexpr base::TimeDelta kEndSessionTimeout = |
+ base::TimeDelta::FromSeconds(10); |
#endif |
using content::BrowserThread; |
@@ -467,12 +470,22 @@ void BrowserProcessImpl::EndSession() { |
ProfileManager* pm = profile_manager(); |
std::vector<Profile*> profiles(pm->GetLoadedProfiles()); |
scoped_refptr<RundownTaskCounter> rundown_counter(new RundownTaskCounter()); |
+ const bool kEnablePrefService = |
+ base::FeatureList::IsEnabled(features::kPrefService); |
+ std::vector<scoped_refptr<base::SequencedTaskRunner>> profile_writer_runners; |
for (size_t i = 0; i < profiles.size(); ++i) { |
Profile* profile = profiles[i]; |
profile->SetExitType(Profile::EXIT_SESSION_ENDED); |
if (profile->GetPrefs()) { |
profile->GetPrefs()->CommitPendingWrite(); |
- rundown_counter->Post(profile->GetIOTaskRunner().get()); |
+ if (kEnablePrefService) { |
+ rundown_counter->Post(content::BrowserThread::GetTaskRunnerForThread( |
+ content::BrowserThread::IO) |
+ .get()); |
+ profile_writer_runners.push_back(profile->GetIOTaskRunner()); |
+ } else { |
+ rundown_counter->Post(profile->GetIOTaskRunner().get()); |
+ } |
} |
} |
@@ -513,8 +526,16 @@ void BrowserProcessImpl::EndSession() { |
// GPU process synchronously. Because the system may not be allowing |
// processes to launch, this can result in a hang. See |
// http://crbug.com/318527. |
- rundown_counter->TimedWait( |
- base::TimeDelta::FromSeconds(kEndSessionTimeoutSeconds)); |
+ base::Time start = base::Time::Now(); |
+ if (rundown_counter->TimedWait(kEndSessionTimeout) && kEnablePrefService) { |
+ scoped_refptr<RundownTaskCounter> profile_write_rundown_counter( |
+ new RundownTaskCounter()); |
+ for (auto& profile_writer_runner : profile_writer_runners) { |
+ profile_write_rundown_counter->Post(profile_writer_runner.get()); |
+ } |
+ profile_write_rundown_counter->TimedWait(kEndSessionTimeout - |
+ (base::Time::Now() - start)); |
+ } |
#else |
NOTIMPLEMENTED(); |
#endif |
@@ -1345,6 +1366,19 @@ void BrowserProcessImpl::Unpin() { |
CHECK(base::MessageLoop::current()->is_running()); |
+ if (base::FeatureList::IsEnabled(features::kPrefService)) { |
+ bool fast_shutdown_enabled = |
+#if !defined(OS_ANDROID) |
+ base::FeatureList::IsEnabled(features::kDesktopFastShutdown); |
+#else |
+ false; |
+#endif |
+ for (auto* profile : profile_manager()->GetLoadedProfiles()) { |
+ profile->SetExitType(fast_shutdown_enabled ? Profile::EXIT_SESSION_ENDED |
+ : Profile::EXIT_NORMAL); |
+ } |
+ } |
+ |
#if defined(OS_MACOSX) |
base::ThreadTaskRunnerHandle::Get()->PostTask( |
FROM_HERE, base::Bind(ChromeBrowserMainPartsMac::DidEndMainMessageLoop)); |