| 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 STORAGE_BROWSER_QUOTA_QUOTA_MANAGER_H_ | 5 #ifndef STORAGE_BROWSER_QUOTA_QUOTA_MANAGER_H_ |
| 6 #define STORAGE_BROWSER_QUOTA_QUOTA_MANAGER_H_ | 6 #define STORAGE_BROWSER_QUOTA_QUOTA_MANAGER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <deque> | 10 #include <deque> |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 namespace storage { | 53 namespace storage { |
| 54 | 54 |
| 55 class QuotaDatabase; | 55 class QuotaDatabase; |
| 56 class QuotaManagerProxy; | 56 class QuotaManagerProxy; |
| 57 class QuotaTemporaryStorageEvictor; | 57 class QuotaTemporaryStorageEvictor; |
| 58 class StorageMonitor; | 58 class StorageMonitor; |
| 59 class UsageTracker; | 59 class UsageTracker; |
| 60 | 60 |
| 61 struct QuotaManagerDeleter; | 61 struct QuotaManagerDeleter; |
| 62 | 62 |
| 63 struct STORAGE_EXPORT UsageAndQuota { | 63 // todo: new file temporary_storage_configuration.h |
| 64 int64_t usage; | 64 // Configuration parameters the storage lib embedder must provide |
| 65 int64_t global_limited_usage; | 65 // to the QuotaManager. |
| 66 int64_t quota; | 66 struct TemporaryStorageConfiguration { |
| 67 int64_t available_disk_space; | 67 TemporaryStorageConfiguration() = default; |
| 68 | 68 |
| 69 UsageAndQuota(); | 69 // The target size in bytes of the shared pool of disk space the quota |
| 70 UsageAndQuota(int64_t usage, | 70 // system allows for use by by websites using HTML5 storage apis, for |
| 71 int64_t global_limited_usage, | 71 // example an embedder may use 50% of the total volume size. |
| 72 int64_t quota, | 72 int64_t pool_size = 0; |
| 73 int64_t available_disk_space); | 73 |
| 74 // The amount in bytes of the pool an individual site may consume. The |
| 75 // value must be less than or equal to the pool_size. |
| 76 int64_t per_host_quota = 0; |
| 77 |
| 78 // The amount of space that must remain available on the storage |
| 79 // volume. As the volume approaches this limit, the quota system gets |
| 80 // more aggressive about evicting data and disallowing new data. |
| 81 int64_t must_remain_available = 0; |
| 82 |
| 83 // The quota system querries the embedder for the TemporaryPoolConfiguration, |
| 84 // but will rate limit the frequency of the querries to no more than once |
| 85 // per refresh interval. |
| 86 base::TimeDelta refresh_interval = base::TimeDelta::Max(); |
| 74 }; | 87 }; |
| 75 | 88 |
| 89 // Function type used to return the temp storage config in response to a |
| 90 // GetTemporaryStorageConfigurationFunc invocation. |
| 91 using TemporaryStorageConfigurationCallback = |
| 92 base::Callback<void(const TemporaryStorageConfiguration&)>; |
| 93 |
| 94 // Function type used to query the embedder about the temporary pool |
| 95 // configuration. This function is invoked on the UI thread. |
| 96 using GetTemporaryStorageConfigurationFunc = base::Callback< |
| 97 void(const base::FilePath& partition_path, bool is_incognito, |
| 98 const TemporaryStorageConfigurationCallback& callback)>; |
| 99 |
| 76 // TODO(calamity): Use this in the temporary storage eviction path. | 100 // TODO(calamity): Use this in the temporary storage eviction path. |
| 77 // An interface for deciding which origin's storage should be evicted when the | 101 // An interface for deciding which origin's storage should be evicted when the |
| 78 // quota is exceeded. | 102 // quota is exceeded. |
| 79 class STORAGE_EXPORT QuotaEvictionPolicy { | 103 class STORAGE_EXPORT QuotaEvictionPolicy { |
| 80 public: | 104 public: |
| 81 virtual ~QuotaEvictionPolicy() {} | 105 virtual ~QuotaEvictionPolicy() {} |
| 82 | 106 |
| 83 // Returns the next origin to evict. It might return an empty GURL when there | 107 // Returns the next origin to evict. It might return an empty GURL when there |
| 84 // are no evictable origins. | 108 // are no evictable origins. |
| 85 virtual void GetEvictionOrigin( | 109 virtual void GetEvictionOrigin( |
| 86 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy, | 110 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy, |
| 87 const std::set<GURL>& exceptions, | 111 const std::set<GURL>& exceptions, |
| 88 const std::map<GURL, int64_t>& usage_map, | 112 const std::map<GURL, int64_t>& usage_map, |
| 89 int64_t global_quota, | 113 int64_t global_quota, |
| 90 const GetOriginCallback& callback) = 0; | 114 const GetOriginCallback& callback) = 0; |
| 91 }; | 115 }; |
| 92 | 116 |
| 93 // An interface called by QuotaTemporaryStorageEvictor. | 117 // An interface called by QuotaTemporaryStorageEvictor. |
| 94 class STORAGE_EXPORT QuotaEvictionHandler { | 118 class STORAGE_EXPORT QuotaEvictionHandler { |
| 95 public: | 119 public: |
| 96 using EvictOriginDataCallback = StatusCallback; | 120 using EvictionRoundInfoCallback = base::Callback< |
| 97 using UsageAndQuotaCallback = base::Callback< | 121 void(QuotaStatusCode status, const TemporaryStorageConfiguration& config, |
| 98 void(QuotaStatusCode status, const UsageAndQuota& usage_and_quota)>; | 122 int64_t available_space, int64_t total_space, |
| 99 using VolumeInfoCallback = base::Callback< | 123 int64_t global_usage, bool global_usage_is_complete)>; |
| 100 void(bool success, uint64_t available_space, uint64_t total_space)>; | 124 |
| 125 // Called at the beginning of an eviction round to gather the info about |
| 126 // the current configuration and usage. |
| 127 virtual void GetEvictionRoundInfo( |
| 128 const EvictionRoundInfoCallback& callback) = 0; |
| 129 |
| 101 | 130 |
| 102 // Returns next origin to evict. It might return an empty GURL when there are | 131 // Returns next origin to evict. It might return an empty GURL when there are |
| 103 // no evictable origins. | 132 // no evictable origins. |
| 104 virtual void GetEvictionOrigin(StorageType type, | 133 virtual void GetEvictionOrigin(StorageType type, |
| 105 const std::set<GURL>& extra_exceptions, | 134 const std::set<GURL>& extra_exceptions, |
| 106 int64_t global_quota, | 135 int64_t global_quota, |
| 107 const GetOriginCallback& callback) = 0; | 136 const GetOriginCallback& callback) = 0; |
| 108 | 137 |
| 138 // Called to evict an origin. |
| 109 virtual void EvictOriginData( | 139 virtual void EvictOriginData( |
| 110 const GURL& origin, | 140 const GURL& origin, |
| 111 StorageType type, | 141 StorageType type, |
| 112 const EvictOriginDataCallback& callback) = 0; | 142 const StatusCallback& callback) = 0; |
| 113 | |
| 114 virtual void AsyncGetVolumeInfo(const VolumeInfoCallback& callback) = 0; | |
| 115 virtual void GetUsageAndQuotaForEviction( | |
| 116 const UsageAndQuotaCallback& callback) = 0; | |
| 117 | 143 |
| 118 protected: | 144 protected: |
| 119 virtual ~QuotaEvictionHandler() {} | 145 virtual ~QuotaEvictionHandler() {} |
| 120 }; | 146 }; |
| 121 | 147 |
| 122 struct UsageInfo { | 148 struct UsageInfo { |
| 123 UsageInfo(const std::string& host, StorageType type, int64_t usage) | 149 UsageInfo(const std::string& host, StorageType type, int64_t usage) |
| 124 : host(host), type(type), usage(usage) {} | 150 : host(host), type(type), usage(usage) {} |
| 125 std::string host; | 151 std::string host; |
| 126 StorageType type; | 152 StorageType type; |
| 127 int64_t usage; | 153 int64_t usage; |
| 128 }; | 154 }; |
| 129 | 155 |
| 130 // The quota manager class. This class is instantiated per profile and | 156 // The quota manager class. This class is instantiated per profile and |
| 131 // held by the profile. With the exception of the constructor and the | 157 // held by the profile. With the exception of the constructor and the |
| 132 // proxy() method, all methods should only be called on the IO thread. | 158 // proxy() method, all methods should only be called on the IO thread. |
| 133 class STORAGE_EXPORT QuotaManager | 159 class STORAGE_EXPORT QuotaManager |
| 134 : public QuotaTaskObserver, | 160 : public QuotaTaskObserver, |
| 135 public QuotaEvictionHandler, | 161 public QuotaEvictionHandler, |
| 136 public base::RefCountedThreadSafe<QuotaManager, QuotaManagerDeleter> { | 162 public base::RefCountedThreadSafe<QuotaManager, QuotaManagerDeleter> { |
| 137 public: | 163 public: |
| 138 typedef base::Callback<void(QuotaStatusCode, | 164 typedef base::Callback<void(QuotaStatusCode, |
| 139 int64_t /* usage */, | 165 int64_t /* usage */, |
| 140 int64_t /* quota */)> GetUsageAndQuotaCallback; | 166 int64_t /* quota */)> UsageAndQuotaCallback; |
| 141 | 167 |
| 142 static const int64_t kIncognitoDefaultQuotaLimit; | |
| 143 static const int64_t kNoLimit; | 168 static const int64_t kNoLimit; |
| 144 | 169 |
| 145 QuotaManager( | 170 QuotaManager( |
| 146 bool is_incognito, | 171 bool is_incognito, |
| 147 const base::FilePath& profile_path, | 172 const base::FilePath& profile_path, |
| 148 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread, | 173 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread, |
| 149 const scoped_refptr<base::SequencedTaskRunner>& db_thread, | 174 const scoped_refptr<base::SequencedTaskRunner>& db_thread, |
| 150 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy); | 175 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy, |
| 176 const GetTemporaryStorageConfigurationFunc& get_config_function); |
| 177 |
| 178 const TemporaryStorageConfiguration& storage_config() const { |
| 179 return storage_config_; |
| 180 } |
| 181 void SetTemporaryStorageConfiguration( |
| 182 const TemporaryStorageConfiguration& storage_config); |
| 151 | 183 |
| 152 // Returns a proxy object that can be used on any thread. | 184 // Returns a proxy object that can be used on any thread. |
| 153 QuotaManagerProxy* proxy() { return proxy_.get(); } | 185 QuotaManagerProxy* proxy() { return proxy_.get(); } |
| 154 | 186 |
| 155 // Called by clients or webapps. Returns usage per host. | 187 // Called by clients or webapps. Returns usage per host. |
| 156 void GetUsageInfo(const GetUsageInfoCallback& callback); | 188 void GetUsageInfo(const GetUsageInfoCallback& callback); |
| 157 | 189 |
| 158 // Called by Web Apps. | 190 // Called by Web Apps. |
| 159 // This method is declared as virtual to allow test code to override it. | 191 // This method is declared as virtual to allow test code to override it. |
| 160 virtual void GetUsageAndQuotaForWebApps( | 192 virtual void GetUsageAndQuotaForWebApps( |
| 161 const GURL& origin, | 193 const GURL& origin, |
| 162 StorageType type, | 194 StorageType type, |
| 163 const GetUsageAndQuotaCallback& callback); | 195 const UsageAndQuotaCallback& callback); |
| 164 | 196 |
| 165 // Called by StorageClients. | 197 // Called by StorageClients. |
| 166 // This method is declared as virtual to allow test code to override it. | 198 // This method is declared as virtual to allow test code to override it. |
| 167 // | 199 // |
| 168 // For UnlimitedStorage origins, this version skips usage and quota handling | 200 // For UnlimitedStorage origins, this version skips usage and quota handling |
| 169 // to avoid extra query cost. | 201 // to avoid extra query cost. |
| 170 // Do not call this method for apps/user-facing code. | 202 // Do not call this method for apps/user-facing code. |
| 171 virtual void GetUsageAndQuota( | 203 virtual void GetUsageAndQuota( |
| 172 const GURL& origin, | 204 const GURL& origin, |
| 173 StorageType type, | 205 StorageType type, |
| 174 const GetUsageAndQuotaCallback& callback); | 206 const UsageAndQuotaCallback& callback); |
| 175 | 207 |
| 176 // Called by clients via proxy. | 208 // Called by clients via proxy. |
| 177 // Client storage should call this method when storage is accessed. | 209 // Client storage should call this method when storage is accessed. |
| 178 // Used to maintain LRU ordering. | 210 // Used to maintain LRU ordering. |
| 179 void NotifyStorageAccessed(QuotaClient::ID client_id, | 211 void NotifyStorageAccessed(QuotaClient::ID client_id, |
| 180 const GURL& origin, | 212 const GURL& origin, |
| 181 StorageType type); | 213 StorageType type); |
| 182 | 214 |
| 183 // Called by clients via proxy. | 215 // Called by clients via proxy. |
| 184 // Client storage must call this method whenever they have made any | 216 // Client storage must call this method whenever they have made any |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 virtual void DeleteOriginData(const GURL& origin, | 248 virtual void DeleteOriginData(const GURL& origin, |
| 217 StorageType type, | 249 StorageType type, |
| 218 int quota_client_mask, | 250 int quota_client_mask, |
| 219 const StatusCallback& callback); | 251 const StatusCallback& callback); |
| 220 void DeleteHostData(const std::string& host, | 252 void DeleteHostData(const std::string& host, |
| 221 StorageType type, | 253 StorageType type, |
| 222 int quota_client_mask, | 254 int quota_client_mask, |
| 223 const StatusCallback& callback); | 255 const StatusCallback& callback); |
| 224 | 256 |
| 225 // Called by UI and internal modules. | 257 // Called by UI and internal modules. |
| 226 void GetAvailableSpace(const AvailableSpaceCallback& callback); | |
| 227 void GetTemporaryGlobalQuota(const QuotaCallback& callback); | |
| 228 | |
| 229 // Ok to call with NULL callback. | |
| 230 void SetTemporaryGlobalOverrideQuota(int64_t new_quota, | |
| 231 const QuotaCallback& callback); | |
| 232 | |
| 233 void GetPersistentHostQuota(const std::string& host, | 258 void GetPersistentHostQuota(const std::string& host, |
| 234 const QuotaCallback& callback); | 259 const QuotaCallback& callback); |
| 235 void SetPersistentHostQuota(const std::string& host, | 260 void SetPersistentHostQuota(const std::string& host, |
| 236 int64_t new_quota, | 261 int64_t new_quota, |
| 237 const QuotaCallback& callback); | 262 const QuotaCallback& callback); |
| 238 void GetGlobalUsage(StorageType type, const GlobalUsageCallback& callback); | 263 void GetGlobalUsage(StorageType type, const GlobalUsageCallback& callback); |
| 239 void GetHostUsage(const std::string& host, StorageType type, | 264 void GetHostUsage(const std::string& host, StorageType type, |
| 240 const UsageCallback& callback); | 265 const UsageCallback& callback); |
| 241 void GetHostUsage(const std::string& host, StorageType type, | 266 void GetHostUsage(const std::string& host, StorageType type, |
| 242 QuotaClient::ID client_id, | 267 QuotaClient::ID client_id, |
| 243 const UsageCallback& callback); | 268 const UsageCallback& callback); |
| 244 | 269 |
| 245 bool IsTrackingHostUsage(StorageType type, QuotaClient::ID client_id) const; | 270 bool IsTrackingHostUsage(StorageType type, QuotaClient::ID client_id) const; |
| 246 | 271 |
| 247 void GetStatistics(std::map<std::string, std::string>* statistics); | 272 void GetStatistics(std::map<std::string, std::string>* statistics); |
| 248 | 273 |
| 249 bool IsStorageUnlimited(const GURL& origin, StorageType type) const; | 274 bool IsStorageUnlimited(const GURL& origin, StorageType type) const; |
| 250 | 275 |
| 251 bool CanQueryDiskSize(const GURL& origin) const { | 276 bool CanQueryDiskSize(const GURL& origin) const { |
| 277 // TODO: not currently used? |
| 252 return special_storage_policy_.get() && | 278 return special_storage_policy_.get() && |
| 253 special_storage_policy_->CanQueryDiskSize(origin); | 279 special_storage_policy_->CanQueryDiskSize(origin); |
| 254 } | 280 } |
| 255 | 281 |
| 256 virtual void GetOriginsModifiedSince(StorageType type, | 282 virtual void GetOriginsModifiedSince(StorageType type, |
| 257 base::Time modified_since, | 283 base::Time modified_since, |
| 258 const GetOriginsCallback& callback); | 284 const GetOriginsCallback& callback); |
| 259 | 285 |
| 260 bool ResetUsageTracker(StorageType type); | 286 bool ResetUsageTracker(StorageType type); |
| 261 | 287 |
| 262 // Used to register/deregister observers that wish to monitor storage events. | 288 // Used to register/deregister observers that wish to monitor storage events. |
| 263 void AddStorageObserver(StorageObserver* observer, | 289 void AddStorageObserver(StorageObserver* observer, |
| 264 const StorageObserver::MonitorParams& params); | 290 const StorageObserver::MonitorParams& params); |
| 265 void RemoveStorageObserver(StorageObserver* observer); | 291 void RemoveStorageObserver(StorageObserver* observer); |
| 266 void RemoveStorageObserverForFilter(StorageObserver* observer, | 292 void RemoveStorageObserverForFilter(StorageObserver* observer, |
| 267 const StorageObserver::Filter& filter); | 293 const StorageObserver::Filter& filter); |
| 268 | 294 |
| 269 // Determines the portion of the temp pool that can be | |
| 270 // utilized by a single host (ie. 5 for 20%). | |
| 271 static const int kPerHostTemporaryPortion; | |
| 272 | |
| 273 static const int64_t kPerHostPersistentQuotaLimit; | 295 static const int64_t kPerHostPersistentQuotaLimit; |
| 274 | |
| 275 static const char kDatabaseName[]; | 296 static const char kDatabaseName[]; |
| 276 | |
| 277 static const int kThresholdOfErrorsToBeBlacklisted; | 297 static const int kThresholdOfErrorsToBeBlacklisted; |
| 278 | |
| 279 static const int kEvictionIntervalInMilliSeconds; | 298 static const int kEvictionIntervalInMilliSeconds; |
| 280 | |
| 281 static const char kTimeBetweenRepeatedOriginEvictionsHistogram[]; | 299 static const char kTimeBetweenRepeatedOriginEvictionsHistogram[]; |
| 282 static const char kEvictedOriginAccessedCountHistogram[]; | 300 static const char kEvictedOriginAccessedCountHistogram[]; |
| 283 static const char kEvictedOriginTimeSinceAccessHistogram[]; | 301 static const char kEvictedOriginTimeSinceAccessHistogram[]; |
| 284 | 302 |
| 285 // These are kept non-const so that test code can change the value. | 303 // Kept non-const so that test code can change the value. |
| 286 // TODO(kinuko): Make this a real const value and add a proper way to set | 304 // TODO(kinuko): Make this a real const value and add a proper way to set |
| 287 // the quota for syncable storage. (http://crbug.com/155488) | 305 // the quota for syncable storage. (http://crbug.com/155488) |
| 288 static int64_t kMinimumPreserveForSystem; | |
| 289 static int64_t kSyncableStorageDefaultHostQuota; | 306 static int64_t kSyncableStorageDefaultHostQuota; |
| 290 | 307 |
| 291 protected: | 308 protected: |
| 292 ~QuotaManager() override; | 309 ~QuotaManager() override; |
| 293 | 310 |
| 294 private: | 311 private: |
| 295 friend class base::DeleteHelper<QuotaManager>; | 312 friend class base::DeleteHelper<QuotaManager>; |
| 296 friend class base::RefCountedThreadSafe<QuotaManager, QuotaManagerDeleter>; | 313 friend class base::RefCountedThreadSafe<QuotaManager, QuotaManagerDeleter>; |
| 297 friend class content::QuotaManagerTest; | 314 friend class content::QuotaManagerTest; |
| 298 friend class content::StorageMonitorTest; | 315 friend class content::StorageMonitorTest; |
| 299 friend class content::MockQuotaManager; | 316 friend class content::MockQuotaManager; |
| 300 friend class content::MockStorageClient; | 317 friend class content::MockStorageClient; |
| 301 friend class quota_internals::QuotaInternalsProxy; | 318 friend class quota_internals::QuotaInternalsProxy; |
| 302 friend class QuotaManagerProxy; | 319 friend class QuotaManagerProxy; |
| 303 friend class QuotaTemporaryStorageEvictor; | 320 friend class QuotaTemporaryStorageEvictor; |
| 304 friend struct QuotaManagerDeleter; | 321 friend struct QuotaManagerDeleter; |
| 305 friend class ::SiteEngagementEvictionPolicyWithQuotaManagerTest; | 322 friend class ::SiteEngagementEvictionPolicyWithQuotaManagerTest; |
| 306 | 323 |
| 324 class EvictionRoundInfoHelper; |
| 325 class UsageAndQuotaHelper; |
| 307 class GetUsageInfoTask; | 326 class GetUsageInfoTask; |
| 308 | |
| 309 class OriginDataDeleter; | 327 class OriginDataDeleter; |
| 310 class HostDataDeleter; | 328 class HostDataDeleter; |
| 311 | |
| 312 class GetModifiedSinceHelper; | 329 class GetModifiedSinceHelper; |
| 313 class DumpQuotaTableHelper; | 330 class DumpQuotaTableHelper; |
| 314 class DumpOriginInfoTableHelper; | 331 class DumpOriginInfoTableHelper; |
| 315 | 332 |
| 316 typedef QuotaDatabase::QuotaTableEntry QuotaTableEntry; | 333 typedef QuotaDatabase::QuotaTableEntry QuotaTableEntry; |
| 317 typedef QuotaDatabase::OriginInfoTableEntry OriginInfoTableEntry; | 334 typedef QuotaDatabase::OriginInfoTableEntry OriginInfoTableEntry; |
| 318 typedef std::vector<QuotaTableEntry> QuotaTableEntries; | 335 typedef std::vector<QuotaTableEntry> QuotaTableEntries; |
| 319 typedef std::vector<OriginInfoTableEntry> OriginInfoTableEntries; | 336 typedef std::vector<OriginInfoTableEntry> OriginInfoTableEntries; |
| 320 | 337 |
| 321 // Function pointer type used to store the function which returns | 338 // Function pointer type used to store the function which returns |
| 322 // information about the volume containing the given FilePath. | 339 // information about the volume containing the given FilePath. |
| 323 using GetVolumeInfoFn = bool(*)(const base::FilePath&, | 340 // The value returned is std::pair<total_space, available_space>. |
| 324 uint64_t* available, uint64_t* total); | 341 using GetVolumeInfoFn = std::pair<int64_t,int64_t>(*)(const base::FilePath&); |
| 325 | 342 |
| 326 typedef base::Callback<void(const QuotaTableEntries&)> | 343 typedef base::Callback<void(const QuotaTableEntries&)> |
| 327 DumpQuotaTableCallback; | 344 DumpQuotaTableCallback; |
| 328 typedef base::Callback<void(const OriginInfoTableEntries&)> | 345 typedef base::Callback<void(const OriginInfoTableEntries&)> |
| 329 DumpOriginInfoTableCallback; | 346 DumpOriginInfoTableCallback; |
| 330 | 347 |
| 331 typedef CallbackQueue<base::Closure> ClosureQueue; | 348 typedef CallbackQueue<base::Closure> ClosureQueue; |
| 332 typedef CallbackQueue<AvailableSpaceCallback, QuotaStatusCode, int64_t> | |
| 333 AvailableSpaceCallbackQueue; | |
| 334 typedef CallbackQueueMap<QuotaCallback, std::string, QuotaStatusCode, int64_t> | 349 typedef CallbackQueueMap<QuotaCallback, std::string, QuotaStatusCode, int64_t> |
| 335 HostQuotaCallbackMap; | 350 HostQuotaCallbackMap; |
| 351 using TemporaryConfigCallbackQueue = |
| 352 CallbackQueue<TemporaryStorageConfigurationCallback, |
| 353 const TemporaryStorageConfiguration&>; |
| 354 |
| 355 // The values returned total_space, available_space. |
| 356 using StorageCapacityCallback = base::Callback<void(int64_t, int64_t)>; |
| 357 using StorageCapacityCallbackQueue = |
| 358 CallbackQueue<StorageCapacityCallback, int64_t, int64_t>; |
| 336 | 359 |
| 337 struct EvictionContext { | 360 struct EvictionContext { |
| 338 EvictionContext(); | 361 EvictionContext(); |
| 339 virtual ~EvictionContext(); | 362 ~EvictionContext(); |
| 340 GURL evicted_origin; | 363 GURL evicted_origin; |
| 341 StorageType evicted_type; | 364 StorageType evicted_type; |
| 342 | 365 StatusCallback evict_origin_data_callback; |
| 343 EvictOriginDataCallback evict_origin_data_callback; | |
| 344 }; | 366 }; |
| 345 | 367 |
| 346 typedef QuotaEvictionHandler::UsageAndQuotaCallback | |
| 347 UsageAndQuotaDispatcherCallback; | |
| 348 | |
| 349 // This initialization method is lazily called on the IO thread | 368 // This initialization method is lazily called on the IO thread |
| 350 // when the first quota manager API is called. | 369 // when the first quota manager API is called. |
| 351 // Initialize must be called after all quota clients are added to the | 370 // Initialize must be called after all quota clients are added to the |
| 352 // manager by RegisterStorage. | 371 // manager by RegisterStorage. |
| 353 void LazyInitialize(); | 372 void LazyInitialize(); |
| 354 | 373 |
| 355 // Called by clients via proxy. | 374 // Called by clients via proxy. |
| 356 // Registers a quota client to the manager. | 375 // Registers a quota client to the manager. |
| 357 // The client must remain valid until OnQuotaManagerDestored is called. | 376 // The client must remain valid until OnQuotaManagerDestored is called. |
| 358 void RegisterClient(QuotaClient* client); | 377 void RegisterClient(QuotaClient* client); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 void DidGetEvictionOrigin(const GetOriginCallback& callback, | 424 void DidGetEvictionOrigin(const GetOriginCallback& callback, |
| 406 const GURL& origin); | 425 const GURL& origin); |
| 407 | 426 |
| 408 // QuotaEvictionHandler. | 427 // QuotaEvictionHandler. |
| 409 void GetEvictionOrigin(StorageType type, | 428 void GetEvictionOrigin(StorageType type, |
| 410 const std::set<GURL>& extra_exceptions, | 429 const std::set<GURL>& extra_exceptions, |
| 411 int64_t global_quota, | 430 int64_t global_quota, |
| 412 const GetOriginCallback& callback) override; | 431 const GetOriginCallback& callback) override; |
| 413 void EvictOriginData(const GURL& origin, | 432 void EvictOriginData(const GURL& origin, |
| 414 StorageType type, | 433 StorageType type, |
| 415 const EvictOriginDataCallback& callback) override; | 434 const StatusCallback& callback) override; |
| 416 void GetUsageAndQuotaForEviction( | 435 void GetEvictionRoundInfo( |
| 417 const UsageAndQuotaCallback& callback) override; | 436 const EvictionRoundInfoCallback& callback) override; |
| 418 void AsyncGetVolumeInfo(const VolumeInfoCallback& callback) override; | |
| 419 | 437 |
| 420 void DidGetVolumeInfo( | |
| 421 const VolumeInfoCallback& callback, | |
| 422 uint64_t* available_space, uint64_t* total_space, bool success); | |
| 423 | 438 |
| 424 void GetLRUOrigin(StorageType type, const GetOriginCallback& callback); | 439 void GetLRUOrigin(StorageType type, const GetOriginCallback& callback); |
| 425 | 440 |
| 426 void DidSetTemporaryGlobalOverrideQuota(const QuotaCallback& callback, | |
| 427 const int64_t* new_quota, | |
| 428 bool success); | |
| 429 void DidGetPersistentHostQuota(const std::string& host, | 441 void DidGetPersistentHostQuota(const std::string& host, |
| 430 const int64_t* quota, | 442 const int64_t* quota, |
| 431 bool success); | 443 bool success); |
| 432 void DidSetPersistentHostQuota(const std::string& host, | 444 void DidSetPersistentHostQuota(const std::string& host, |
| 433 const QuotaCallback& callback, | 445 const QuotaCallback& callback, |
| 434 const int64_t* new_quota, | 446 const int64_t* new_quota, |
| 435 bool success); | 447 bool success); |
| 436 void DidInitialize(int64_t* temporary_quota_override, | |
| 437 int64_t* desired_available_space, | |
| 438 bool success); | |
| 439 void DidGetLRUOrigin(const GURL* origin, | 448 void DidGetLRUOrigin(const GURL* origin, |
| 440 bool success); | 449 bool success); |
| 441 void DidGetInitialTemporaryGlobalQuota(base::TimeTicks start_ticks, | |
| 442 QuotaStatusCode status, | |
| 443 int64_t quota_unused); | |
| 444 void DidInitializeTemporaryOriginsInfo(bool success); | 450 void DidInitializeTemporaryOriginsInfo(bool success); |
| 445 void DidGetAvailableSpace(int64_t space); | 451 void GetTemporaryStorageConfig( |
| 452 const TemporaryStorageConfigurationCallback& callback); |
| 453 void DidGetTemporaryStorageConfig( |
| 454 const TemporaryStorageConfiguration& storage_config); |
| 455 void GetDeviceStorageCapacity( |
| 456 const StorageCapacityCallback& callback); |
| 457 void ContinueIncognitoGetStorageCapacity( |
| 458 const TemporaryStorageConfiguration& config); |
| 459 void DidGetDeviceStorageCapacity( |
| 460 const std::pair<int64_t, int64_t>& total_and_available); |
| 461 |
| 446 void DidDatabaseWork(bool success); | 462 void DidDatabaseWork(bool success); |
| 447 | 463 |
| 448 void DeleteOnCorrectThread() const; | 464 void DeleteOnCorrectThread() const; |
| 449 | 465 |
| 450 void PostTaskAndReplyWithResultForDBThread( | 466 void PostTaskAndReplyWithResultForDBThread( |
| 451 const tracked_objects::Location& from_here, | 467 const tracked_objects::Location& from_here, |
| 452 const base::Callback<bool(QuotaDatabase*)>& task, | 468 const base::Callback<bool(QuotaDatabase*)>& task, |
| 453 const base::Callback<void(bool)>& reply); | 469 const base::Callback<void(bool)>& reply); |
| 454 | 470 |
| 455 static int64_t CallGetAmountOfFreeDiskSpace( | 471 static std::pair<int64_t, int64_t> CallGetVolumeInfo( |
| 456 GetVolumeInfoFn get_vol_info_fn, | 472 GetVolumeInfoFn get_volume_info_fn, |
| 457 const base::FilePath& profile_path); | 473 const base::FilePath& path); |
| 458 static bool GetVolumeInfo(const base::FilePath& path, | 474 static std::pair<int64_t,int64_t> GetVolumeInfo(const base::FilePath& path); |
| 459 uint64_t* available_space, | |
| 460 uint64_t* total_size); | |
| 461 | 475 |
| 462 const bool is_incognito_; | 476 const bool is_incognito_; |
| 463 const base::FilePath profile_path_; | 477 const base::FilePath profile_path_; |
| 464 | 478 |
| 465 scoped_refptr<QuotaManagerProxy> proxy_; | 479 scoped_refptr<QuotaManagerProxy> proxy_; |
| 466 bool db_disabled_; | 480 bool db_disabled_; |
| 467 bool eviction_disabled_; | 481 bool eviction_disabled_; |
| 468 scoped_refptr<base::SingleThreadTaskRunner> io_thread_; | 482 scoped_refptr<base::SingleThreadTaskRunner> io_thread_; |
| 469 scoped_refptr<base::SequencedTaskRunner> db_thread_; | 483 scoped_refptr<base::SequencedTaskRunner> db_thread_; |
| 470 mutable std::unique_ptr<QuotaDatabase> database_; | 484 mutable std::unique_ptr<QuotaDatabase> database_; |
| 471 | 485 |
| 486 GetTemporaryStorageConfigurationFunc get_config_function_; |
| 487 scoped_refptr<base::TaskRunner> get_config_task_runner_; |
| 488 TemporaryStorageConfiguration storage_config_; |
| 489 base::TimeTicks storage_config_timestamp_; |
| 490 TemporaryConfigCallbackQueue storage_config_callbacks_; |
| 491 StorageCapacityCallbackQueue storage_capacity_callbacks_; |
| 492 |
| 472 GetOriginCallback lru_origin_callback_; | 493 GetOriginCallback lru_origin_callback_; |
| 473 std::set<GURL> access_notified_origins_; | 494 std::set<GURL> access_notified_origins_; |
| 474 | 495 |
| 475 QuotaClientList clients_; | 496 QuotaClientList clients_; |
| 476 | 497 |
| 477 std::unique_ptr<UsageTracker> temporary_usage_tracker_; | 498 std::unique_ptr<UsageTracker> temporary_usage_tracker_; |
| 478 std::unique_ptr<UsageTracker> persistent_usage_tracker_; | 499 std::unique_ptr<UsageTracker> persistent_usage_tracker_; |
| 479 std::unique_ptr<UsageTracker> syncable_usage_tracker_; | 500 std::unique_ptr<UsageTracker> syncable_usage_tracker_; |
| 480 // TODO(michaeln): Need a way to clear the cache, drop and | 501 // TODO(michaeln): Need a way to clear the cache, drop and |
| 481 // reinstantiate the trackers when they're not handling requests. | 502 // reinstantiate the trackers when they're not handling requests. |
| 482 | 503 |
| 483 std::unique_ptr<QuotaTemporaryStorageEvictor> temporary_storage_evictor_; | 504 std::unique_ptr<QuotaTemporaryStorageEvictor> temporary_storage_evictor_; |
| 484 EvictionContext eviction_context_; | 505 EvictionContext eviction_context_; |
| 485 std::unique_ptr<QuotaEvictionPolicy> temporary_storage_eviction_policy_; | 506 std::unique_ptr<QuotaEvictionPolicy> temporary_storage_eviction_policy_; |
| 486 bool is_getting_eviction_origin_; | 507 bool is_getting_eviction_origin_; |
| 487 | 508 |
| 488 ClosureQueue db_initialization_callbacks_; | |
| 489 AvailableSpaceCallbackQueue available_space_callbacks_; | |
| 490 HostQuotaCallbackMap persistent_host_quota_callbacks_; | 509 HostQuotaCallbackMap persistent_host_quota_callbacks_; |
| 491 | 510 |
| 492 bool temporary_quota_initialized_; | |
| 493 int64_t temporary_quota_override_; | |
| 494 int64_t desired_available_space_; | |
| 495 | |
| 496 // Map from origin to count. | 511 // Map from origin to count. |
| 497 std::map<GURL, int> origins_in_use_; | 512 std::map<GURL, int> origins_in_use_; |
| 498 // Map from origin to error count. | 513 // Map from origin to error count. |
| 499 std::map<GURL, int> origins_in_error_; | 514 std::map<GURL, int> origins_in_error_; |
| 500 | 515 |
| 501 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; | 516 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; |
| 502 | 517 |
| 503 base::RepeatingTimer histogram_timer_; | 518 base::RepeatingTimer histogram_timer_; |
| 504 | 519 |
| 505 // Pointer to the function used to get volume information. This is | 520 // Pointer to the function used to get volume information. This is |
| (...skipping 10 matching lines...) Expand all Loading... |
| 516 | 531 |
| 517 struct QuotaManagerDeleter { | 532 struct QuotaManagerDeleter { |
| 518 static void Destruct(const QuotaManager* manager) { | 533 static void Destruct(const QuotaManager* manager) { |
| 519 manager->DeleteOnCorrectThread(); | 534 manager->DeleteOnCorrectThread(); |
| 520 } | 535 } |
| 521 }; | 536 }; |
| 522 | 537 |
| 523 } // namespace storage | 538 } // namespace storage |
| 524 | 539 |
| 525 #endif // STORAGE_BROWSER_QUOTA_QUOTA_MANAGER_H_ | 540 #endif // STORAGE_BROWSER_QUOTA_QUOTA_MANAGER_H_ |
| OLD | NEW |