Chromium Code Reviews| Index: chrome/browser/sync/profile_sync_service.cc |
| diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc |
| index 2ac3deed199641b1b73d1e363b6f6284ebfac33c..bf4600189a8021a1bb3d6946de7a15c6ee27ed12 100644 |
| --- a/chrome/browser/sync/profile_sync_service.cc |
| +++ b/chrome/browser/sync/profile_sync_service.cc |
| @@ -365,6 +365,8 @@ void ProfileSyncService::Initialize() { |
| DCHECK(!running_rollback); |
| #endif |
| + memory_pressure_listener_.reset(new base::MemoryPressureListener(base::Bind( |
| + &ProfileSyncService::OnMemoryPressure, weak_factory_.GetWeakPtr()))); |
| startup_controller_->Reset(GetRegisteredDataTypes()); |
| startup_controller_->TryStart(); |
| } |
| @@ -702,6 +704,8 @@ void ProfileSyncService::StartUpSlowBackendComponents( |
| InitializeBackend(ShouldDeleteSyncFolder()); |
| UpdateFirstSyncTimePref(); |
| + |
| + CheckPreviousShutdownMemoryWarning(); |
| } |
| void ProfileSyncService::OnGetTokenSuccess( |
| @@ -912,6 +916,8 @@ void ProfileSyncService::ShutdownImpl(syncer::ShutdownReason reason) { |
| UpdateAuthErrorState(GoogleServiceAuthError::AuthErrorNone()); |
| NotifyObservers(); |
| + |
| + sync_prefs_.SetCurrentShutdown(false); |
|
stanisc
2015/05/15 20:31:04
Please add comment explaining this.
Gang Wu
2015/05/15 21:13:46
Done.
|
| } |
| void ProfileSyncService::DisableForUser() { |
| @@ -2720,3 +2726,28 @@ void ProfileSyncService::RemoveClientFromServer() const { |
| access_token_, cache_guid, birthday); |
| } |
| } |
| + |
| +void ProfileSyncService::OnMemoryPressure( |
| + base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| + if (memory_pressure_level == |
| + base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
| + sync_prefs_.SetMemoryPressure(sync_prefs_.GetMemoryPressure() + 1); |
|
stanisc
2015/05/15 20:31:04
Looking at function names, GetMemoryPressure and S
Gang Wu
2015/05/15 21:13:46
Done.
|
| + } |
| +} |
| + |
| +void ProfileSyncService::CheckPreviousShutdownMemoryWarning() { |
| + int warning_received = sync_prefs_.GetMemoryPressure(); |
| + |
| + if (-1 != warning_received) { |
| + // -1 means it is new client |
|
stanisc
2015/05/15 20:31:04
Indent this comment and add "." at the end.
Gang Wu
2015/05/15 21:13:46
Done.
|
| + if (sync_prefs_.IsPreviousCrashed()) { |
| + UMA_HISTOGRAM_COUNTS("Sync.MemoryPressureWarningBeforeCrash", |
| + warning_received); |
| + } else { |
| + UMA_HISTOGRAM_COUNTS("Sync.MemoryPressureWarningwithoutCrash", |
|
stanisc
2015/05/15 20:31:04
without should start with capital W
Gang Wu
2015/05/15 21:13:46
Done.
|
| + warning_received); |
| + } |
| + } |
| + sync_prefs_.SetMemoryPressure(0); |
| + sync_prefs_.SetCurrentShutdown(true); |
| +} |