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

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

Issue 8070001: Use base::Callback in Quota related code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 2 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') | webkit/quota/mock_quota_manager_unittest.cc » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
14 #include "webkit/quota/quota_client.h" 14 #include "webkit/quota/quota_client.h"
15 #include "webkit/quota/quota_manager.h" 15 #include "webkit/quota/quota_manager.h"
16 #include "webkit/quota/quota_task.h" 16 #include "webkit/quota/quota_task.h"
17 #include "webkit/quota/quota_types.h" 17 #include "webkit/quota/quota_types.h"
18 18
19 namespace quota { 19 namespace quota {
20 20
21 class MockQuotaManager::GetModifiedSinceTask : public QuotaThreadTask { 21 class MockQuotaManager::GetModifiedSinceTask : public QuotaThreadTask {
22 public: 22 public:
23 GetModifiedSinceTask(MockQuotaManager* manager, 23 GetModifiedSinceTask(MockQuotaManager* manager,
24 const std::set<GURL>& origins, 24 const std::set<GURL>& origins,
25 StorageType type, 25 StorageType type,
26 GetOriginsCallback* callback) 26 const GetOriginsCallback& callback)
27 : QuotaThreadTask(manager, manager->io_thread_), 27 : QuotaThreadTask(manager, manager->io_thread_),
28 origins_(origins), 28 origins_(origins),
29 type_(type), 29 type_(type),
30 callback_(callback) {} 30 callback_(callback) {}
31 31
32 protected: 32 protected:
33 virtual void RunOnTargetThread() OVERRIDE {} 33 virtual void RunOnTargetThread() OVERRIDE {}
34 34
35 virtual void Completed() OVERRIDE { 35 virtual void Completed() OVERRIDE {
36 callback_->Run(origins_, type_); 36 callback_.Run(origins_, type_);
37 } 37 }
38 38
39 virtual void Aborted() OVERRIDE { 39 virtual void Aborted() OVERRIDE {
40 callback_->Run(std::set<GURL>(), type_); 40 callback_.Run(std::set<GURL>(), type_);
41 } 41 }
42 42
43 private: 43 private:
44 std::set<GURL> origins_; 44 std::set<GURL> origins_;
45 StorageType type_; 45 StorageType type_;
46 scoped_ptr<GetOriginsCallback> callback_; 46 GetOriginsCallback callback_;
47 47
48 DISALLOW_COPY_AND_ASSIGN(GetModifiedSinceTask); 48 DISALLOW_COPY_AND_ASSIGN(GetModifiedSinceTask);
49 }; 49 };
50 50
51 class MockQuotaManager::DeleteOriginDataTask : public QuotaThreadTask { 51 class MockQuotaManager::DeleteOriginDataTask : public QuotaThreadTask {
52 public: 52 public:
53 DeleteOriginDataTask(MockQuotaManager* manager, 53 DeleteOriginDataTask(MockQuotaManager* manager,
54 StatusCallback* callback) 54 const StatusCallback& callback)
55 : QuotaThreadTask(manager, manager->io_thread_), 55 : QuotaThreadTask(manager, manager->io_thread_),
56 callback_(callback) {} 56 callback_(callback) {}
57 57
58 protected: 58 protected:
59 virtual void RunOnTargetThread() OVERRIDE {} 59 virtual void RunOnTargetThread() OVERRIDE {}
60 60
61 virtual void Completed() OVERRIDE { 61 virtual void Completed() OVERRIDE {
62 callback_->Run(quota::kQuotaStatusOk); 62 callback_.Run(quota::kQuotaStatusOk);
63 } 63 }
64 64
65 virtual void Aborted() OVERRIDE { 65 virtual void Aborted() OVERRIDE {
66 callback_->Run(quota::kQuotaErrorAbort); 66 callback_.Run(quota::kQuotaErrorAbort);
67 } 67 }
68 68
69 private: 69 private:
70 scoped_ptr<StatusCallback> callback_; 70 StatusCallback callback_;
71 71
72 DISALLOW_COPY_AND_ASSIGN(DeleteOriginDataTask); 72 DISALLOW_COPY_AND_ASSIGN(DeleteOriginDataTask);
73 }; 73 };
74 74
75 MockQuotaManager::OriginInfo::OriginInfo( 75 MockQuotaManager::OriginInfo::OriginInfo(
76 const GURL& origin, 76 const GURL& origin,
77 StorageType type, 77 StorageType type,
78 base::Time modified) 78 base::Time modified)
79 : origin(origin), 79 : origin(origin),
80 type(type), 80 type(type),
(...skipping 22 matching lines...) Expand all
103 StorageType type) const { 103 StorageType type) const {
104 for (std::vector<OriginInfo>::const_iterator current = origins_.begin(); 104 for (std::vector<OriginInfo>::const_iterator current = origins_.begin();
105 current != origins_.end(); 105 current != origins_.end();
106 ++current) { 106 ++current) {
107 if (current->origin == origin && current->type == type) 107 if (current->origin == origin && current->type == type)
108 return true; 108 return true;
109 } 109 }
110 return false; 110 return false;
111 } 111 }
112 112
113 void MockQuotaManager::GetOriginsModifiedSince(StorageType type, 113 void MockQuotaManager::GetOriginsModifiedSince(
114 base::Time modified_since, GetOriginsCallback* callback) { 114 StorageType type,
115 base::Time modified_since,
116 const GetOriginsCallback& callback) {
115 std::set<GURL> origins_to_return; 117 std::set<GURL> origins_to_return;
116 for (std::vector<OriginInfo>::const_iterator current = origins_.begin(); 118 for (std::vector<OriginInfo>::const_iterator current = origins_.begin();
117 current != origins_.end(); 119 current != origins_.end();
118 ++current) { 120 ++current) {
119 if (current->type == type && current->modified >= modified_since) 121 if (current->type == type && current->modified >= modified_since)
120 origins_to_return.insert(current->origin); 122 origins_to_return.insert(current->origin);
121 } 123 }
122 make_scoped_refptr(new GetModifiedSinceTask(this, origins_to_return, type, 124 make_scoped_refptr(new GetModifiedSinceTask(this, origins_to_return, type,
123 callback))->Start(); 125 callback))->Start();
124 } 126 }
125 127
126 void MockQuotaManager::DeleteOriginData(const GURL& origin, StorageType type, 128 void MockQuotaManager::DeleteOriginData(const GURL& origin, StorageType type,
127 StatusCallback* callback) { 129 const StatusCallback& callback) {
128 for (std::vector<OriginInfo>::iterator current = origins_.begin(); 130 for (std::vector<OriginInfo>::iterator current = origins_.begin();
129 current != origins_.end(); 131 current != origins_.end();
130 ++current) { 132 ++current) {
131 if (current->origin == origin && current->type == type) { 133 if (current->origin == origin && current->type == type) {
132 origins_.erase(current); 134 origins_.erase(current);
133 break; 135 break;
134 } 136 }
135 } 137 }
136 make_scoped_refptr(new DeleteOriginDataTask(this, callback))->Start(); 138 make_scoped_refptr(new DeleteOriginDataTask(this, callback))->Start();
137 } 139 }
138 140
139 } // namespace quota 141 } // namespace quota
OLDNEW
« no previous file with comments | « webkit/quota/mock_quota_manager.h ('k') | webkit/quota/mock_quota_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698