| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_BROWSER_QUOTA_QUOTA_MANAGER_H_ | 5 #ifndef WEBKIT_BROWSER_QUOTA_QUOTA_MANAGER_H_ |
| 6 #define WEBKIT_BROWSER_QUOTA_QUOTA_MANAGER_H_ | 6 #define WEBKIT_BROWSER_QUOTA_QUOTA_MANAGER_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> | 10 #include <map> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <utility> | 13 #include <utility> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 17 #include "base/callback.h" | 17 #include "base/callback.h" |
| 18 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
| 19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| 21 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
| 22 #include "base/sequenced_task_runner_helpers.h" | 22 #include "base/sequenced_task_runner_helpers.h" |
| 23 #include "webkit/browser/quota/quota_callbacks.h" | 23 #include "storage/browser/quota/quota_callbacks.h" |
| 24 #include "webkit/browser/quota/quota_client.h" | 24 #include "storage/browser/quota/quota_client.h" |
| 25 #include "webkit/browser/quota/quota_database.h" | 25 #include "storage/browser/quota/quota_database.h" |
| 26 #include "webkit/browser/quota/quota_task.h" | 26 #include "storage/browser/quota/quota_task.h" |
| 27 #include "webkit/browser/quota/special_storage_policy.h" | 27 #include "storage/browser/quota/special_storage_policy.h" |
| 28 #include "webkit/browser/quota/storage_observer.h" | 28 #include "storage/browser/quota/storage_observer.h" |
| 29 #include "webkit/browser/webkit_storage_browser_export.h" | 29 #include "storage/common/storage_export.h" |
| 30 | 30 |
| 31 namespace base { | 31 namespace base { |
| 32 class FilePath; | 32 class FilePath; |
| 33 class SequencedTaskRunner; | 33 class SequencedTaskRunner; |
| 34 class SingleThreadTaskRunner; | 34 class SingleThreadTaskRunner; |
| 35 } | 35 } |
| 36 | 36 |
| 37 namespace quota_internals { | 37 namespace quota_internals { |
| 38 class QuotaInternalsProxy; | 38 class QuotaInternalsProxy; |
| 39 } | 39 } |
| 40 | 40 |
| 41 namespace content { | 41 namespace content { |
| 42 class MockQuotaManager; | 42 class MockQuotaManager; |
| 43 class MockStorageClient; | 43 class MockStorageClient; |
| 44 class QuotaManagerTest; | 44 class QuotaManagerTest; |
| 45 class StorageMonitorTest; | 45 class StorageMonitorTest; |
| 46 | |
| 47 } | 46 } |
| 48 | 47 |
| 49 namespace quota { | 48 namespace quota { |
| 50 | 49 |
| 51 class QuotaDatabase; | 50 class QuotaDatabase; |
| 52 class QuotaManagerProxy; | 51 class QuotaManagerProxy; |
| 53 class QuotaTemporaryStorageEvictor; | 52 class QuotaTemporaryStorageEvictor; |
| 54 class StorageMonitor; | 53 class StorageMonitor; |
| 55 class UsageTracker; | 54 class UsageTracker; |
| 56 | 55 |
| 57 struct QuotaManagerDeleter; | 56 struct QuotaManagerDeleter; |
| 58 | 57 |
| 59 struct WEBKIT_STORAGE_BROWSER_EXPORT UsageAndQuota { | 58 struct STORAGE_EXPORT UsageAndQuota { |
| 60 int64 usage; | 59 int64 usage; |
| 61 int64 global_limited_usage; | 60 int64 global_limited_usage; |
| 62 int64 quota; | 61 int64 quota; |
| 63 int64 available_disk_space; | 62 int64 available_disk_space; |
| 64 | 63 |
| 65 UsageAndQuota(); | 64 UsageAndQuota(); |
| 66 UsageAndQuota(int64 usage, | 65 UsageAndQuota(int64 usage, |
| 67 int64 global_limited_usage, | 66 int64 global_limited_usage, |
| 68 int64 quota, | 67 int64 quota, |
| 69 int64 available_disk_space); | 68 int64 available_disk_space); |
| 70 }; | 69 }; |
| 71 | 70 |
| 72 // An interface called by QuotaTemporaryStorageEvictor. | 71 // An interface called by QuotaTemporaryStorageEvictor. |
| 73 class WEBKIT_STORAGE_BROWSER_EXPORT QuotaEvictionHandler { | 72 class STORAGE_EXPORT QuotaEvictionHandler { |
| 74 public: | 73 public: |
| 75 typedef base::Callback<void(const GURL&)> GetLRUOriginCallback; | 74 typedef base::Callback<void(const GURL&)> GetLRUOriginCallback; |
| 76 typedef StatusCallback EvictOriginDataCallback; | 75 typedef StatusCallback EvictOriginDataCallback; |
| 77 typedef base::Callback<void(QuotaStatusCode status, | 76 typedef base::Callback< |
| 78 const UsageAndQuota& usage_and_quota)> | 77 void(QuotaStatusCode status, const UsageAndQuota& usage_and_quota)> |
| 79 UsageAndQuotaCallback; | 78 UsageAndQuotaCallback; |
| 80 | 79 |
| 81 // Returns the least recently used origin. It might return empty | 80 // Returns the least recently used origin. It might return empty |
| 82 // GURL when there are no evictable origins. | 81 // GURL when there are no evictable origins. |
| 83 virtual void GetLRUOrigin( | 82 virtual void GetLRUOrigin(StorageType type, |
| 84 StorageType type, | 83 const GetLRUOriginCallback& callback) = 0; |
| 85 const GetLRUOriginCallback& callback) = 0; | |
| 86 | 84 |
| 87 virtual void EvictOriginData( | 85 virtual void EvictOriginData(const GURL& origin, |
| 88 const GURL& origin, | 86 StorageType type, |
| 89 StorageType type, | 87 const EvictOriginDataCallback& callback) = 0; |
| 90 const EvictOriginDataCallback& callback) = 0; | |
| 91 | 88 |
| 92 virtual void GetUsageAndQuotaForEviction( | 89 virtual void GetUsageAndQuotaForEviction( |
| 93 const UsageAndQuotaCallback& callback) = 0; | 90 const UsageAndQuotaCallback& callback) = 0; |
| 94 | 91 |
| 95 protected: | 92 protected: |
| 96 virtual ~QuotaEvictionHandler() {} | 93 virtual ~QuotaEvictionHandler() {} |
| 97 }; | 94 }; |
| 98 | 95 |
| 99 struct UsageInfo { | 96 struct UsageInfo { |
| 100 UsageInfo(const std::string& host, StorageType type, int64 usage) | 97 UsageInfo(const std::string& host, StorageType type, int64 usage) |
| 101 : host(host), | 98 : host(host), type(type), usage(usage) {} |
| 102 type(type), | |
| 103 usage(usage) {} | |
| 104 std::string host; | 99 std::string host; |
| 105 StorageType type; | 100 StorageType type; |
| 106 int64 usage; | 101 int64 usage; |
| 107 }; | 102 }; |
| 108 | 103 |
| 109 // The quota manager class. This class is instantiated per profile and | 104 // The quota manager class. This class is instantiated per profile and |
| 110 // held by the profile. With the exception of the constructor and the | 105 // held by the profile. With the exception of the constructor and the |
| 111 // proxy() method, all methods should only be called on the IO thread. | 106 // proxy() method, all methods should only be called on the IO thread. |
| 112 class WEBKIT_STORAGE_BROWSER_EXPORT QuotaManager | 107 class STORAGE_EXPORT QuotaManager |
| 113 : public QuotaTaskObserver, | 108 : public QuotaTaskObserver, |
| 114 public QuotaEvictionHandler, | 109 public QuotaEvictionHandler, |
| 115 public base::RefCountedThreadSafe<QuotaManager, QuotaManagerDeleter> { | 110 public base::RefCountedThreadSafe<QuotaManager, QuotaManagerDeleter> { |
| 116 public: | 111 public: |
| 117 typedef base::Callback<void(QuotaStatusCode, | 112 typedef base::Callback< |
| 118 int64 /* usage */, | 113 void(QuotaStatusCode, int64 /* usage */, int64 /* quota */)> |
| 119 int64 /* quota */)> | |
| 120 GetUsageAndQuotaCallback; | 114 GetUsageAndQuotaCallback; |
| 121 | 115 |
| 122 static const int64 kIncognitoDefaultQuotaLimit; | 116 static const int64 kIncognitoDefaultQuotaLimit; |
| 123 static const int64 kNoLimit; | 117 static const int64 kNoLimit; |
| 124 | 118 |
| 125 QuotaManager(bool is_incognito, | 119 QuotaManager(bool is_incognito, |
| 126 const base::FilePath& profile_path, | 120 const base::FilePath& profile_path, |
| 127 base::SingleThreadTaskRunner* io_thread, | 121 base::SingleThreadTaskRunner* io_thread, |
| 128 base::SequencedTaskRunner* db_thread, | 122 base::SequencedTaskRunner* db_thread, |
| 129 SpecialStoragePolicy* special_storage_policy); | 123 SpecialStoragePolicy* special_storage_policy); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 140 const GURL& origin, | 134 const GURL& origin, |
| 141 StorageType type, | 135 StorageType type, |
| 142 const GetUsageAndQuotaCallback& callback); | 136 const GetUsageAndQuotaCallback& callback); |
| 143 | 137 |
| 144 // Called by StorageClients. | 138 // Called by StorageClients. |
| 145 // This method is declared as virtual to allow test code to override it. | 139 // This method is declared as virtual to allow test code to override it. |
| 146 // | 140 // |
| 147 // For UnlimitedStorage origins, this version skips usage and quota handling | 141 // For UnlimitedStorage origins, this version skips usage and quota handling |
| 148 // to avoid extra query cost. | 142 // to avoid extra query cost. |
| 149 // Do not call this method for apps/user-facing code. | 143 // Do not call this method for apps/user-facing code. |
| 150 virtual void GetUsageAndQuota( | 144 virtual void GetUsageAndQuota(const GURL& origin, |
| 151 const GURL& origin, | 145 StorageType type, |
| 152 StorageType type, | 146 const GetUsageAndQuotaCallback& callback); |
| 153 const GetUsageAndQuotaCallback& callback); | |
| 154 | 147 |
| 155 // Called by clients via proxy. | 148 // Called by clients via proxy. |
| 156 // Client storage should call this method when storage is accessed. | 149 // Client storage should call this method when storage is accessed. |
| 157 // Used to maintain LRU ordering. | 150 // Used to maintain LRU ordering. |
| 158 void NotifyStorageAccessed(QuotaClient::ID client_id, | 151 void NotifyStorageAccessed(QuotaClient::ID client_id, |
| 159 const GURL& origin, | 152 const GURL& origin, |
| 160 StorageType type); | 153 StorageType type); |
| 161 | 154 |
| 162 // Called by clients via proxy. | 155 // Called by clients via proxy. |
| 163 // Client storage must call this method whenever they have made any | 156 // Client storage must call this method whenever they have made any |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 // Ok to call with NULL callback. | 197 // Ok to call with NULL callback. |
| 205 void SetTemporaryGlobalOverrideQuota(int64 new_quota, | 198 void SetTemporaryGlobalOverrideQuota(int64 new_quota, |
| 206 const QuotaCallback& callback); | 199 const QuotaCallback& callback); |
| 207 | 200 |
| 208 void GetPersistentHostQuota(const std::string& host, | 201 void GetPersistentHostQuota(const std::string& host, |
| 209 const QuotaCallback& callback); | 202 const QuotaCallback& callback); |
| 210 void SetPersistentHostQuota(const std::string& host, | 203 void SetPersistentHostQuota(const std::string& host, |
| 211 int64 new_quota, | 204 int64 new_quota, |
| 212 const QuotaCallback& callback); | 205 const QuotaCallback& callback); |
| 213 void GetGlobalUsage(StorageType type, const GlobalUsageCallback& callback); | 206 void GetGlobalUsage(StorageType type, const GlobalUsageCallback& callback); |
| 214 void GetHostUsage(const std::string& host, StorageType type, | 207 void GetHostUsage(const std::string& host, |
| 208 StorageType type, |
| 215 const UsageCallback& callback); | 209 const UsageCallback& callback); |
| 216 void GetHostUsage(const std::string& host, StorageType type, | 210 void GetHostUsage(const std::string& host, |
| 211 StorageType type, |
| 217 QuotaClient::ID client_id, | 212 QuotaClient::ID client_id, |
| 218 const UsageCallback& callback); | 213 const UsageCallback& callback); |
| 219 | 214 |
| 220 bool IsTrackingHostUsage(StorageType type, QuotaClient::ID client_id) const; | 215 bool IsTrackingHostUsage(StorageType type, QuotaClient::ID client_id) const; |
| 221 | 216 |
| 222 void GetStatistics(std::map<std::string, std::string>* statistics); | 217 void GetStatistics(std::map<std::string, std::string>* statistics); |
| 223 | 218 |
| 224 bool IsStorageUnlimited(const GURL& origin, StorageType type) const; | 219 bool IsStorageUnlimited(const GURL& origin, StorageType type) const; |
| 225 | 220 |
| 226 bool CanQueryDiskSize(const GURL& origin) const { | 221 bool CanQueryDiskSize(const GURL& origin) const { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 280 |
| 286 typedef QuotaDatabase::QuotaTableEntry QuotaTableEntry; | 281 typedef QuotaDatabase::QuotaTableEntry QuotaTableEntry; |
| 287 typedef QuotaDatabase::OriginInfoTableEntry OriginInfoTableEntry; | 282 typedef QuotaDatabase::OriginInfoTableEntry OriginInfoTableEntry; |
| 288 typedef std::vector<QuotaTableEntry> QuotaTableEntries; | 283 typedef std::vector<QuotaTableEntry> QuotaTableEntries; |
| 289 typedef std::vector<OriginInfoTableEntry> OriginInfoTableEntries; | 284 typedef std::vector<OriginInfoTableEntry> OriginInfoTableEntries; |
| 290 | 285 |
| 291 // Function pointer type used to store the function which returns the | 286 // Function pointer type used to store the function which returns the |
| 292 // available disk space for the disk containing the given FilePath. | 287 // available disk space for the disk containing the given FilePath. |
| 293 typedef int64 (*GetAvailableDiskSpaceFn)(const base::FilePath&); | 288 typedef int64 (*GetAvailableDiskSpaceFn)(const base::FilePath&); |
| 294 | 289 |
| 295 typedef base::Callback<void(const QuotaTableEntries&)> | 290 typedef base::Callback<void(const QuotaTableEntries&)> DumpQuotaTableCallback; |
| 296 DumpQuotaTableCallback; | |
| 297 typedef base::Callback<void(const OriginInfoTableEntries&)> | 291 typedef base::Callback<void(const OriginInfoTableEntries&)> |
| 298 DumpOriginInfoTableCallback; | 292 DumpOriginInfoTableCallback; |
| 299 | 293 |
| 300 struct EvictionContext { | 294 struct EvictionContext { |
| 301 EvictionContext(); | 295 EvictionContext(); |
| 302 virtual ~EvictionContext(); | 296 virtual ~EvictionContext(); |
| 303 GURL evicted_origin; | 297 GURL evicted_origin; |
| 304 StorageType evicted_type; | 298 StorageType evicted_type; |
| 305 | 299 |
| 306 EvictOriginDataCallback evict_origin_data_callback; | 300 EvictOriginDataCallback evict_origin_data_callback; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 320 // The client must remain valid until OnQuotaManagerDestored is called. | 314 // The client must remain valid until OnQuotaManagerDestored is called. |
| 321 void RegisterClient(QuotaClient* client); | 315 void RegisterClient(QuotaClient* client); |
| 322 | 316 |
| 323 UsageTracker* GetUsageTracker(StorageType type) const; | 317 UsageTracker* GetUsageTracker(StorageType type) const; |
| 324 | 318 |
| 325 // Extract cached origins list from the usage tracker. | 319 // Extract cached origins list from the usage tracker. |
| 326 // (Might return empty list if no origin is tracked by the tracker.) | 320 // (Might return empty list if no origin is tracked by the tracker.) |
| 327 void GetCachedOrigins(StorageType type, std::set<GURL>* origins); | 321 void GetCachedOrigins(StorageType type, std::set<GURL>* origins); |
| 328 | 322 |
| 329 // These internal methods are separately defined mainly for testing. | 323 // These internal methods are separately defined mainly for testing. |
| 330 void NotifyStorageAccessedInternal( | 324 void NotifyStorageAccessedInternal(QuotaClient::ID client_id, |
| 331 QuotaClient::ID client_id, | 325 const GURL& origin, |
| 332 const GURL& origin, | 326 StorageType type, |
| 333 StorageType type, | 327 base::Time accessed_time); |
| 334 base::Time accessed_time); | 328 void NotifyStorageModifiedInternal(QuotaClient::ID client_id, |
| 335 void NotifyStorageModifiedInternal( | 329 const GURL& origin, |
| 336 QuotaClient::ID client_id, | 330 StorageType type, |
| 337 const GURL& origin, | 331 int64 delta, |
| 338 StorageType type, | 332 base::Time modified_time); |
| 339 int64 delta, | |
| 340 base::Time modified_time); | |
| 341 | 333 |
| 342 void DumpQuotaTable(const DumpQuotaTableCallback& callback); | 334 void DumpQuotaTable(const DumpQuotaTableCallback& callback); |
| 343 void DumpOriginInfoTable(const DumpOriginInfoTableCallback& callback); | 335 void DumpOriginInfoTable(const DumpOriginInfoTableCallback& callback); |
| 344 | 336 |
| 345 // Methods for eviction logic. | 337 // Methods for eviction logic. |
| 346 void StartEviction(); | 338 void StartEviction(); |
| 347 void DeleteOriginFromDatabase(const GURL& origin, StorageType type); | 339 void DeleteOriginFromDatabase(const GURL& origin, StorageType type); |
| 348 | 340 |
| 349 void DidOriginDataEvicted(QuotaStatusCode status); | 341 void DidOriginDataEvicted(QuotaStatusCode status); |
| 350 | 342 |
| 351 void ReportHistogram(); | 343 void ReportHistogram(); |
| 352 void DidGetTemporaryGlobalUsageForHistogram(int64 usage, | 344 void DidGetTemporaryGlobalUsageForHistogram(int64 usage, |
| 353 int64 unlimited_usage); | 345 int64 unlimited_usage); |
| 354 void DidGetPersistentGlobalUsageForHistogram(int64 usage, | 346 void DidGetPersistentGlobalUsageForHistogram(int64 usage, |
| 355 int64 unlimited_usage); | 347 int64 unlimited_usage); |
| 356 | 348 |
| 357 // QuotaEvictionHandler. | 349 // QuotaEvictionHandler. |
| 358 virtual void GetLRUOrigin( | 350 virtual void GetLRUOrigin(StorageType type, |
| 359 StorageType type, | 351 const GetLRUOriginCallback& callback) OVERRIDE; |
| 360 const GetLRUOriginCallback& callback) OVERRIDE; | |
| 361 virtual void EvictOriginData( | 352 virtual void EvictOriginData( |
| 362 const GURL& origin, | 353 const GURL& origin, |
| 363 StorageType type, | 354 StorageType type, |
| 364 const EvictOriginDataCallback& callback) OVERRIDE; | 355 const EvictOriginDataCallback& callback) OVERRIDE; |
| 365 virtual void GetUsageAndQuotaForEviction( | 356 virtual void GetUsageAndQuotaForEviction( |
| 366 const UsageAndQuotaCallback& callback) OVERRIDE; | 357 const UsageAndQuotaCallback& callback) OVERRIDE; |
| 367 | 358 |
| 368 void DidSetTemporaryGlobalOverrideQuota(const QuotaCallback& callback, | 359 void DidSetTemporaryGlobalOverrideQuota(const QuotaCallback& callback, |
| 369 const int64* new_quota, | 360 const int64* new_quota, |
| 370 bool success); | 361 bool success); |
| 371 void DidGetPersistentHostQuota(const std::string& host, | 362 void DidGetPersistentHostQuota(const std::string& host, |
| 372 const int64* quota, | 363 const int64* quota, |
| 373 bool success); | 364 bool success); |
| 374 void DidSetPersistentHostQuota(const std::string& host, | 365 void DidSetPersistentHostQuota(const std::string& host, |
| 375 const QuotaCallback& callback, | 366 const QuotaCallback& callback, |
| 376 const int64* new_quota, | 367 const int64* new_quota, |
| 377 bool success); | 368 bool success); |
| 378 void DidInitialize(int64* temporary_quota_override, | 369 void DidInitialize(int64* temporary_quota_override, |
| 379 int64* desired_available_space, | 370 int64* desired_available_space, |
| 380 bool success); | 371 bool success); |
| 381 void DidGetLRUOrigin(const GURL* origin, | 372 void DidGetLRUOrigin(const GURL* origin, bool success); |
| 382 bool success); | |
| 383 void DidGetInitialTemporaryGlobalQuota(QuotaStatusCode status, | 373 void DidGetInitialTemporaryGlobalQuota(QuotaStatusCode status, |
| 384 int64 quota_unused); | 374 int64 quota_unused); |
| 385 void DidInitializeTemporaryOriginsInfo(bool success); | 375 void DidInitializeTemporaryOriginsInfo(bool success); |
| 386 void DidGetAvailableSpace(int64 space); | 376 void DidGetAvailableSpace(int64 space); |
| 387 void DidDatabaseWork(bool success); | 377 void DidDatabaseWork(bool success); |
| 388 | 378 |
| 389 void DeleteOnCorrectThread() const; | 379 void DeleteOnCorrectThread() const; |
| 390 | 380 |
| 391 void PostTaskAndReplyWithResultForDBThread( | 381 void PostTaskAndReplyWithResultForDBThread( |
| 392 const tracked_objects::Location& from_here, | 382 const tracked_objects::Location& from_here, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 | 440 |
| 451 struct QuotaManagerDeleter { | 441 struct QuotaManagerDeleter { |
| 452 static void Destruct(const QuotaManager* manager) { | 442 static void Destruct(const QuotaManager* manager) { |
| 453 manager->DeleteOnCorrectThread(); | 443 manager->DeleteOnCorrectThread(); |
| 454 } | 444 } |
| 455 }; | 445 }; |
| 456 | 446 |
| 457 } // namespace quota | 447 } // namespace quota |
| 458 | 448 |
| 459 #endif // WEBKIT_BROWSER_QUOTA_QUOTA_MANAGER_H_ | 449 #endif // WEBKIT_BROWSER_QUOTA_QUOTA_MANAGER_H_ |
| OLD | NEW |