| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 const StatusCallback& callback); | 170 const StatusCallback& callback); |
| 171 void ClearUserData(int64 registration_id, | 171 void ClearUserData(int64 registration_id, |
| 172 const std::string& key, | 172 const std::string& key, |
| 173 const StatusCallback& callback); | 173 const StatusCallback& callback); |
| 174 // Returns all registrations that have user data with a particular key, as | 174 // Returns all registrations that have user data with a particular key, as |
| 175 // well as that user data. | 175 // well as that user data. |
| 176 void GetUserDataForAllRegistrations( | 176 void GetUserDataForAllRegistrations( |
| 177 const std::string& key, | 177 const std::string& key, |
| 178 const GetUserDataForAllRegistrationsCallback& callback); | 178 const GetUserDataForAllRegistrationsCallback& callback); |
| 179 | 179 |
| 180 // Returns true if any service workers at |origin| have registered for foreign |
| 181 // fetch. |
| 182 bool OriginHasForeignFetchRegistrations(const GURL& origin); |
| 183 |
| 180 // Deletes the storage and starts over. | 184 // Deletes the storage and starts over. |
| 181 void DeleteAndStartOver(const StatusCallback& callback); | 185 void DeleteAndStartOver(const StatusCallback& callback); |
| 182 | 186 |
| 183 // Returns new IDs which are guaranteed to be unique in the storage. | 187 // Returns new IDs which are guaranteed to be unique in the storage. |
| 184 int64 NewRegistrationId(); | 188 int64 NewRegistrationId(); |
| 185 int64 NewVersionId(); | 189 int64 NewVersionId(); |
| 186 int64 NewResourceId(); | 190 int64 NewResourceId(); |
| 187 | 191 |
| 188 // Intended for use only by ServiceWorkerRegisterJob and | 192 // Intended for use only by ServiceWorkerRegisterJob and |
| 189 // ServiceWorkerRegistration. | 193 // ServiceWorkerRegistration. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageDiskTest, | 246 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageDiskTest, |
| 243 DeleteAndStartOver_OpenedFileExists); | 247 DeleteAndStartOver_OpenedFileExists); |
| 244 | 248 |
| 245 struct InitialData { | 249 struct InitialData { |
| 246 int64 next_registration_id; | 250 int64 next_registration_id; |
| 247 int64 next_version_id; | 251 int64 next_version_id; |
| 248 int64 next_resource_id; | 252 int64 next_resource_id; |
| 249 std::set<GURL> origins; | 253 std::set<GURL> origins; |
| 250 bool disk_cache_migration_needed; | 254 bool disk_cache_migration_needed; |
| 251 bool old_disk_cache_deletion_needed; | 255 bool old_disk_cache_deletion_needed; |
| 256 std::set<GURL> foreign_fetch_origins; |
| 252 | 257 |
| 253 InitialData(); | 258 InitialData(); |
| 254 ~InitialData(); | 259 ~InitialData(); |
| 255 }; | 260 }; |
| 256 | 261 |
| 257 // Because there are too many params for base::Bind to wrap a closure around. | 262 // Because there are too many params for base::Bind to wrap a closure around. |
| 258 struct DidDeleteRegistrationParams { | 263 struct DidDeleteRegistrationParams { |
| 259 int64 registration_id; | 264 int64 registration_id; |
| 260 GURL origin; | 265 GURL origin; |
| 261 StatusCallback callback; | 266 StatusCallback callback; |
| 262 | 267 |
| 263 DidDeleteRegistrationParams(); | 268 DidDeleteRegistrationParams(); |
| 264 ~DidDeleteRegistrationParams(); | 269 ~DidDeleteRegistrationParams(); |
| 265 }; | 270 }; |
| 266 | 271 |
| 272 enum class OriginState { |
| 273 // Other registrations with foreign fetch scopes exist for the origin. |
| 274 KEEP_ALL, |
| 275 // Other registrations exist at this origin, but none of them have foreign |
| 276 // fetch scopes. |
| 277 DELETE_FROM_FOREIGN_FETCH, |
| 278 // No other registrations exist at this origin. |
| 279 DELETE_FROM_ALL |
| 280 }; |
| 281 |
| 267 typedef std::vector<ServiceWorkerDatabase::RegistrationData> RegistrationList; | 282 typedef std::vector<ServiceWorkerDatabase::RegistrationData> RegistrationList; |
| 268 typedef std::map<int64, scoped_refptr<ServiceWorkerRegistration> > | 283 typedef std::map<int64, scoped_refptr<ServiceWorkerRegistration> > |
| 269 RegistrationRefsById; | 284 RegistrationRefsById; |
| 270 typedef base::Callback<void(scoped_ptr<InitialData> data, | 285 typedef base::Callback<void(scoped_ptr<InitialData> data, |
| 271 ServiceWorkerDatabase::Status status)> | 286 ServiceWorkerDatabase::Status status)> |
| 272 InitializeCallback; | 287 InitializeCallback; |
| 273 typedef base::Callback<void(ServiceWorkerDatabase::Status status)> | 288 typedef base::Callback<void(ServiceWorkerDatabase::Status status)> |
| 274 DatabaseStatusCallback; | 289 DatabaseStatusCallback; |
| 275 typedef base::Callback<void( | 290 typedef base::Callback<void( |
| 276 const GURL& origin, | 291 const GURL& origin, |
| 277 const ServiceWorkerDatabase::RegistrationData& deleted_version_data, | 292 const ServiceWorkerDatabase::RegistrationData& deleted_version_data, |
| 278 const std::vector<int64>& newly_purgeable_resources, | 293 const std::vector<int64>& newly_purgeable_resources, |
| 279 ServiceWorkerDatabase::Status status)> WriteRegistrationCallback; | 294 ServiceWorkerDatabase::Status status)> WriteRegistrationCallback; |
| 280 typedef base::Callback<void( | 295 typedef base::Callback<void( |
| 281 bool origin_is_deletable, | 296 OriginState origin_state, |
| 282 const ServiceWorkerDatabase::RegistrationData& deleted_version_data, | 297 const ServiceWorkerDatabase::RegistrationData& deleted_version_data, |
| 283 const std::vector<int64>& newly_purgeable_resources, | 298 const std::vector<int64>& newly_purgeable_resources, |
| 284 ServiceWorkerDatabase::Status status)> DeleteRegistrationCallback; | 299 ServiceWorkerDatabase::Status status)> DeleteRegistrationCallback; |
| 285 typedef base::Callback<void( | 300 typedef base::Callback<void( |
| 286 const ServiceWorkerDatabase::RegistrationData& data, | 301 const ServiceWorkerDatabase::RegistrationData& data, |
| 287 const ResourceList& resources, | 302 const ResourceList& resources, |
| 288 ServiceWorkerDatabase::Status status)> FindInDBCallback; | 303 ServiceWorkerDatabase::Status status)> FindInDBCallback; |
| 289 typedef base::Callback<void( | 304 typedef base::Callback<void( |
| 290 const std::string& data, | 305 const std::string& data, |
| 291 ServiceWorkerDatabase::Status)> GetUserDataInDBCallback; | 306 ServiceWorkerDatabase::Status)> GetUserDataInDBCallback; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 const ServiceWorkerDatabase::RegistrationData& new_version, | 365 const ServiceWorkerDatabase::RegistrationData& new_version, |
| 351 const GURL& origin, | 366 const GURL& origin, |
| 352 const ServiceWorkerDatabase::RegistrationData& deleted_version, | 367 const ServiceWorkerDatabase::RegistrationData& deleted_version, |
| 353 const std::vector<int64>& newly_purgeable_resources, | 368 const std::vector<int64>& newly_purgeable_resources, |
| 354 ServiceWorkerDatabase::Status status); | 369 ServiceWorkerDatabase::Status status); |
| 355 void DidUpdateToActiveState( | 370 void DidUpdateToActiveState( |
| 356 const StatusCallback& callback, | 371 const StatusCallback& callback, |
| 357 ServiceWorkerDatabase::Status status); | 372 ServiceWorkerDatabase::Status status); |
| 358 void DidDeleteRegistration( | 373 void DidDeleteRegistration( |
| 359 const DidDeleteRegistrationParams& params, | 374 const DidDeleteRegistrationParams& params, |
| 360 bool origin_is_deletable, | 375 OriginState origin_state, |
| 361 const ServiceWorkerDatabase::RegistrationData& deleted_version, | 376 const ServiceWorkerDatabase::RegistrationData& deleted_version, |
| 362 const std::vector<int64>& newly_purgeable_resources, | 377 const std::vector<int64>& newly_purgeable_resources, |
| 363 ServiceWorkerDatabase::Status status); | 378 ServiceWorkerDatabase::Status status); |
| 364 void DidWriteUncommittedResourceIds(ServiceWorkerDatabase::Status status); | 379 void DidWriteUncommittedResourceIds(ServiceWorkerDatabase::Status status); |
| 365 void DidPurgeUncommittedResourceIds(const std::set<int64>& resource_ids, | 380 void DidPurgeUncommittedResourceIds(const std::set<int64>& resource_ids, |
| 366 ServiceWorkerDatabase::Status status); | 381 ServiceWorkerDatabase::Status status); |
| 367 void DidStoreUserData( | 382 void DidStoreUserData( |
| 368 const StatusCallback& callback, | 383 const StatusCallback& callback, |
| 369 ServiceWorkerDatabase::Status status); | 384 ServiceWorkerDatabase::Status status); |
| 370 void DidGetUserData( | 385 void DidGetUserData( |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 void DidDeleteDiskCache( | 502 void DidDeleteDiskCache( |
| 488 const StatusCallback& callback, | 503 const StatusCallback& callback, |
| 489 bool result); | 504 bool result); |
| 490 | 505 |
| 491 // For finding registrations being installed or uninstalled. | 506 // For finding registrations being installed or uninstalled. |
| 492 RegistrationRefsById installing_registrations_; | 507 RegistrationRefsById installing_registrations_; |
| 493 RegistrationRefsById uninstalling_registrations_; | 508 RegistrationRefsById uninstalling_registrations_; |
| 494 | 509 |
| 495 // Origins having registations. | 510 // Origins having registations. |
| 496 std::set<GURL> registered_origins_; | 511 std::set<GURL> registered_origins_; |
| 512 std::set<GURL> foreign_fetch_origins_; |
| 497 | 513 |
| 498 // Pending database tasks waiting for initialization. | 514 // Pending database tasks waiting for initialization. |
| 499 std::vector<base::Closure> pending_tasks_; | 515 std::vector<base::Closure> pending_tasks_; |
| 500 | 516 |
| 501 int64 next_registration_id_; | 517 int64 next_registration_id_; |
| 502 int64 next_version_id_; | 518 int64 next_version_id_; |
| 503 int64 next_resource_id_; | 519 int64 next_resource_id_; |
| 504 | 520 |
| 505 enum State { | 521 enum State { |
| 506 UNINITIALIZED, | 522 UNINITIALIZED, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 534 std::set<int64> pending_deletions_; | 550 std::set<int64> pending_deletions_; |
| 535 | 551 |
| 536 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_; | 552 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_; |
| 537 | 553 |
| 538 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); | 554 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); |
| 539 }; | 555 }; |
| 540 | 556 |
| 541 } // namespace content | 557 } // namespace content |
| 542 | 558 |
| 543 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ | 559 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ |
| OLD | NEW |