| 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 STORAGE_BROWSER_QUOTA_STORAGE_MONITOR_H_ | 5 #ifndef STORAGE_BROWSER_QUOTA_STORAGE_MONITOR_H_ |
| 6 #define STORAGE_BROWSER_QUOTA_STORAGE_MONITOR_H_ | 6 #define STORAGE_BROWSER_QUOTA_STORAGE_MONITOR_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> |
| 11 | 12 |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
| 16 #include "storage/browser/quota/storage_observer.h" | 17 #include "storage/browser/quota/storage_observer.h" |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 class StorageMonitorTestBase; | 20 class StorageMonitorTestBase; |
| 20 } | 21 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 void RemoveObserverForFilter(StorageObserver* observer, | 134 void RemoveObserverForFilter(StorageObserver* observer, |
| 134 const StorageObserver::Filter& filter); | 135 const StorageObserver::Filter& filter); |
| 135 | 136 |
| 136 // Returns the observers of a specific host. | 137 // Returns the observers of a specific host. |
| 137 const HostStorageObservers* GetHostObservers(const std::string& host) const; | 138 const HostStorageObservers* GetHostObservers(const std::string& host) const; |
| 138 | 139 |
| 139 // Handles a usage change. | 140 // Handles a usage change. |
| 140 void NotifyUsageChange(const StorageObserver::Filter& filter, int64_t delta); | 141 void NotifyUsageChange(const StorageObserver::Filter& filter, int64_t delta); |
| 141 | 142 |
| 142 private: | 143 private: |
| 143 typedef std::map<std::string, HostStorageObservers*> HostObserversMap; | |
| 144 | |
| 145 QuotaManager* quota_manager_; | 144 QuotaManager* quota_manager_; |
| 146 HostObserversMap host_observers_map_; | 145 std::map<std::string, std::unique_ptr<HostStorageObservers>> |
| 146 host_observers_map_; |
| 147 | 147 |
| 148 DISALLOW_COPY_AND_ASSIGN(StorageTypeObservers); | 148 DISALLOW_COPY_AND_ASSIGN(StorageTypeObservers); |
| 149 }; | 149 }; |
| 150 | 150 |
| 151 | 151 |
| 152 // Storage monitor manages observers and dispatches storage events to them. | 152 // Storage monitor manages observers and dispatches storage events to them. |
| 153 class STORAGE_EXPORT StorageMonitor { | 153 class STORAGE_EXPORT StorageMonitor { |
| 154 public: | 154 public: |
| 155 explicit StorageMonitor(QuotaManager* quota_manager); | 155 explicit StorageMonitor(QuotaManager* quota_manager); |
| 156 virtual ~StorageMonitor(); | 156 virtual ~StorageMonitor(); |
| 157 | 157 |
| 158 // Adds and removes an observer. | 158 // Adds and removes an observer. |
| 159 void AddObserver(StorageObserver* observer, | 159 void AddObserver(StorageObserver* observer, |
| 160 const StorageObserver::MonitorParams& params); | 160 const StorageObserver::MonitorParams& params); |
| 161 void RemoveObserver(StorageObserver* observer); | 161 void RemoveObserver(StorageObserver* observer); |
| 162 void RemoveObserverForFilter(StorageObserver* observer, | 162 void RemoveObserverForFilter(StorageObserver* observer, |
| 163 const StorageObserver::Filter& filter); | 163 const StorageObserver::Filter& filter); |
| 164 | 164 |
| 165 // Returns the observers of a specific storage type. | 165 // Returns the observers of a specific storage type. |
| 166 const StorageTypeObservers* GetStorageTypeObservers( | 166 const StorageTypeObservers* GetStorageTypeObservers( |
| 167 StorageType storage_type) const; | 167 StorageType storage_type) const; |
| 168 | 168 |
| 169 // Handles a usage change. | 169 // Handles a usage change. |
| 170 void NotifyUsageChange(const StorageObserver::Filter& filter, int64_t delta); | 170 void NotifyUsageChange(const StorageObserver::Filter& filter, int64_t delta); |
| 171 | 171 |
| 172 private: | 172 private: |
| 173 typedef std::map<StorageType, StorageTypeObservers*> StorageTypeObserversMap; | |
| 174 | |
| 175 QuotaManager* quota_manager_; | 173 QuotaManager* quota_manager_; |
| 176 StorageTypeObserversMap storage_type_observers_map_; | 174 std::map<StorageType, std::unique_ptr<StorageTypeObservers>> |
| 175 storage_type_observers_map_; |
| 177 | 176 |
| 178 DISALLOW_COPY_AND_ASSIGN(StorageMonitor); | 177 DISALLOW_COPY_AND_ASSIGN(StorageMonitor); |
| 179 }; | 178 }; |
| 180 | 179 |
| 181 } // namespace storage | 180 } // namespace storage |
| 182 | 181 |
| 183 #endif // STORAGE_BROWSER_QUOTA_STORAGE_MONITOR_H_ | 182 #endif // STORAGE_BROWSER_QUOTA_STORAGE_MONITOR_H_ |
| OLD | NEW |