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> |
11 #include <map> | 11 #include <map> |
12 #include <set> | 12 #include <set> |
13 #include <string> | 13 #include <string> |
| 14 #include <utility> |
14 #include <vector> | 15 #include <vector> |
15 | 16 |
16 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
17 #include "base/callback.h" | 18 #include "base/callback.h" |
18 #include "base/file_path.h" | 19 #include "base/file_path.h" |
19 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
20 #include "base/memory/scoped_callback_factory.h" | 21 #include "base/memory/weak_ptr.h" |
21 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
22 #include "base/memory/weak_ptr.h" | 23 #include "base/memory/weak_ptr.h" |
23 #include "webkit/quota/quota_database.h" | 24 #include "webkit/quota/quota_database.h" |
24 #include "webkit/quota/quota_client.h" | 25 #include "webkit/quota/quota_client.h" |
25 #include "webkit/quota/quota_task.h" | 26 #include "webkit/quota/quota_task.h" |
26 #include "webkit/quota/quota_types.h" | 27 #include "webkit/quota/quota_types.h" |
27 #include "webkit/quota/special_storage_policy.h" | 28 #include "webkit/quota/special_storage_policy.h" |
28 | 29 |
29 class FilePath; | 30 class FilePath; |
30 | 31 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 67 |
67 // Returns the least recently used origin. It might return empty | 68 // Returns the least recently used origin. It might return empty |
68 // GURL when there are no evictable origins. | 69 // GURL when there are no evictable origins. |
69 virtual void GetLRUOrigin( | 70 virtual void GetLRUOrigin( |
70 StorageType type, | 71 StorageType type, |
71 const GetLRUOriginCallback& callback) = 0; | 72 const GetLRUOriginCallback& callback) = 0; |
72 | 73 |
73 virtual void EvictOriginData( | 74 virtual void EvictOriginData( |
74 const GURL& origin, | 75 const GURL& origin, |
75 StorageType type, | 76 StorageType type, |
76 EvictOriginDataCallback* callback) = 0; | 77 const EvictOriginDataCallback& callback) = 0; |
77 | 78 |
78 virtual void GetUsageAndQuotaForEviction( | 79 virtual void GetUsageAndQuotaForEviction( |
79 const GetUsageAndQuotaForEvictionCallback& callback) = 0; | 80 const GetUsageAndQuotaForEvictionCallback& callback) = 0; |
80 }; | 81 }; |
81 | 82 |
82 struct UsageInfo { | 83 struct UsageInfo { |
83 UsageInfo(const std::string& host, StorageType type, int64 usage) | 84 UsageInfo(const std::string& host, StorageType type, int64 usage) |
84 : host(host), | 85 : host(host), |
85 type(type), | 86 type(type), |
86 usage(usage) {} | 87 usage(usage) {} |
87 std::string host; | 88 std::string host; |
88 StorageType type; | 89 StorageType type; |
89 int64 usage; | 90 int64 usage; |
90 }; | 91 }; |
91 | 92 |
92 // The quota manager class. This class is instantiated per profile and | 93 // The quota manager class. This class is instantiated per profile and |
93 // held by the profile. With the exception of the constructor and the | 94 // held by the profile. With the exception of the constructor and the |
94 // proxy() method, all methods should only be called on the IO thread. | 95 // proxy() method, all methods should only be called on the IO thread. |
95 class QuotaManager : public QuotaTaskObserver, | 96 class QuotaManager : public QuotaTaskObserver, |
96 public QuotaEvictionHandler, | 97 public QuotaEvictionHandler, |
97 public base::RefCountedThreadSafe< | 98 public base::RefCountedThreadSafe< |
98 QuotaManager, QuotaManagerDeleter> { | 99 QuotaManager, QuotaManagerDeleter> { |
99 public: | 100 public: |
100 typedef Callback3<QuotaStatusCode, | 101 typedef base::Callback<void(QuotaStatusCode, |
101 int64 /* usage */, | 102 int64 /* usage */, |
102 int64 /* quota */>::Type GetUsageAndQuotaCallback; | 103 int64 /* quota */)> |
| 104 GetUsageAndQuotaCallback; |
103 | 105 |
104 QuotaManager(bool is_incognito, | 106 QuotaManager(bool is_incognito, |
105 const FilePath& profile_path, | 107 const FilePath& profile_path, |
106 base::MessageLoopProxy* io_thread, | 108 base::MessageLoopProxy* io_thread, |
107 base::MessageLoopProxy* db_thread, | 109 base::MessageLoopProxy* db_thread, |
108 SpecialStoragePolicy* special_storage_policy); | 110 SpecialStoragePolicy* special_storage_policy); |
109 | 111 |
110 virtual ~QuotaManager(); | 112 virtual ~QuotaManager(); |
111 | 113 |
112 // Returns a proxy object that can be used on any thread. | 114 // Returns a proxy object that can be used on any thread. |
113 QuotaManagerProxy* proxy() { return proxy_.get(); } | 115 QuotaManagerProxy* proxy() { return proxy_.get(); } |
114 | 116 |
115 // Called by clients or webapps. Returns usage per host. | 117 // Called by clients or webapps. Returns usage per host. |
116 void GetUsageInfo(GetUsageInfoCallback* callback); | 118 void GetUsageInfo(const GetUsageInfoCallback& callback); |
117 | 119 |
118 // Called by clients or webapps. | 120 // Called by clients or webapps. |
119 // This method is declared as virtual to allow test code to override it. | 121 // This method is declared as virtual to allow test code to override it. |
120 // note: returns host usage and quota | 122 // note: returns host usage and quota |
121 virtual void GetUsageAndQuota(const GURL& origin, | 123 virtual void GetUsageAndQuota(const GURL& origin, |
122 StorageType type, | 124 StorageType type, |
123 GetUsageAndQuotaCallback* callback); | 125 const GetUsageAndQuotaCallback& callback); |
124 | 126 |
125 // Called by clients via proxy. | 127 // Called by clients via proxy. |
126 // Client storage should call this method when storage is accessed. | 128 // Client storage should call this method when storage is accessed. |
127 // Used to maintain LRU ordering. | 129 // Used to maintain LRU ordering. |
128 void NotifyStorageAccessed(QuotaClient::ID client_id, | 130 void NotifyStorageAccessed(QuotaClient::ID client_id, |
129 const GURL& origin, | 131 const GURL& origin, |
130 StorageType type); | 132 StorageType type); |
131 | 133 |
132 // Called by clients via proxy. | 134 // Called by clients via proxy. |
133 // Client storage must call this method whenever they have made any | 135 // Client storage must call this method whenever they have made any |
134 // modifications that change the amount of data stored in their storage. | 136 // modifications that change the amount of data stored in their storage. |
135 void NotifyStorageModified(QuotaClient::ID client_id, | 137 void NotifyStorageModified(QuotaClient::ID client_id, |
136 const GURL& origin, | 138 const GURL& origin, |
137 StorageType type, | 139 StorageType type, |
138 int64 delta); | 140 int64 delta); |
139 | 141 |
140 // Used to avoid evicting origins with open pages. | 142 // Used to avoid evicting origins with open pages. |
141 // A call to NotifyOriginInUse must be balanced by a later call | 143 // A call to NotifyOriginInUse must be balanced by a later call |
142 // to NotifyOriginNoLongerInUse. | 144 // to NotifyOriginNoLongerInUse. |
143 void NotifyOriginInUse(const GURL& origin); | 145 void NotifyOriginInUse(const GURL& origin); |
144 void NotifyOriginNoLongerInUse(const GURL& origin); | 146 void NotifyOriginNoLongerInUse(const GURL& origin); |
145 bool IsOriginInUse(const GURL& origin) const { | 147 bool IsOriginInUse(const GURL& origin) const { |
146 return origins_in_use_.find(origin) != origins_in_use_.end(); | 148 return origins_in_use_.find(origin) != origins_in_use_.end(); |
147 } | 149 } |
148 | 150 |
149 // Called by UI. | 151 // Called by UI. |
150 virtual void DeleteOriginData(const GURL& origin, | 152 virtual void DeleteOriginData(const GURL& origin, |
151 StorageType type, | 153 StorageType type, |
152 StatusCallback* callback); | 154 const StatusCallback& callback); |
153 | 155 |
154 // Called by UI and internal modules. | 156 // Called by UI and internal modules. |
155 void GetAvailableSpace(AvailableSpaceCallback* callback); | 157 void GetAvailableSpace(const AvailableSpaceCallback& callback); |
156 void GetTemporaryGlobalQuota(QuotaCallback* callback); | 158 void GetTemporaryGlobalQuota(const QuotaCallback& callback); |
157 | 159 |
158 // Ok to call with NULL callback. | 160 // Ok to call with NULL callback. |
159 void SetTemporaryGlobalOverrideQuota(int64 new_quota, | 161 void SetTemporaryGlobalOverrideQuota(int64 new_quota, |
160 QuotaCallback* callback); | 162 const QuotaCallback& callback); |
161 | 163 |
162 void GetPersistentHostQuota(const std::string& host, | 164 void GetPersistentHostQuota(const std::string& host, |
163 HostQuotaCallback* callback); | 165 const HostQuotaCallback& callback); |
164 void SetPersistentHostQuota(const std::string& host, | 166 void SetPersistentHostQuota(const std::string& host, |
165 int64 new_quota, | 167 int64 new_quota, |
166 HostQuotaCallback* callback); | 168 const HostQuotaCallback& callback); |
167 void GetGlobalUsage(StorageType type, GlobalUsageCallback* callback); | 169 void GetGlobalUsage(StorageType type, const GlobalUsageCallback& callback); |
168 void GetHostUsage(const std::string& host, StorageType type, | 170 void GetHostUsage(const std::string& host, StorageType type, |
169 HostUsageCallback* callback); | 171 const HostUsageCallback& callback); |
170 | 172 |
171 void GetStatistics(std::map<std::string, std::string>* statistics); | 173 void GetStatistics(std::map<std::string, std::string>* statistics); |
172 | 174 |
173 bool IsStorageUnlimited(const GURL& origin) const { | 175 bool IsStorageUnlimited(const GURL& origin) const { |
174 return special_storage_policy_.get() && | 176 return special_storage_policy_.get() && |
175 special_storage_policy_->IsStorageUnlimited(origin); | 177 special_storage_policy_->IsStorageUnlimited(origin); |
176 } | 178 } |
177 | 179 |
178 virtual void GetOriginsModifiedSince(StorageType type, | 180 virtual void GetOriginsModifiedSince(StorageType type, |
179 base::Time modified_since, | 181 base::Time modified_since, |
180 GetOriginsCallback* callback); | 182 const GetOriginsCallback& callback); |
181 | 183 |
182 bool ResetUsageTracker(StorageType type); | 184 bool ResetUsageTracker(StorageType type); |
183 | 185 |
184 // Determines the portion of the temp pool that can be | 186 // Determines the portion of the temp pool that can be |
185 // utilized by a single host (ie. 5 for 20%). | 187 // utilized by a single host (ie. 5 for 20%). |
186 static const int kPerHostTemporaryPortion; | 188 static const int kPerHostTemporaryPortion; |
187 | 189 |
188 static const char kDatabaseName[]; | 190 static const char kDatabaseName[]; |
189 | 191 |
190 static const int kThresholdOfErrorsToBeBlacklisted; | 192 static const int kThresholdOfErrorsToBeBlacklisted; |
(...skipping 23 matching lines...) Expand all Loading... |
214 | 216 |
215 class AvailableSpaceQueryTask; | 217 class AvailableSpaceQueryTask; |
216 class DumpQuotaTableTask; | 218 class DumpQuotaTableTask; |
217 class DumpOriginInfoTableTask; | 219 class DumpOriginInfoTableTask; |
218 | 220 |
219 typedef QuotaDatabase::QuotaTableEntry QuotaTableEntry; | 221 typedef QuotaDatabase::QuotaTableEntry QuotaTableEntry; |
220 typedef QuotaDatabase::OriginInfoTableEntry OriginInfoTableEntry; | 222 typedef QuotaDatabase::OriginInfoTableEntry OriginInfoTableEntry; |
221 typedef std::vector<QuotaTableEntry> QuotaTableEntries; | 223 typedef std::vector<QuotaTableEntry> QuotaTableEntries; |
222 typedef std::vector<OriginInfoTableEntry> OriginInfoTableEntries; | 224 typedef std::vector<OriginInfoTableEntry> OriginInfoTableEntries; |
223 | 225 |
224 typedef Callback1<const QuotaTableEntries&>::Type DumpQuotaTableCallback; | 226 typedef base::Callback<void(const QuotaTableEntries&)> |
225 typedef Callback1<const OriginInfoTableEntries&>::Type | 227 DumpQuotaTableCallback; |
| 228 typedef base::Callback<void(const OriginInfoTableEntries&)> |
226 DumpOriginInfoTableCallback; | 229 DumpOriginInfoTableCallback; |
227 | 230 |
228 struct EvictionContext { | 231 struct EvictionContext { |
229 EvictionContext() : evicted_type(kStorageTypeUnknown) {} | 232 EvictionContext() : evicted_type(kStorageTypeUnknown) {} |
230 virtual ~EvictionContext() {} | 233 virtual ~EvictionContext() {} |
231 GURL evicted_origin; | 234 GURL evicted_origin; |
232 StorageType evicted_type; | 235 StorageType evicted_type; |
233 scoped_ptr<EvictOriginDataCallback> evict_origin_data_callback; | 236 |
| 237 EvictOriginDataCallback evict_origin_data_callback; |
234 }; | 238 }; |
235 | 239 |
236 typedef std::pair<std::string, StorageType> HostAndType; | 240 typedef std::pair<std::string, StorageType> HostAndType; |
237 typedef std::map<HostAndType, UsageAndQuotaDispatcherTask*> | 241 typedef std::map<HostAndType, UsageAndQuotaDispatcherTask*> |
238 UsageAndQuotaDispatcherTaskMap; | 242 UsageAndQuotaDispatcherTaskMap; |
239 | 243 |
240 typedef QuotaEvictionHandler::GetUsageAndQuotaForEvictionCallback | 244 typedef QuotaEvictionHandler::GetUsageAndQuotaForEvictionCallback |
241 UsageAndQuotaDispatcherCallback; | 245 UsageAndQuotaDispatcherCallback; |
242 | 246 |
243 friend class quota_internals::QuotaInternalsProxy; | 247 friend class quota_internals::QuotaInternalsProxy; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 int64 delta, | 282 int64 delta, |
279 base::Time modified_time); | 283 base::Time modified_time); |
280 | 284 |
281 // |origin| can be empty if |global| is true. | 285 // |origin| can be empty if |global| is true. |
282 void GetUsageAndQuotaInternal( | 286 void GetUsageAndQuotaInternal( |
283 const GURL& origin, | 287 const GURL& origin, |
284 StorageType type, | 288 StorageType type, |
285 bool global, | 289 bool global, |
286 const UsageAndQuotaDispatcherCallback& callback); | 290 const UsageAndQuotaDispatcherCallback& callback); |
287 | 291 |
288 void DumpQuotaTable(DumpQuotaTableCallback* callback); | 292 void DumpQuotaTable(const DumpQuotaTableCallback& callback); |
289 void DumpOriginInfoTable(DumpOriginInfoTableCallback* callback); | 293 void DumpOriginInfoTable(const DumpOriginInfoTableCallback& callback); |
290 | 294 |
291 // Methods for eviction logic. | 295 // Methods for eviction logic. |
292 void StartEviction(); | 296 void StartEviction(); |
293 void DeleteOriginFromDatabase(const GURL& origin, StorageType type); | 297 void DeleteOriginFromDatabase(const GURL& origin, StorageType type); |
294 | 298 |
295 void DidOriginDataEvicted(QuotaStatusCode status); | 299 void DidOriginDataEvicted(QuotaStatusCode status); |
296 void DidGetGlobalUsageAndQuotaForEviction(QuotaStatusCode status, | 300 void DidGetGlobalUsageAndQuotaForEviction(QuotaStatusCode status, |
297 StorageType type, | 301 StorageType type, |
298 int64 usage, | 302 int64 usage, |
299 int64 unlimited_usage, | 303 int64 unlimited_usage, |
300 int64 quota, | 304 int64 quota, |
301 int64 available_space); | 305 int64 available_space); |
302 | 306 |
303 void ReportHistogram(); | 307 void ReportHistogram(); |
304 void DidGetTemporaryGlobalUsageForHistogram(StorageType type, | 308 void DidGetTemporaryGlobalUsageForHistogram(StorageType type, |
305 int64 usage, | 309 int64 usage, |
306 int64 unlimited_usage); | 310 int64 unlimited_usage); |
307 void DidGetPersistentGlobalUsageForHistogram(StorageType type, | 311 void DidGetPersistentGlobalUsageForHistogram(StorageType type, |
308 int64 usage, | 312 int64 usage, |
309 int64 unlimited_usage); | 313 int64 unlimited_usage); |
310 | 314 |
311 // QuotaEvictionHandler. | 315 // QuotaEvictionHandler. |
312 virtual void GetLRUOrigin( | 316 virtual void GetLRUOrigin( |
313 StorageType type, | 317 StorageType type, |
314 const GetLRUOriginCallback& callback) OVERRIDE; | 318 const GetLRUOriginCallback& callback) OVERRIDE; |
315 virtual void EvictOriginData( | 319 virtual void EvictOriginData( |
316 const GURL& origin, | 320 const GURL& origin, |
317 StorageType type, | 321 StorageType type, |
318 EvictOriginDataCallback* callback) OVERRIDE; | 322 const EvictOriginDataCallback& callback) OVERRIDE; |
319 virtual void GetUsageAndQuotaForEviction( | 323 virtual void GetUsageAndQuotaForEviction( |
320 const GetUsageAndQuotaForEvictionCallback& callback) OVERRIDE; | 324 const GetUsageAndQuotaForEvictionCallback& callback) OVERRIDE; |
321 | 325 |
322 void DidRunInitializeTask(); | 326 void DidRunInitializeTask(); |
323 void DidGetInitialTemporaryGlobalQuota(QuotaStatusCode status, | 327 void DidGetInitialTemporaryGlobalQuota(QuotaStatusCode status, |
324 StorageType type, | 328 StorageType type, |
325 int64 quota_unused); | 329 int64 quota_unused); |
326 void DidGetDatabaseLRUOrigin(const GURL& origin); | 330 void DidGetDatabaseLRUOrigin(const GURL& origin); |
327 | 331 |
328 void DeleteOnCorrectThread() const; | 332 void DeleteOnCorrectThread() const; |
(...skipping 28 matching lines...) Expand all Loading... |
357 | 361 |
358 int64 desired_available_space_; | 362 int64 desired_available_space_; |
359 | 363 |
360 // Map from origin to count. | 364 // Map from origin to count. |
361 std::map<GURL, int> origins_in_use_; | 365 std::map<GURL, int> origins_in_use_; |
362 // Map from origin to error count. | 366 // Map from origin to error count. |
363 std::map<GURL, int> origins_in_error_; | 367 std::map<GURL, int> origins_in_error_; |
364 | 368 |
365 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; | 369 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; |
366 | 370 |
367 base::ScopedCallbackFactory<QuotaManager> callback_factory_; | |
368 base::WeakPtrFactory<QuotaManager> weak_factory_; | 371 base::WeakPtrFactory<QuotaManager> weak_factory_; |
369 base::RepeatingTimer<QuotaManager> histogram_timer_; | 372 base::RepeatingTimer<QuotaManager> histogram_timer_; |
370 | 373 |
371 DISALLOW_COPY_AND_ASSIGN(QuotaManager); | 374 DISALLOW_COPY_AND_ASSIGN(QuotaManager); |
372 }; | 375 }; |
373 | 376 |
374 struct QuotaManagerDeleter { | 377 struct QuotaManagerDeleter { |
375 static void Destruct(const QuotaManager* manager) { | 378 static void Destruct(const QuotaManager* manager) { |
376 manager->DeleteOnCorrectThread(); | 379 manager->DeleteOnCorrectThread(); |
377 } | 380 } |
(...skipping 27 matching lines...) Expand all Loading... |
405 | 408 |
406 QuotaManager* manager_; // only accessed on the io thread | 409 QuotaManager* manager_; // only accessed on the io thread |
407 scoped_refptr<base::MessageLoopProxy> io_thread_; | 410 scoped_refptr<base::MessageLoopProxy> io_thread_; |
408 | 411 |
409 DISALLOW_COPY_AND_ASSIGN(QuotaManagerProxy); | 412 DISALLOW_COPY_AND_ASSIGN(QuotaManagerProxy); |
410 }; | 413 }; |
411 | 414 |
412 } // namespace quota | 415 } // namespace quota |
413 | 416 |
414 #endif // WEBKIT_QUOTA_QUOTA_MANAGER_H_ | 417 #endif // WEBKIT_QUOTA_QUOTA_MANAGER_H_ |
OLD | NEW |