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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 void GetHostUsage(const std::string& host, StorageType type, | 139 void GetHostUsage(const std::string& host, StorageType type, |
140 HostUsageCallback* callback); | 140 HostUsageCallback* callback); |
141 | 141 |
142 void GetStatistics(std::map<std::string, std::string>* statistics); | 142 void GetStatistics(std::map<std::string, std::string>* statistics); |
143 | 143 |
144 bool IsStorageUnlimited(const GURL& origin) const { | 144 bool IsStorageUnlimited(const GURL& origin) const { |
145 return special_storage_policy_.get() && | 145 return special_storage_policy_.get() && |
146 special_storage_policy_->IsStorageUnlimited(origin); | 146 special_storage_policy_->IsStorageUnlimited(origin); |
147 } | 147 } |
148 | 148 |
149 void GetOriginsModifiedSince( | |
150 StorageType type, | |
151 base::Time modified_since, | |
152 GetOriginsCallback* callback); | |
153 | |
154 // Used to determine the total size of the temp pool. | 149 // Used to determine the total size of the temp pool. |
155 static const int64 kTemporaryStorageQuotaDefaultSize; | 150 static const int64 kTemporaryStorageQuotaDefaultSize; |
156 static const int64 kTemporaryStorageQuotaMaxSize; | 151 static const int64 kTemporaryStorageQuotaMaxSize; |
157 static const int64 kIncognitoDefaultTemporaryQuota; | 152 static const int64 kIncognitoDefaultTemporaryQuota; |
158 | 153 |
159 // Determines the portion of the temp pool that can be | 154 // Determines the portion of the temp pool that can be |
160 // utilized by a single host (ie. 5 for 20%). | 155 // utilized by a single host (ie. 5 for 20%). |
161 static const int kPerHostTemporaryPortion; | 156 static const int kPerHostTemporaryPortion; |
162 | 157 |
163 static const char kDatabaseName[]; | 158 static const char kDatabaseName[]; |
164 | 159 |
165 static const int kThresholdOfErrorsToBeBlacklisted; | 160 static const int kThresholdOfErrorsToBeBlacklisted; |
166 | 161 |
167 static const int kEvictionIntervalInMilliSeconds; | 162 static const int kEvictionIntervalInMilliSeconds; |
168 | 163 |
169 private: | 164 private: |
170 class DatabaseTaskBase; | 165 class DatabaseTaskBase; |
171 class InitializeTask; | 166 class InitializeTask; |
172 class UpdateTemporaryGlobalQuotaTask; | 167 class TemporaryGlobalQuotaUpdateTask; |
173 class GetPersistentHostQuotaTask; | 168 class PersistentHostQuotaQueryTask; |
174 class UpdatePersistentHostQuotaTask; | 169 class PersistentHostQuotaUpdateTask; |
175 class GetLRUOriginTask; | 170 class GetLRUOriginTask; |
176 class DeleteOriginInfo; | 171 class OriginDeletionDatabaseTask; |
177 class InitializeTemporaryOriginsInfoTask; | 172 class TemporaryOriginsRegistrationTask; |
178 class UpdateAccesTimeTask; | 173 class OriginAccessRecordDatabaseTask; |
179 class UpdateModifiedTimeTask; | |
180 class GetModifiedSinceTask; | |
181 | 174 |
182 class UsageAndQuotaDispatcherTask; | 175 class UsageAndQuotaDispatcherTask; |
183 class UsageAndQuotaDispatcherTaskForTemporary; | 176 class UsageAndQuotaDispatcherTaskForTemporary; |
184 class UsageAndQuotaDispatcherTaskForPersistent; | 177 class UsageAndQuotaDispatcherTaskForPersistent; |
185 | 178 |
186 class OriginDataDeleter; | 179 class OriginDataDeleter; |
187 | 180 |
188 class AvailableSpaceQueryTask; | 181 class AvailableSpaceQueryTask; |
189 class DumpQuotaTableTask; | 182 class DumpQuotaTableTask; |
190 class DumpOriginInfoTableTask; | 183 class DumpLastAccessTimeTableTask; |
191 | 184 |
192 typedef QuotaDatabase::QuotaTableEntry QuotaTableEntry; | 185 typedef QuotaDatabase::QuotaTableEntry QuotaTableEntry; |
193 typedef QuotaDatabase::OriginInfoTableEntry OriginInfoTableEntry; | 186 typedef QuotaDatabase::LastAccessTimeTableEntry LastAccessTimeTableEntry; |
194 typedef std::vector<QuotaTableEntry> QuotaTableEntries; | 187 typedef std::vector<QuotaTableEntry> QuotaTableEntries; |
195 typedef std::vector<OriginInfoTableEntry> OriginInfoTableEntries; | 188 typedef std::vector<LastAccessTimeTableEntry> LastAccessTimeTableEntries; |
196 | 189 |
197 typedef Callback1<const QuotaTableEntries&>::Type DumpQuotaTableCallback; | 190 typedef Callback1<const QuotaTableEntries&>::Type DumpQuotaTableCallback; |
198 typedef Callback1<const OriginInfoTableEntries&>::Type | 191 typedef Callback1<const LastAccessTimeTableEntries&>::Type |
199 DumpOriginInfoTableCallback; | 192 DumpLastAccessTimeTableCallback; |
200 | 193 |
201 struct EvictionContext { | 194 struct EvictionContext { |
202 EvictionContext() | 195 EvictionContext() |
203 : evicted_type(kStorageTypeUnknown), | 196 : evicted_type(kStorageTypeUnknown), |
204 usage(0), | 197 usage(0), |
205 unlimited_usage(0), | 198 unlimited_usage(0), |
206 quota(0) {} | 199 quota(0) {} |
207 virtual ~EvictionContext() {} | 200 virtual ~EvictionContext() {} |
208 | 201 |
209 GURL evicted_origin; | 202 GURL evicted_origin; |
210 StorageType evicted_type; | 203 StorageType evicted_type; |
211 | 204 |
212 scoped_ptr<EvictOriginDataCallback> evict_origin_data_callback; | 205 scoped_ptr<EvictOriginDataCallback> evict_origin_data_callback; |
213 | 206 |
214 scoped_ptr<GetUsageAndQuotaForEvictionCallback> | 207 scoped_ptr<GetUsageAndQuotaForEvictionCallback> |
215 get_usage_and_quota_callback; | 208 get_usage_and_quota_callback; |
216 int64 usage; | 209 int64 usage; |
217 int64 unlimited_usage; | 210 int64 unlimited_usage; |
218 int64 quota; | 211 int64 quota; |
219 }; | 212 }; |
220 | 213 |
221 typedef std::pair<std::string, StorageType> HostAndType; | 214 typedef std::pair<std::string, StorageType> HostAndType; |
222 typedef std::map<HostAndType, UsageAndQuotaDispatcherTask*> | 215 typedef std::map<HostAndType, UsageAndQuotaDispatcherTask*> |
223 UsageAndQuotaDispatcherTaskMap; | 216 UsageAndQuotaDispatcherTaskMap; |
224 | 217 |
225 friend struct QuotaManagerDeleter; | 218 friend struct QuotaManagerDeleter; |
226 friend class MockStorageClient; | |
227 friend class QuotaManagerProxy; | 219 friend class QuotaManagerProxy; |
228 friend class QuotaManagerTest; | 220 friend class QuotaManagerTest; |
229 friend class QuotaTemporaryStorageEvictor; | 221 friend class QuotaTemporaryStorageEvictor; |
230 | 222 |
231 // This initialization method is lazily called on the IO thread | 223 // This initialization method is lazily called on the IO thread |
232 // when the first quota manager API is called. | 224 // when the first quota manager API is called. |
233 // Initialize must be called after all quota clients are added to the | 225 // Initialize must be called after all quota clients are added to the |
234 // manager by RegisterStorage. | 226 // manager by RegisterStorage. |
235 void LazyInitialize(); | 227 void LazyInitialize(); |
236 | 228 |
237 // Called by clients via proxy. | 229 // Called by clients via proxy. |
238 // Registers a quota client to the manager. | 230 // Registers a quota client to the manager. |
239 // The client must remain valid until OnQuotaManagerDestored is called. | 231 // The client must remain valid until OnQuotaManagerDestored is called. |
240 void RegisterClient(QuotaClient* client); | 232 void RegisterClient(QuotaClient* client); |
241 | 233 |
242 UsageTracker* GetUsageTracker(StorageType type) const; | 234 UsageTracker* GetUsageTracker(StorageType type) const; |
243 | 235 |
244 // Extract cached origins list from the usage tracker. | 236 // Extract cached origins list from the usage tracker. |
245 // (Might return empty list if no origin is tracked by the tracker.) | 237 // (Might return empty list if no origin is tracked by the tracker.) |
246 void GetCachedOrigins(StorageType type, std::set<GURL>* origins); | 238 void GetCachedOrigins(StorageType type, std::set<GURL>* origins); |
247 | 239 |
248 // These internal methods are separately defined mainly for testing. | 240 // This internal method is separately defined mainly for testing. |
249 void NotifyStorageAccessedInternal( | 241 void NotifyStorageAccessedInternal( |
250 QuotaClient::ID client_id, | 242 QuotaClient::ID client_id, |
251 const GURL& origin, | 243 const GURL& origin, |
252 StorageType type, | 244 StorageType type, |
253 base::Time accessed_time); | 245 base::Time accessed_time); |
254 void NotifyStorageModifiedInternal( | |
255 QuotaClient::ID client_id, | |
256 const GURL& origin, | |
257 StorageType type, | |
258 int64 delta, | |
259 base::Time modified_time); | |
260 | 246 |
261 void DumpQuotaTable(DumpQuotaTableCallback* callback); | 247 void DumpQuotaTable(DumpQuotaTableCallback* callback); |
262 void DumpOriginInfoTable(DumpOriginInfoTableCallback* callback); | 248 void DumpLastAccessTimeTable(DumpLastAccessTimeTableCallback* callback); |
263 | 249 |
264 // Methods for eviction logic. | 250 // Methods for eviction logic. |
265 void StartEviction(); | 251 void StartEviction(); |
266 void DeleteOriginFromDatabase(const GURL& origin, StorageType type); | 252 void DeleteOriginFromDatabase(const GURL& origin, StorageType type); |
267 | 253 |
268 void DidOriginDataEvicted(QuotaStatusCode status); | 254 void DidOriginDataEvicted(QuotaStatusCode status); |
269 void DidGetAvailableSpaceForEviction( | 255 void DidGetAvailableSpaceForEviction( |
270 QuotaStatusCode status, | 256 QuotaStatusCode status, |
271 int64 available_space); | 257 int64 available_space); |
272 void DidGetGlobalQuotaForEviction( | 258 void DidGetGlobalQuotaForEviction( |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 355 |
370 QuotaManager* manager_; // only accessed on the io thread | 356 QuotaManager* manager_; // only accessed on the io thread |
371 scoped_refptr<base::MessageLoopProxy> io_thread_; | 357 scoped_refptr<base::MessageLoopProxy> io_thread_; |
372 | 358 |
373 DISALLOW_COPY_AND_ASSIGN(QuotaManagerProxy); | 359 DISALLOW_COPY_AND_ASSIGN(QuotaManagerProxy); |
374 }; | 360 }; |
375 | 361 |
376 } // namespace quota | 362 } // namespace quota |
377 | 363 |
378 #endif // WEBKIT_QUOTA_QUOTA_MANAGER_H_ | 364 #endif // WEBKIT_QUOTA_QUOTA_MANAGER_H_ |
OLD | NEW |