| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 120 // cache but not yet stored with a registration. | 120 // cache but not yet stored with a registration. |
| 121 void StoreUncommittedReponseId(int64 id); | 121 void StoreUncommittedResponseId(int64 id); |
| 122 | 122 |
| 123 // Removes |id| from uncommitted list, adds it to the | 123 // Removes |id| from uncommitted list, adds it to the |
| 124 // purgeable list and purges it. | 124 // purgeable list and purges it. |
| 125 void DoomUncommittedResponse(int64 id); | 125 void DoomUncommittedResponse(int64 id); |
| 126 | 126 |
| 127 // Deletes the storage and starts over. | 127 // Deletes the storage and starts over. |
| 128 void DeleteAndStartOver(const StatusCallback& callback); | 128 void DeleteAndStartOver(const StatusCallback& callback); |
| 129 | 129 |
| 130 // Returns new IDs which are guaranteed to be unique in the storage. | 130 // Returns new IDs which are guaranteed to be unique in the storage. |
| 131 int64 NewRegistrationId(); | 131 int64 NewRegistrationId(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 152 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, | 152 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, |
| 153 UpdateRegistration); | 153 UpdateRegistration); |
| 154 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageDiskTest, | 154 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageDiskTest, |
| 155 CleanupOnRestart); | 155 CleanupOnRestart); |
| 156 | 156 |
| 157 struct InitialData { | 157 struct InitialData { |
| 158 int64 next_registration_id; | 158 int64 next_registration_id; |
| 159 int64 next_version_id; | 159 int64 next_version_id; |
| 160 int64 next_resource_id; | 160 int64 next_resource_id; |
| 161 std::set<GURL> origins; | 161 std::set<GURL> origins; |
| 162 std::set<int64> purgeable_resource_ids; | |
| 163 | 162 |
| 164 InitialData(); | 163 InitialData(); |
| 165 ~InitialData(); | 164 ~InitialData(); |
| 166 }; | 165 }; |
| 167 | 166 |
| 168 typedef std::vector<ServiceWorkerDatabase::RegistrationData> RegistrationList; | 167 typedef std::vector<ServiceWorkerDatabase::RegistrationData> RegistrationList; |
| 169 typedef std::map<int64, scoped_refptr<ServiceWorkerRegistration> > | 168 typedef std::map<int64, scoped_refptr<ServiceWorkerRegistration> > |
| 170 RegistrationRefsById; | 169 RegistrationRefsById; |
| 171 typedef base::Callback<void( | 170 typedef base::Callback<void( |
| 172 InitialData* data, | 171 InitialData* data, |
| 173 ServiceWorkerDatabase::Status status)> InitializeCallback; | 172 ServiceWorkerDatabase::Status status)> InitializeCallback; |
| 174 typedef base::Callback< | 173 typedef base::Callback< |
| 175 void(const GURL& origin, | 174 void(const GURL& origin, |
| 176 int64 deleted_version_id, | 175 int64 deleted_version_id, |
| 177 const std::vector<int64>& newly_purgeable_resources, | 176 const std::vector<int64>& newly_purgeable_resources, |
| 178 ServiceWorkerDatabase::Status status)> WriteRegistrationCallback; | 177 ServiceWorkerDatabase::Status status)> WriteRegistrationCallback; |
| 179 typedef base::Callback< | 178 typedef base::Callback< |
| 180 void(bool origin_is_deletable, | 179 void(bool origin_is_deletable, |
| 181 int64 version_id, | 180 int64 version_id, |
| 182 const std::vector<int64>& newly_purgeable_resources, | 181 const std::vector<int64>& newly_purgeable_resources, |
| 183 ServiceWorkerDatabase::Status status)> DeleteRegistrationCallback; | 182 ServiceWorkerDatabase::Status status)> DeleteRegistrationCallback; |
| 184 typedef base::Callback<void( | 183 typedef base::Callback<void( |
| 185 const ServiceWorkerDatabase::RegistrationData& data, | 184 const ServiceWorkerDatabase::RegistrationData& data, |
| 186 const ResourceList& resources, | 185 const ResourceList& resources, |
| 187 ServiceWorkerDatabase::Status status)> FindInDBCallback; | 186 ServiceWorkerDatabase::Status status)> FindInDBCallback; |
| 187 typedef base::Callback<void(const std::vector<int64>& resource_ids, |
| 188 ServiceWorkerDatabase::Status status)> |
| 189 GetResourcesCallback; |
| 188 | 190 |
| 189 ServiceWorkerStorage(const base::FilePath& path, | 191 ServiceWorkerStorage(const base::FilePath& path, |
| 190 base::WeakPtr<ServiceWorkerContextCore> context, | 192 base::WeakPtr<ServiceWorkerContextCore> context, |
| 191 base::SequencedTaskRunner* database_task_runner, | 193 base::SequencedTaskRunner* database_task_runner, |
| 192 base::MessageLoopProxy* disk_cache_thread, | 194 base::MessageLoopProxy* disk_cache_thread, |
| 193 quota::QuotaManagerProxy* quota_manager_proxy); | 195 quota::QuotaManagerProxy* quota_manager_proxy); |
| 194 | 196 |
| 195 base::FilePath GetDatabasePath(); | 197 base::FilePath GetDatabasePath(); |
| 196 base::FilePath GetDiskCachePath(); | 198 base::FilePath GetDiskCachePath(); |
| 197 | 199 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 virtual void OnNoControllees(ServiceWorkerVersion* version) OVERRIDE; | 257 virtual void OnNoControllees(ServiceWorkerVersion* version) OVERRIDE; |
| 256 | 258 |
| 257 void SchedulePurgeResources(int64 version_id, | 259 void SchedulePurgeResources(int64 version_id, |
| 258 const std::vector<int64>& resources); | 260 const std::vector<int64>& resources); |
| 259 void StartPurgingResources(const std::vector<int64>& ids); | 261 void StartPurgingResources(const std::vector<int64>& ids); |
| 260 void StartPurgingResources(const ResourceList& resources); | 262 void StartPurgingResources(const ResourceList& resources); |
| 261 void ContinuePurgingResources(); | 263 void ContinuePurgingResources(); |
| 262 void PurgeResource(int64 id); | 264 void PurgeResource(int64 id); |
| 263 void OnResourcePurged(int64 id, int rv); | 265 void OnResourcePurged(int64 id, int rv); |
| 264 | 266 |
| 267 // Deletes purgeable and uncommitted resources left over from the previous |
| 268 // browser session. This must be called once per session before any database |
| 269 // operation that may mutate the purgeable or uncommitted resource lists. |
| 270 void DeleteStaleResources(); |
| 271 void DidCollectStaleResources(const std::vector<int64>& stale_resource_ids, |
| 272 ServiceWorkerDatabase::Status status); |
| 273 |
| 265 // Static cross-thread helpers. | 274 // Static cross-thread helpers. |
| 275 static void CollectStaleResourcesFromDB( |
| 276 ServiceWorkerDatabase* database, |
| 277 scoped_refptr<base::SequencedTaskRunner> original_task_runner, |
| 278 const GetResourcesCallback& callback); |
| 266 static void ReadInitialDataFromDB( | 279 static void ReadInitialDataFromDB( |
| 267 ServiceWorkerDatabase* database, | 280 ServiceWorkerDatabase* database, |
| 268 scoped_refptr<base::SequencedTaskRunner> original_task_runner, | 281 scoped_refptr<base::SequencedTaskRunner> original_task_runner, |
| 269 const InitializeCallback& callback); | 282 const InitializeCallback& callback); |
| 270 static void DeleteRegistrationFromDB( | 283 static void DeleteRegistrationFromDB( |
| 271 ServiceWorkerDatabase* database, | 284 ServiceWorkerDatabase* database, |
| 272 scoped_refptr<base::SequencedTaskRunner> original_task_runner, | 285 scoped_refptr<base::SequencedTaskRunner> original_task_runner, |
| 273 int64 registration_id, | 286 int64 registration_id, |
| 274 const GURL& origin, | 287 const GURL& origin, |
| 275 const DeleteRegistrationCallback& callback); | 288 const DeleteRegistrationCallback& callback); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 | 343 |
| 331 // Only accessed on |database_task_runner_|. | 344 // Only accessed on |database_task_runner_|. |
| 332 scoped_ptr<ServiceWorkerDatabase> database_; | 345 scoped_ptr<ServiceWorkerDatabase> database_; |
| 333 | 346 |
| 334 scoped_refptr<base::SequencedTaskRunner> database_task_runner_; | 347 scoped_refptr<base::SequencedTaskRunner> database_task_runner_; |
| 335 scoped_refptr<base::MessageLoopProxy> disk_cache_thread_; | 348 scoped_refptr<base::MessageLoopProxy> disk_cache_thread_; |
| 336 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; | 349 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; |
| 337 scoped_ptr<ServiceWorkerDiskCache> disk_cache_; | 350 scoped_ptr<ServiceWorkerDiskCache> disk_cache_; |
| 338 std::deque<int64> purgeable_resource_ids_; | 351 std::deque<int64> purgeable_resource_ids_; |
| 339 bool is_purge_pending_; | 352 bool is_purge_pending_; |
| 353 bool has_checked_for_stale_resources_; |
| 340 std::map<int64, std::vector<int64> > deleted_version_resource_ids_; | 354 std::map<int64, std::vector<int64> > deleted_version_resource_ids_; |
| 341 | 355 |
| 342 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_; | 356 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_; |
| 343 | 357 |
| 344 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); | 358 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); |
| 345 }; | 359 }; |
| 346 | 360 |
| 347 } // namespace content | 361 } // namespace content |
| 348 | 362 |
| 349 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ | 363 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ |
| OLD | NEW |