| Index: net/sdch/sdch_owner.h
|
| diff --git a/net/sdch/sdch_owner.h b/net/sdch/sdch_owner.h
|
| index e75c780fc7e6b2a7ce57230eb32e25889e2c82c4..a187a6e0b56c3d2cb5ed0afdc1fdceee18693e75 100644
|
| --- a/net/sdch/sdch_owner.h
|
| +++ b/net/sdch/sdch_owner.h
|
| @@ -5,13 +5,19 @@
|
| #ifndef NET_SDCH_SDCH_OWNER_H_
|
| #define NET_SDCH_SDCH_OWNER_H_
|
|
|
| +#include <map>
|
| #include <string>
|
|
|
| #include "base/memory/memory_pressure_listener.h"
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/prefs/pref_store.h"
|
| #include "net/base/sdch_observer.h"
|
| #include "net/url_request/sdch_dictionary_fetcher.h"
|
|
|
| class GURL;
|
| +class PersistentPrefStore;
|
| +class ValueMapPrefStore;
|
| +class WriteablePrefStore;
|
|
|
| namespace base {
|
| class Clock;
|
| @@ -25,7 +31,8 @@ class URLRequestContext;
|
| // 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 {
|
| +class NET_EXPORT SdchOwner : public net::SdchObserver,
|
| + public PrefStore::Observer {
|
| public:
|
| static const size_t kMaxTotalDictionarySize;
|
| static const size_t kMinSpaceForDictionaryFetch;
|
| @@ -35,6 +42,13 @@ class NET_EXPORT SdchOwner : public net::SdchObserver {
|
| SdchOwner(net::SdchManager* sdch_manager, net::URLRequestContext* context);
|
| ~SdchOwner() override;
|
|
|
| + // Enables use of pref persistence. Note that |pref_store| is owned
|
| + // by the caller, but must be guaranteed to outlive SdchOwner. The
|
| + // actual mechanisms by which the PersistentPrefStore are persisted
|
| + // are the responsibility of the caller. This routine may only be
|
| + // called once per SdchOwner instance.
|
| + void EnablePersistentStorage(PersistentPrefStore* pref_store);
|
| +
|
| // Defaults to kMaxTotalDictionarySize.
|
| void SetMaxTotalDictionarySize(size_t max_total_dictionary_size);
|
|
|
| @@ -49,18 +63,34 @@ class NET_EXPORT SdchOwner : public net::SdchObserver {
|
| 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.
|
| + // PrefStore::Observer implementation.
|
| + void OnPrefValueChanged(const std::string& key) override;
|
| + void OnInitializationCompleted(bool succeeded) override;
|
| +
|
| + // Implementation detail--this is the function callback by the callback
|
| + // passed to the fetcher through which the fetcher informs the SdchOwner
|
| + // that it's gotten the dictionary. The first two arguments are
|
| + // bound locally.
|
| // Public for testing.
|
| - void OnDictionaryFetched(const std::string& dictionary_text,
|
| + void OnDictionaryFetched(base::Time last_used,
|
| + int use_count,
|
| + const std::string& dictionary_text,
|
| const GURL& dictionary_url,
|
| const net::BoundNetLog& net_log);
|
|
|
| void SetClockForTesting(scoped_ptr<base::Clock> clock);
|
|
|
| + // Returns the total number of dictionaries loaded.
|
| + int GetDictionaryCountForTesting() const;
|
| +
|
| + // Returns whether this SdchOwner has dictionary from |url| loaded.
|
| + bool HasDictionaryFromURLForTesting(const GURL& url) const;
|
| +
|
| + void SetFetcherForTesting(scoped_ptr<SdchDictionaryFetcher> fetcher);
|
| +
|
| private:
|
| // For each active dictionary, stores local info.
|
| - // Indexed by server hash.
|
| + // Indexed by the server hash of the dictionary.
|
| struct DictionaryInfo {
|
| base::Time last_used;
|
| int use_count;
|
| @@ -76,10 +106,18 @@ class NET_EXPORT SdchOwner : public net::SdchObserver {
|
| void OnMemoryPressure(
|
| base::MemoryPressureListener::MemoryPressureLevel level);
|
|
|
| + // Schedule loading of all dictionaries described in |persisted_info|.
|
| + // Returns false and does not schedule a load if |persisted_info| has an
|
| + // unsupported version or no dictionaries key. Skips any dictionaries that are
|
| + // malformed in |persisted_info|.
|
| + bool SchedulePersistedDictionaryLoads(
|
| + const base::DictionaryValue& persisted_info);
|
| +
|
| + bool IsPersistingDictionaries() const;
|
| +
|
| net::SdchManager* manager_;
|
| - net::SdchDictionaryFetcher fetcher_;
|
| + scoped_ptr<net::SdchDictionaryFetcher> fetcher_;
|
|
|
| - std::map<std::string, DictionaryInfo> local_dictionary_info_;
|
| size_t total_dictionary_bytes_;
|
|
|
| scoped_ptr<base::Clock> clock_;
|
| @@ -95,6 +133,30 @@ class NET_EXPORT SdchOwner : public net::SdchObserver {
|
| // TODO(rmcilroy) Add back memory_pressure_listener_ when
|
| // http://crbug.com/447208 is fixed
|
|
|
| + // Dictionary persistence machinery.
|
| + // * |in_memory_pref_store_| is created on construction and used in
|
| + // the absence of any call to EnablePersistentStorage().
|
| + // * |external_pref_store_| holds the preference store specified
|
| + // by EnablePersistentStorage() (if any), while it is being read in.
|
| + // A non-null value here signals that the SdchOwner is observing
|
| + // the pref store; when read-in completes and observation is no longer
|
| + // needed, the pointer is set to null. This is to avoid lots of
|
| + // extra irrelevant function calls; the only observer interface this
|
| + // class is interested in is OnInitializationCompleted().
|
| + // * |pref_store_| holds an unowned pointer to the currently
|
| + // active pref store (one of the preceding two).
|
| + scoped_refptr<ValueMapPrefStore> in_memory_pref_store_;
|
| + PersistentPrefStore* external_pref_store_;
|
| +
|
| + WriteablePrefStore* pref_store_;
|
| +
|
| + // The use counts of dictionaries when they were loaded from the persistent
|
| + // store, keyed by server hash. These are stored to avoid generating
|
| + // misleading ever-increasing use counts for dictionaries that are persisted,
|
| + // since the UMA histogram for use counts is only supposed to be since last
|
| + // load.
|
| + std::map<std::string, int> use_counts_at_load_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(SdchOwner);
|
| };
|
|
|
|
|