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