Commit e10e500b authored by hajimehoshi's avatar hajimehoshi Committed by Commit bot

Make SSLClientSessionCache a client of memory coordinator

When the memory coordinator is enabled, SSLClientSessionCache 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/2384703002
Cr-Commit-Position: refs/heads/master@{#422697}
parent e37ae427
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <utility> #include <utility>
#include "base/memory/memory_coordinator_client_registry.h"
#include "base/time/clock.h" #include "base/time/clock.h"
#include "base/time/default_clock.h" #include "base/time/default_clock.h"
...@@ -18,10 +19,12 @@ SSLClientSessionCache::SSLClientSessionCache(const Config& config) ...@@ -18,10 +19,12 @@ SSLClientSessionCache::SSLClientSessionCache(const Config& config)
lookups_since_flush_(0) { lookups_since_flush_(0) {
memory_pressure_listener_.reset(new base::MemoryPressureListener(base::Bind( memory_pressure_listener_.reset(new base::MemoryPressureListener(base::Bind(
&SSLClientSessionCache::OnMemoryPressure, base::Unretained(this)))); &SSLClientSessionCache::OnMemoryPressure, base::Unretained(this))));
base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this);
} }
SSLClientSessionCache::~SSLClientSessionCache() { SSLClientSessionCache::~SSLClientSessionCache() {
Flush(); Flush();
base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this);
} }
size_t SSLClientSessionCache::size() const { size_t SSLClientSessionCache::size() const {
...@@ -112,4 +115,22 @@ void SSLClientSessionCache::OnMemoryPressure( ...@@ -112,4 +115,22 @@ void SSLClientSessionCache::OnMemoryPressure(
} }
} }
void SSLClientSessionCache::OnMemoryStateChange(base::MemoryState state) {
// TODO(hajimehoshi): When the state changes, adjust the sizes of the caches
// to reduce the limits. SSLClientSessionCache doesn't have the ability to
// limit at present.
switch (state) {
case base::MemoryState::NORMAL:
break;
case base::MemoryState::THROTTLED:
Flush();
break;
case base::MemoryState::SUSPENDED:
// Note: Not supported at present. Fall through.
case base::MemoryState::UNKNOWN:
NOTREACHED();
break;
}
}
} // namespace net } // namespace net
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/containers/mru_cache.h" #include "base/containers/mru_cache.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/memory_coordinator_client.h"
#include "base/memory/memory_pressure_monitor.h" #include "base/memory/memory_pressure_monitor.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
...@@ -27,7 +28,7 @@ class Clock; ...@@ -27,7 +28,7 @@ class Clock;
namespace net { namespace net {
class NET_EXPORT SSLClientSessionCache { class NET_EXPORT SSLClientSessionCache : public base::MemoryCoordinatorClient {
public: public:
struct Config { struct Config {
// The maximum number of entries in the cache. // The maximum number of entries in the cache.
...@@ -39,7 +40,7 @@ class NET_EXPORT SSLClientSessionCache { ...@@ -39,7 +40,7 @@ class NET_EXPORT SSLClientSessionCache {
}; };
explicit SSLClientSessionCache(const Config& config); explicit SSLClientSessionCache(const Config& config);
~SSLClientSessionCache(); ~SSLClientSessionCache() override;
size_t size() const; size_t size() const;
...@@ -70,6 +71,9 @@ class NET_EXPORT SSLClientSessionCache { ...@@ -70,6 +71,9 @@ class NET_EXPORT SSLClientSessionCache {
using CacheEntryMap = using CacheEntryMap =
base::HashingMRUCache<std::string, std::unique_ptr<CacheEntry>>; base::HashingMRUCache<std::string, std::unique_ptr<CacheEntry>>;
// base::MemoryCoordinatorClient implementation:
void OnMemoryStateChange(base::MemoryState state) override;
// Returns true if |entry| is expired as of |now|. // Returns true if |entry| is expired as of |now|.
bool IsExpired(CacheEntry* entry, const base::Time& now); bool IsExpired(CacheEntry* entry, const base::Time& now);
......
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