ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / net / sdch / sdch_owner.h
blobe75c780fc7e6b2a7ce57230eb32e25889e2c82c4
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.
5 #ifndef NET_SDCH_SDCH_OWNER_H_
6 #define NET_SDCH_SDCH_OWNER_H_
8 #include <string>
10 #include "base/memory/memory_pressure_listener.h"
11 #include "net/base/sdch_observer.h"
12 #include "net/url_request/sdch_dictionary_fetcher.h"
14 class GURL;
16 namespace base {
17 class Clock;
20 namespace net {
21 class SdchManager;
22 class URLRequestContext;
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;
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;
38 // Defaults to kMaxTotalDictionarySize.
39 void SetMaxTotalDictionarySize(size_t max_total_dictionary_size);
41 // Defaults to kMinSpaceForDictionaryFetch.
42 void SetMinSpaceForDictionaryFetch(size_t min_space_for_dictionary_fetch);
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;
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);
59 void SetClockForTesting(scoped_ptr<base::Clock> clock);
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;
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;
76 void OnMemoryPressure(
77 base::MemoryPressureListener::MemoryPressureLevel level);
79 net::SdchManager* manager_;
80 net::SdchDictionaryFetcher fetcher_;
82 std::map<std::string, DictionaryInfo> local_dictionary_info_;
83 size_t total_dictionary_bytes_;
85 scoped_ptr<base::Clock> clock_;
87 size_t max_total_dictionary_size_;
88 size_t min_space_for_dictionary_fetch_;
90 #if defined(OS_CHROMEOS)
91 // For debugging http://crbug.com/454198; remove when resolved.
92 unsigned int destroyed_;
93 #endif
95 // TODO(rmcilroy) Add back memory_pressure_listener_ when
96 // http://crbug.com/447208 is fixed
98 DISALLOW_COPY_AND_ASSIGN(SdchOwner);
101 } // namespace net
103 #endif // NET_SDCH_SDCH_OWNER_H_