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

Side by Side Diff: webkit/quota/quota_types.h

Issue 8070001: Use base::Callback in Quota related code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: choke lint 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
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 #ifndef WEBKIT_QUOTA_QUOTA_TYPES_H_ 5 #ifndef WEBKIT_QUOTA_QUOTA_TYPES_H_
6 #define WEBKIT_QUOTA_QUOTA_TYPES_H_ 6 #define WEBKIT_QUOTA_QUOTA_TYPES_H_
7 #pragma once 7 #pragma once
8 8
9 #include <deque> 9 #include <deque>
10 #include <map> 10 #include <map>
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/callback_old.h" 15 #include "base/callback.h"
16 #include "base/stl_util.h"
17 16
18 class GURL; 17 class GURL;
19 18
20 namespace quota { 19 namespace quota {
21 20
22 enum StorageType { 21 enum StorageType {
23 kStorageTypeTemporary, 22 kStorageTypeTemporary,
24 kStorageTypePersistent, 23 kStorageTypePersistent,
25 kStorageTypeUnknown, 24 kStorageTypeUnknown,
26 }; 25 };
27 26
28 // The numbers should match with the error code defined in 27 // The numbers should match with the error code defined in
29 // third_party/WebKit/Source/WebCore/dom/ExceptionCode.h. 28 // third_party/WebKit/Source/WebCore/dom/ExceptionCode.h.
30 enum QuotaStatusCode { 29 enum QuotaStatusCode {
31 kQuotaStatusOk = 0, 30 kQuotaStatusOk = 0,
32 kQuotaErrorNotSupported = 9, // NOT_SUPPORTED_ERR 31 kQuotaErrorNotSupported = 9, // NOT_SUPPORTED_ERR
33 kQuotaErrorInvalidModification = 13, // INVALID_MODIFICATION_ERR 32 kQuotaErrorInvalidModification = 13, // INVALID_MODIFICATION_ERR
34 kQuotaErrorInvalidAccess = 15, // INVALID_ACCESS_ERR 33 kQuotaErrorInvalidAccess = 15, // INVALID_ACCESS_ERR
35 kQuotaErrorAbort = 20, // ABORT_ERR 34 kQuotaErrorAbort = 20, // ABORT_ERR
36 kQuotaStatusUnknown = -1, 35 kQuotaStatusUnknown = -1,
37 }; 36 };
38 37
39 // Common callback types that are used throughout in the quota module. 38 // Common callback types that are used throughout in the quota module.
40 typedef Callback2<StorageType, int64>::Type UsageCallback; 39 typedef base::Callback<void (StorageType, int64)> UsageCallback;
awong 2011/09/29 18:05:15 remove space after void.
tzik 2011/10/11 04:53:57 Done.
41 typedef Callback3<StorageType, int64, int64>::Type GlobalUsageCallback; 40 typedef base::Callback<void (StorageType, int64, int64)> GlobalUsageCallback;
42 typedef Callback3<QuotaStatusCode, 41 typedef base::Callback<void (QuotaStatusCode, StorageType, int64)>
43 StorageType, 42 QuotaCallback;
44 int64>::Type QuotaCallback; 43 typedef base::Callback<void (const std::string&, StorageType, int64)>
45 typedef Callback3<const std::string& /* host */, 44 HostUsageCallback;
46 StorageType, 45 typedef base::Callback<void (QuotaStatusCode,
47 int64>::Type HostUsageCallback; 46 const std::string&,
48 typedef Callback4<QuotaStatusCode, 47 StorageType,
49 const std::string& /* host */, 48 int64)> HostQuotaCallback;
50 StorageType, 49 typedef base::Callback<void (QuotaStatusCode, int64)> AvailableSpaceCallback;
51 int64>::Type HostQuotaCallback; 50 typedef base::Callback<void (QuotaStatusCode)> StatusCallback;
52 typedef Callback2<QuotaStatusCode, 51 typedef base::Callback<void (const std::set<GURL>&, StorageType)>
53 int64>::Type AvailableSpaceCallback; 52 GetOriginsCallback;
54 typedef Callback1<QuotaStatusCode>::Type StatusCallback;
55 typedef Callback2<const std::set<GURL>&, StorageType>::Type GetOriginsCallback;
56 53
57 // Simple template wrapper for a callback queue. 54 // Simple template wrapper for a callback queue.
58 template <typename CallbackType> 55 template <typename CallbackType>
59 class CallbackQueueBase { 56 class CallbackQueueBase {
60 public: 57 public:
61 typedef typename std::deque<CallbackType> Queue; 58 typedef typename std::deque<CallbackType> Queue;
62 typedef typename Queue::iterator iterator; 59 typedef typename Queue::iterator iterator;
63 60
64 virtual ~CallbackQueueBase() { 61 virtual ~CallbackQueueBase() {}
65 STLDeleteContainerPointers(callbacks_.begin(), callbacks_.end());
66 }
67 62
68 // Returns true if the given |callback| is the first one added to the queue. 63 // Returns true if the given |callback| is the first one added to the queue.
69 bool Add(CallbackType callback) { 64 bool Add(CallbackType callback) {
70 callbacks_.push_back(callback); 65 callbacks_.push_back(callback);
71 return (callbacks_.size() == 1); 66 return (callbacks_.size() == 1);
72 } 67 }
73 68
74 bool HasCallbacks() const { 69 bool HasCallbacks() const {
75 return !callbacks_.empty(); 70 return !callbacks_.empty();
76 } 71 }
77 72
78 protected: 73 protected:
79 std::deque<CallbackType> callbacks_; 74 std::deque<CallbackType> callbacks_;
80 }; 75 };
81 76
82 template <typename CallbackType1, typename A1> 77 template <typename CallbackType1, typename A1>
83 class CallbackQueue1 : public CallbackQueueBase<CallbackType1> { 78 class CallbackQueue1 : public CallbackQueueBase<CallbackType1> {
84 public: 79 public:
85 typedef typename CallbackQueueBase<CallbackType1>::Queue Queue; 80 typedef typename CallbackQueueBase<CallbackType1>::Queue Queue;
86 // Runs the callbacks added to the queue and clears the queue. 81 // Runs the callbacks added to the queue and clears the queue.
87 void Run(A1 arg) { 82 void Run(A1 arg) {
88 // Note: template-derived class needs 'this->' to access its base class. 83 // Note: template-derived class needs 'this->' to access its base class.
89 for (typename Queue::iterator iter = this->callbacks_.begin(); 84 for (typename Queue::iterator iter = this->callbacks_.begin();
90 iter != this->callbacks_.end(); ++iter) { 85 iter != this->callbacks_.end(); ++iter) {
91 (*iter)->Run(arg); 86 iter->Run(arg);
92 delete *iter;
93 } 87 }
94 this->callbacks_.clear(); 88 this->callbacks_.clear();
95 } 89 }
96 }; 90 };
97 91
98 template <typename CallbackType2, typename A1, typename A2> 92 template <typename CallbackType2, typename A1, typename A2>
99 class CallbackQueue2 : public CallbackQueueBase<CallbackType2> { 93 class CallbackQueue2 : public CallbackQueueBase<CallbackType2> {
100 public: 94 public:
101 typedef typename CallbackQueueBase<CallbackType2>::Queue Queue; 95 typedef typename CallbackQueueBase<CallbackType2>::Queue Queue;
102 // Runs the callbacks added to the queue and clears the queue. 96 // Runs the callbacks added to the queue and clears the queue.
103 void Run(A1 arg1, A2 arg2) { 97 void Run(A1 arg1, A2 arg2) {
104 for (typename Queue::iterator iter = this->callbacks_.begin(); 98 for (typename Queue::iterator iter = this->callbacks_.begin();
105 iter != this->callbacks_.end(); ++iter) { 99 iter != this->callbacks_.end(); ++iter) {
106 (*iter)->Run(arg1, arg2); 100 iter->Run(arg1, arg2);
107 delete *iter;
108 } 101 }
109 this->callbacks_.clear(); 102 this->callbacks_.clear();
110 } 103 }
111 }; 104 };
112 105
113 template <typename CallbackType3, typename A1, typename A2, typename A3> 106 template <typename CallbackType3, typename A1, typename A2, typename A3>
114 class CallbackQueue3 : public CallbackQueueBase<CallbackType3> { 107 class CallbackQueue3 : public CallbackQueueBase<CallbackType3> {
115 public: 108 public:
116 typedef typename CallbackQueueBase<CallbackType3>::Queue Queue; 109 typedef typename CallbackQueueBase<CallbackType3>::Queue Queue;
117 // Runs the callbacks added to the queue and clears the queue. 110 // Runs the callbacks added to the queue and clears the queue.
118 void Run(A1 arg1, A2 arg2, A3 arg3) { 111 void Run(A1 arg1, A2 arg2, A3 arg3) {
119 for (typename Queue::iterator iter = this->callbacks_.begin(); 112 for (typename Queue::iterator iter = this->callbacks_.begin();
120 iter != this->callbacks_.end(); ++iter) { 113 iter != this->callbacks_.end(); ++iter) {
121 (*iter)->Run(arg1, arg2, arg3); 114 iter->Run(arg1, arg2, arg3);
122 delete *iter;
123 } 115 }
124 this->callbacks_.clear(); 116 this->callbacks_.clear();
125 } 117 }
126 }; 118 };
127 119
128 template <typename CallbackType4, 120 template <typename CallbackType4,
129 typename A1, typename A2, typename A3, typename A4> 121 typename A1, typename A2, typename A3, typename A4>
130 class CallbackQueue4 : public CallbackQueueBase<CallbackType4> { 122 class CallbackQueue4 : public CallbackQueueBase<CallbackType4> {
131 public: 123 public:
132 typedef typename CallbackQueueBase<CallbackType4>::Queue Queue; 124 typedef typename CallbackQueueBase<CallbackType4>::Queue Queue;
133 // Runs the callbacks added to the queue and clears the queue. 125 // Runs the callbacks added to the queue and clears the queue.
134 void Run(A1 arg1, A2 arg2, A3 arg3, A4 arg4) { 126 void Run(A1 arg1, A2 arg2, A3 arg3, A4 arg4) {
135 for (typename Queue::iterator iter = this->callbacks_.begin(); 127 for (typename Queue::iterator iter = this->callbacks_.begin();
136 iter != this->callbacks_.end(); ++iter) { 128 iter != this->callbacks_.end(); ++iter) {
137 (*iter)->Run(arg1, arg2, arg3, arg4); 129 iter->Run(arg1, arg2, arg3, arg4);
138 delete *iter;
139 } 130 }
140 this->callbacks_.clear(); 131 this->callbacks_.clear();
141 } 132 }
142 }; 133 };
143 134
144 typedef CallbackQueue2<UsageCallback*, 135 typedef CallbackQueue2<UsageCallback,
145 StorageType, int64> UsageCallbackQueue; 136 StorageType, int64> UsageCallbackQueue;
146 typedef CallbackQueue3<GlobalUsageCallback*, 137 typedef CallbackQueue3<GlobalUsageCallback,
147 StorageType, int64, int64> GlobalUsageCallbackQueue; 138 StorageType, int64, int64> GlobalUsageCallbackQueue;
148 typedef CallbackQueue3<QuotaCallback*, 139 typedef CallbackQueue3<QuotaCallback,
149 QuotaStatusCode, 140 QuotaStatusCode,
150 StorageType, int64> QuotaCallbackQueue; 141 StorageType, int64> QuotaCallbackQueue;
151 142
152 template <typename CallbackType, typename CallbackQueueType, typename KEY> 143 template <typename CallbackType, typename CallbackQueueType, typename KEY>
153 class CallbackQueueMapBase { 144 class CallbackQueueMapBase {
154 public: 145 public:
155 typedef std::map<KEY, CallbackQueueType> CallbackMap; 146 typedef std::map<KEY, CallbackQueueType> CallbackMap;
156 typedef typename CallbackMap::iterator iterator; 147 typedef typename CallbackMap::iterator iterator;
157 148
158 bool Add(const KEY& key, CallbackType callback) { 149 bool Add(const KEY& key, CallbackType callback) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 // from the map. 256 // from the map.
266 void Run(const KEY& key, ARG1 arg1, ARG2 arg2, ARG3 arg3, ARG4 arg4) { 257 void Run(const KEY& key, ARG1 arg1, ARG2 arg2, ARG3 arg3, ARG4 arg4) {
267 if (!this->HasCallbacks(key)) 258 if (!this->HasCallbacks(key))
268 return; 259 return;
269 Queue& queue = this->callback_map_[key]; 260 Queue& queue = this->callback_map_[key];
270 queue.Run(arg1, arg2, arg3, arg4); 261 queue.Run(arg1, arg2, arg3, arg4);
271 this->callback_map_.erase(key); 262 this->callback_map_.erase(key);
272 } 263 }
273 }; 264 };
274 265
275 typedef CallbackQueueMap3<HostUsageCallback*, std::string, 266 typedef CallbackQueueMap3<HostUsageCallback, std::string,
276 const std::string&, 267 const std::string&,
277 StorageType, int64> HostUsageCallbackMap; 268 StorageType, int64> HostUsageCallbackMap;
278 typedef CallbackQueueMap4<HostQuotaCallback*, std::string, 269 typedef CallbackQueueMap4<HostQuotaCallback, std::string,
279 QuotaStatusCode, 270 QuotaStatusCode,
280 const std::string&, 271 const std::string&,
281 StorageType, int64> HostQuotaCallbackMap; 272 StorageType, int64> HostQuotaCallbackMap;
282 273
283 } // namespace quota 274 } // namespace quota
284 275
285 #endif // WEBKIT_QUOTA_QUOTA_TYPES_H_ 276 #endif // WEBKIT_QUOTA_QUOTA_TYPES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698