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 CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "content/common/service_worker/service_worker_status_code.h" | 21 #include "content/common/service_worker/service_worker_status_code.h" |
22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
23 | 23 |
24 namespace base { | 24 namespace base { |
25 class SequencedTaskRunner; | 25 class SequencedTaskRunner; |
26 class SingleThreadTaskRunner; | 26 class SingleThreadTaskRunner; |
27 } | 27 } |
28 | 28 |
29 namespace storage { | 29 namespace storage { |
30 class QuotaManagerProxy; | 30 class QuotaManagerProxy; |
| 31 class SpecialStoragePolicy; |
31 } | 32 } |
32 | 33 |
33 namespace content { | 34 namespace content { |
34 | 35 |
35 class ServiceWorkerContextCore; | 36 class ServiceWorkerContextCore; |
36 class ServiceWorkerDiskCache; | 37 class ServiceWorkerDiskCache; |
37 class ServiceWorkerRegistration; | 38 class ServiceWorkerRegistration; |
38 class ServiceWorkerRegistrationInfo; | 39 class ServiceWorkerRegistrationInfo; |
39 class ServiceWorkerResponseReader; | 40 class ServiceWorkerResponseReader; |
40 class ServiceWorkerResponseWriter; | 41 class ServiceWorkerResponseWriter; |
(...skipping 15 matching lines...) Expand all Loading... |
56 void(ServiceWorkerStatusCode status, bool are_equal)> | 57 void(ServiceWorkerStatusCode status, bool are_equal)> |
57 CompareCallback; | 58 CompareCallback; |
58 | 59 |
59 virtual ~ServiceWorkerStorage(); | 60 virtual ~ServiceWorkerStorage(); |
60 | 61 |
61 static scoped_ptr<ServiceWorkerStorage> Create( | 62 static scoped_ptr<ServiceWorkerStorage> Create( |
62 const base::FilePath& path, | 63 const base::FilePath& path, |
63 base::WeakPtr<ServiceWorkerContextCore> context, | 64 base::WeakPtr<ServiceWorkerContextCore> context, |
64 const scoped_refptr<base::SequencedTaskRunner>& database_task_runner, | 65 const scoped_refptr<base::SequencedTaskRunner>& database_task_runner, |
65 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, | 66 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, |
66 storage::QuotaManagerProxy* quota_manager_proxy); | 67 storage::QuotaManagerProxy* quota_manager_proxy, |
| 68 storage::SpecialStoragePolicy* special_storage_policy); |
67 | 69 |
68 // Used for DeleteAndStartOver. Creates new storage based on |old_storage|. | 70 // Used for DeleteAndStartOver. Creates new storage based on |old_storage|. |
69 static scoped_ptr<ServiceWorkerStorage> Create( | 71 static scoped_ptr<ServiceWorkerStorage> Create( |
70 base::WeakPtr<ServiceWorkerContextCore> context, | 72 base::WeakPtr<ServiceWorkerContextCore> context, |
71 ServiceWorkerStorage* old_storage); | 73 ServiceWorkerStorage* old_storage); |
72 | 74 |
73 // Finds registration for |document_url| or |pattern| or |registration_id|. | 75 // Finds registration for |document_url| or |pattern| or |registration_id|. |
74 // The Find methods will find stored and initially installing registrations. | 76 // The Find methods will find stored and initially installing registrations. |
75 // Returns SERVICE_WORKER_OK with non-null registration if registration | 77 // Returns SERVICE_WORKER_OK with non-null registration if registration |
76 // is found, or returns SERVICE_WORKER_ERROR_NOT_FOUND if no matching | 78 // is found, or returns SERVICE_WORKER_ERROR_NOT_FOUND if no matching |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, | 170 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, |
169 DeleteRegistration_NoLiveVersion); | 171 DeleteRegistration_NoLiveVersion); |
170 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, | 172 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, |
171 DeleteRegistration_WaitingVersion); | 173 DeleteRegistration_WaitingVersion); |
172 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, | 174 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, |
173 DeleteRegistration_ActiveVersion); | 175 DeleteRegistration_ActiveVersion); |
174 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, | 176 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, |
175 UpdateRegistration); | 177 UpdateRegistration); |
176 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageDiskTest, | 178 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageDiskTest, |
177 CleanupOnRestart); | 179 CleanupOnRestart); |
| 180 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageDiskTest, |
| 181 ClearOnExit); |
178 | 182 |
179 struct InitialData { | 183 struct InitialData { |
180 int64 next_registration_id; | 184 int64 next_registration_id; |
181 int64 next_version_id; | 185 int64 next_version_id; |
182 int64 next_resource_id; | 186 int64 next_resource_id; |
183 std::set<GURL> origins; | 187 std::set<GURL> origins; |
184 | 188 |
185 InitialData(); | 189 InitialData(); |
186 ~InitialData(); | 190 ~InitialData(); |
187 }; | 191 }; |
(...skipping 30 matching lines...) Expand all Loading... |
218 ServiceWorkerDatabase::Status status)> FindInDBCallback; | 222 ServiceWorkerDatabase::Status status)> FindInDBCallback; |
219 typedef base::Callback<void(const std::vector<int64>& resource_ids, | 223 typedef base::Callback<void(const std::vector<int64>& resource_ids, |
220 ServiceWorkerDatabase::Status status)> | 224 ServiceWorkerDatabase::Status status)> |
221 GetResourcesCallback; | 225 GetResourcesCallback; |
222 | 226 |
223 ServiceWorkerStorage( | 227 ServiceWorkerStorage( |
224 const base::FilePath& path, | 228 const base::FilePath& path, |
225 base::WeakPtr<ServiceWorkerContextCore> context, | 229 base::WeakPtr<ServiceWorkerContextCore> context, |
226 const scoped_refptr<base::SequencedTaskRunner>& database_task_runner, | 230 const scoped_refptr<base::SequencedTaskRunner>& database_task_runner, |
227 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, | 231 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, |
228 storage::QuotaManagerProxy* quota_manager_proxy); | 232 storage::QuotaManagerProxy* quota_manager_proxy, |
| 233 storage::SpecialStoragePolicy* special_storage_policy); |
229 | 234 |
230 base::FilePath GetDatabasePath(); | 235 base::FilePath GetDatabasePath(); |
231 base::FilePath GetDiskCachePath(); | 236 base::FilePath GetDiskCachePath(); |
232 | 237 |
233 bool LazyInitialize( | 238 bool LazyInitialize( |
234 const base::Closure& callback); | 239 const base::Closure& callback); |
235 void DidReadInitialData( | 240 void DidReadInitialData( |
236 InitialData* data, | 241 InitialData* data, |
237 ServiceWorkerDatabase::Status status); | 242 ServiceWorkerDatabase::Status status); |
238 void DidFindRegistrationForDocument( | 243 void DidFindRegistrationForDocument( |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 void PurgeResource(int64 id); | 300 void PurgeResource(int64 id); |
296 void OnResourcePurged(int64 id, int rv); | 301 void OnResourcePurged(int64 id, int rv); |
297 | 302 |
298 // Deletes purgeable and uncommitted resources left over from the previous | 303 // Deletes purgeable and uncommitted resources left over from the previous |
299 // browser session. This must be called once per session before any database | 304 // browser session. This must be called once per session before any database |
300 // operation that may mutate the purgeable or uncommitted resource lists. | 305 // operation that may mutate the purgeable or uncommitted resource lists. |
301 void DeleteStaleResources(); | 306 void DeleteStaleResources(); |
302 void DidCollectStaleResources(const std::vector<int64>& stale_resource_ids, | 307 void DidCollectStaleResources(const std::vector<int64>& stale_resource_ids, |
303 ServiceWorkerDatabase::Status status); | 308 ServiceWorkerDatabase::Status status); |
304 | 309 |
| 310 void ClearSessionOnlyOrigins(); |
| 311 |
305 // Static cross-thread helpers. | 312 // Static cross-thread helpers. |
306 static void CollectStaleResourcesFromDB( | 313 static void CollectStaleResourcesFromDB( |
307 ServiceWorkerDatabase* database, | 314 ServiceWorkerDatabase* database, |
308 scoped_refptr<base::SequencedTaskRunner> original_task_runner, | 315 scoped_refptr<base::SequencedTaskRunner> original_task_runner, |
309 const GetResourcesCallback& callback); | 316 const GetResourcesCallback& callback); |
310 static void ReadInitialDataFromDB( | 317 static void ReadInitialDataFromDB( |
311 ServiceWorkerDatabase* database, | 318 ServiceWorkerDatabase* database, |
312 scoped_refptr<base::SequencedTaskRunner> original_task_runner, | 319 scoped_refptr<base::SequencedTaskRunner> original_task_runner, |
313 const InitializeCallback& callback); | 320 const InitializeCallback& callback); |
314 static void DeleteRegistrationFromDB( | 321 static void DeleteRegistrationFromDB( |
(...skipping 17 matching lines...) Expand all Loading... |
332 ServiceWorkerDatabase* database, | 339 ServiceWorkerDatabase* database, |
333 scoped_refptr<base::SequencedTaskRunner> original_task_runner, | 340 scoped_refptr<base::SequencedTaskRunner> original_task_runner, |
334 const GURL& scope, | 341 const GURL& scope, |
335 const FindInDBCallback& callback); | 342 const FindInDBCallback& callback); |
336 static void FindForIdInDB( | 343 static void FindForIdInDB( |
337 ServiceWorkerDatabase* database, | 344 ServiceWorkerDatabase* database, |
338 scoped_refptr<base::SequencedTaskRunner> original_task_runner, | 345 scoped_refptr<base::SequencedTaskRunner> original_task_runner, |
339 int64 registration_id, | 346 int64 registration_id, |
340 const GURL& origin, | 347 const GURL& origin, |
341 const FindInDBCallback& callback); | 348 const FindInDBCallback& callback); |
| 349 static void DeleteAllDataForOriginsFromDB( |
| 350 ServiceWorkerDatabase* database, |
| 351 const std::set<GURL>& origins); |
342 | 352 |
343 void ScheduleDeleteAndStartOver(); | 353 void ScheduleDeleteAndStartOver(); |
344 void DidDeleteDatabase( | 354 void DidDeleteDatabase( |
345 const StatusCallback& callback, | 355 const StatusCallback& callback, |
346 ServiceWorkerDatabase::Status status); | 356 ServiceWorkerDatabase::Status status); |
347 void DidDeleteDiskCache( | 357 void DidDeleteDiskCache( |
348 const StatusCallback& callback, | 358 const StatusCallback& callback, |
349 bool result); | 359 bool result); |
350 | 360 |
351 // For finding registrations being installed or uninstalled. | 361 // For finding registrations being installed or uninstalled. |
(...skipping 20 matching lines...) Expand all Loading... |
372 | 382 |
373 base::FilePath path_; | 383 base::FilePath path_; |
374 base::WeakPtr<ServiceWorkerContextCore> context_; | 384 base::WeakPtr<ServiceWorkerContextCore> context_; |
375 | 385 |
376 // Only accessed on |database_task_runner_|. | 386 // Only accessed on |database_task_runner_|. |
377 scoped_ptr<ServiceWorkerDatabase> database_; | 387 scoped_ptr<ServiceWorkerDatabase> database_; |
378 | 388 |
379 scoped_refptr<base::SequencedTaskRunner> database_task_runner_; | 389 scoped_refptr<base::SequencedTaskRunner> database_task_runner_; |
380 scoped_refptr<base::SingleThreadTaskRunner> disk_cache_thread_; | 390 scoped_refptr<base::SingleThreadTaskRunner> disk_cache_thread_; |
381 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; | 391 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; |
| 392 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_; |
382 scoped_ptr<ServiceWorkerDiskCache> disk_cache_; | 393 scoped_ptr<ServiceWorkerDiskCache> disk_cache_; |
383 std::deque<int64> purgeable_resource_ids_; | 394 std::deque<int64> purgeable_resource_ids_; |
384 bool is_purge_pending_; | 395 bool is_purge_pending_; |
385 bool has_checked_for_stale_resources_; | 396 bool has_checked_for_stale_resources_; |
386 std::set<int64> pending_deletions_; | 397 std::set<int64> pending_deletions_; |
387 | 398 |
388 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_; | 399 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_; |
389 | 400 |
390 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); | 401 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); |
391 }; | 402 }; |
392 | 403 |
393 } // namespace content | 404 } // namespace content |
394 | 405 |
395 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ | 406 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ |
OLD | NEW |