| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 const FindRegistrationCallback& callback); | 85 const FindRegistrationCallback& callback); |
| 86 void FindRegistrationForId(int64 registration_id, | 86 void FindRegistrationForId(int64 registration_id, |
| 87 const GURL& origin, | 87 const GURL& origin, |
| 88 const FindRegistrationCallback& callback); | 88 const FindRegistrationCallback& callback); |
| 89 | 89 |
| 90 // Returns info about all stored and initially installing registrations. | 90 // Returns info about all stored and initially installing registrations. |
| 91 void GetAllRegistrations(const GetAllRegistrationInfosCallback& callback); | 91 void GetAllRegistrations(const GetAllRegistrationInfosCallback& callback); |
| 92 | 92 |
| 93 // Commits |registration| with the installed but not activated |version| | 93 // Commits |registration| with the installed but not activated |version| |
| 94 // to storage, overwritting any pre-existing registration data for the scope. | 94 // to storage, overwritting any pre-existing registration data for the scope. |
| 95 // A pre-existing version's script resources will remain available until | 95 // A pre-existing version's script resources remain available if that version |
| 96 // it no longer controls a page, or a browser restart occurs. | 96 // is live. PurgeResources should be called when it's OK to delete them. |
| 97 void StoreRegistration( | 97 void StoreRegistration( |
| 98 ServiceWorkerRegistration* registration, | 98 ServiceWorkerRegistration* registration, |
| 99 ServiceWorkerVersion* version, | 99 ServiceWorkerVersion* version, |
| 100 const StatusCallback& callback); | 100 const StatusCallback& callback); |
| 101 | 101 |
| 102 // Updates the state of the registration's stored version to active. | 102 // Updates the state of the registration's stored version to active. |
| 103 void UpdateToActiveState( | 103 void UpdateToActiveState( |
| 104 ServiceWorkerRegistration* registration, | 104 ServiceWorkerRegistration* registration, |
| 105 const StatusCallback& callback); | 105 const StatusCallback& callback); |
| 106 | 106 |
| 107 // Deletes the registration data for |registration_id|. The script resources | 107 // Deletes the registration data for |registration_id|. If the registration's |
| 108 // for the registration's stored version will remain available until that | 108 // version is live, its script resources will remain available. |
| 109 // version no longer controls a page, or a browser restart occurs. | 109 // PurgeResources should be called when it's OK to delete them. |
| 110 void DeleteRegistration(int64 registration_id, | 110 void DeleteRegistration(int64 registration_id, |
| 111 const GURL& origin, | 111 const GURL& origin, |
| 112 const StatusCallback& callback); | 112 const StatusCallback& callback); |
| 113 | 113 |
| 114 scoped_ptr<ServiceWorkerResponseReader> CreateResponseReader( | 114 scoped_ptr<ServiceWorkerResponseReader> CreateResponseReader( |
| 115 int64 response_id); | 115 int64 response_id); |
| 116 scoped_ptr<ServiceWorkerResponseWriter> CreateResponseWriter( | 116 scoped_ptr<ServiceWorkerResponseWriter> CreateResponseWriter( |
| 117 int64 response_id); | 117 int64 response_id); |
| 118 | 118 |
| 119 // Adds |id| to the set of resources ids that are in the disk | 119 // Adds |id| to the set of resources ids that are in the disk |
| (...skipping 16 matching lines...) Expand all Loading... |
| 136 void NotifyInstallingRegistration( | 136 void NotifyInstallingRegistration( |
| 137 ServiceWorkerRegistration* registration); | 137 ServiceWorkerRegistration* registration); |
| 138 void NotifyDoneInstallingRegistration( | 138 void NotifyDoneInstallingRegistration( |
| 139 ServiceWorkerRegistration* registration, | 139 ServiceWorkerRegistration* registration, |
| 140 ServiceWorkerVersion* version, | 140 ServiceWorkerVersion* version, |
| 141 ServiceWorkerStatusCode status); | 141 ServiceWorkerStatusCode status); |
| 142 | 142 |
| 143 void Disable(); | 143 void Disable(); |
| 144 bool IsDisabled() const; | 144 bool IsDisabled() const; |
| 145 | 145 |
| 146 // |resources| must already be on the purgeable list. |
| 147 void PurgeResources(const ResourceList& resources); |
| 148 |
| 146 private: | 149 private: |
| 147 friend class ServiceWorkerResourceStorageTest; | 150 friend class ServiceWorkerResourceStorageTest; |
| 148 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, | 151 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, |
| 152 DeleteRegistration_NoLiveVersion); |
| 153 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, |
| 149 DeleteRegistration_WaitingVersion); | 154 DeleteRegistration_WaitingVersion); |
| 150 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, | 155 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, |
| 151 DeleteRegistration_ActiveVersion); | 156 DeleteRegistration_ActiveVersion); |
| 152 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, | 157 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, |
| 153 UpdateRegistration); | 158 UpdateRegistration); |
| 154 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageDiskTest, | 159 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageDiskTest, |
| 155 CleanupOnRestart); | 160 CleanupOnRestart); |
| 156 | 161 |
| 157 struct InitialData { | 162 struct InitialData { |
| 158 int64 next_registration_id; | 163 int64 next_registration_id; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 const GURL& document_url); | 251 const GURL& document_url); |
| 247 ServiceWorkerRegistration* FindInstallingRegistrationForPattern( | 252 ServiceWorkerRegistration* FindInstallingRegistrationForPattern( |
| 248 const GURL& scope); | 253 const GURL& scope); |
| 249 ServiceWorkerRegistration* FindInstallingRegistrationForId( | 254 ServiceWorkerRegistration* FindInstallingRegistrationForId( |
| 250 int64 registration_id); | 255 int64 registration_id); |
| 251 | 256 |
| 252 // Lazy disk_cache getter. | 257 // Lazy disk_cache getter. |
| 253 ServiceWorkerDiskCache* disk_cache(); | 258 ServiceWorkerDiskCache* disk_cache(); |
| 254 void OnDiskCacheInitialized(int rv); | 259 void OnDiskCacheInitialized(int rv); |
| 255 | 260 |
| 256 // ServiceWorkerVersion::Listener override | |
| 257 virtual void OnNoControllees(ServiceWorkerVersion* version) OVERRIDE; | |
| 258 | |
| 259 void SchedulePurgeResources(int64 version_id, | |
| 260 const std::vector<int64>& resources); | |
| 261 void StartPurgingResources(const std::vector<int64>& ids); | 261 void StartPurgingResources(const std::vector<int64>& ids); |
| 262 void StartPurgingResources(const ResourceList& resources); | 262 void StartPurgingResources(const ResourceList& resources); |
| 263 void ContinuePurgingResources(); | 263 void ContinuePurgingResources(); |
| 264 void PurgeResource(int64 id); | 264 void PurgeResource(int64 id); |
| 265 void OnResourcePurged(int64 id, int rv); | 265 void OnResourcePurged(int64 id, int rv); |
| 266 | 266 |
| 267 // Deletes purgeable and uncommitted resources left over from the previous | 267 // Deletes purgeable and uncommitted resources left over from the previous |
| 268 // browser session. This must be called once per session before any database | 268 // browser session. This must be called once per session before any database |
| 269 // operation that may mutate the purgeable or uncommitted resource lists. | 269 // operation that may mutate the purgeable or uncommitted resource lists. |
| 270 void DeleteStaleResources(); | 270 void DeleteStaleResources(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 // Only accessed on |database_task_runner_|. | 344 // Only accessed on |database_task_runner_|. |
| 345 scoped_ptr<ServiceWorkerDatabase> database_; | 345 scoped_ptr<ServiceWorkerDatabase> database_; |
| 346 | 346 |
| 347 scoped_refptr<base::SequencedTaskRunner> database_task_runner_; | 347 scoped_refptr<base::SequencedTaskRunner> database_task_runner_; |
| 348 scoped_refptr<base::MessageLoopProxy> disk_cache_thread_; | 348 scoped_refptr<base::MessageLoopProxy> disk_cache_thread_; |
| 349 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; | 349 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; |
| 350 scoped_ptr<ServiceWorkerDiskCache> disk_cache_; | 350 scoped_ptr<ServiceWorkerDiskCache> disk_cache_; |
| 351 std::deque<int64> purgeable_resource_ids_; | 351 std::deque<int64> purgeable_resource_ids_; |
| 352 bool is_purge_pending_; | 352 bool is_purge_pending_; |
| 353 bool has_checked_for_stale_resources_; | 353 bool has_checked_for_stale_resources_; |
| 354 std::map<int64, std::vector<int64> > deleted_version_resource_ids_; | |
| 355 | 354 |
| 356 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_; | 355 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_; |
| 357 | 356 |
| 358 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); | 357 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); |
| 359 }; | 358 }; |
| 360 | 359 |
| 361 } // namespace content | 360 } // namespace content |
| 362 | 361 |
| 363 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ | 362 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ |
| OLD | NEW |