| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_MOCK_QUOTA_MANAGER_H_ | 5 #ifndef WEBKIT_BROWSER_QUOTA_MOCK_QUOTA_MANAGER_H_ |
| 6 #define WEBKIT_BROWSER_QUOTA_MOCK_QUOTA_MANAGER_H_ | 6 #define WEBKIT_BROWSER_QUOTA_MOCK_QUOTA_MANAGER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <map> |
| 9 #include <set> |
| 10 #include <utility> |
| 9 #include <vector> | 11 #include <vector> |
| 10 | 12 |
| 11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 12 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 13 #include "webkit/browser/quota/quota_client.h" | 15 #include "webkit/browser/quota/quota_client.h" |
| 14 #include "webkit/browser/quota/quota_manager.h" | 16 #include "webkit/browser/quota/quota_manager.h" |
| 15 #include "webkit/browser/quota/quota_task.h" | 17 #include "webkit/browser/quota/quota_task.h" |
| 16 #include "webkit/common/quota/quota_types.h" | 18 #include "webkit/common/quota/quota_types.h" |
| 17 | 19 |
| 18 namespace quota { | 20 namespace quota { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 QuotaStatusCode status); | 132 QuotaStatusCode status); |
| 131 | 133 |
| 132 // The list of stored origins that have been added via AddOrigin. | 134 // The list of stored origins that have been added via AddOrigin. |
| 133 std::vector<OriginInfo> origins_; | 135 std::vector<OriginInfo> origins_; |
| 134 UsageAndQuotaMap usage_and_quota_map_; | 136 UsageAndQuotaMap usage_and_quota_map_; |
| 135 base::WeakPtrFactory<MockQuotaManager> weak_factory_; | 137 base::WeakPtrFactory<MockQuotaManager> weak_factory_; |
| 136 | 138 |
| 137 DISALLOW_COPY_AND_ASSIGN(MockQuotaManager); | 139 DISALLOW_COPY_AND_ASSIGN(MockQuotaManager); |
| 138 }; | 140 }; |
| 139 | 141 |
| 140 // MockQuotaManagerProxy. | |
| 141 class MockQuotaManagerProxy : public QuotaManagerProxy { | |
| 142 public: | |
| 143 // It is ok to give NULL to |quota_manager|. | |
| 144 MockQuotaManagerProxy(MockQuotaManager* quota_manager, | |
| 145 base::SingleThreadTaskRunner* task_runner); | |
| 146 | |
| 147 virtual void RegisterClient(QuotaClient* client) OVERRIDE; | |
| 148 | |
| 149 void SimulateQuotaManagerDestroyed(); | |
| 150 | |
| 151 // We don't mock them. | |
| 152 virtual void NotifyOriginInUse(const GURL& origin) OVERRIDE {} | |
| 153 virtual void NotifyOriginNoLongerInUse(const GURL& origin) OVERRIDE {} | |
| 154 virtual void SetUsageCacheEnabled(QuotaClient::ID client_id, | |
| 155 const GURL& origin, | |
| 156 StorageType type, | |
| 157 bool enabled) OVERRIDE {} | |
| 158 virtual void GetUsageAndQuota( | |
| 159 base::SequencedTaskRunner* original_task_runner, | |
| 160 const GURL& origin, | |
| 161 StorageType type, | |
| 162 const QuotaManager::GetUsageAndQuotaCallback& callback) OVERRIDE {} | |
| 163 | |
| 164 // Validates the |client_id| and updates the internal access count | |
| 165 // which can be accessed via notify_storage_accessed_count(). | |
| 166 // The also records the |origin| and |type| in last_notified_origin_ and | |
| 167 // last_notified_type_. | |
| 168 virtual void NotifyStorageAccessed(QuotaClient::ID client_id, | |
| 169 const GURL& origin, | |
| 170 StorageType type) OVERRIDE; | |
| 171 | |
| 172 // Records the |origin|, |type| and |delta| as last_notified_origin_, | |
| 173 // last_notified_type_ and last_notified_delta_ respecitvely. | |
| 174 // If non-null MockQuotaManager is given to the constructor this also | |
| 175 // updates the manager's internal usage information. | |
| 176 virtual void NotifyStorageModified(QuotaClient::ID client_id, | |
| 177 const GURL& origin, | |
| 178 StorageType type, | |
| 179 int64 delta) OVERRIDE; | |
| 180 | |
| 181 int notify_storage_accessed_count() const { return storage_accessed_count_; } | |
| 182 int notify_storage_modified_count() const { return storage_modified_count_; } | |
| 183 GURL last_notified_origin() const { return last_notified_origin_; } | |
| 184 StorageType last_notified_type() const { return last_notified_type_; } | |
| 185 int64 last_notified_delta() const { return last_notified_delta_; } | |
| 186 | |
| 187 protected: | |
| 188 virtual ~MockQuotaManagerProxy(); | |
| 189 | |
| 190 private: | |
| 191 MockQuotaManager* mock_manager() const { | |
| 192 return static_cast<MockQuotaManager*>(quota_manager()); | |
| 193 } | |
| 194 | |
| 195 int storage_accessed_count_; | |
| 196 int storage_modified_count_; | |
| 197 GURL last_notified_origin_; | |
| 198 StorageType last_notified_type_; | |
| 199 int64 last_notified_delta_; | |
| 200 | |
| 201 QuotaClient* registered_client_; | |
| 202 }; | |
| 203 | |
| 204 } // namespace quota | 142 } // namespace quota |
| 205 | 143 |
| 206 #endif // WEBKIT_BROWSER_QUOTA_MOCK_QUOTA_MANAGER_H_ | 144 #endif // WEBKIT_BROWSER_QUOTA_MOCK_QUOTA_MANAGER_H_ |
| OLD | NEW |