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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <deque> | 10 #include <deque> |
(...skipping 30 matching lines...) Expand all Loading... |
41 class ServiceWorkerContextCore; | 41 class ServiceWorkerContextCore; |
42 class ServiceWorkerDiskCache; | 42 class ServiceWorkerDiskCache; |
43 class ServiceWorkerRegistration; | 43 class ServiceWorkerRegistration; |
44 class ServiceWorkerResponseMetadataWriter; | 44 class ServiceWorkerResponseMetadataWriter; |
45 class ServiceWorkerResponseReader; | 45 class ServiceWorkerResponseReader; |
46 class ServiceWorkerResponseWriter; | 46 class ServiceWorkerResponseWriter; |
47 struct ServiceWorkerRegistrationInfo; | 47 struct ServiceWorkerRegistrationInfo; |
48 | 48 |
49 // This class provides an interface to store and retrieve ServiceWorker | 49 // This class provides an interface to store and retrieve ServiceWorker |
50 // registration data. The lifetime is equal to ServiceWorkerContextCore that is | 50 // registration data. The lifetime is equal to ServiceWorkerContextCore that is |
51 // an owner of this class. | 51 // an owner of this class. When a storage operation fails, this is marked as |
| 52 // disabled and all subsequent requests are aborted until the context core is |
| 53 // restarted. |
52 class CONTENT_EXPORT ServiceWorkerStorage | 54 class CONTENT_EXPORT ServiceWorkerStorage |
53 : NON_EXPORTED_BASE(public ServiceWorkerVersion::Listener) { | 55 : NON_EXPORTED_BASE(public ServiceWorkerVersion::Listener) { |
54 public: | 56 public: |
55 typedef std::vector<ServiceWorkerDatabase::ResourceRecord> ResourceList; | 57 typedef std::vector<ServiceWorkerDatabase::ResourceRecord> ResourceList; |
56 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback; | 58 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback; |
57 typedef base::Callback<void(ServiceWorkerStatusCode status, | 59 typedef base::Callback<void(ServiceWorkerStatusCode status, |
58 const scoped_refptr<ServiceWorkerRegistration>& | 60 const scoped_refptr<ServiceWorkerRegistration>& |
59 registration)> FindRegistrationCallback; | 61 registration)> FindRegistrationCallback; |
60 typedef base::Callback<void( | 62 typedef base::Callback<void( |
| 63 ServiceWorkerStatusCode status, |
61 const std::vector<scoped_refptr<ServiceWorkerRegistration>>& | 64 const std::vector<scoped_refptr<ServiceWorkerRegistration>>& |
62 registrations)> GetRegistrationsCallback; | 65 registrations)> |
63 typedef base::Callback<void(const std::vector<ServiceWorkerRegistrationInfo>& | 66 GetRegistrationsCallback; |
64 registrations)> GetRegistrationsInfosCallback; | 67 typedef base::Callback<void( |
| 68 ServiceWorkerStatusCode status, |
| 69 const std::vector<ServiceWorkerRegistrationInfo>& registrations)> |
| 70 GetRegistrationsInfosCallback; |
65 typedef base::Callback< | 71 typedef base::Callback< |
66 void(const std::string& data, ServiceWorkerStatusCode status)> | 72 void(const std::string& data, ServiceWorkerStatusCode status)> |
67 GetUserDataCallback; | 73 GetUserDataCallback; |
68 typedef base::Callback<void( | 74 typedef base::Callback<void( |
69 const std::vector<std::pair<int64_t, std::string>>& user_data, | 75 const std::vector<std::pair<int64_t, std::string>>& user_data, |
70 ServiceWorkerStatusCode status)> GetUserDataForAllRegistrationsCallback; | 76 ServiceWorkerStatusCode status)> GetUserDataForAllRegistrationsCallback; |
71 | 77 |
72 ~ServiceWorkerStorage() override; | 78 ~ServiceWorkerStorage() override; |
73 | 79 |
74 static scoped_ptr<ServiceWorkerStorage> Create( | 80 static scoped_ptr<ServiceWorkerStorage> Create( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 // registration->last_update_check(). | 141 // registration->last_update_check(). |
136 void UpdateLastUpdateCheckTime(ServiceWorkerRegistration* registration); | 142 void UpdateLastUpdateCheckTime(ServiceWorkerRegistration* registration); |
137 | 143 |
138 // Deletes the registration data for |registration_id|. If the registration's | 144 // Deletes the registration data for |registration_id|. If the registration's |
139 // version is live, its script resources will remain available. | 145 // version is live, its script resources will remain available. |
140 // PurgeResources should be called when it's OK to delete them. | 146 // PurgeResources should be called when it's OK to delete them. |
141 void DeleteRegistration(int64_t registration_id, | 147 void DeleteRegistration(int64_t registration_id, |
142 const GURL& origin, | 148 const GURL& origin, |
143 const StatusCallback& callback); | 149 const StatusCallback& callback); |
144 | 150 |
| 151 // Creates a resource accessor. Never returns nullptr but an accessor may be |
| 152 // associated with the disabled disk cache if the storage is disabled. |
145 scoped_ptr<ServiceWorkerResponseReader> CreateResponseReader( | 153 scoped_ptr<ServiceWorkerResponseReader> CreateResponseReader( |
146 int64_t resource_id); | 154 int64_t resource_id); |
147 scoped_ptr<ServiceWorkerResponseWriter> CreateResponseWriter( | 155 scoped_ptr<ServiceWorkerResponseWriter> CreateResponseWriter( |
148 int64_t resource_id); | 156 int64_t resource_id); |
149 scoped_ptr<ServiceWorkerResponseMetadataWriter> CreateResponseMetadataWriter( | 157 scoped_ptr<ServiceWorkerResponseMetadataWriter> CreateResponseMetadataWriter( |
150 int64_t resource_id); | 158 int64_t resource_id); |
151 | 159 |
152 // Adds |resource_id| to the set of resources that are in the disk cache | 160 // Adds |resource_id| to the set of resources that are in the disk cache |
153 // but not yet stored with a registration. | 161 // but not yet stored with a registration. |
154 void StoreUncommittedResourceId(int64_t resource_id); | 162 void StoreUncommittedResourceId(int64_t resource_id); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 ServiceWorkerRegistration* registration); | 212 ServiceWorkerRegistration* registration); |
205 void NotifyDoneInstallingRegistration( | 213 void NotifyDoneInstallingRegistration( |
206 ServiceWorkerRegistration* registration, | 214 ServiceWorkerRegistration* registration, |
207 ServiceWorkerVersion* version, | 215 ServiceWorkerVersion* version, |
208 ServiceWorkerStatusCode status); | 216 ServiceWorkerStatusCode status); |
209 void NotifyUninstallingRegistration(ServiceWorkerRegistration* registration); | 217 void NotifyUninstallingRegistration(ServiceWorkerRegistration* registration); |
210 void NotifyDoneUninstallingRegistration( | 218 void NotifyDoneUninstallingRegistration( |
211 ServiceWorkerRegistration* registration); | 219 ServiceWorkerRegistration* registration); |
212 | 220 |
213 void Disable(); | 221 void Disable(); |
214 bool IsDisabled() const; | |
215 | 222 |
216 // |resources| must already be on the purgeable list. | 223 // |resources| must already be on the purgeable list. |
217 void PurgeResources(const ResourceList& resources); | 224 void PurgeResources(const ResourceList& resources); |
218 | 225 |
219 private: | 226 private: |
220 friend class ServiceWorkerHandleTest; | 227 friend class ServiceWorkerHandleTest; |
221 friend class ServiceWorkerStorageTest; | 228 friend class ServiceWorkerStorageTest; |
222 friend class ServiceWorkerResourceStorageTest; | 229 friend class ServiceWorkerResourceStorageTest; |
223 friend class ServiceWorkerControlleeRequestHandlerTest; | 230 friend class ServiceWorkerControlleeRequestHandlerTest; |
224 friend class ServiceWorkerContextRequestHandlerTest; | 231 friend class ServiceWorkerContextRequestHandlerTest; |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 const GetUserDataInDBCallback& callback); | 481 const GetUserDataInDBCallback& callback); |
475 static void GetUserDataForAllRegistrationsInDB( | 482 static void GetUserDataForAllRegistrationsInDB( |
476 ServiceWorkerDatabase* database, | 483 ServiceWorkerDatabase* database, |
477 scoped_refptr<base::SequencedTaskRunner> original_task_runner, | 484 scoped_refptr<base::SequencedTaskRunner> original_task_runner, |
478 const std::string& key, | 485 const std::string& key, |
479 const GetUserDataForAllRegistrationsInDBCallback& callback); | 486 const GetUserDataForAllRegistrationsInDBCallback& callback); |
480 static void DeleteAllDataForOriginsFromDB( | 487 static void DeleteAllDataForOriginsFromDB( |
481 ServiceWorkerDatabase* database, | 488 ServiceWorkerDatabase* database, |
482 const std::set<GURL>& origins); | 489 const std::set<GURL>& origins); |
483 | 490 |
| 491 bool IsDisabled() const; |
484 void ScheduleDeleteAndStartOver(); | 492 void ScheduleDeleteAndStartOver(); |
485 void DidDeleteDatabase( | 493 void DidDeleteDatabase( |
486 const StatusCallback& callback, | 494 const StatusCallback& callback, |
487 ServiceWorkerDatabase::Status status); | 495 ServiceWorkerDatabase::Status status); |
488 void DidDeleteDiskCache( | 496 void DidDeleteDiskCache( |
489 const StatusCallback& callback, | 497 const StatusCallback& callback, |
490 bool result); | 498 bool result); |
491 | 499 |
492 // For finding registrations being installed or uninstalled. | 500 // For finding registrations being installed or uninstalled. |
493 RegistrationRefsById installing_registrations_; | 501 RegistrationRefsById installing_registrations_; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 std::set<int64_t> pending_deletions_; | 541 std::set<int64_t> pending_deletions_; |
534 | 542 |
535 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_; | 543 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_; |
536 | 544 |
537 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); | 545 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); |
538 }; | 546 }; |
539 | 547 |
540 } // namespace content | 548 } // namespace content |
541 | 549 |
542 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ | 550 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ |
OLD | NEW |