Chromium Code Reviews| 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 |
| 200 bool IsReady(); | |
| 201 | |
| 198 bool LazyInitialize( | 202 bool LazyInitialize( |
| 199 const base::Closure& callback); | 203 const base::Closure& callback); |
| 200 void DidReadInitialData( | 204 void DidReadInitialData( |
| 201 InitialData* data, | 205 InitialData* data, |
| 202 ServiceWorkerDatabase::Status status); | 206 ServiceWorkerDatabase::Status status); |
| 203 void DidFindRegistrationForDocument( | 207 void DidFindRegistrationForDocument( |
| 204 const GURL& document_url, | 208 const GURL& document_url, |
| 205 const FindRegistrationCallback& callback, | 209 const FindRegistrationCallback& callback, |
| 206 const ServiceWorkerDatabase::RegistrationData& data, | 210 const ServiceWorkerDatabase::RegistrationData& data, |
| 207 const ResourceList& resources, | 211 const ResourceList& resources, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 virtual void OnNoControllees(ServiceWorkerVersion* version) OVERRIDE; | 259 virtual void OnNoControllees(ServiceWorkerVersion* version) OVERRIDE; |
| 256 | 260 |
| 257 void SchedulePurgeResources(int64 version_id, | 261 void SchedulePurgeResources(int64 version_id, |
| 258 const std::vector<int64>& resources); | 262 const std::vector<int64>& resources); |
| 259 void StartPurgingResources(const std::vector<int64>& ids); | 263 void StartPurgingResources(const std::vector<int64>& ids); |
| 260 void StartPurgingResources(const ResourceList& resources); | 264 void StartPurgingResources(const ResourceList& resources); |
| 261 void ContinuePurgingResources(); | 265 void ContinuePurgingResources(); |
| 262 void PurgeResource(int64 id); | 266 void PurgeResource(int64 id); |
| 263 void OnResourcePurged(int64 id, int rv); | 267 void OnResourcePurged(int64 id, int rv); |
| 264 | 268 |
| 269 // Deletes purgeable and uncommitted resources left over from the previous | |
| 270 // browser session. This must be called once per session before any database | |
| 271 // operation that may mutate the purgeable or uncommitted resource lists. | |
| 272 void DeleteStaleResources(); | |
| 273 void DidCollectStaleResources(const std::vector<int64>& stale_resource_ids, | |
| 274 ServiceWorkerDatabase::Status status); | |
| 275 | |
| 265 // Static cross-thread helpers. | 276 // Static cross-thread helpers. |
| 277 static void CollectStaleResourcesFromDB( | |
| 278 ServiceWorkerDatabase* database, | |
| 279 scoped_refptr<base::SequencedTaskRunner> original_task_runner, | |
| 280 const GetResourcesCallback& callback); | |
| 266 static void ReadInitialDataFromDB( | 281 static void ReadInitialDataFromDB( |
| 267 ServiceWorkerDatabase* database, | 282 ServiceWorkerDatabase* database, |
| 268 scoped_refptr<base::SequencedTaskRunner> original_task_runner, | 283 scoped_refptr<base::SequencedTaskRunner> original_task_runner, |
| 269 const InitializeCallback& callback); | 284 const InitializeCallback& callback); |
| 270 static void DeleteRegistrationFromDB( | 285 static void DeleteRegistrationFromDB( |
| 271 ServiceWorkerDatabase* database, | 286 ServiceWorkerDatabase* database, |
| 272 scoped_refptr<base::SequencedTaskRunner> original_task_runner, | 287 scoped_refptr<base::SequencedTaskRunner> original_task_runner, |
| 273 int64 registration_id, | 288 int64 registration_id, |
| 274 const GURL& origin, | 289 const GURL& origin, |
| 275 const DeleteRegistrationCallback& callback); | 290 const DeleteRegistrationCallback& callback); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 // Pending database tasks waiting for initialization. | 328 // Pending database tasks waiting for initialization. |
| 314 std::vector<base::Closure> pending_tasks_; | 329 std::vector<base::Closure> pending_tasks_; |
| 315 | 330 |
| 316 int64 next_registration_id_; | 331 int64 next_registration_id_; |
| 317 int64 next_version_id_; | 332 int64 next_version_id_; |
| 318 int64 next_resource_id_; | 333 int64 next_resource_id_; |
| 319 | 334 |
| 320 enum State { | 335 enum State { |
| 321 UNINITIALIZED, | 336 UNINITIALIZED, |
| 322 INITIALIZING, | 337 INITIALIZING, |
| 338 HAS_STALE_RESOURCES, | |
|
michaeln
2014/07/09 02:36:11
bikesheddy...
This one is a little different then
falken
2014/07/09 04:31:14
I was a bit torn when writing this. I liked State
| |
| 323 INITIALIZED, | 339 INITIALIZED, |
| 324 DISABLED, | 340 DISABLED, |
| 325 }; | 341 }; |
| 326 State state_; | 342 State state_; |
| 327 | 343 |
| 328 base::FilePath path_; | 344 base::FilePath path_; |
| 329 base::WeakPtr<ServiceWorkerContextCore> context_; | 345 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 330 | 346 |
| 331 // Only accessed on |database_task_runner_|. | 347 // Only accessed on |database_task_runner_|. |
| 332 scoped_ptr<ServiceWorkerDatabase> database_; | 348 scoped_ptr<ServiceWorkerDatabase> database_; |
| 333 | 349 |
| 334 scoped_refptr<base::SequencedTaskRunner> database_task_runner_; | 350 scoped_refptr<base::SequencedTaskRunner> database_task_runner_; |
| 335 scoped_refptr<base::MessageLoopProxy> disk_cache_thread_; | 351 scoped_refptr<base::MessageLoopProxy> disk_cache_thread_; |
| 336 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; | 352 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; |
| 337 scoped_ptr<ServiceWorkerDiskCache> disk_cache_; | 353 scoped_ptr<ServiceWorkerDiskCache> disk_cache_; |
| 338 std::deque<int64> purgeable_resource_ids_; | 354 std::deque<int64> purgeable_resource_ids_; |
| 339 bool is_purge_pending_; | 355 bool is_purge_pending_; |
| 340 std::map<int64, std::vector<int64> > deleted_version_resource_ids_; | 356 std::map<int64, std::vector<int64> > deleted_version_resource_ids_; |
| 341 | 357 |
| 342 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_; | 358 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_; |
| 343 | 359 |
| 344 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); | 360 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); |
| 345 }; | 361 }; |
| 346 | 362 |
| 347 } // namespace content | 363 } // namespace content |
| 348 | 364 |
| 349 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ | 365 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ |
| OLD | NEW |