Chromium Code Reviews| Index: components/browser_sync/profile_sync_service.cc |
| diff --git a/components/browser_sync/profile_sync_service.cc b/components/browser_sync/profile_sync_service.cc |
| index 0b9152f3ca5e0f83cbf97a5e9fe344a67dbaac3c..f127e2ffca21796fd68e60d61b7c3a6171dc07f2 100644 |
| --- a/components/browser_sync/profile_sync_service.cc |
| +++ b/components/browser_sync/profile_sync_service.cc |
| @@ -16,6 +16,7 @@ |
| #include "base/feature_list.h" |
| #include "base/files/file_util.h" |
| #include "base/logging.h" |
| +#include "base/memory/memory_coordinator_client_registry.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/metrics/histogram.h" |
| @@ -239,6 +240,8 @@ ProfileSyncService::ProfileSyncService(InitParams init_params) |
| current_version.substr(0, current_version.find('.'))) { |
| passphrase_prompt_triggered_by_version_ = true; |
| } |
| + |
| + base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); |
| } |
| ProfileSyncService::~ProfileSyncService() { |
| @@ -247,6 +250,7 @@ ProfileSyncService::~ProfileSyncService() { |
| sync_prefs_.RemoveSyncPrefObserver(this); |
| // Shutdown() should have been called before destruction. |
| CHECK(!backend_initialized_); |
| + base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this); |
| } |
| bool ProfileSyncService::CanSyncStart() const { |
| @@ -2445,11 +2449,33 @@ void ProfileSyncService::OnMemoryPressure( |
| base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| if (memory_pressure_level == |
| base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
| - sync_prefs_.SetMemoryPressureWarningCount( |
| - sync_prefs_.GetMemoryPressureWarningCount() + 1); |
| + IncrementMemoryPressureWarningCount(); |
| + } |
| +} |
| + |
| +void ProfileSyncService::OnMemoryStateChange(base::MemoryState state) { |
| + // TODO(hajimehoshi): Adjust the size of this memory usage according to |
| + // |state|. ProfileSyncService doesn't have a feature to limit memory usage at |
| + // present. |
| + switch (state) { |
| + case base::MemoryState::NORMAL: |
| + break; |
| + case base::MemoryState::THROTTLED: |
| + IncrementMemoryPressureWarningCount(); |
| + break; |
| + case base::MemoryState::SUSPENDED: |
| + // Note: Not supported at present. Fall through. |
| + case base::MemoryState::UNKNOWN: |
| + NOTREACHED(); |
| + break; |
| } |
| } |
| +void ProfileSyncService::IncrementMemoryPressureWarningCount() { |
| + sync_prefs_.SetMemoryPressureWarningCount( |
| + sync_prefs_.GetMemoryPressureWarningCount() + 1); |
|
bashi
2016/10/03 23:26:53
Do we use the warning count to change behavior of
|
| +} |
| + |
| void ProfileSyncService::ReportPreviousSessionMemoryWarningCount() { |
| int warning_received = sync_prefs_.GetMemoryPressureWarningCount(); |