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

Side by Side Diff: net/sdch/sdch_owner.h

Issue 881413003: Make SDCH dictionaries persistent across browser restart. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated Matt's comments. Created 5 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_SDCH_SDCH_OWNER_H_ 5 #ifndef NET_SDCH_SDCH_OWNER_H_
6 #define NET_SDCH_SDCH_OWNER_H_ 6 #define NET_SDCH_SDCH_OWNER_H_
7 7
8 #include <map>
8 #include <string> 9 #include <string>
9 10
10 #include "base/memory/memory_pressure_listener.h" 11 #include "base/memory/memory_pressure_listener.h"
12 #include "base/prefs/pref_store.h"
11 #include "net/base/sdch_observer.h" 13 #include "net/base/sdch_observer.h"
12 #include "net/url_request/sdch_dictionary_fetcher.h" 14 #include "net/url_request/sdch_dictionary_fetcher.h"
13 15
14 class GURL; 16 class GURL;
17 class PersistentPrefStore;
18 class ValueMapPrefStore;
19 class WriteablePrefStore;
15 20
16 namespace base { 21 namespace base {
17 class Clock; 22 class Clock;
18 } 23 }
19 24
20 namespace net { 25 namespace net {
21 class SdchManager; 26 class SdchManager;
22 class URLRequestContext; 27 class URLRequestContext;
23 28
24 // This class owns the SDCH objects not owned as part of URLRequestContext, and 29 // This class owns the SDCH objects not owned as part of URLRequestContext, and
25 // exposes interface for setting SDCH policy. It should be instantiated by 30 // exposes interface for setting SDCH policy. It should be instantiated by
26 // the net/ embedder. 31 // the net/ embedder.
27 // TODO(rdsmith): Implement dictionary prioritization. 32 // TODO(rdsmith): Implement dictionary prioritization.
28 class NET_EXPORT SdchOwner : public net::SdchObserver { 33 class NET_EXPORT SdchOwner : public net::SdchObserver,
34 public PrefStore::Observer {
29 public: 35 public:
30 static const size_t kMaxTotalDictionarySize; 36 static const size_t kMaxTotalDictionarySize;
31 static const size_t kMinSpaceForDictionaryFetch; 37 static const size_t kMinSpaceForDictionaryFetch;
32 38
33 // Consumer must guarantee that |sdch_manager| and |context| outlive 39 // Consumer must guarantee that |sdch_manager| and |context| outlive
34 // this object. 40 // this object.
35 SdchOwner(net::SdchManager* sdch_manager, net::URLRequestContext* context); 41 SdchOwner(net::SdchManager* sdch_manager, net::URLRequestContext* context);
36 ~SdchOwner() override; 42 ~SdchOwner() override;
37 43
44 // Enables use of pref persistence. Dictionaries added to the SdchManager
45 // before this call is made will not be added to the pref store.
46 // Note that |pref_store| is owned by the caller, but must be guaranteed
47 // to outlive SdchOwner.
48 // This routine may only be called once per SdchOwner instance.
49 void EnablePersistentStorage(PersistentPrefStore* pref_store);
50
38 // Defaults to kMaxTotalDictionarySize. 51 // Defaults to kMaxTotalDictionarySize.
39 void SetMaxTotalDictionarySize(size_t max_total_dictionary_size); 52 void SetMaxTotalDictionarySize(size_t max_total_dictionary_size);
40 53
41 // Defaults to kMinSpaceForDictionaryFetch. 54 // Defaults to kMinSpaceForDictionaryFetch.
42 void SetMinSpaceForDictionaryFetch(size_t min_space_for_dictionary_fetch); 55 void SetMinSpaceForDictionaryFetch(size_t min_space_for_dictionary_fetch);
43 56
44 // SdchObserver implementation. 57 // SdchObserver implementation.
45 void OnDictionaryUsed(SdchManager* manager, 58 void OnDictionaryUsed(SdchManager* manager,
46 const std::string& server_hash) override; 59 const std::string& server_hash) override;
47 void OnGetDictionary(net::SdchManager* manager, 60 void OnGetDictionary(net::SdchManager* manager,
48 const GURL& request_url, 61 const GURL& request_url,
49 const GURL& dictionary_url) override; 62 const GURL& dictionary_url) override;
50 void OnClearDictionaries(net::SdchManager* manager) override; 63 void OnClearDictionaries(net::SdchManager* manager) override;
51 64
65 // PrefStore::Observer implementation.
66 void OnPrefValueChanged(const std::string& key) override;
67 void OnInitializationCompleted(bool succeeded) override;
68
52 // Implementation detail--this is the pathway through which the 69 // Implementation detail--this is the pathway through which the
53 // fetcher informs the SdchOwner that it's gotten the dictionary. 70 // fetcher informs the SdchOwner that it's gotten the dictionary.
54 // Public for testing. 71 // Public for testing.
55 void OnDictionaryFetched(const std::string& dictionary_text, 72 void OnDictionaryFetched(const std::string& dictionary_text,
56 const GURL& dictionary_url, 73 const GURL& dictionary_url,
74 scoped_ptr<SdchDictionaryFetcher::Data> extra_data,
57 const net::BoundNetLog& net_log); 75 const net::BoundNetLog& net_log);
58 76
59 void SetClockForTesting(scoped_ptr<base::Clock> clock); 77 void SetClockForTesting(scoped_ptr<base::Clock> clock);
60 78
61 private: 79 private:
62 // For each active dictionary, stores local info. 80 // For each active dictionary, stores local info.
63 // Indexed by server hash. 81 // Indexed by server hash.
mmenke 2015/02/02 16:35:28 Should define server hash. I'm assuming it's the
Randy Smith (Not in Mondays) 2015/02/04 19:29:03 Done (though it will be moot).
64 struct DictionaryInfo { 82 struct DictionaryInfo {
65 base::Time last_used; 83 base::Time last_used;
66 int use_count; 84 int use_count;
67 size_t size; 85 size_t size;
68 86
69 DictionaryInfo() : use_count(0), size(0) {} 87 DictionaryInfo() : use_count(0), size(0) {}
70 DictionaryInfo(const base::Time& last_used, size_t size) 88 DictionaryInfo(const base::Time& last_used, size_t size)
71 : last_used(last_used), use_count(0), size(size) {} 89 : last_used(last_used), use_count(0), size(size) {}
72 DictionaryInfo(const DictionaryInfo& rhs) = default; 90 DictionaryInfo(const DictionaryInfo& rhs) = default;
73 DictionaryInfo& operator=(const DictionaryInfo& rhs) = default; 91 DictionaryInfo& operator=(const DictionaryInfo& rhs) = default;
74 }; 92 };
75 93
76 void OnMemoryPressure( 94 void OnMemoryPressure(
77 base::MemoryPressureListener::MemoryPressureLevel level); 95 base::MemoryPressureListener::MemoryPressureLevel level);
78 96
97 // Returns false if the load fails for some reason.
98 bool LoadPersistedDictionaries(const base::DictionaryValue& persisted_info);
mmenke 2015/02/02 16:35:28 These needs a lot more detail, and maybe a rename,
Randy Smith (Not in Mondays) 2015/02/04 19:29:03 I've rewritten the comment and renamed the functio
99
79 net::SdchManager* manager_; 100 net::SdchManager* manager_;
80 net::SdchDictionaryFetcher fetcher_; 101 net::SdchDictionaryFetcher fetcher_;
81 102
82 std::map<std::string, DictionaryInfo> local_dictionary_info_; 103 std::map<std::string, DictionaryInfo> local_dictionary_info_;
83 size_t total_dictionary_bytes_; 104 size_t total_dictionary_bytes_;
84 105
85 scoped_ptr<base::Clock> clock_; 106 scoped_ptr<base::Clock> clock_;
86 107
87 size_t max_total_dictionary_size_; 108 size_t max_total_dictionary_size_;
88 size_t min_space_for_dictionary_fetch_; 109 size_t min_space_for_dictionary_fetch_;
89 110
111 // Dictionary persistence machinery. |in_memory_pref_store_|
112 // is created on construction and used in the absence of any call
113 // to EnablePersistentStorage(). |persistent_pref_store_| holds the
114 // preference store specified by EnablePersistentStorage() (if any).
115 // |pref_store_| is shifted from the first to the second after the
116 // persistent pref store information is fully read in.
117 scoped_refptr<ValueMapPrefStore> in_memory_pref_store_;
118 PersistentPrefStore* persistent_pref_store_;
119
120 WriteablePrefStore* pref_store_;
121
90 base::MemoryPressureListener memory_pressure_listener_; 122 base::MemoryPressureListener memory_pressure_listener_;
91 123
92 DISALLOW_COPY_AND_ASSIGN(SdchOwner); 124 DISALLOW_COPY_AND_ASSIGN(SdchOwner);
93 }; 125 };
94 126
95 } // namespace net 127 } // namespace net
96 128
97 #endif // NET_SDCH_SDCH_OWNER_H_ 129 #endif // NET_SDCH_SDCH_OWNER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698