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

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

Issue 136573007: Quota: Factor out (Mock)QuotaManagerProxy into its own file for readability (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fix Created 6 years, 11 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
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 #include "webkit/browser/quota/mock_quota_manager.h" 5 #include "webkit/browser/quota/mock_quota_manager.h"
6 6
7 #include <set>
8 #include <string>
9 #include <vector>
10
11 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
14 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
15 #include "url/gurl.h" 11 #include "url/gurl.h"
16 12
17 namespace quota { 13 namespace quota {
18 14
19 MockQuotaManager::OriginInfo::OriginInfo( 15 MockQuotaManager::OriginInfo::OriginInfo(
20 const GURL& origin, 16 const GURL& origin,
21 StorageType type, 17 StorageType type,
22 int quota_client_mask, 18 int quota_client_mask,
23 base::Time modified) 19 base::Time modified)
24 : origin(origin), 20 : origin(origin),
25 type(type), 21 type(type),
26 quota_client_mask(quota_client_mask), 22 quota_client_mask(quota_client_mask),
27 modified(modified) { 23 modified(modified) {
28 } 24 }
29 25
30 MockQuotaManager::OriginInfo::~OriginInfo() {} 26 MockQuotaManager::OriginInfo::~OriginInfo() {}
31 27
32 MockQuotaManager::StorageInfo::StorageInfo() : usage(0), quota(kint64max) {} 28 MockQuotaManager::StorageInfo::StorageInfo() : usage(0), quota(kint64max) {}
33 MockQuotaManager::StorageInfo::~StorageInfo() {} 29 MockQuotaManager::StorageInfo::~StorageInfo() {}
34 30
35 // MockQuotaManager ----------------------------------------------------------
36
37 MockQuotaManager::MockQuotaManager( 31 MockQuotaManager::MockQuotaManager(
38 bool is_incognito, 32 bool is_incognito,
39 const base::FilePath& profile_path, 33 const base::FilePath& profile_path,
40 base::SingleThreadTaskRunner* io_thread, 34 base::SingleThreadTaskRunner* io_thread,
41 base::SequencedTaskRunner* db_thread, 35 base::SequencedTaskRunner* db_thread,
42 SpecialStoragePolicy* special_storage_policy) 36 SpecialStoragePolicy* special_storage_policy)
43 : QuotaManager(is_incognito, profile_path, io_thread, db_thread, 37 : QuotaManager(is_incognito, profile_path, io_thread, db_thread,
44 special_storage_policy), 38 special_storage_policy),
45 weak_factory_(this) { 39 weak_factory_(this) {
46 } 40 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 StorageType storage_type) { 135 StorageType storage_type) {
142 callback.Run(*origins, storage_type); 136 callback.Run(*origins, storage_type);
143 } 137 }
144 138
145 void MockQuotaManager::DidDeleteOriginData( 139 void MockQuotaManager::DidDeleteOriginData(
146 const StatusCallback& callback, 140 const StatusCallback& callback,
147 QuotaStatusCode status) { 141 QuotaStatusCode status) {
148 callback.Run(status); 142 callback.Run(status);
149 } 143 }
150 144
151 // MockQuotaManagerProxy -----------------------------------------------------
152
153 MockQuotaManagerProxy::MockQuotaManagerProxy(
154 MockQuotaManager* quota_manager,
155 base::SingleThreadTaskRunner* task_runner)
156 : QuotaManagerProxy(quota_manager, task_runner),
157 storage_accessed_count_(0),
158 storage_modified_count_(0),
159 last_notified_type_(kStorageTypeUnknown),
160 last_notified_delta_(0),
161 registered_client_(NULL) {}
162
163 void MockQuotaManagerProxy::RegisterClient(QuotaClient* client) {
164 DCHECK(!registered_client_);
165 registered_client_ = client;
166 }
167
168 void MockQuotaManagerProxy::SimulateQuotaManagerDestroyed() {
169 if (registered_client_) {
170 // We cannot call this in the destructor as the client (indirectly)
171 // holds a refptr of the proxy.
172 registered_client_->OnQuotaManagerDestroyed();
173 registered_client_ = NULL;
174 }
175 }
176
177 void MockQuotaManagerProxy::NotifyStorageAccessed(
178 QuotaClient::ID client_id, const GURL& origin, StorageType type) {
179 ++storage_accessed_count_;
180 last_notified_origin_ = origin;
181 last_notified_type_ = type;
182 }
183
184 void MockQuotaManagerProxy::NotifyStorageModified(
185 QuotaClient::ID client_id, const GURL& origin,
186 StorageType type, int64 delta) {
187 ++storage_modified_count_;
188 last_notified_origin_ = origin;
189 last_notified_type_ = type;
190 last_notified_delta_ = delta;
191 if (mock_manager())
192 mock_manager()->UpdateUsage(origin, type, delta);
193 }
194
195 MockQuotaManagerProxy::~MockQuotaManagerProxy() {
196 DCHECK(!registered_client_);
197 }
198
199 } // namespace quota 145 } // namespace quota
OLDNEW
« no previous file with comments | « webkit/browser/quota/mock_quota_manager.h ('k') | webkit/browser/quota/mock_quota_manager_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698