OLD | NEW |
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 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 28 matching lines...) Expand all Loading... |
39 struct UsageInfo; | 39 struct UsageInfo; |
40 typedef std::vector<UsageInfo> UsageInfoEntries; | 40 typedef std::vector<UsageInfo> UsageInfoEntries; |
41 | 41 |
42 // Common callback types that are used throughout in the quota module. | 42 // Common callback types that are used throughout in the quota module. |
43 typedef base::Callback<void(StorageType status, | 43 typedef base::Callback<void(StorageType status, |
44 int64 usage, | 44 int64 usage, |
45 int64 unlimited_usage)> GlobalUsageCallback; | 45 int64 unlimited_usage)> GlobalUsageCallback; |
46 typedef base::Callback<void(QuotaStatusCode status, | 46 typedef base::Callback<void(QuotaStatusCode status, |
47 StorageType type, | 47 StorageType type, |
48 int64 quota)> QuotaCallback; | 48 int64 quota)> QuotaCallback; |
49 // TODO(kinuko,nhiroki): HostUsageCallback could be probably replaced with | 49 typedef base::Callback<void(int64 usage)> UsageCallback; |
50 // simple Callback<void(int64)> callback by binding host and type with Bind. | |
51 typedef base::Callback<void(const std::string& host, | |
52 StorageType type, | |
53 int64 host_usage)> HostUsageCallback; | |
54 typedef base::Callback<void(QuotaStatusCode status, | 50 typedef base::Callback<void(QuotaStatusCode status, |
55 const std::string& host, | |
56 StorageType type, | |
57 int64 quota)> HostQuotaCallback; | 51 int64 quota)> HostQuotaCallback; |
58 typedef base::Callback<void(QuotaStatusCode, int64)> AvailableSpaceCallback; | 52 typedef base::Callback<void(QuotaStatusCode, int64)> AvailableSpaceCallback; |
59 typedef base::Callback<void(QuotaStatusCode)> StatusCallback; | 53 typedef base::Callback<void(QuotaStatusCode)> StatusCallback; |
60 typedef base::Callback<void(const std::set<GURL>& origins, | 54 typedef base::Callback<void(const std::set<GURL>& origins, |
61 StorageType type)> GetOriginsCallback; | 55 StorageType type)> GetOriginsCallback; |
62 typedef base::Callback<void(const UsageInfoEntries&)> GetUsageInfoCallback; | 56 typedef base::Callback<void(const UsageInfoEntries&)> GetUsageInfoCallback; |
63 | 57 |
64 // Simple template wrapper for a callback queue. | 58 // Simple template wrapper for a callback queue. |
65 template <typename CallbackType> | 59 template <typename CallbackType> |
66 class CallbackQueueBase { | 60 class CallbackQueueBase { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 // from the map. | 190 // from the map. |
197 void Run(const KEY& key, ARG1 arg1, ARG2 arg2) { | 191 void Run(const KEY& key, ARG1 arg1, ARG2 arg2) { |
198 if (!this->HasCallbacks(key)) | 192 if (!this->HasCallbacks(key)) |
199 return; | 193 return; |
200 Queue& queue = this->callback_map_[key]; | 194 Queue& queue = this->callback_map_[key]; |
201 queue.Run(arg1, arg2); | 195 queue.Run(arg1, arg2); |
202 this->callback_map_.erase(key); | 196 this->callback_map_.erase(key); |
203 } | 197 } |
204 }; | 198 }; |
205 | 199 |
206 template <typename CallbackType3, typename KEY, | 200 typedef CallbackQueueMap1<UsageCallback, std::string, int64> |
207 typename ARG1, typename ARG2, typename ARG3> | 201 HostUsageCallbackMap; |
208 class CallbackQueueMap3 | |
209 : public CallbackQueueMapBase<CallbackType3, | |
210 CallbackQueue3<CallbackType3, | |
211 ARG1, ARG2, ARG3>, | |
212 KEY> { | |
213 public: | |
214 typedef typename CallbackQueueMapBase< | |
215 CallbackType3, | |
216 CallbackQueue3<CallbackType3, ARG1, ARG2, ARG3>, | |
217 KEY>::iterator iterator; | |
218 typedef CallbackQueue3<CallbackType3, ARG1, ARG2, ARG3> Queue; | |
219 | |
220 // Runs the callbacks added for the given |key| and clears the key | |
221 // from the map. | |
222 void Run(const KEY& key, ARG1 arg1, ARG2 arg2, ARG3 arg3) { | |
223 if (!this->HasCallbacks(key)) | |
224 return; | |
225 Queue& queue = this->callback_map_[key]; | |
226 queue.Run(arg1, arg2, arg3); | |
227 this->callback_map_.erase(key); | |
228 } | |
229 }; | |
230 | |
231 typedef CallbackQueueMap3<HostUsageCallback, std::string, | |
232 const std::string&, | |
233 StorageType, int64> HostUsageCallbackMap; | |
234 | 202 |
235 } // namespace quota | 203 } // namespace quota |
236 | 204 |
237 #endif // WEBKIT_QUOTA_QUOTA_TYPES_H_ | 205 #endif // WEBKIT_QUOTA_QUOTA_TYPES_H_ |
OLD | NEW |