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_MANAGER_H_ | 5 #ifndef WEBKIT_QUOTA_QUOTA_MANAGER_H_ |
6 #define WEBKIT_QUOTA_QUOTA_MANAGER_H_ | 6 #define WEBKIT_QUOTA_QUOTA_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <deque> | 9 #include <deque> |
10 #include <list> | 10 #include <list> |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 StorageType type, | 49 StorageType type, |
50 GetLRUOriginCallback* callback) = 0; | 50 GetLRUOriginCallback* callback) = 0; |
51 | 51 |
52 virtual void EvictOriginData( | 52 virtual void EvictOriginData( |
53 const GURL& origin, | 53 const GURL& origin, |
54 StorageType type, | 54 StorageType type, |
55 EvictOriginDataCallback* callback) = 0; | 55 EvictOriginDataCallback* callback) = 0; |
56 | 56 |
57 virtual void GetUsageAndQuotaForEviction( | 57 virtual void GetUsageAndQuotaForEviction( |
58 GetUsageAndQuotaForEvictionCallback* callback) = 0; | 58 GetUsageAndQuotaForEvictionCallback* callback) = 0; |
| 59 |
| 60 protected: |
| 61 virtual ~QuotaEvictionHandler() {} |
59 }; | 62 }; |
60 | 63 |
61 // The quota manager class. This class is instantiated per profile and | 64 // The quota manager class. This class is instantiated per profile and |
62 // held by the profile. With the exception of the constructor and the | 65 // held by the profile. With the exception of the constructor and the |
63 // proxy() method, all methods should only be called on the IO thread. | 66 // proxy() method, all methods should only be called on the IO thread. |
64 class QuotaManager : public QuotaTaskObserver, | 67 class QuotaManager : public QuotaTaskObserver, |
65 public QuotaEvictionHandler, | 68 public QuotaEvictionHandler, |
66 public base::RefCountedThreadSafe< | 69 public base::RefCountedThreadSafe< |
67 QuotaManager, QuotaManagerDeleter> { | 70 QuotaManager, QuotaManagerDeleter> { |
68 public: | 71 public: |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 class PersistentHostQuotaQueryTask; | 150 class PersistentHostQuotaQueryTask; |
148 class GetLRUOriginTask; | 151 class GetLRUOriginTask; |
149 class OriginDeletionDatabaseTask; | 152 class OriginDeletionDatabaseTask; |
150 | 153 |
151 class UsageAndQuotaDispatcherTask; | 154 class UsageAndQuotaDispatcherTask; |
152 class UsageAndQuotaDispatcherTaskForTemporary; | 155 class UsageAndQuotaDispatcherTaskForTemporary; |
153 class UsageAndQuotaDispatcherTaskForPersistent; | 156 class UsageAndQuotaDispatcherTaskForPersistent; |
154 | 157 |
155 class AvailableSpaceQueryTask; | 158 class AvailableSpaceQueryTask; |
156 | 159 |
| 160 struct EvictionContext { |
| 161 EvictionContext() |
| 162 : num_eviction_requested_clients(0), |
| 163 num_evicted_clients(0), |
| 164 usage(0), |
| 165 quota(0) {} |
| 166 virtual ~EvictionContext() {} |
| 167 |
| 168 scoped_ptr<EvictOriginDataCallback> evict_origin_data_callback; |
| 169 int num_eviction_requested_clients; |
| 170 int num_evicted_clients; |
| 171 |
| 172 scoped_ptr<GetUsageAndQuotaForEvictionCallback> |
| 173 get_usage_and_quota_callback; |
| 174 int64 usage; |
| 175 int64 quota; |
| 176 }; |
| 177 |
157 typedef std::pair<std::string, StorageType> HostAndType; | 178 typedef std::pair<std::string, StorageType> HostAndType; |
158 typedef std::map<HostAndType, UsageAndQuotaDispatcherTask*> | 179 typedef std::map<HostAndType, UsageAndQuotaDispatcherTask*> |
159 UsageAndQuotaDispatcherTaskMap; | 180 UsageAndQuotaDispatcherTaskMap; |
160 | 181 |
161 friend struct QuotaManagerDeleter; | 182 friend struct QuotaManagerDeleter; |
162 friend class QuotaManagerProxy; | 183 friend class QuotaManagerProxy; |
163 friend class QuotaManagerTest; | 184 friend class QuotaManagerTest; |
164 | 185 |
165 // This initialization method is lazily called on the IO thread | 186 // This initialization method is lazily called on the IO thread |
166 // when the first quota manager API is called. | 187 // when the first quota manager API is called. |
167 // Initialize must be called after all quota clients are added to the | 188 // Initialize must be called after all quota clients are added to the |
168 // manager by RegisterStorage. | 189 // manager by RegisterStorage. |
169 void LazyInitialize(); | 190 void LazyInitialize(); |
170 | 191 |
171 // Called by clients via proxy. | 192 // Called by clients via proxy. |
172 // Registers a quota client to the manager. | 193 // Registers a quota client to the manager. |
173 // The client must remain valid until OnQuotaManagerDestored is called. | 194 // The client must remain valid until OnQuotaManagerDestored is called. |
174 void RegisterClient(QuotaClient* client); | 195 void RegisterClient(QuotaClient* client); |
175 | 196 |
176 UsageTracker* GetUsageTracker(StorageType type) const; | 197 UsageTracker* GetUsageTracker(StorageType type) const; |
177 | 198 |
178 void DidGetTemporaryGlobalQuota(int64 quota); | 199 void DidGetTemporaryGlobalQuota(int64 quota); |
179 | 200 |
180 // Methods for eviction logic. | 201 // Methods for eviction logic. |
181 void DeleteOriginFromDatabase(const GURL& origin, StorageType type); | 202 void DeleteOriginFromDatabase(const GURL& origin, StorageType type); |
182 | 203 |
183 void DidOriginDataEvicted(QuotaStatusCode status); | 204 void DidOriginDataEvicted(QuotaStatusCode status); |
| 205 void DidGetAvailableSpaceForEviction( |
| 206 QuotaStatusCode status, |
| 207 int64 available_space); |
| 208 void DidGetGlobalQuotaForEviction( |
| 209 QuotaStatusCode status, |
| 210 int64 quota); |
| 211 void DidGetGlobalUsageForEviction(int64 usage); |
184 | 212 |
185 virtual void GetLRUOrigin( | 213 virtual void GetLRUOrigin( |
186 StorageType type, | 214 StorageType type, |
187 GetLRUOriginCallback* callback) OVERRIDE; | 215 GetLRUOriginCallback* callback) OVERRIDE; |
188 virtual void EvictOriginData( | 216 virtual void EvictOriginData( |
189 const GURL& origin, | 217 const GURL& origin, |
190 StorageType type, | 218 StorageType type, |
191 EvictOriginDataCallback* callback) OVERRIDE; | 219 EvictOriginDataCallback* callback) OVERRIDE; |
192 virtual void GetUsageAndQuotaForEviction( | 220 virtual void GetUsageAndQuotaForEviction( |
193 GetUsageAndQuotaForEvictionCallback* callback) OVERRIDE; | 221 GetUsageAndQuotaForEvictionCallback* callback) OVERRIDE; |
194 | 222 |
195 void DeleteOnCorrectThread() const; | 223 void DeleteOnCorrectThread() const; |
196 | 224 |
197 const bool is_incognito_; | 225 const bool is_incognito_; |
198 const FilePath profile_path_; | 226 const FilePath profile_path_; |
199 | 227 |
200 scoped_refptr<QuotaManagerProxy> proxy_; | 228 scoped_refptr<QuotaManagerProxy> proxy_; |
201 bool db_disabled_; | 229 bool db_disabled_; |
202 scoped_refptr<base::MessageLoopProxy> io_thread_; | 230 scoped_refptr<base::MessageLoopProxy> io_thread_; |
203 scoped_refptr<base::MessageLoopProxy> db_thread_; | 231 scoped_refptr<base::MessageLoopProxy> db_thread_; |
204 mutable scoped_ptr<QuotaDatabase> database_; | 232 mutable scoped_ptr<QuotaDatabase> database_; |
205 | 233 |
206 QuotaClientList clients_; | 234 QuotaClientList clients_; |
207 | 235 |
208 scoped_ptr<UsageTracker> temporary_usage_tracker_; | 236 scoped_ptr<UsageTracker> temporary_usage_tracker_; |
209 scoped_ptr<UsageTracker> persistent_usage_tracker_; | 237 scoped_ptr<UsageTracker> persistent_usage_tracker_; |
210 | 238 |
| 239 EvictionContext eviction_context_; |
| 240 |
211 UsageAndQuotaDispatcherTaskMap usage_and_quota_dispatchers_; | 241 UsageAndQuotaDispatcherTaskMap usage_and_quota_dispatchers_; |
212 | 242 |
213 scoped_ptr<EvictOriginDataCallback> evict_origin_data_callback_; | |
214 int num_eviction_requested_clients_; | |
215 int num_evicted_clients_; | |
216 | |
217 int64 temporary_global_quota_; | 243 int64 temporary_global_quota_; |
218 QuotaCallbackQueue temporary_global_quota_callbacks_; | 244 QuotaCallbackQueue temporary_global_quota_callbacks_; |
219 | 245 |
220 // Map from origin to count. | 246 // Map from origin to count. |
221 std::map<GURL, int> origins_in_use_; | 247 std::map<GURL, int> origins_in_use_; |
222 | 248 |
223 base::ScopedCallbackFactory<QuotaManager> callback_factory_; | 249 base::ScopedCallbackFactory<QuotaManager> callback_factory_; |
224 | 250 |
225 DISALLOW_COPY_AND_ASSIGN(QuotaManager); | 251 DISALLOW_COPY_AND_ASSIGN(QuotaManager); |
226 }; | 252 }; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 QuotaManager* manager_; // only accessed on the io thread | 286 QuotaManager* manager_; // only accessed on the io thread |
261 scoped_refptr<base::MessageLoopProxy> io_thread_; | 287 scoped_refptr<base::MessageLoopProxy> io_thread_; |
262 | 288 |
263 DISALLOW_COPY_AND_ASSIGN(QuotaManagerProxy); | 289 DISALLOW_COPY_AND_ASSIGN(QuotaManagerProxy); |
264 }; | 290 }; |
265 | 291 |
266 | 292 |
267 } // namespace quota | 293 } // namespace quota |
268 | 294 |
269 #endif // WEBKIT_QUOTA_QUOTA_MANAGER_H_ | 295 #endif // WEBKIT_QUOTA_QUOTA_MANAGER_H_ |
OLD | NEW |