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

Side by Side Diff: webkit/quota/mock_quota_manager.cc

Issue 10915202: Cleanup: merge MockQuotaManager in multiple places (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase2 Created 8 years, 3 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
« no previous file with comments | « webkit/quota/mock_quota_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include "webkit/quota/mock_quota_manager.h" 5 #include "webkit/quota/mock_quota_manager.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 int quota_client_mask, 83 int quota_client_mask,
84 base::Time modified) 84 base::Time modified)
85 : origin(origin), 85 : origin(origin),
86 type(type), 86 type(type),
87 quota_client_mask(quota_client_mask), 87 quota_client_mask(quota_client_mask),
88 modified(modified) { 88 modified(modified) {
89 } 89 }
90 90
91 MockQuotaManager::OriginInfo::~OriginInfo() {} 91 MockQuotaManager::OriginInfo::~OriginInfo() {}
92 92
93 MockQuotaManager::StorageInfo::StorageInfo() : usage(0), quota(kint64max) {}
94 MockQuotaManager::StorageInfo::~StorageInfo() {}
95
96 // MockQuotaManager ----------------------------------------------------------
97
93 MockQuotaManager::MockQuotaManager( 98 MockQuotaManager::MockQuotaManager(
94 bool is_incognito, 99 bool is_incognito,
95 const FilePath& profile_path, 100 const FilePath& profile_path,
96 base::SingleThreadTaskRunner* io_thread, 101 base::SingleThreadTaskRunner* io_thread,
97 base::SequencedTaskRunner* db_thread, 102 base::SequencedTaskRunner* db_thread,
98 SpecialStoragePolicy* special_storage_policy) 103 SpecialStoragePolicy* special_storage_policy)
99 : QuotaManager(is_incognito, profile_path, io_thread, db_thread, 104 : QuotaManager(is_incognito, profile_path, io_thread, db_thread,
100 special_storage_policy) { 105 special_storage_policy) {
101 } 106 }
102 107
108 void MockQuotaManager::GetUsageAndQuota(
109 const GURL& origin,
110 quota::StorageType type,
111 const GetUsageAndQuotaCallback& callback) {
112 StorageInfo& info = usage_and_quota_map_[std::make_pair(origin, type)];
113 callback.Run(quota::kQuotaStatusOk, info.usage, info.quota);
114 }
115
116 void MockQuotaManager::SetQuota(const GURL& origin, StorageType type,
117 int64 quota) {
118 usage_and_quota_map_[std::make_pair(origin, type)].quota = quota;
119 }
120
103 bool MockQuotaManager::AddOrigin( 121 bool MockQuotaManager::AddOrigin(
104 const GURL& origin, 122 const GURL& origin,
105 StorageType type, 123 StorageType type,
106 int quota_client_mask, 124 int quota_client_mask,
107 base::Time modified) { 125 base::Time modified) {
108 origins_.push_back(OriginInfo(origin, type, quota_client_mask, modified)); 126 origins_.push_back(OriginInfo(origin, type, quota_client_mask, modified));
109 return true; 127 return true;
110 } 128 }
111 129
112 bool MockQuotaManager::OriginHasData( 130 bool MockQuotaManager::OriginHasData(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 if (current->quota_client_mask == 0) 171 if (current->quota_client_mask == 0)
154 origins_.erase(current); 172 origins_.erase(current);
155 break; 173 break;
156 } 174 }
157 } 175 }
158 make_scoped_refptr(new DeleteOriginDataTask(this, callback))->Start(); 176 make_scoped_refptr(new DeleteOriginDataTask(this, callback))->Start();
159 } 177 }
160 178
161 MockQuotaManager::~MockQuotaManager() {} 179 MockQuotaManager::~MockQuotaManager() {}
162 180
181 void MockQuotaManager::UpdateUsage(
182 const GURL& origin, StorageType type, int64 delta) {
183 usage_and_quota_map_[std::make_pair(origin, type)].usage += delta;
184 }
185
186 // MockQuotaManagerProxy -----------------------------------------------------
187
188 MockQuotaManagerProxy::MockQuotaManagerProxy(
189 MockQuotaManager* quota_manager,
190 base::SingleThreadTaskRunner* task_runner)
191 : QuotaManagerProxy(quota_manager, task_runner),
192 storage_accessed_count_(0),
193 storage_modified_count_(0),
194 last_notified_type_(kStorageTypeUnknown),
195 last_notified_delta_(0),
196 registered_client_(NULL) {}
197
198 void MockQuotaManagerProxy::RegisterClient(QuotaClient* client) {
199 DCHECK(!registered_client_);
200 registered_client_ = client;
201 }
202
203 void MockQuotaManagerProxy::SimulateQuotaManagerDestroyed() {
204 if (registered_client_) {
205 // We cannot call this in the destructor as the client (indirectly)
206 // holds a refptr of the proxy.
207 registered_client_->OnQuotaManagerDestroyed();
208 registered_client_ = NULL;
209 }
210 }
211
212 void MockQuotaManagerProxy::NotifyStorageAccessed(
213 QuotaClient::ID client_id, const GURL& origin, StorageType type) {
214 ++storage_accessed_count_;
215 last_notified_origin_ = origin;
216 last_notified_type_ = type;
217 }
218
219 void MockQuotaManagerProxy::NotifyStorageModified(
220 QuotaClient::ID client_id, const GURL& origin,
221 StorageType type, int64 delta) {
222 ++storage_modified_count_;
223 last_notified_origin_ = origin;
224 last_notified_type_ = type;
225 last_notified_delta_ = delta;
226 if (mock_manager())
227 mock_manager()->UpdateUsage(origin, type, delta);
228 }
229
230 MockQuotaManagerProxy::~MockQuotaManagerProxy() {
231 DCHECK(!registered_client_);
232 }
233
163 } // namespace quota 234 } // namespace quota
OLDNEW
« no previous file with comments | « webkit/quota/mock_quota_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698