diff options
author | rdsmith <rdsmith@chromium.org> | 2015-01-08 12:18:17 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-08 20:19:44 +0000 |
commit | a8a4e3c851d3e12ad27ac25493b6b690b867e39c (patch) | |
tree | 7022b0edeb8e2095afcd57873e0130e002876b55 /net/sdch/sdch_owner.h | |
parent | 9742c5d33b5a2d7378997f7990e3fc31f06c3ee8 (diff) | |
download | chromium_src-a8a4e3c851d3e12ad27ac25493b6b690b867e39c.zip chromium_src-a8a4e3c851d3e12ad27ac25493b6b690b867e39c.tar.gz chromium_src-a8a4e3c851d3e12ad27ac25493b6b690b867e39c.tar.bz2 |
Add an eviction mechanism for SDCH dictionaries.
Implemented policy:
* If space is needed for a newly loaded dictionary, evict any dictionaries
that haven't been used in a day to make room, oldest first.
* If the system signals memory pressure, flush all dictionaries.
Also moved chrome_sdch_policy.* -> net/sdch/sdch_owner.*.
BUG=387883
BUG=374916
Review URL: https://codereview.chromium.org/841883002
Cr-Commit-Position: refs/heads/master@{#310584}
Diffstat (limited to 'net/sdch/sdch_owner.h')
-rw-r--r-- | net/sdch/sdch_owner.h | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/net/sdch/sdch_owner.h b/net/sdch/sdch_owner.h new file mode 100644 index 0000000..9620326 --- /dev/null +++ b/net/sdch/sdch_owner.h @@ -0,0 +1,97 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_SDCH_SDCH_OWNER_H_ +#define NET_SDCH_SDCH_OWNER_H_ + +#include <string> + +#include "base/memory/memory_pressure_listener.h" +#include "net/base/sdch_observer.h" +#include "net/url_request/sdch_dictionary_fetcher.h" + +class GURL; + +namespace base { +class Clock; +} + +namespace net { +class SdchManager; +class URLRequestContext; + +// This class owns the SDCH objects not owned as part of URLRequestContext, and +// exposes interface for setting SDCH policy. It should be instantiated by +// the net/ embedder. +// TODO(rdsmith): Implement dictionary prioritization. +class NET_EXPORT SdchOwner : public net::SdchObserver { + public: + static const size_t kMaxTotalDictionarySize; + static const size_t kMinSpaceForDictionaryFetch; + + // Consumer must guarantee that |sdch_manager| and |context| outlive + // this object. + SdchOwner(net::SdchManager* sdch_manager, net::URLRequestContext* context); + ~SdchOwner() override; + + // Defaults to kMaxTotalDictionarySize. + void SetMaxTotalDictionarySize(size_t max_total_dictionary_size); + + // Defaults to kMinSpaceForDictionaryFetch. + void SetMinSpaceForDictionaryFetch(size_t min_space_for_dictionary_fetch); + + // SdchObserver implementation. + void OnDictionaryUsed(SdchManager* manager, + const std::string& server_hash) override; + void OnGetDictionary(net::SdchManager* manager, + const GURL& request_url, + const GURL& dictionary_url) override; + void OnClearDictionaries(net::SdchManager* manager) override; + + // Implementation detail--this is the pathway through which the + // fetcher informs the SdchOwner that it's gotten the dictionary. + // Public for testing. + void OnDictionaryFetched(const std::string& dictionary_text, + const GURL& dictionary_url, + const net::BoundNetLog& net_log); + + void SetClockForTesting(scoped_ptr<base::Clock> clock); + + private: + // For each active dictionary, stores local info. + // Indexed by server hash. + struct DictionaryInfo { + base::Time last_used; + int use_count; + size_t size; + + DictionaryInfo() : use_count(0), size(0) {} + DictionaryInfo(const base::Time& last_used, size_t size) + : last_used(last_used), use_count(0), size(size) {} + DictionaryInfo(const DictionaryInfo& rhs) = default; + DictionaryInfo& operator=(const DictionaryInfo& rhs) = default; + }; + + void OnMemoryPressure( + base::MemoryPressureListener::MemoryPressureLevel level); + + net::SdchManager* manager_; + net::SdchDictionaryFetcher fetcher_; + + std::map<std::string, DictionaryInfo> local_dictionary_info_; + size_t total_dictionary_bytes_; + + scoped_ptr<base::Clock> clock_; + + size_t max_total_dictionary_size_; + size_t min_space_for_dictionary_fetch_; + + base::MemoryPressureListener memory_pressure_listener_; + + DISALLOW_COPY_AND_ASSIGN(SdchOwner); +}; + +} // namespace net + +#endif // NET_SDCH_SDCH_OWNER_H_ |