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

Unified Diff: net/sdch/sdch_owner.cc

Issue 2390603002: Make SdchOwner a client of memory coordinator (Closed)
Patch Set: Fix comments 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 | « net/sdch/sdch_owner.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/sdch/sdch_owner.cc
diff --git a/net/sdch/sdch_owner.cc b/net/sdch/sdch_owner.cc
index c7fca71f2b2a8bc888dc3bdc0a9562d69476b285..94a725f11df8daed172869a1172a0d3b443ff6e3 100644
--- a/net/sdch/sdch_owner.cc
+++ b/net/sdch/sdch_owner.cc
@@ -10,6 +10,7 @@
#include "base/debug/alias.h"
#include "base/logging.h"
#include "base/macros.h"
+#include "base/memory/memory_coordinator_client_registry.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_util.h"
@@ -310,6 +311,7 @@ SdchOwner::SdchOwner(SdchManager* sdch_manager, URLRequestContext* context)
creation_time_(clock_->Now()) {
manager_->AddObserver(this);
InitializePrefStore(pref_store_);
+ base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this);
}
SdchOwner::~SdchOwner() {
@@ -338,6 +340,7 @@ SdchOwner::~SdchOwner() {
val / object_lifetime);
}
}
+ base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this);
}
void SdchOwner::EnablePersistentStorage(
@@ -673,7 +676,28 @@ void SdchOwner::SetFetcherForTesting(
void SdchOwner::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel level) {
DCHECK_NE(base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE, level);
+ ClearData();
+}
+
+void SdchOwner::OnMemoryStateChange(base::MemoryState state) {
+ // TODO(hajimehoshi): When the state changes, adjust the sizes of the caches
+ // to reduce the limits. SdchOwner doesn't have the ability to limit at
+ // present.
+ switch (state) {
+ case base::MemoryState::NORMAL:
+ break;
+ case base::MemoryState::THROTTLED:
+ ClearData();
+ break;
+ case base::MemoryState::SUSPENDED:
+ // Note: Not supported at present. Fall through.
+ case base::MemoryState::UNKNOWN:
+ NOTREACHED();
+ break;
+ }
+}
+void SdchOwner::ClearData() {
for (DictionaryPreferenceIterator it(pref_store_); !it.IsAtEnd();
it.Advance()) {
int new_uses = it.use_count() - use_counts_at_load_[it.server_hash()];
« no previous file with comments | « net/sdch/sdch_owner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698