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 WEBKIT_BROWSER_QUOTA_STORAGE_MONITOR_H_ | 5 #ifndef WEBKIT_BROWSER_QUOTA_STORAGE_MONITOR_H_ |
6 #define WEBKIT_BROWSER_QUOTA_STORAGE_MONITOR_H_ | 6 #define WEBKIT_BROWSER_QUOTA_STORAGE_MONITOR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
13 #include "webkit/browser/quota/storage_observer.h" | 13 #include "storage/browser/quota/storage_observer.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 class StorageMonitorTestBase; | 16 class StorageMonitorTestBase; |
17 } | 17 } |
18 | 18 |
19 namespace quota { | 19 namespace quota { |
20 | 20 |
21 class QuotaManager; | 21 class QuotaManager; |
22 | 22 |
23 // This class dispatches storage events to observers of a common | 23 // This class dispatches storage events to observers of a common |
24 // StorageObserver::Filter. | 24 // StorageObserver::Filter. |
25 class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE StorageObserverList { | 25 class STORAGE_EXPORT_PRIVATE StorageObserverList { |
26 public: | 26 public: |
27 StorageObserverList(); | 27 StorageObserverList(); |
28 virtual ~StorageObserverList(); | 28 virtual ~StorageObserverList(); |
29 | 29 |
30 // Adds/removes an observer. | 30 // Adds/removes an observer. |
31 void AddObserver(StorageObserver* observer, | 31 void AddObserver(StorageObserver* observer, |
32 const StorageObserver::MonitorParams& params); | 32 const StorageObserver::MonitorParams& params); |
33 void RemoveObserver(StorageObserver* observer); | 33 void RemoveObserver(StorageObserver* observer); |
34 | 34 |
35 // Returns the number of observers. | 35 // Returns the number of observers. |
36 int ObserverCount() const; | 36 int ObserverCount() const; |
37 | 37 |
38 // Forwards a storage change to observers. The event may be dispatched | 38 // Forwards a storage change to observers. The event may be dispatched |
39 // immediately to an observer or after a delay, depending on the desired event | 39 // immediately to an observer or after a delay, depending on the desired event |
40 // rate of the observer. | 40 // rate of the observer. |
41 void OnStorageChange(const StorageObserver::Event& event); | 41 void OnStorageChange(const StorageObserver::Event& event); |
42 | 42 |
43 // Dispatch an event to observers that require it. | 43 // Dispatch an event to observers that require it. |
44 void MaybeDispatchEvent(const StorageObserver::Event& event); | 44 void MaybeDispatchEvent(const StorageObserver::Event& event); |
45 | 45 |
46 // Ensure the specified observer receives the next dispatched event. | 46 // Ensure the specified observer receives the next dispatched event. |
47 void ScheduleUpdateForObserver(StorageObserver* observer); | 47 void ScheduleUpdateForObserver(StorageObserver* observer); |
48 | 48 |
49 private: | 49 private: |
50 struct WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE ObserverState { | 50 struct STORAGE_EXPORT_PRIVATE ObserverState { |
51 GURL origin; | 51 GURL origin; |
52 base::TimeTicks last_notification_time; | 52 base::TimeTicks last_notification_time; |
53 base::TimeDelta rate; | 53 base::TimeDelta rate; |
54 bool requires_update; | 54 bool requires_update; |
55 | 55 |
56 ObserverState(); | 56 ObserverState(); |
57 }; | 57 }; |
58 typedef std::map<StorageObserver*, ObserverState> StorageObserverStateMap; | 58 typedef std::map<StorageObserver*, ObserverState> StorageObserverStateMap; |
59 | 59 |
60 void DispatchPendingEvent(); | 60 void DispatchPendingEvent(); |
61 | 61 |
62 StorageObserverStateMap observers_; | 62 StorageObserverStateMap observers_; |
63 base::OneShotTimer<StorageObserverList> notification_timer_; | 63 base::OneShotTimer<StorageObserverList> notification_timer_; |
64 StorageObserver::Event pending_event_; | 64 StorageObserver::Event pending_event_; |
65 | 65 |
66 friend class content::StorageMonitorTestBase; | 66 friend class content::StorageMonitorTestBase; |
67 | 67 |
68 DISALLOW_COPY_AND_ASSIGN(StorageObserverList); | 68 DISALLOW_COPY_AND_ASSIGN(StorageObserverList); |
69 }; | 69 }; |
70 | 70 |
71 | |
72 // Manages the storage observers of a common host. Caches the usage and quota of | 71 // Manages the storage observers of a common host. Caches the usage and quota of |
73 // the host to avoid accumulating for every change. | 72 // the host to avoid accumulating for every change. |
74 class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE HostStorageObservers { | 73 class STORAGE_EXPORT_PRIVATE HostStorageObservers { |
75 public: | 74 public: |
76 explicit HostStorageObservers(QuotaManager* quota_manager); | 75 explicit HostStorageObservers(QuotaManager* quota_manager); |
77 virtual ~HostStorageObservers(); | 76 virtual ~HostStorageObservers(); |
78 | 77 |
79 bool is_initialized() const { return initialized_; } | 78 bool is_initialized() const { return initialized_; } |
80 | 79 |
81 // Adds/removes an observer. | 80 // Adds/removes an observer. |
82 void AddObserver( | 81 void AddObserver(StorageObserver* observer, |
83 StorageObserver* observer, | 82 const StorageObserver::MonitorParams& params); |
84 const StorageObserver::MonitorParams& params); | |
85 void RemoveObserver(StorageObserver* observer); | 83 void RemoveObserver(StorageObserver* observer); |
86 bool ContainsObservers() const; | 84 bool ContainsObservers() const; |
87 | 85 |
88 // Handles a usage change. | 86 // Handles a usage change. |
89 void NotifyUsageChange(const StorageObserver::Filter& filter, int64 delta); | 87 void NotifyUsageChange(const StorageObserver::Filter& filter, int64 delta); |
90 | 88 |
91 private: | 89 private: |
92 void StartInitialization(const StorageObserver::Filter& filter); | 90 void StartInitialization(const StorageObserver::Filter& filter); |
93 void GotHostUsageAndQuota(const StorageObserver::Filter& filter, | 91 void GotHostUsageAndQuota(const StorageObserver::Filter& filter, |
94 QuotaStatusCode status, | 92 QuotaStatusCode status, |
(...skipping 14 matching lines...) Expand all Loading... |
109 int64 cached_usage_; | 107 int64 cached_usage_; |
110 int64 cached_quota_; | 108 int64 cached_quota_; |
111 | 109 |
112 base::WeakPtrFactory<HostStorageObservers> weak_factory_; | 110 base::WeakPtrFactory<HostStorageObservers> weak_factory_; |
113 | 111 |
114 friend class content::StorageMonitorTestBase; | 112 friend class content::StorageMonitorTestBase; |
115 | 113 |
116 DISALLOW_COPY_AND_ASSIGN(HostStorageObservers); | 114 DISALLOW_COPY_AND_ASSIGN(HostStorageObservers); |
117 }; | 115 }; |
118 | 116 |
119 | |
120 // Manages the observers of a common storage type. | 117 // Manages the observers of a common storage type. |
121 class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE StorageTypeObservers { | 118 class STORAGE_EXPORT_PRIVATE StorageTypeObservers { |
122 public: | 119 public: |
123 explicit StorageTypeObservers(QuotaManager* quota_manager); | 120 explicit StorageTypeObservers(QuotaManager* quota_manager); |
124 virtual ~StorageTypeObservers(); | 121 virtual ~StorageTypeObservers(); |
125 | 122 |
126 // Adds and removes an observer. | 123 // Adds and removes an observer. |
127 void AddObserver(StorageObserver* observer, | 124 void AddObserver(StorageObserver* observer, |
128 const StorageObserver::MonitorParams& params); | 125 const StorageObserver::MonitorParams& params); |
129 void RemoveObserver(StorageObserver* observer); | 126 void RemoveObserver(StorageObserver* observer); |
130 void RemoveObserverForFilter(StorageObserver* observer, | 127 void RemoveObserverForFilter(StorageObserver* observer, |
131 const StorageObserver::Filter& filter); | 128 const StorageObserver::Filter& filter); |
132 | 129 |
133 // Returns the observers of a specific host. | 130 // Returns the observers of a specific host. |
134 const HostStorageObservers* GetHostObservers(const std::string& host) const; | 131 const HostStorageObservers* GetHostObservers(const std::string& host) const; |
135 | 132 |
136 // Handles a usage change. | 133 // Handles a usage change. |
137 void NotifyUsageChange(const StorageObserver::Filter& filter, int64 delta); | 134 void NotifyUsageChange(const StorageObserver::Filter& filter, int64 delta); |
138 | 135 |
139 private: | 136 private: |
140 typedef std::map<std::string, HostStorageObservers*> HostObserversMap; | 137 typedef std::map<std::string, HostStorageObservers*> HostObserversMap; |
141 | 138 |
142 QuotaManager* quota_manager_; | 139 QuotaManager* quota_manager_; |
143 HostObserversMap host_observers_map_; | 140 HostObserversMap host_observers_map_; |
144 | 141 |
145 DISALLOW_COPY_AND_ASSIGN(StorageTypeObservers); | 142 DISALLOW_COPY_AND_ASSIGN(StorageTypeObservers); |
146 }; | 143 }; |
147 | 144 |
148 | |
149 // Storage monitor manages observers and dispatches storage events to them. | 145 // Storage monitor manages observers and dispatches storage events to them. |
150 class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE StorageMonitor { | 146 class STORAGE_EXPORT_PRIVATE StorageMonitor { |
151 public: | 147 public: |
152 explicit StorageMonitor(QuotaManager* quota_manager); | 148 explicit StorageMonitor(QuotaManager* quota_manager); |
153 virtual ~StorageMonitor(); | 149 virtual ~StorageMonitor(); |
154 | 150 |
155 // Adds and removes an observer. | 151 // Adds and removes an observer. |
156 void AddObserver(StorageObserver* observer, | 152 void AddObserver(StorageObserver* observer, |
157 const StorageObserver::MonitorParams& params); | 153 const StorageObserver::MonitorParams& params); |
158 void RemoveObserver(StorageObserver* observer); | 154 void RemoveObserver(StorageObserver* observer); |
159 void RemoveObserverForFilter(StorageObserver* observer, | 155 void RemoveObserverForFilter(StorageObserver* observer, |
160 const StorageObserver::Filter& filter); | 156 const StorageObserver::Filter& filter); |
(...skipping 10 matching lines...) Expand all Loading... |
171 | 167 |
172 QuotaManager* quota_manager_; | 168 QuotaManager* quota_manager_; |
173 StorageTypeObserversMap storage_type_observers_map_; | 169 StorageTypeObserversMap storage_type_observers_map_; |
174 | 170 |
175 DISALLOW_COPY_AND_ASSIGN(StorageMonitor); | 171 DISALLOW_COPY_AND_ASSIGN(StorageMonitor); |
176 }; | 172 }; |
177 | 173 |
178 } // namespace quota | 174 } // namespace quota |
179 | 175 |
180 #endif // WEBKIT_BROWSER_QUOTA_STORAGE_MONITOR_H_ | 176 #endif // WEBKIT_BROWSER_QUOTA_STORAGE_MONITOR_H_ |
OLD | NEW |