Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Unified Diff: components/browser_sync/profile_sync_service.cc

Issue 2385083002: Make ProfileSyncService a client of memory coordinator (Closed)
Patch Set: (rebasing) Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/browser_sync/profile_sync_service.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
« no previous file with comments | « components/browser_sync/profile_sync_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698