Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(723)

Side by Side Diff: webkit/browser/quota/mock_quota_manager.h

Issue 214233005: Move mock_quota_manager and friends from webkit/ to content/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef WEBKIT_BROWSER_QUOTA_MOCK_QUOTA_MANAGER_H_
6 #define WEBKIT_BROWSER_QUOTA_MOCK_QUOTA_MANAGER_H_
7
8 #include <map>
9 #include <set>
10 #include <utility>
11 #include <vector>
12
13 #include "base/memory/scoped_ptr.h"
14 #include "url/gurl.h"
15 #include "webkit/browser/quota/quota_client.h"
16 #include "webkit/browser/quota/quota_manager.h"
17 #include "webkit/browser/quota/quota_task.h"
18 #include "webkit/common/quota/quota_types.h"
19
20 namespace quota {
21
22 // Mocks the pieces of QuotaManager's interface.
23 //
24 // For usage/quota tracking test:
25 // Usage and quota information can be updated by following private helper
26 // methods: SetQuota() and UpdateUsage().
27 //
28 // For time-based deletion test:
29 // Origins can be added to the mock by calling AddOrigin, and that list of
30 // origins is then searched through in GetOriginsModifiedSince.
31 // Neither GetOriginsModifiedSince nor DeleteOriginData touches the actual
32 // origin data stored in the profile.
33 class MockQuotaManager : public QuotaManager {
34 public:
35 MockQuotaManager(bool is_incognito,
36 const base::FilePath& profile_path,
37 base::SingleThreadTaskRunner* io_thread,
38 base::SequencedTaskRunner* db_thread,
39 SpecialStoragePolicy* special_storage_policy);
40
41 // Overrides QuotaManager's implementation. The internal usage data is
42 // updated when MockQuotaManagerProxy::NotifyStorageModified() is
43 // called. The internal quota value can be updated by calling
44 // a helper method MockQuotaManagerProxy::SetQuota().
45 virtual void GetUsageAndQuota(
46 const GURL& origin,
47 quota::StorageType type,
48 const GetUsageAndQuotaCallback& callback) OVERRIDE;
49
50 // Overrides QuotaManager's implementation with a canned implementation that
51 // allows clients to set up the origin database that should be queried. This
52 // method will only search through the origins added explicitly via AddOrigin.
53 virtual void GetOriginsModifiedSince(
54 StorageType type,
55 base::Time modified_since,
56 const GetOriginsCallback& callback) OVERRIDE;
57
58 // Removes an origin from the canned list of origins, but doesn't touch
59 // anything on disk. The caller must provide |quota_client_mask| which
60 // specifies the types of QuotaClients which should be removed from this
61 // origin as a bitmask built from QuotaClient::IDs. Setting the mask to
62 // QuotaClient::kAllClientsMask will remove all clients from the origin,
63 // regardless of type.
64 virtual void DeleteOriginData(const GURL& origin,
65 StorageType type,
66 int quota_client_mask,
67 const StatusCallback& callback) OVERRIDE;
68
69 // Helper method for updating internal quota info.
70 void SetQuota(const GURL& origin, StorageType type, int64 quota);
71
72 // Helper methods for timed-deletion testing:
73 // Adds an origin to the canned list that will be searched through via
74 // GetOriginsModifiedSince. The caller must provide |quota_client_mask|
75 // which specifies the types of QuotaClients this canned origin contains
76 // as a bitmask built from QuotaClient::IDs.
77 bool AddOrigin(const GURL& origin,
78 StorageType type,
79 int quota_client_mask,
80 base::Time modified);
81
82 // Helper methods for timed-deletion testing:
83 // Checks an origin and type against the origins that have been added via
84 // AddOrigin and removed via DeleteOriginData. If the origin exists in the
85 // canned list with the proper StorageType and client, returns true.
86 bool OriginHasData(const GURL& origin,
87 StorageType type,
88 QuotaClient::ID quota_client) const;
89
90 protected:
91 virtual ~MockQuotaManager();
92
93 private:
94 friend class MockQuotaManagerProxy;
95
96 // Contains the essential bits of information about an origin that the
97 // MockQuotaManager needs to understand for time-based deletion:
98 // the origin itself, the StorageType and its modification time.
99 struct OriginInfo {
100 OriginInfo(const GURL& origin,
101 StorageType type,
102 int quota_client_mask,
103 base::Time modified);
104 ~OriginInfo();
105
106 GURL origin;
107 StorageType type;
108 int quota_client_mask;
109 base::Time modified;
110 };
111
112 // Contains the essential information for each origin for usage/quota testing.
113 // (Ideally this should probably merged into the above struct, but for
114 // regular usage/quota testing we hardly need modified time but only
115 // want to keep usage and quota information, so this struct exists.
116 struct StorageInfo {
117 StorageInfo();
118 ~StorageInfo();
119 int64 usage;
120 int64 quota;
121 };
122
123 typedef std::pair<GURL, StorageType> OriginAndType;
124 typedef std::map<OriginAndType, StorageInfo> UsageAndQuotaMap;
125
126 // This must be called via MockQuotaManagerProxy.
127 void UpdateUsage(const GURL& origin, StorageType type, int64 delta);
128 void DidGetModifiedSince(const GetOriginsCallback& callback,
129 std::set<GURL>* origins,
130 StorageType storage_type);
131 void DidDeleteOriginData(const StatusCallback& callback,
132 QuotaStatusCode status);
133
134 // The list of stored origins that have been added via AddOrigin.
135 std::vector<OriginInfo> origins_;
136 UsageAndQuotaMap usage_and_quota_map_;
137 base::WeakPtrFactory<MockQuotaManager> weak_factory_;
138
139 DISALLOW_COPY_AND_ASSIGN(MockQuotaManager);
140 };
141
142 } // namespace quota
143
144 #endif // WEBKIT_BROWSER_QUOTA_MOCK_QUOTA_MANAGER_H_
OLDNEW
« no previous file with comments | « webkit/browser/appcache/appcache_storage_unittest.cc ('k') | webkit/browser/quota/mock_quota_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698