Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: content/browser/service_worker/service_worker_storage.h

Issue 1152543002: ServiceWorker: Migrate the script cache backend from BlockFile to Simple (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: incorporate falken@'s comments Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/gtest_prod_util.h" 16 #include "base/gtest_prod_util.h"
17 #include "base/memory/scoped_vector.h" 17 #include "base/memory/scoped_vector.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "content/browser/service_worker/service_worker_database.h" 19 #include "content/browser/service_worker/service_worker_database.h"
20 #include "content/browser/service_worker/service_worker_database_task_manager.h" 20 #include "content/browser/service_worker/service_worker_database_task_manager.h"
21 #include "content/browser/service_worker/service_worker_metrics.h"
21 #include "content/browser/service_worker/service_worker_version.h" 22 #include "content/browser/service_worker/service_worker_version.h"
22 #include "content/common/content_export.h" 23 #include "content/common/content_export.h"
23 #include "content/common/service_worker/service_worker_status_code.h" 24 #include "content/common/service_worker/service_worker_status_code.h"
24 #include "url/gurl.h" 25 #include "url/gurl.h"
25 26
26 namespace base { 27 namespace base {
27 class SequencedTaskRunner; 28 class SequencedTaskRunner;
28 class SingleThreadTaskRunner; 29 class SingleThreadTaskRunner;
29 } 30 }
30 31
31 namespace storage { 32 namespace storage {
32 class QuotaManagerProxy; 33 class QuotaManagerProxy;
33 class SpecialStoragePolicy; 34 class SpecialStoragePolicy;
34 } 35 }
35 36
36 namespace content { 37 namespace content {
37 38
38 class ServiceWorkerContextCore; 39 class ServiceWorkerContextCore;
39 class ServiceWorkerDiskCache; 40 class ServiceWorkerDiskCache;
41 class ServiceWorkerDiskCacheMigrator;
40 class ServiceWorkerRegistration; 42 class ServiceWorkerRegistration;
41 class ServiceWorkerResponseMetadataWriter; 43 class ServiceWorkerResponseMetadataWriter;
42 class ServiceWorkerResponseReader; 44 class ServiceWorkerResponseReader;
43 class ServiceWorkerResponseWriter; 45 class ServiceWorkerResponseWriter;
44 struct ServiceWorkerRegistrationInfo; 46 struct ServiceWorkerRegistrationInfo;
45 47
46 // This class provides an interface to store and retrieve ServiceWorker 48 // This class provides an interface to store and retrieve ServiceWorker
47 // registration data. 49 // registration data.
48 class CONTENT_EXPORT ServiceWorkerStorage 50 class CONTENT_EXPORT ServiceWorkerStorage
49 : NON_EXPORTED_BASE(public ServiceWorkerVersion::Listener) { 51 : NON_EXPORTED_BASE(public ServiceWorkerVersion::Listener) {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 207
206 // |resources| must already be on the purgeable list. 208 // |resources| must already be on the purgeable list.
207 void PurgeResources(const ResourceList& resources); 209 void PurgeResources(const ResourceList& resources);
208 210
209 private: 211 private:
210 friend class ServiceWorkerHandleTest; 212 friend class ServiceWorkerHandleTest;
211 friend class ServiceWorkerStorageTest; 213 friend class ServiceWorkerStorageTest;
212 friend class ServiceWorkerResourceStorageTest; 214 friend class ServiceWorkerResourceStorageTest;
213 friend class ServiceWorkerControlleeRequestHandlerTest; 215 friend class ServiceWorkerControlleeRequestHandlerTest;
214 friend class ServiceWorkerContextRequestHandlerTest; 216 friend class ServiceWorkerContextRequestHandlerTest;
217 friend class ServiceWorkerDiskCacheMigratorTest;
215 friend class ServiceWorkerRequestHandlerTest; 218 friend class ServiceWorkerRequestHandlerTest;
216 friend class ServiceWorkerURLRequestJobTest; 219 friend class ServiceWorkerURLRequestJobTest;
217 friend class ServiceWorkerVersionBrowserTest; 220 friend class ServiceWorkerVersionBrowserTest;
218 friend class ServiceWorkerVersionTest; 221 friend class ServiceWorkerVersionTest;
219 friend class ServiceWorkerWriteToCacheJobTest; 222 friend class ServiceWorkerWriteToCacheJobTest;
223 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDiskCacheMigratorTest,
224 MigrateOnDiskCacheAccess);
225 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDiskCacheMigratorTest,
226 NotMigrateOnDatabaseAccess);
220 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, 227 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest,
221 CleanupOnRendererCrash); 228 CleanupOnRendererCrash);
222 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, 229 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest,
223 DeleteRegistration_NoLiveVersion); 230 DeleteRegistration_NoLiveVersion);
224 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, 231 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest,
225 DeleteRegistration_WaitingVersion); 232 DeleteRegistration_WaitingVersion);
226 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, 233 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest,
227 DeleteRegistration_ActiveVersion); 234 DeleteRegistration_ActiveVersion);
228 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest, 235 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerResourceStorageTest,
229 UpdateRegistration); 236 UpdateRegistration);
(...skipping 18 matching lines...) Expand all
248 GURL origin; 255 GURL origin;
249 StatusCallback callback; 256 StatusCallback callback;
250 257
251 DidDeleteRegistrationParams(); 258 DidDeleteRegistrationParams();
252 ~DidDeleteRegistrationParams(); 259 ~DidDeleteRegistrationParams();
253 }; 260 };
254 261
255 typedef std::vector<ServiceWorkerDatabase::RegistrationData> RegistrationList; 262 typedef std::vector<ServiceWorkerDatabase::RegistrationData> RegistrationList;
256 typedef std::map<int64, scoped_refptr<ServiceWorkerRegistration> > 263 typedef std::map<int64, scoped_refptr<ServiceWorkerRegistration> >
257 RegistrationRefsById; 264 RegistrationRefsById;
258 typedef base::Callback<void( 265 typedef base::Callback<void(InitialData* data,
259 InitialData* data, 266 bool needs_disk_cache_migration,
260 ServiceWorkerDatabase::Status status)> InitializeCallback; 267 ServiceWorkerDatabase::Status status)>
268 InitializeCallback;
261 typedef base::Callback<void( 269 typedef base::Callback<void(
262 const GURL& origin, 270 const GURL& origin,
263 const ServiceWorkerDatabase::RegistrationData& deleted_version_data, 271 const ServiceWorkerDatabase::RegistrationData& deleted_version_data,
264 const std::vector<int64>& newly_purgeable_resources, 272 const std::vector<int64>& newly_purgeable_resources,
265 ServiceWorkerDatabase::Status status)> WriteRegistrationCallback; 273 ServiceWorkerDatabase::Status status)> WriteRegistrationCallback;
266 typedef base::Callback<void( 274 typedef base::Callback<void(
267 bool origin_is_deletable, 275 bool origin_is_deletable,
268 const ServiceWorkerDatabase::RegistrationData& deleted_version_data, 276 const ServiceWorkerDatabase::RegistrationData& deleted_version_data,
269 const std::vector<int64>& newly_purgeable_resources, 277 const std::vector<int64>& newly_purgeable_resources,
270 ServiceWorkerDatabase::Status status)> DeleteRegistrationCallback; 278 ServiceWorkerDatabase::Status status)> DeleteRegistrationCallback;
(...skipping 16 matching lines...) Expand all
287 const base::FilePath& path, 295 const base::FilePath& path,
288 base::WeakPtr<ServiceWorkerContextCore> context, 296 base::WeakPtr<ServiceWorkerContextCore> context,
289 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager, 297 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager,
290 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, 298 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread,
291 storage::QuotaManagerProxy* quota_manager_proxy, 299 storage::QuotaManagerProxy* quota_manager_proxy,
292 storage::SpecialStoragePolicy* special_storage_policy); 300 storage::SpecialStoragePolicy* special_storage_policy);
293 301
294 base::FilePath GetDatabasePath(); 302 base::FilePath GetDatabasePath();
295 base::FilePath GetDiskCachePath(); 303 base::FilePath GetDiskCachePath();
296 304
297 // Loads the registration data from backend storage. This must be called 305 // Returns a path to an old diskcache backed with BlockFile. This is used for
298 // before any method that requires registration data. 306 // the diskcache migration (see service_worker_disk_cache_migrator.h).
307 // TODO(nhiroki): Remove this after several milestones pass
308 // (http://crbug.com/487482)
309 base::FilePath GetOldDiskCachePath();
310
299 bool LazyInitialize( 311 bool LazyInitialize(
300 const base::Closure& callback); 312 const base::Closure& callback);
301 void DidReadInitialData( 313 void DidReadInitialData(InitialData* data,
302 InitialData* data, 314 bool needs_disk_cache_migration,
303 ServiceWorkerDatabase::Status status); 315 ServiceWorkerDatabase::Status status);
304 void DidFindRegistrationForDocument( 316 void DidFindRegistrationForDocument(
305 const GURL& document_url, 317 const GURL& document_url,
306 const FindRegistrationCallback& callback, 318 const FindRegistrationCallback& callback,
307 int64 callback_id, 319 int64 callback_id,
308 const ServiceWorkerDatabase::RegistrationData& data, 320 const ServiceWorkerDatabase::RegistrationData& data,
309 const ResourceList& resources, 321 const ResourceList& resources,
310 ServiceWorkerDatabase::Status status); 322 ServiceWorkerDatabase::Status status);
311 void DidFindRegistrationForPattern( 323 void DidFindRegistrationForPattern(
312 const GURL& scope, 324 const GURL& scope,
313 const FindRegistrationCallback& callback, 325 const FindRegistrationCallback& callback,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 const ResourceList& resources); 376 const ResourceList& resources);
365 ServiceWorkerRegistration* FindInstallingRegistrationForDocument( 377 ServiceWorkerRegistration* FindInstallingRegistrationForDocument(
366 const GURL& document_url); 378 const GURL& document_url);
367 ServiceWorkerRegistration* FindInstallingRegistrationForPattern( 379 ServiceWorkerRegistration* FindInstallingRegistrationForPattern(
368 const GURL& scope); 380 const GURL& scope);
369 ServiceWorkerRegistration* FindInstallingRegistrationForId( 381 ServiceWorkerRegistration* FindInstallingRegistrationForId(
370 int64 registration_id); 382 int64 registration_id);
371 383
372 // Lazy disk_cache getter. 384 // Lazy disk_cache getter.
373 ServiceWorkerDiskCache* disk_cache(); 385 ServiceWorkerDiskCache* disk_cache();
386 void PrepareDiskCacheForMigration();
387 void DidInitializeDiskCacheForMigration(bool* is_failed,
michaeln 2015/06/08 21:36:33 Since the storage class is pretty big, it might be
nhiroki 2015/06/09 15:41:57 Moved the initialization code from storage to migr
388 const base::Closure& barrier_closure,
389 int result);
390 void DidPrepareDiskCacheForMigration(
391 scoped_ptr<ServiceWorkerDiskCache> src_disk_cache,
392 scoped_ptr<ServiceWorkerDiskCache> dest_disk_cache,
393 bool* is_failed);
394 void DidMigrateDiskCache(scoped_ptr<ServiceWorkerDiskCacheMigrator> migrator,
395 scoped_ptr<ServiceWorkerDiskCache> src_disk_cache,
396 scoped_ptr<ServiceWorkerDiskCache> dest_disk_cache,
397 ServiceWorkerStatusCode status);
398 void DidDeleteOldDiskCache(bool deleted);
399 void AbortDiskCacheMigration(
400 ServiceWorkerMetrics::DiskCacheMigrationResult result);
401 void InitializeDiskCache();
374 void OnDiskCacheInitialized(int rv); 402 void OnDiskCacheInitialized(int rv);
375 403
376 void StartPurgingResources(const std::vector<int64>& ids); 404 void StartPurgingResources(const std::vector<int64>& ids);
377 void StartPurgingResources(const ResourceList& resources); 405 void StartPurgingResources(const ResourceList& resources);
378 void ContinuePurgingResources(); 406 void ContinuePurgingResources();
379 void PurgeResource(int64 id); 407 void PurgeResource(int64 id);
380 void OnResourcePurged(int64 id, int rv); 408 void OnResourcePurged(int64 id, int rv);
381 409
382 // Deletes purgeable and uncommitted resources left over from the previous 410 // Deletes purgeable and uncommitted resources left over from the previous
383 // browser session. This must be called once per session before any database 411 // browser session. This must be called once per session before any database
384 // operation that may mutate the purgeable or uncommitted resource lists. 412 // operation that may mutate the purgeable or uncommitted resource lists.
385 void DeleteStaleResources(); 413 void DeleteStaleResources();
386 void DidCollectStaleResources(const std::vector<int64>& stale_resource_ids, 414 void DidCollectStaleResources(const std::vector<int64>& stale_resource_ids,
387 ServiceWorkerDatabase::Status status); 415 ServiceWorkerDatabase::Status status);
388 416
389 void ClearSessionOnlyOrigins(); 417 void ClearSessionOnlyOrigins();
390 418
391 // Static cross-thread helpers. 419 // Static cross-thread helpers.
392 static void CollectStaleResourcesFromDB( 420 static void CollectStaleResourcesFromDB(
393 ServiceWorkerDatabase* database, 421 ServiceWorkerDatabase* database,
394 scoped_refptr<base::SequencedTaskRunner> original_task_runner, 422 scoped_refptr<base::SequencedTaskRunner> original_task_runner,
395 const GetResourcesCallback& callback); 423 const GetResourcesCallback& callback);
396 static void ReadInitialDataFromDB( 424 static void ReadInitialDataFromDB(
397 ServiceWorkerDatabase* database, 425 ServiceWorkerDatabase* database,
398 scoped_refptr<base::SequencedTaskRunner> original_task_runner, 426 scoped_refptr<base::SequencedTaskRunner> original_task_runner,
427 const base::FilePath& old_disk_cache_path,
399 const InitializeCallback& callback); 428 const InitializeCallback& callback);
400 static void DeleteRegistrationFromDB( 429 static void DeleteRegistrationFromDB(
401 ServiceWorkerDatabase* database, 430 ServiceWorkerDatabase* database,
402 scoped_refptr<base::SequencedTaskRunner> original_task_runner, 431 scoped_refptr<base::SequencedTaskRunner> original_task_runner,
403 int64 registration_id, 432 int64 registration_id,
404 const GURL& origin, 433 const GURL& origin,
405 const DeleteRegistrationCallback& callback); 434 const DeleteRegistrationCallback& callback);
406 static void WriteRegistrationInDB( 435 static void WriteRegistrationInDB(
407 ServiceWorkerDatabase* database, 436 ServiceWorkerDatabase* database,
408 scoped_refptr<base::SequencedTaskRunner> original_task_runner, 437 scoped_refptr<base::SequencedTaskRunner> original_task_runner,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 base::FilePath path_; 507 base::FilePath path_;
479 base::WeakPtr<ServiceWorkerContextCore> context_; 508 base::WeakPtr<ServiceWorkerContextCore> context_;
480 509
481 // Only accessed using |database_task_manager_|. 510 // Only accessed using |database_task_manager_|.
482 scoped_ptr<ServiceWorkerDatabase> database_; 511 scoped_ptr<ServiceWorkerDatabase> database_;
483 512
484 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager_; 513 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager_;
485 scoped_refptr<base::SingleThreadTaskRunner> disk_cache_thread_; 514 scoped_refptr<base::SingleThreadTaskRunner> disk_cache_thread_;
486 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; 515 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_;
487 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_; 516 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_;
517
488 scoped_ptr<ServiceWorkerDiskCache> disk_cache_; 518 scoped_ptr<ServiceWorkerDiskCache> disk_cache_;
519 bool needs_disk_cache_migration_;
520
489 std::deque<int64> purgeable_resource_ids_; 521 std::deque<int64> purgeable_resource_ids_;
490 bool is_purge_pending_; 522 bool is_purge_pending_;
491 bool has_checked_for_stale_resources_; 523 bool has_checked_for_stale_resources_;
492 std::set<int64> pending_deletions_; 524 std::set<int64> pending_deletions_;
493 525
494 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_; 526 base::WeakPtrFactory<ServiceWorkerStorage> weak_factory_;
495 527
496 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage); 528 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerStorage);
497 }; 529 };
498 530
499 } // namespace content 531 } // namespace content
500 532
501 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_ 533 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_STORAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698