Fix Win8 metro startup crash from window switcher button
[chromium-blink-merge.git] / webkit / quota / mock_storage_client.h
blobf8c3dd03ec326c65f3c1133dbd2a5acb48dafb46
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.
5 #ifndef WEBKIT_QUOTA_MOCK_STORAGE_CLIENT_H_
6 #define WEBKIT_QUOTA_MOCK_STORAGE_CLIENT_H_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <utility>
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"
19 namespace quota {
21 class QuotaManagerProxy;
23 struct MockOriginData {
24 const char* origin;
25 StorageType type;
26 int64 usage;
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();
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();
45 void AddOriginToErrorSet(const GURL& origin_url, StorageType type);
47 base::Time IncrementMockTime();
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;
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);
76 void Populate(const MockOriginData* mock_data, size_t mock_data_size);
78 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_;
79 const ID id_;
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_;
86 int mock_time_counter_;
88 base::WeakPtrFactory<MockStorageClient> weak_factory_;
90 DISALLOW_COPY_AND_ASSIGN(MockStorageClient);
93 } // namespace quota
95 #endif // WEBKIT_QUOTA_MOCK_STORAGE_CLIENT_H_