| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 WEBKIT_QUOTA_MOCK_STORAGE_CLIENT_H_ | |
| 6 #define WEBKIT_QUOTA_MOCK_STORAGE_CLIENT_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <set> | |
| 10 #include <string> | |
| 11 #include <utility> | |
| 12 | |
| 13 #include "base/compiler_specific.h" | |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 #include "base/time.h" | |
| 16 #include "googleurl/src/gurl.h" | |
| 17 #include "webkit/quota/quota_client.h" | |
| 18 | |
| 19 namespace quota { | |
| 20 | |
| 21 class QuotaManagerProxy; | |
| 22 | |
| 23 struct MockOriginData { | |
| 24 const char* origin; | |
| 25 StorageType type; | |
| 26 int64 usage; | |
| 27 }; | |
| 28 | |
| 29 // Mock storage class for testing. | |
| 30 class MockStorageClient : public QuotaClient { | |
| 31 public: | |
| 32 MockStorageClient(QuotaManagerProxy* quota_manager_proxy, | |
| 33 const MockOriginData* mock_data, | |
| 34 QuotaClient::ID id, | |
| 35 size_t mock_data_size); | |
| 36 virtual ~MockStorageClient(); | |
| 37 | |
| 38 // To add or modify mock data in this client. | |
| 39 void AddOriginAndNotify( | |
| 40 const GURL& origin_url, StorageType type, int64 size); | |
| 41 void ModifyOriginAndNotify( | |
| 42 const GURL& origin_url, StorageType type, int64 delta); | |
| 43 void TouchAllOriginsAndNotify(); | |
| 44 | |
| 45 void AddOriginToErrorSet(const GURL& origin_url, StorageType type); | |
| 46 | |
| 47 base::Time IncrementMockTime(); | |
| 48 | |
| 49 // QuotaClient methods. | |
| 50 virtual QuotaClient::ID id() const OVERRIDE; | |
| 51 virtual void OnQuotaManagerDestroyed() OVERRIDE; | |
| 52 virtual void GetOriginUsage(const GURL& origin_url, | |
| 53 StorageType type, | |
| 54 const GetUsageCallback& callback) OVERRIDE; | |
| 55 virtual void GetOriginsForType(StorageType type, | |
| 56 const GetOriginsCallback& callback) OVERRIDE; | |
| 57 virtual void GetOriginsForHost(StorageType type, const std::string& host, | |
| 58 const GetOriginsCallback& callback) OVERRIDE; | |
| 59 virtual void DeleteOriginData(const GURL& origin, | |
| 60 StorageType type, | |
| 61 const DeletionCallback& callback) OVERRIDE; | |
| 62 | |
| 63 private: | |
| 64 void RunGetOriginUsage(const GURL& origin_url, | |
| 65 StorageType type, | |
| 66 const GetUsageCallback& callback); | |
| 67 void RunGetOriginsForType(StorageType type, | |
| 68 const GetOriginsCallback& callback); | |
| 69 void RunGetOriginsForHost(StorageType type, | |
| 70 const std::string& host, | |
| 71 const GetOriginsCallback& callback); | |
| 72 void RunDeleteOriginData(const GURL& origin_url, | |
| 73 StorageType type, | |
| 74 const DeletionCallback& callback); | |
| 75 | |
| 76 void Populate(const MockOriginData* mock_data, size_t mock_data_size); | |
| 77 | |
| 78 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; | |
| 79 const ID id_; | |
| 80 | |
| 81 typedef std::map<std::pair<GURL, StorageType>, int64> OriginDataMap; | |
| 82 OriginDataMap origin_data_; | |
| 83 typedef std::set<std::pair<GURL, StorageType> > ErrorOriginSet; | |
| 84 ErrorOriginSet error_origins_; | |
| 85 | |
| 86 int mock_time_counter_; | |
| 87 | |
| 88 base::WeakPtrFactory<MockStorageClient> weak_factory_; | |
| 89 | |
| 90 DISALLOW_COPY_AND_ASSIGN(MockStorageClient); | |
| 91 }; | |
| 92 | |
| 93 } // namespace quota | |
| 94 | |
| 95 #endif // WEBKIT_QUOTA_MOCK_STORAGE_CLIENT_H_ | |
| OLD | NEW |