| Index: content/browser/service_worker/service_worker_storage.h
|
| diff --git a/content/browser/service_worker/service_worker_storage.h b/content/browser/service_worker/service_worker_storage.h
|
| index d815bf8cdf6b298498b343c6eb980f18fe3d8f8b..27c3d976d0e149c1af1053e62b07bfe1fa54a2aa 100644
|
| --- a/content/browser/service_worker/service_worker_storage.h
|
| +++ b/content/browser/service_worker/service_worker_storage.h
|
| @@ -5,6 +5,7 @@
|
| #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_
|
| #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_
|
|
|
| +#include <deque>
|
| #include <map>
|
| #include <set>
|
| #include <vector>
|
| @@ -53,16 +54,6 @@ class CONTENT_EXPORT ServiceWorkerStorage {
|
| void(ServiceWorkerStatusCode status, int result)>
|
| CompareCallback;
|
|
|
| - struct InitialData {
|
| - int64 next_registration_id;
|
| - int64 next_version_id;
|
| - int64 next_resource_id;
|
| - std::set<GURL> origins;
|
| -
|
| - InitialData();
|
| - ~InitialData();
|
| - };
|
| -
|
| ServiceWorkerStorage(const base::FilePath& path,
|
| base::WeakPtr<ServiceWorkerContextCore> context,
|
| base::SequencedTaskRunner* database_task_runner,
|
| @@ -130,37 +121,72 @@ class CONTENT_EXPORT ServiceWorkerStorage {
|
|
|
| private:
|
| friend class ServiceWorkerStorageTest;
|
| + FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStorageTest,
|
| + ResourceIdsAreStoredAndPurged);
|
| +
|
| + struct InitialData {
|
| + int64 next_registration_id;
|
| + int64 next_version_id;
|
| + int64 next_resource_id;
|
| + std::set<GURL> origins;
|
| +
|
| + InitialData();
|
| + ~InitialData();
|
| + };
|
|
|
| typedef std::vector<ServiceWorkerDatabase::RegistrationData> RegistrationList;
|
| typedef std::vector<ServiceWorkerDatabase::ResourceRecord> ResourceList;
|
| + typedef std::map<int64, scoped_refptr<ServiceWorkerRegistration> >
|
| + RegistrationRefsById;
|
| + typedef base::Callback<void(
|
| + InitialData* data,
|
| + ServiceWorkerDatabase::Status status)> InitializeCallback;
|
| + typedef base::Callback<void(
|
| + const GURL& origin,
|
| + const std::vector<int64>& newly_purgeable_resources,
|
| + ServiceWorkerDatabase::Status status)> WriteRegistrationCallback;
|
| + typedef base::Callback<void(
|
| + bool origin_is_deletable,
|
| + const std::vector<int64>& newly_purgeable_resources,
|
| + ServiceWorkerDatabase::Status status)> DeleteRegistrationCallback;
|
| + typedef base::Callback<void(
|
| + const ServiceWorkerDatabase::RegistrationData& data,
|
| + const ResourceList& resources,
|
| + ServiceWorkerDatabase::Status status)> FindInDBCallback;
|
| +
|
| + base::FilePath GetDatabasePath();
|
| + base::FilePath GetDiskCachePath();
|
|
|
| bool LazyInitialize(
|
| const base::Closure& callback);
|
| void DidReadInitialData(
|
| InitialData* data,
|
| ServiceWorkerDatabase::Status status);
|
| - void DidGetRegistrationsForPattern(
|
| - const GURL& scope,
|
| + void DidFindRegistrationForDocument(
|
| + const GURL& document_url,
|
| const FindRegistrationCallback& callback,
|
| - RegistrationList* registrations,
|
| + const ServiceWorkerDatabase::RegistrationData& data,
|
| + const ResourceList& resources,
|
| ServiceWorkerDatabase::Status status);
|
| - void DidGetRegistrationsForDocument(
|
| + void DidFindRegistrationForPattern(
|
| const GURL& scope,
|
| const FindRegistrationCallback& callback,
|
| - RegistrationList* registrations,
|
| + const ServiceWorkerDatabase::RegistrationData& data,
|
| + const ResourceList& resources,
|
| ServiceWorkerDatabase::Status status);
|
| - void DidReadRegistrationForId(
|
| + void DidFindRegistrationForId(
|
| const FindRegistrationCallback& callback,
|
| - ServiceWorkerDatabase::RegistrationData* registration,
|
| - ResourceList* resources,
|
| + const ServiceWorkerDatabase::RegistrationData& data,
|
| + const ResourceList& resources,
|
| ServiceWorkerDatabase::Status status);
|
| void DidGetAllRegistrations(
|
| const GetAllRegistrationInfosCallback& callback,
|
| RegistrationList* registrations,
|
| ServiceWorkerDatabase::Status status);
|
| void DidStoreRegistration(
|
| - const GURL& origin,
|
| const StatusCallback& callback,
|
| + const GURL& origin,
|
| + const std::vector<int64>& newly_purgeable_resources,
|
| ServiceWorkerDatabase::Status status);
|
| void DidUpdateToActiveState(
|
| const StatusCallback& callback,
|
| @@ -169,10 +195,12 @@ class CONTENT_EXPORT ServiceWorkerStorage {
|
| const GURL& origin,
|
| const StatusCallback& callback,
|
| bool origin_is_deletable,
|
| + const std::vector<int64>& newly_purgeable_resources,
|
| ServiceWorkerDatabase::Status status);
|
|
|
| - scoped_refptr<ServiceWorkerRegistration> CreateRegistration(
|
| - const ServiceWorkerDatabase::RegistrationData& data);
|
| + scoped_refptr<ServiceWorkerRegistration> GetOrCreateRegistration(
|
| + const ServiceWorkerDatabase::RegistrationData& data,
|
| + const ResourceList& resources);
|
| ServiceWorkerRegistration* FindInstallingRegistrationForDocument(
|
| const GURL& document_url);
|
| ServiceWorkerRegistration* FindInstallingRegistrationForPattern(
|
| @@ -180,13 +208,50 @@ class CONTENT_EXPORT ServiceWorkerStorage {
|
| ServiceWorkerRegistration* FindInstallingRegistrationForId(
|
| int64 registration_id);
|
|
|
| - // For finding registrations being installed.
|
| - typedef std::map<int64, scoped_refptr<ServiceWorkerRegistration> >
|
| - RegistrationRefsById;
|
| - RegistrationRefsById installing_registrations_;
|
| -
|
| // Lazy disk_cache getter.
|
| ServiceWorkerDiskCache* disk_cache();
|
| + void OnDiskCacheInitialized(int rv);
|
| +
|
| + void StartPurgingResources(const std::vector<int64>& ids);
|
| + void PurgeResource(int64 id);
|
| + void OnResourcePurged(int64 id, int rv);
|
| +
|
| + // Static cross-thread helpers.
|
| + static void ReadInitialDataFromDB(
|
| + ServiceWorkerDatabase* database,
|
| + scoped_refptr<base::SequencedTaskRunner> original_task_runner,
|
| + const InitializeCallback& callback);
|
| + static void DeleteRegistrationFromDB(
|
| + ServiceWorkerDatabase* database,
|
| + scoped_refptr<base::SequencedTaskRunner> original_task_runner,
|
| + int64 registration_id,
|
| + const GURL& origin,
|
| + const DeleteRegistrationCallback& callback);
|
| + static void WriteRegistrationInDB(
|
| + ServiceWorkerDatabase* database,
|
| + scoped_refptr<base::SequencedTaskRunner> original_task_runner,
|
| + const ServiceWorkerDatabase::RegistrationData& registration,
|
| + const ResourceList& resources,
|
| + const WriteRegistrationCallback& callback);
|
| + static void FindForDocumentInDB(
|
| + ServiceWorkerDatabase* database,
|
| + scoped_refptr<base::SequencedTaskRunner> original_task_runner,
|
| + const GURL& document_url,
|
| + const FindInDBCallback& callback);
|
| + static void FindForPatternInDB(
|
| + ServiceWorkerDatabase* database,
|
| + scoped_refptr<base::SequencedTaskRunner> original_task_runner,
|
| + const GURL& scope,
|
| + const FindInDBCallback& callback);
|
| + static void FindForIdInDB(
|
| + ServiceWorkerDatabase* database,
|
| + scoped_refptr<base::SequencedTaskRunner> original_task_runner,
|
| + int64 registration_id,
|
| + const GURL& origin,
|
| + const FindInDBCallback& callback);
|
| +
|
| + // For finding registrations being installed.
|
| + RegistrationRefsById installing_registrations_;
|
|
|
| // Origins having registations.
|
| std::set<GURL> registered_origins_;
|
| @@ -216,6 +281,8 @@ class CONTENT_EXPORT ServiceWorkerStorage {
|
| scoped_refptr<base::MessageLoopProxy> disk_cache_thread_;
|
| scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_;
|
| scoped_ptr<ServiceWorkerDiskCache> disk_cache_;
|
| + std::deque<int64> purgeable_reource_ids_;
|
| + bool is_purge_pending_;
|
|
|
| base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_;
|
|
|
|
|