Commit 651a10b4 authored by hajimehoshi's avatar hajimehoshi Committed by Commit bot

Make SdchOwner a client of memory coordinator

When the memory coordinator is enabled, SdchOwner becomes a client of
the memory coordinator instead of installing MemoryPressureListener.

In the implmentation of this CL, both MemoryPressureListener and
MemoryCoordinatorClient are installed regardless of the flag, but as
default MemoryCoordinator is not enabled and when MemoryCoordinator is
enabled by a flag, it is planed to suppress MemoryPressureMonitor
features.

Design Doc: https://docs.google.com/document/d/1a69mMr7jI7qK0OfKNlrZ350xiXizVMCCe8orGX7K8Uo/edit?ts=57d7968b#

BUG=639700

Review-Url: https://codereview.chromium.org/2390603002
Cr-Commit-Position: refs/heads/master@{#422698}
parent e10e500b
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/debug/alias.h" #include "base/debug/alias.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/memory_coordinator_client_registry.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
...@@ -311,6 +312,7 @@ SdchOwner::SdchOwner(SdchManager* sdch_manager, URLRequestContext* context) ...@@ -311,6 +312,7 @@ SdchOwner::SdchOwner(SdchManager* sdch_manager, URLRequestContext* context)
creation_time_(clock_->Now()) { creation_time_(clock_->Now()) {
manager_->AddObserver(this); manager_->AddObserver(this);
InitializePrefStore(pref_store_); InitializePrefStore(pref_store_);
base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this);
} }
SdchOwner::~SdchOwner() { SdchOwner::~SdchOwner() {
...@@ -339,6 +341,7 @@ SdchOwner::~SdchOwner() { ...@@ -339,6 +341,7 @@ SdchOwner::~SdchOwner() {
val / object_lifetime); val / object_lifetime);
} }
} }
base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this);
} }
void SdchOwner::EnablePersistentStorage( void SdchOwner::EnablePersistentStorage(
...@@ -674,7 +677,28 @@ void SdchOwner::SetFetcherForTesting( ...@@ -674,7 +677,28 @@ void SdchOwner::SetFetcherForTesting(
void SdchOwner::OnMemoryPressure( void SdchOwner::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel level) { base::MemoryPressureListener::MemoryPressureLevel level) {
DCHECK_NE(base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE, 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(); for (DictionaryPreferenceIterator it(pref_store_); !it.IsAtEnd();
it.Advance()) { it.Advance()) {
int new_uses = it.use_count() - use_counts_at_load_[it.server_hash()]; int new_uses = it.use_count() - use_counts_at_load_[it.server_hash()];
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <string> #include <string>
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/memory_coordinator_client.h"
#include "base/memory/memory_pressure_listener.h" #include "base/memory/memory_pressure_listener.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "net/base/sdch_observer.h" #include "net/base/sdch_observer.h"
...@@ -32,7 +33,8 @@ class URLRequestContext; ...@@ -32,7 +33,8 @@ class URLRequestContext;
// exposes interface for setting SDCH policy. It should be instantiated by // exposes interface for setting SDCH policy. It should be instantiated by
// the net/ embedder. // the net/ embedder.
// TODO(rdsmith): Implement dictionary prioritization. // TODO(rdsmith): Implement dictionary prioritization.
class NET_EXPORT SdchOwner : public SdchObserver { class NET_EXPORT SdchOwner : public SdchObserver,
public base::MemoryCoordinatorClient {
public: public:
// Abstact storage interface for storing settings that allows the embedder // Abstact storage interface for storing settings that allows the embedder
// to provide the appropriate storage backend. // to provide the appropriate storage backend.
...@@ -157,9 +159,15 @@ class NET_EXPORT SdchOwner : public SdchObserver { ...@@ -157,9 +159,15 @@ class NET_EXPORT SdchOwner : public SdchObserver {
DictionaryInfo& operator=(const DictionaryInfo& rhs) = default; DictionaryInfo& operator=(const DictionaryInfo& rhs) = default;
}; };
// base::MemoryCoordinatorClient implementation:
void OnMemoryStateChange(base::MemoryState state) override;
void OnMemoryPressure( void OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel level); base::MemoryPressureListener::MemoryPressureLevel level);
// Clears data to save memory usage.
void ClearData();
// Schedule loading of all dictionaries described in |persisted_info|. // Schedule loading of all dictionaries described in |persisted_info|.
// Returns false and does not schedule a load if |persisted_info| has an // Returns false and does not schedule a load if |persisted_info| has an
// unsupported version or no dictionaries key. Skips any dictionaries that are // unsupported version or no dictionaries key. Skips any dictionaries that are
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment