OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_SDCH_SDCH_OWNER_H_ |
| 6 #define NET_SDCH_SDCH_OWNER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/memory/memory_pressure_listener.h" |
| 11 #include "net/base/sdch_observer.h" |
| 12 #include "net/url_request/sdch_dictionary_fetcher.h" |
| 13 |
| 14 class GURL; |
| 15 |
| 16 namespace base { |
| 17 class Clock; |
| 18 } |
| 19 |
| 20 namespace net { |
| 21 class SdchManager; |
| 22 class URLRequestContext; |
| 23 |
| 24 // 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 |
| 26 // the net/ embedder. |
| 27 // TODO(rdsmith): Implement dictionary prioritization. |
| 28 class NET_EXPORT SdchOwner : public net::SdchObserver { |
| 29 public: |
| 30 static const size_t kMaxTotalDictionarySize; |
| 31 static const size_t kMinSpaceForDictionaryFetch; |
| 32 |
| 33 // Consumer must guarantee that |sdch_manager| and |context| outlive |
| 34 // this object. |
| 35 SdchOwner(net::SdchManager* sdch_manager, net::URLRequestContext* context); |
| 36 ~SdchOwner() override; |
| 37 |
| 38 // Defaults to kMaxTotalDictionarySize. |
| 39 void SetMaxTotalDictionarySize(size_t max_total_dictionary_size); |
| 40 |
| 41 // Defaults to kMinSpaceForDictionaryFetch. |
| 42 void SetMinSpaceForDictionaryFetch(size_t min_space_for_dictionary_fetch); |
| 43 |
| 44 // SdchObserver implementation. |
| 45 void OnDictionaryUsed(SdchManager* manager, |
| 46 const std::string& server_hash) override; |
| 47 void OnGetDictionary(net::SdchManager* manager, |
| 48 const GURL& request_url, |
| 49 const GURL& dictionary_url) override; |
| 50 void OnClearDictionaries(net::SdchManager* manager) override; |
| 51 |
| 52 // Implementation detail--this is the pathway through which the |
| 53 // fetcher informs the SdchOwner that it's gotten the dictionary. |
| 54 // Public for testing. |
| 55 void OnDictionaryFetched(const std::string& dictionary_text, |
| 56 const GURL& dictionary_url, |
| 57 const net::BoundNetLog& net_log); |
| 58 |
| 59 void SetClockForTesting(scoped_ptr<base::Clock> clock); |
| 60 |
| 61 private: |
| 62 // For each active dictionary, stores local info. |
| 63 // Indexed by server hash. |
| 64 struct DictionaryInfo { |
| 65 base::Time last_used; |
| 66 int use_count; |
| 67 size_t size; |
| 68 |
| 69 DictionaryInfo() : use_count(0), size(0) {} |
| 70 DictionaryInfo(const base::Time& last_used, size_t size) |
| 71 : last_used(last_used), use_count(0), size(size) {} |
| 72 DictionaryInfo(const DictionaryInfo& rhs) = default; |
| 73 DictionaryInfo& operator=(const DictionaryInfo& rhs) = default; |
| 74 }; |
| 75 |
| 76 void OnMemoryPressure( |
| 77 base::MemoryPressureListener::MemoryPressureLevel level); |
| 78 |
| 79 net::SdchManager* manager_; |
| 80 net::SdchDictionaryFetcher fetcher_; |
| 81 |
| 82 std::map<std::string, DictionaryInfo> local_dictionary_info_; |
| 83 size_t total_dictionary_bytes_; |
| 84 |
| 85 scoped_ptr<base::Clock> clock_; |
| 86 |
| 87 size_t max_total_dictionary_size_; |
| 88 size_t min_space_for_dictionary_fetch_; |
| 89 |
| 90 base::MemoryPressureListener memory_pressure_listener_; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(SdchOwner); |
| 93 }; |
| 94 |
| 95 } // namespace net |
| 96 |
| 97 #endif // NET_SDCH_SDCH_OWNER_H_ |
OLD | NEW |