| 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 <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
| 17 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "content/browser/service_worker/service_worker_database.h" | 19 #include "content/browser/service_worker/service_worker_database.h" |
| 20 #include "content/browser/service_worker/service_worker_database_task_manager.h" | 20 #include "content/browser/service_worker/service_worker_database_task_manager.h" |
| 21 #include "content/browser/service_worker/service_worker_metrics.h" |
| 21 #include "content/browser/service_worker/service_worker_version.h" | 22 #include "content/browser/service_worker/service_worker_version.h" |
| 22 #include "content/common/content_export.h" | 23 #include "content/common/content_export.h" |
| 23 #include "content/common/service_worker/service_worker_status_code.h" | 24 #include "content/common/service_worker/service_worker_status_code.h" |
| 24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 25 | 26 |
| 26 namespace base { | 27 namespace base { |
| 27 class SequencedTaskRunner; | 28 class SequencedTaskRunner; |
| 28 class SingleThreadTaskRunner; | 29 class SingleThreadTaskRunner; |
| 29 } | 30 } |
| 30 | 31 |
| 31 namespace storage { | 32 namespace storage { |
| 32 class QuotaManagerProxy; | 33 class QuotaManagerProxy; |
| 33 class SpecialStoragePolicy; | 34 class SpecialStoragePolicy; |
| 34 } | 35 } |
| 35 | 36 |
| 36 namespace content { | 37 namespace content { |
| 37 | 38 |
| 38 class ServiceWorkerContextCore; | 39 class ServiceWorkerContextCore; |
| 39 class ServiceWorkerDiskCache; | 40 class ServiceWorkerDiskCache; |
| 41 class ServiceWorkerDiskCacheMigrator; |
| 40 class ServiceWorkerRegistration; | 42 class ServiceWorkerRegistration; |
| 41 class ServiceWorkerResponseMetadataWriter; | 43 class ServiceWorkerResponseMetadataWriter; |
| 42 class ServiceWorkerResponseReader; | 44 class ServiceWorkerResponseReader; |
| 43 class ServiceWorkerResponseWriter; | 45 class ServiceWorkerResponseWriter; |
| 44 struct ServiceWorkerRegistrationInfo; | 46 struct ServiceWorkerRegistrationInfo; |
| 45 | 47 |
| 46 // This class provides an interface to store and retrieve ServiceWorker | 48 // This class provides an interface to store and retrieve ServiceWorker |
| 47 // registration data. | 49 // registration data. |
| 48 class CONTENT_EXPORT ServiceWorkerStorage | 50 class CONTENT_EXPORT ServiceWorkerStorage |
| 49 : NON_EXPORTED_BASE(public ServiceWorkerVersion::Listener) { | 51 : NON_EXPORTED_BASE(public ServiceWorkerVersion::Listener) { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 | 207 |
| 206 // |resources| must already be on the purgeable list. | 208 // |resources| must already be on the purgeable list. |
| 207 void PurgeResources(const ResourceList& resources); | 209 void PurgeResources(const ResourceList& resources); |
| 208 | 210 |
| 209 private: | 211 private: |
| 210 friend class ServiceWorkerHandleTest; | 212 friend class ServiceWorkerHandleTest; |
| 211 friend class ServiceWorkerStorageTest; | 213 friend class ServiceWorkerStorageTest; |
| 212 friend class ServiceWorkerResourceStorageTest; | 214 friend class ServiceWorkerResourceStorageTest; |
| 213 friend class ServiceWorkerControlleeRequestHandlerTest; | 215 friend class ServiceWorkerControlleeRequestHandlerTest; |
| 214 friend class ServiceWorkerContextRequestHandlerTest; | 216 friend class ServiceWorkerContextRequestHandlerTest; |
| 217 friend class ServiceWorkerDiskCacheMigratorTest; |
| 215 friend class ServiceWorkerRequestHandlerTest; | 218 friend class ServiceWorkerRequestHandlerTest; |
| 216 friend class ServiceWorkerURLRequestJobTest; | 219 friend class ServiceWorkerURLRequestJobTest; |
| 217 friend class ServiceWorkerVersionBrowserTest; | 220 friend class ServiceWorkerVersionBrowserTest; |
| 218 friend class ServiceWorkerVersionTest; | 221 friend class ServiceWorkerVersionTest; |
| 219 friend class ServiceWorkerWriteToCacheJobTest; | 222 friend class ServiceWorkerWriteToCacheJobTest; |
| 223 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDiskCacheMigratorTest, |
| 224 MigrateOnDiskCacheAccess); |
| 225 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDiskCacheMigratorTest, |
| 226 NotMigrateOnDatabaseAccess); |
| 220 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, | 227 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, |
| 221 CleanupOnRendererCrash); | 228 CleanupOnRendererCrash); |
| 222 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, | 229 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, |
| 223 DeleteRegistration_NoLiveVersion); | 230 DeleteRegistration_NoLiveVersion); |
| 224 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, | 231 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, |
| 225 DeleteRegistration_WaitingVersion); | 232 DeleteRegistration_WaitingVersion); |
| 226 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, | 233 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, |
| 227 DeleteRegistration_ActiveVersion); | 234 DeleteRegistration_ActiveVersion); |
| 228 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, | 235 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, |
| 229 UpdateRegistration); | 236 UpdateRegistration); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 248 GURL origin; | 255 GURL origin; |
| 249 StatusCallback callback; | 256 StatusCallback callback; |
| 250 | 257 |
| 251 DidDeleteRegistrationParams(); | 258 DidDeleteRegistrationParams(); |
| 252 ~DidDeleteRegistrationParams(); | 259 ~DidDeleteRegistrationParams(); |
| 253 }; | 260 }; |
| 254 | 261 |
| 255 typedef std::vector<ServiceWorkerDatabase::RegistrationData> RegistrationList; | 262 typedef std::vector<ServiceWorkerDatabase::RegistrationData> RegistrationList; |
| 256 typedef std::map<int64, scoped_refptr<ServiceWorkerRegistration> > | 263 typedef std::map<int64, scoped_refptr<ServiceWorkerRegistration> > |
| 257 RegistrationRefsById; | 264 RegistrationRefsById; |
| 258 typedef base::Callback<void( | 265 typedef base::Callback<void(InitialData* data, |
| 259 InitialData* data, | 266 int64 current_disk_cache_version, |
| 260 ServiceWorkerDatabase::Status status)> InitializeCallback; | 267 const std::vector<std::string>& purgeable_files, |
| 268 ServiceWorkerDatabase::Status status)> |
| 269 InitializeCallback; |
| 261 typedef base::Callback<void( | 270 typedef base::Callback<void( |
| 262 const GURL& origin, | 271 const GURL& origin, |
| 263 const ServiceWorkerDatabase::RegistrationData& deleted_version_data, | 272 const ServiceWorkerDatabase::RegistrationData& deleted_version_data, |
| 264 const std::vector<int64>& newly_purgeable_resources, | 273 const std::vector<int64>& newly_purgeable_resources, |
| 265 ServiceWorkerDatabase::Status status)> WriteRegistrationCallback; | 274 ServiceWorkerDatabase::Status status)> WriteRegistrationCallback; |
| 266 typedef base::Callback<void( | 275 typedef base::Callback<void( |
| 267 bool origin_is_deletable, | 276 bool origin_is_deletable, |
| 268 const ServiceWorkerDatabase::RegistrationData& deleted_version_data, | 277 const ServiceWorkerDatabase::RegistrationData& deleted_version_data, |
| 269 const std::vector<int64>& newly_purgeable_resources, | 278 const std::vector<int64>& newly_purgeable_resources, |
| 270 ServiceWorkerDatabase::Status status)> DeleteRegistrationCallback; | 279 ServiceWorkerDatabase::Status status)> DeleteRegistrationCallback; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 287 const base::FilePath& path, | 296 const base::FilePath& path, |
| 288 base::WeakPtr<ServiceWorkerContextCore> context, | 297 base::WeakPtr<ServiceWorkerContextCore> context, |
| 289 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager, | 298 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager, |
| 290 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, | 299 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, |
| 291 storage::QuotaManagerProxy* quota_manager_proxy, | 300 storage::QuotaManagerProxy* quota_manager_proxy, |
| 292 storage::SpecialStoragePolicy* special_storage_policy); | 301 storage::SpecialStoragePolicy* special_storage_policy); |
| 293 | 302 |
| 294 base::FilePath GetDatabasePath(); | 303 base::FilePath GetDatabasePath(); |
| 295 base::FilePath GetDiskCachePath(); | 304 base::FilePath GetDiskCachePath(); |
| 296 | 305 |
| 297 // Loads the registration data from backend storage. This must be called | 306 // Returns a path to an old diskcache backed with BlockFile. This is used for |
| 298 // before any method that requires registration data. | 307 // the diskcache migration (see service_worker_disk_cache_migrator.h). |
| 308 // TODO(nhiroki): Remove this after several milestones pass |
| 309 // (http://crbug.com/487482) |
| 310 base::FilePath GetOldDiskCachePath(); |
| 311 |
| 299 bool LazyInitialize( | 312 bool LazyInitialize( |
| 300 const base::Closure& callback); | 313 const base::Closure& callback); |
| 301 void DidReadInitialData( | 314 void DidReadInitialData(InitialData* data, |
| 302 InitialData* data, | 315 int64 current_disk_cache_version, |
| 303 ServiceWorkerDatabase::Status status); | 316 const std::vector<std::string>& purgeable_files, |
| 317 ServiceWorkerDatabase::Status status); |
| 304 void DidFindRegistrationForDocument( | 318 void DidFindRegistrationForDocument( |
| 305 const GURL& document_url, | 319 const GURL& document_url, |
| 306 const FindRegistrationCallback& callback, | 320 const FindRegistrationCallback& callback, |
| 307 int64 callback_id, | 321 int64 callback_id, |
| 308 const ServiceWorkerDatabase::RegistrationData& data, | 322 const ServiceWorkerDatabase::RegistrationData& data, |
| 309 const ResourceList& resources, | 323 const ResourceList& resources, |
| 310 ServiceWorkerDatabase::Status status); | 324 ServiceWorkerDatabase::Status status); |
| 311 void DidFindRegistrationForPattern( | 325 void DidFindRegistrationForPattern( |
| 312 const GURL& scope, | 326 const GURL& scope, |
| 313 const FindRegistrationCallback& callback, | 327 const FindRegistrationCallback& callback, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 const StatusCallback& callback, | 365 const StatusCallback& callback, |
| 352 ServiceWorkerDatabase::Status status); | 366 ServiceWorkerDatabase::Status status); |
| 353 void DidGetUserDataForAllRegistrations( | 367 void DidGetUserDataForAllRegistrations( |
| 354 const GetUserDataForAllRegistrationsCallback& callback, | 368 const GetUserDataForAllRegistrationsCallback& callback, |
| 355 const std::vector<std::pair<int64, std::string>>& user_data, | 369 const std::vector<std::pair<int64, std::string>>& user_data, |
| 356 ServiceWorkerDatabase::Status status); | 370 ServiceWorkerDatabase::Status status); |
| 357 void ReturnFoundRegistration( | 371 void ReturnFoundRegistration( |
| 358 const FindRegistrationCallback& callback, | 372 const FindRegistrationCallback& callback, |
| 359 const ServiceWorkerDatabase::RegistrationData& data, | 373 const ServiceWorkerDatabase::RegistrationData& data, |
| 360 const ResourceList& resources); | 374 const ResourceList& resources); |
| 375 void DidWriteDatabase(ServiceWorkerDatabase::Status status); |
| 361 | 376 |
| 362 scoped_refptr<ServiceWorkerRegistration> GetOrCreateRegistration( | 377 scoped_refptr<ServiceWorkerRegistration> GetOrCreateRegistration( |
| 363 const ServiceWorkerDatabase::RegistrationData& data, | 378 const ServiceWorkerDatabase::RegistrationData& data, |
| 364 const ResourceList& resources); | 379 const ResourceList& resources); |
| 365 ServiceWorkerRegistration* FindInstallingRegistrationForDocument( | 380 ServiceWorkerRegistration* FindInstallingRegistrationForDocument( |
| 366 const GURL& document_url); | 381 const GURL& document_url); |
| 367 ServiceWorkerRegistration* FindInstallingRegistrationForPattern( | 382 ServiceWorkerRegistration* FindInstallingRegistrationForPattern( |
| 368 const GURL& scope); | 383 const GURL& scope); |
| 369 ServiceWorkerRegistration* FindInstallingRegistrationForId( | 384 ServiceWorkerRegistration* FindInstallingRegistrationForId( |
| 370 int64 registration_id); | 385 int64 registration_id); |
| 371 | 386 |
| 372 // Lazy disk_cache getter. | 387 // Lazy disk_cache getter. |
| 373 ServiceWorkerDiskCache* disk_cache(); | 388 ServiceWorkerDiskCache* disk_cache(); |
| 389 void MigrateDiskCache(); |
| 390 void DidMigrateDiskCache(ServiceWorkerStatusCode status); |
| 391 void DidPurgeFile(bool deleted); |
| 392 void InitializeDiskCache(); |
| 374 void OnDiskCacheInitialized(int rv); | 393 void OnDiskCacheInitialized(int rv); |
| 375 | 394 |
| 376 void StartPurgingResources(const std::vector<int64>& ids); | 395 void StartPurgingResources(const std::vector<int64>& ids); |
| 377 void StartPurgingResources(const ResourceList& resources); | 396 void StartPurgingResources(const ResourceList& resources); |
| 378 void ContinuePurgingResources(); | 397 void ContinuePurgingResources(); |
| 379 void PurgeResource(int64 id); | 398 void PurgeResource(int64 id); |
| 380 void OnResourcePurged(int64 id, int rv); | 399 void OnResourcePurged(int64 id, int rv); |
| 381 | 400 |
| 382 // Deletes purgeable and uncommitted resources left over from the previous | 401 // Deletes purgeable and uncommitted resources left over from the previous |
| 383 // browser session. This must be called once per session before any database | 402 // browser session. This must be called once per session before any database |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 base::FilePath path_; | 497 base::FilePath path_; |
| 479 base::WeakPtr<ServiceWorkerContextCore> context_; | 498 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 480 | 499 |
| 481 // Only accessed using |database_task_manager_|. | 500 // Only accessed using |database_task_manager_|. |
| 482 scoped_ptr<ServiceWorkerDatabase> database_; | 501 scoped_ptr<ServiceWorkerDatabase> database_; |
| 483 | 502 |
| 484 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager_; | 503 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager_; |
| 485 scoped_refptr<base::SingleThreadTaskRunner> disk_cache_thread_; | 504 scoped_refptr<base::SingleThreadTaskRunner> disk_cache_thread_; |
| 486 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; | 505 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; |
| 487 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_; | 506 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_; |
| 507 |
| 488 scoped_ptr<ServiceWorkerDiskCache> disk_cache_; | 508 scoped_ptr<ServiceWorkerDiskCache> disk_cache_; |
| 509 scoped_ptr<ServiceWorkerDiskCacheMigrator> disk_cache_migrator_; |
| 510 int64 current_disk_cache_version_; |
| 511 |
| 489 std::deque<int64> purgeable_resource_ids_; | 512 std::deque<int64> purgeable_resource_ids_; |
| 490 bool is_purge_pending_; | 513 bool is_purge_pending_; |
| 491 bool has_checked_for_stale_resources_; | 514 bool has_checked_for_stale_resources_; |
| 492 std::set<int64> pending_deletions_; | 515 std::set<int64> pending_deletions_; |
| 493 | 516 |
| 494 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_; | 517 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_; |
| 495 | 518 |
| 496 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); | 519 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); |
| 497 }; | 520 }; |
| 498 | 521 |
| 499 } // namespace content | 522 } // namespace content |
| 500 | 523 |
| 501 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ | 524 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ |
| OLD | NEW |