| OLD | NEW |
| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 virtual ~PrefStorage(); | 64 virtual ~PrefStorage(); |
| 65 | 65 |
| 66 // Returns the read error if any. Valid to be called after initialization | 66 // Returns the read error if any. Valid to be called after initialization |
| 67 // is complete (see IsInitializationComplete). | 67 // is complete (see IsInitializationComplete). |
| 68 virtual ReadError GetReadError() const = 0; | 68 virtual ReadError GetReadError() const = 0; |
| 69 | 69 |
| 70 // Gets or sets the value in the preferences store. | 70 // Gets or sets the value in the preferences store. |
| 71 virtual bool GetValue(const base::DictionaryValue** result) const = 0; | 71 virtual bool GetValue(const base::DictionaryValue** result) const = 0; |
| 72 virtual bool GetMutableValue(base::DictionaryValue** result) = 0; | 72 virtual bool GetMutableValue(base::DictionaryValue** result) = 0; |
| 73 virtual void SetValue(scoped_ptr<base::DictionaryValue> value) = 0; | 73 virtual void SetValue(std::unique_ptr<base::DictionaryValue> value) = 0; |
| 74 | 74 |
| 75 // Notifies the storage system that a value was changed via mutating the | 75 // Notifies the storage system that a value was changed via mutating the |
| 76 // result of GetMutableValue(). | 76 // result of GetMutableValue(). |
| 77 virtual void ReportValueChanged() = 0; | 77 virtual void ReportValueChanged() = 0; |
| 78 | 78 |
| 79 // Returns true if the store's init is complete. See the Start/Stop | 79 // Returns true if the store's init is complete. See the Start/Stop |
| 80 // functions below for observing changes to this value. | 80 // functions below for observing changes to this value. |
| 81 virtual bool IsInitializationComplete() = 0; | 81 virtual bool IsInitializationComplete() = 0; |
| 82 | 82 |
| 83 // Starts and stops observing preferences storage init. There will only | 83 // Starts and stops observing preferences storage init. There will only |
| 84 // be one observer active at a time. The store should call | 84 // be one observer active at a time. The store should call |
| 85 // OnPrefStorageInitializationComplete() when it transitions to initialized | 85 // OnPrefStorageInitializationComplete() when it transitions to initialized |
| 86 // and there is an observer active. See also IsInitializationComplete(). | 86 // and there is an observer active. See also IsInitializationComplete(). |
| 87 virtual void StartObservingInit(SdchOwner* observer) = 0; | 87 virtual void StartObservingInit(SdchOwner* observer) = 0; |
| 88 virtual void StopObservingInit() = 0; | 88 virtual void StopObservingInit() = 0; |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 static const size_t kMaxTotalDictionarySize; | 91 static const size_t kMaxTotalDictionarySize; |
| 92 static const size_t kMinSpaceForDictionaryFetch; | 92 static const size_t kMinSpaceForDictionaryFetch; |
| 93 | 93 |
| 94 // Consumer must guarantee that |sdch_manager| and |context| outlive | 94 // Consumer must guarantee that |sdch_manager| and |context| outlive |
| 95 // this object. | 95 // this object. |
| 96 SdchOwner(SdchManager* sdch_manager, URLRequestContext* context); | 96 SdchOwner(SdchManager* sdch_manager, URLRequestContext* context); |
| 97 ~SdchOwner() override; | 97 ~SdchOwner() override; |
| 98 | 98 |
| 99 // Enables use of pref persistence. Ownership of the storage will be passed. | 99 // Enables use of pref persistence. Ownership of the storage will be passed. |
| 100 // This routine may only be called once per SdchOwner instance. | 100 // This routine may only be called once per SdchOwner instance. |
| 101 void EnablePersistentStorage(scoped_ptr<PrefStorage> pref_store); | 101 void EnablePersistentStorage(std::unique_ptr<PrefStorage> pref_store); |
| 102 | 102 |
| 103 // Defaults to kMaxTotalDictionarySize. | 103 // Defaults to kMaxTotalDictionarySize. |
| 104 void SetMaxTotalDictionarySize(size_t max_total_dictionary_size); | 104 void SetMaxTotalDictionarySize(size_t max_total_dictionary_size); |
| 105 | 105 |
| 106 // Defaults to kMinSpaceForDictionaryFetch. | 106 // Defaults to kMinSpaceForDictionaryFetch. |
| 107 void SetMinSpaceForDictionaryFetch(size_t min_space_for_dictionary_fetch); | 107 void SetMinSpaceForDictionaryFetch(size_t min_space_for_dictionary_fetch); |
| 108 | 108 |
| 109 // SdchObserver implementation. | 109 // SdchObserver implementation. |
| 110 void OnDictionaryAdded(const GURL& dictionary_url, | 110 void OnDictionaryAdded(const GURL& dictionary_url, |
| 111 const std::string& server_hash) override; | 111 const std::string& server_hash) override; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 124 // gotten the dictionary. The first two arguments are bound locally. | 124 // gotten the dictionary. The first two arguments are bound locally. |
| 125 // Public for testing. | 125 // Public for testing. |
| 126 void OnDictionaryFetched(base::Time last_used, | 126 void OnDictionaryFetched(base::Time last_used, |
| 127 base::Time created_time, | 127 base::Time created_time, |
| 128 int use_count, | 128 int use_count, |
| 129 const std::string& dictionary_text, | 129 const std::string& dictionary_text, |
| 130 const GURL& dictionary_url, | 130 const GURL& dictionary_url, |
| 131 const BoundNetLog& net_log, | 131 const BoundNetLog& net_log, |
| 132 bool was_from_cache); | 132 bool was_from_cache); |
| 133 | 133 |
| 134 void SetClockForTesting(scoped_ptr<base::Clock> clock); | 134 void SetClockForTesting(std::unique_ptr<base::Clock> clock); |
| 135 | 135 |
| 136 // Returns the total number of dictionaries loaded. | 136 // Returns the total number of dictionaries loaded. |
| 137 int GetDictionaryCountForTesting() const; | 137 int GetDictionaryCountForTesting() const; |
| 138 | 138 |
| 139 // Returns whether this SdchOwner has dictionary from |url| loaded. | 139 // Returns whether this SdchOwner has dictionary from |url| loaded. |
| 140 bool HasDictionaryFromURLForTesting(const GURL& url) const; | 140 bool HasDictionaryFromURLForTesting(const GURL& url) const; |
| 141 | 141 |
| 142 void SetFetcherForTesting(scoped_ptr<SdchDictionaryFetcher> fetcher); | 142 void SetFetcherForTesting(std::unique_ptr<SdchDictionaryFetcher> fetcher); |
| 143 | 143 |
| 144 private: | 144 private: |
| 145 // For each active dictionary, stores local info. | 145 // For each active dictionary, stores local info. |
| 146 // Indexed by the server hash of the dictionary. | 146 // Indexed by the server hash of the dictionary. |
| 147 struct DictionaryInfo { | 147 struct DictionaryInfo { |
| 148 base::Time last_used; | 148 base::Time last_used; |
| 149 int use_count; | 149 int use_count; |
| 150 size_t size; | 150 size_t size; |
| 151 | 151 |
| 152 DictionaryInfo() : use_count(0), size(0) {} | 152 DictionaryInfo() : use_count(0), size(0) {} |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 void RecordDictionaryFate(DictionaryFate fate); | 208 void RecordDictionaryFate(DictionaryFate fate); |
| 209 | 209 |
| 210 // Record the lifetime memory use of a specified dictionary, identified by | 210 // Record the lifetime memory use of a specified dictionary, identified by |
| 211 // server hash. | 211 // server hash. |
| 212 void RecordDictionaryEvictionOrUnload( | 212 void RecordDictionaryEvictionOrUnload( |
| 213 const std::string& server_hash, | 213 const std::string& server_hash, |
| 214 size_t size, | 214 size_t size, |
| 215 int use_count, DictionaryFate fate); | 215 int use_count, DictionaryFate fate); |
| 216 | 216 |
| 217 net::SdchManager* manager_; | 217 net::SdchManager* manager_; |
| 218 scoped_ptr<net::SdchDictionaryFetcher> fetcher_; | 218 std::unique_ptr<net::SdchDictionaryFetcher> fetcher_; |
| 219 | 219 |
| 220 size_t total_dictionary_bytes_; | 220 size_t total_dictionary_bytes_; |
| 221 | 221 |
| 222 scoped_ptr<base::Clock> clock_; | 222 std::unique_ptr<base::Clock> clock_; |
| 223 | 223 |
| 224 size_t max_total_dictionary_size_; | 224 size_t max_total_dictionary_size_; |
| 225 size_t min_space_for_dictionary_fetch_; | 225 size_t min_space_for_dictionary_fetch_; |
| 226 | 226 |
| 227 base::MemoryPressureListener memory_pressure_listener_; | 227 base::MemoryPressureListener memory_pressure_listener_; |
| 228 | 228 |
| 229 // Dictionary persistence machinery. | 229 // Dictionary persistence machinery. |
| 230 // * |in_memory_pref_store_| is created on construction and used in the | 230 // * |in_memory_pref_store_| is created on construction and used in the |
| 231 // absence of any call to EnablePersistentStorage(). | 231 // absence of any call to EnablePersistentStorage(). |
| 232 // * |external_pref_store_| holds the preference store specified by | 232 // * |external_pref_store_| holds the preference store specified by |
| 233 // EnablePersistentStorage() (if any). | 233 // EnablePersistentStorage() (if any). |
| 234 // * The external pref store is initialized asynchronously. During this time, | 234 // * The external pref store is initialized asynchronously. During this time, |
| 235 // both pointers will be value, pref_store_ will point to the in-memory | 235 // both pointers will be value, pref_store_ will point to the in-memory |
| 236 // one, and this class will be observing the initialization of the external | 236 // one, and this class will be observing the initialization of the external |
| 237 // store. | 237 // store. |
| 238 // * When the external pref store is initialized, the in-memory version will | 238 // * When the external pref store is initialized, the in-memory version will |
| 239 // be freed, and pref_store_ will point to the external one. | 239 // be freed, and pref_store_ will point to the external one. |
| 240 // * |pref_store_| holds an unowned pointer to the currently | 240 // * |pref_store_| holds an unowned pointer to the currently |
| 241 // active pref store (one of the preceding two). | 241 // active pref store (one of the preceding two). |
| 242 scoped_ptr<PrefStorage> in_memory_pref_store_; | 242 std::unique_ptr<PrefStorage> in_memory_pref_store_; |
| 243 scoped_ptr<PrefStorage> external_pref_store_; | 243 std::unique_ptr<PrefStorage> external_pref_store_; |
| 244 PrefStorage* pref_store_; | 244 PrefStorage* pref_store_; |
| 245 | 245 |
| 246 // The use counts of dictionaries when they were loaded from the persistent | 246 // The use counts of dictionaries when they were loaded from the persistent |
| 247 // store, keyed by server hash. These are stored to avoid generating | 247 // store, keyed by server hash. These are stored to avoid generating |
| 248 // misleading ever-increasing use counts for dictionaries that are persisted, | 248 // misleading ever-increasing use counts for dictionaries that are persisted, |
| 249 // since the UMA histogram for use counts is only supposed to be since last | 249 // since the UMA histogram for use counts is only supposed to be since last |
| 250 // load. | 250 // load. |
| 251 std::map<std::string, int> use_counts_at_load_; | 251 std::map<std::string, int> use_counts_at_load_; |
| 252 | 252 |
| 253 // Load times for loaded dictionaries, keyed by server hash. These are used to | 253 // Load times for loaded dictionaries, keyed by server hash. These are used to |
| 254 // track the durations that dictionaries are in memory. | 254 // track the durations that dictionaries are in memory. |
| 255 std::map<std::string, base::Time> load_times_; | 255 std::map<std::string, base::Time> load_times_; |
| 256 | 256 |
| 257 // Byte-seconds consumed by dictionaries that have been unloaded. These are | 257 // Byte-seconds consumed by dictionaries that have been unloaded. These are |
| 258 // stored for later uploading in the SdchOwner destructor. | 258 // stored for later uploading in the SdchOwner destructor. |
| 259 std::vector<int64_t> consumed_byte_seconds_; | 259 std::vector<int64_t> consumed_byte_seconds_; |
| 260 | 260 |
| 261 // Creation time for this SdchOwner object, used for reporting temporal memory | 261 // Creation time for this SdchOwner object, used for reporting temporal memory |
| 262 // pressure. | 262 // pressure. |
| 263 base::Time creation_time_; | 263 base::Time creation_time_; |
| 264 | 264 |
| 265 DISALLOW_COPY_AND_ASSIGN(SdchOwner); | 265 DISALLOW_COPY_AND_ASSIGN(SdchOwner); |
| 266 }; | 266 }; |
| 267 | 267 |
| 268 } // namespace net | 268 } // namespace net |
| 269 | 269 |
| 270 #endif // NET_SDCH_SDCH_OWNER_H_ | 270 #endif // NET_SDCH_SDCH_OWNER_H_ |
| OLD | NEW |