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

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: 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 <string> 8 #include <string>
9 9
10 #include "base/memory/memory_pressure_listener.h" 10 #include "base/memory/memory_pressure_listener.h"
11 #include "base/prefs/pref_store.h"
11 #include "net/base/sdch_observer.h" 12 #include "net/base/sdch_observer.h"
12 #include "net/url_request/sdch_dictionary_fetcher.h" 13 #include "net/url_request/sdch_dictionary_fetcher.h"
13 14
14 class GURL; 15 class GURL;
16 class PersistentPrefStore;
17 class ValueMapPrefStore;
18 class WriteablePrefStore;
15 19
16 namespace base { 20 namespace base {
17 class Clock; 21 class Clock;
18 } 22 }
19 23
20 namespace net { 24 namespace net {
21 class SdchManager; 25 class SdchManager;
22 class URLRequestContext; 26 class URLRequestContext;
23 27
24 // This class owns the SDCH objects not owned as part of URLRequestContext, and 28 // 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 29 // exposes interface for setting SDCH policy. It should be instantiated by
26 // the net/ embedder. 30 // the net/ embedder.
27 // TODO(rdsmith): Implement dictionary prioritization. 31 // TODO(rdsmith): Implement dictionary prioritization.
28 class NET_EXPORT SdchOwner : public net::SdchObserver { 32 class NET_EXPORT SdchOwner : public net::SdchObserver,
33 public PrefStore::Observer {
29 public: 34 public:
30 static const size_t kMaxTotalDictionarySize; 35 static const size_t kMaxTotalDictionarySize;
31 static const size_t kMinSpaceForDictionaryFetch; 36 static const size_t kMinSpaceForDictionaryFetch;
32 37
33 // Consumer must guarantee that |sdch_manager| and |context| outlive 38 // Consumer must guarantee that |sdch_manager| and |context| outlive
34 // this object. 39 // this object.
35 SdchOwner(net::SdchManager* sdch_manager, net::URLRequestContext* context); 40 SdchOwner(net::SdchManager* sdch_manager, net::URLRequestContext* context);
36 ~SdchOwner() override; 41 ~SdchOwner() override;
37 42
43 // Enables use of pref persistence. Dictionaries added to the SdchManager
44 // before this call is made will not be added to the pref store.
45 // Note that |pref_store| is owned by the caller, but must be guaranteed
46 // to outlive SdchOwner.
47 // This routine may only be called once per SdchOwner instance.
48 void EnablePersistentStorage(PersistentPrefStore* pref_store);
49
38 // Defaults to kMaxTotalDictionarySize. 50 // Defaults to kMaxTotalDictionarySize.
39 void SetMaxTotalDictionarySize(size_t max_total_dictionary_size); 51 void SetMaxTotalDictionarySize(size_t max_total_dictionary_size);
40 52
41 // Defaults to kMinSpaceForDictionaryFetch. 53 // Defaults to kMinSpaceForDictionaryFetch.
42 void SetMinSpaceForDictionaryFetch(size_t min_space_for_dictionary_fetch); 54 void SetMinSpaceForDictionaryFetch(size_t min_space_for_dictionary_fetch);
43 55
44 // SdchObserver implementation. 56 // SdchObserver implementation.
45 void OnDictionaryUsed(SdchManager* manager, 57 void OnDictionaryUsed(SdchManager* manager,
46 const std::string& server_hash) override; 58 const std::string& server_hash) override;
47 void OnGetDictionary(net::SdchManager* manager, 59 void OnGetDictionary(net::SdchManager* manager,
48 const GURL& request_url, 60 const GURL& request_url,
49 const GURL& dictionary_url) override; 61 const GURL& dictionary_url) override;
50 void OnClearDictionaries(net::SdchManager* manager) override; 62 void OnClearDictionaries(net::SdchManager* manager) override;
51 63
64 // PrefStore::Observer implementation.
65 void OnPrefValueChanged(const std::string& key) override;
66 void OnInitializationCompleted(bool succeeded) override;
67
52 // Implementation detail--this is the pathway through which the 68 // Implementation detail--this is the pathway through which the
53 // fetcher informs the SdchOwner that it's gotten the dictionary. 69 // fetcher informs the SdchOwner that it's gotten the dictionary.
54 // Public for testing. 70 // Public for testing.
55 void OnDictionaryFetched(const std::string& dictionary_text, 71 void OnDictionaryFetched(const std::string& dictionary_text,
56 const GURL& dictionary_url, 72 const GURL& dictionary_url,
73 scoped_ptr<SdchDictionaryFetcher::Data> extra_data,
57 const net::BoundNetLog& net_log); 74 const net::BoundNetLog& net_log);
58 75
59 void SetClockForTesting(scoped_ptr<base::Clock> clock); 76 void SetClockForTesting(scoped_ptr<base::Clock> clock);
60 77
61 private: 78 private:
62 // For each active dictionary, stores local info. 79 // For each active dictionary, stores local info.
63 // Indexed by server hash. 80 // Indexed by server hash.
64 struct DictionaryInfo { 81 struct DictionaryInfo {
65 base::Time last_used; 82 base::Time last_used;
66 int use_count; 83 int use_count;
67 size_t size; 84 size_t size;
68 85
69 DictionaryInfo() : use_count(0), size(0) {} 86 DictionaryInfo() : use_count(0), size(0) {}
70 DictionaryInfo(const base::Time& last_used, size_t size) 87 DictionaryInfo(const base::Time& last_used, size_t size)
71 : last_used(last_used), use_count(0), size(size) {} 88 : last_used(last_used), use_count(0), size(size) {}
72 DictionaryInfo(const DictionaryInfo& rhs) = default; 89 DictionaryInfo(const DictionaryInfo& rhs) = default;
73 DictionaryInfo& operator=(const DictionaryInfo& rhs) = default; 90 DictionaryInfo& operator=(const DictionaryInfo& rhs) = default;
74 }; 91 };
75 92
76 void OnMemoryPressure( 93 void OnMemoryPressure(
77 base::MemoryPressureListener::MemoryPressureLevel level); 94 base::MemoryPressureListener::MemoryPressureLevel level);
78 95
96 // Returns false if the load fails for some reason.
97 bool LoadPersistedDictionaries(const base::DictionaryValue& persisted_info);
98
79 net::SdchManager* manager_; 99 net::SdchManager* manager_;
80 net::SdchDictionaryFetcher fetcher_; 100 net::SdchDictionaryFetcher fetcher_;
81 101
82 std::map<std::string, DictionaryInfo> local_dictionary_info_; 102 std::map<std::string, DictionaryInfo> local_dictionary_info_;
mmenke 2015/01/30 20:18:41 While you're here, should include <map>
Randy Smith (Not in Mondays) 2015/01/31 02:53:29 Done.
83 size_t total_dictionary_bytes_; 103 size_t total_dictionary_bytes_;
84 104
85 scoped_ptr<base::Clock> clock_; 105 scoped_ptr<base::Clock> clock_;
86 106
87 size_t max_total_dictionary_size_; 107 size_t max_total_dictionary_size_;
88 size_t min_space_for_dictionary_fetch_; 108 size_t min_space_for_dictionary_fetch_;
89 109
110 // Dictionary persistence machinery. |temporary_pref_store_|
111 // is created on construction and used in the absence of any call
112 // to EnablePersistentStorage(). |persistent_pref_store_| holds the
113 // preference store specified by EnablePersistentStorage() (if any).
114 // |pref_store_| is shifted from the first to the second after the
115 // persistent pref store information is fully read in.
116 scoped_refptr<ValueMapPrefStore> temporary_pref_store_;
mmenke 2015/01/30 20:18:41 I think "in_memory_pref_sort_" is more accurate -
Randy Smith (Not in Mondays) 2015/01/31 02:53:29 Done.
117 PersistentPrefStore* persistent_pref_store_;
Bernhard Bauer 2015/01/29 17:42:23 Can't this be a scoped_refptr?
Randy Smith (Not in Mondays) 2015/01/30 20:11:10 Hmmm. My orientation (as backed up by bludgeoning
mmenke 2015/01/30 20:18:41 The general bias of the network stack team is to a
Randy Smith (Not in Mondays) 2015/01/31 02:53:29 Acknowledged.
118
119 WriteablePrefStore* pref_store_;
120
90 base::MemoryPressureListener memory_pressure_listener_; 121 base::MemoryPressureListener memory_pressure_listener_;
91 122
92 DISALLOW_COPY_AND_ASSIGN(SdchOwner); 123 DISALLOW_COPY_AND_ASSIGN(SdchOwner);
93 }; 124 };
94 125
95 } // namespace net 126 } // namespace net
96 127
97 #endif // NET_SDCH_SDCH_OWNER_H_ 128 #endif // NET_SDCH_SDCH_OWNER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698