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

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

Issue 1155063002: ServiceWorker: Introduce ServiceWorkerDiskCacheMigrator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use fixed time for tests Created 5 years, 7 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/service_worker/service_worker_disk_cache.h"
6
7 #include "base/id_map.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "content/browser/service_worker/service_worker_database.h"
10 #include "content/common/service_worker/service_worker_status_code.h"
11
12 namespace content {
13
14 // This is used for migrating the ServiceWorkerDiskCache from the BlockFile
15 // backend to the Simple backend. The migrator iterates over resources in the
16 // src DiskCache and copies them into the dest DiskCache one by one. This does
17 // not delete the resources in the src DiskCache.
18 //
19 // TODO(nhiroki): Remove this migrator after several milestones pass
20 // (http://crbug.com/487482)
21 class CONTENT_EXPORT ServiceWorkerDiskCacheMigrator {
22 public:
23 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode)>;
24
25 ServiceWorkerDiskCacheMigrator(ServiceWorkerDiskCache* src,
26 ServiceWorkerDiskCache* dest);
27 ~ServiceWorkerDiskCacheMigrator();
28
29 // Returns SERVICE_WORKER_OK if all resources are successfully migrated. The
30 // caller should delete the src DiskCache after migration.
31 void Start(const StatusCallback& callback);
32
33 private:
34 class Task;
35
36 using InflightTaskMap = IDMap<Task, IDMapOwnPointer>;
37
38 void ContinueMigratingResources();
39 void OnOpenNextEntry(disk_cache::Entry** entry, int result);
40 void OnResourceMigrated(InflightTaskMap::KeyType task_id,
41 ServiceWorkerStatusCode status);
42 void Complete(ServiceWorkerStatusCode status);
43
44 scoped_ptr<disk_cache::Backend::Iterator> iterator_;
45 ServiceWorkerDiskCache* src_;
46 ServiceWorkerDiskCache* dest_;
47
48 InflightTaskMap::KeyType next_task_id_ = 0;
49 InflightTaskMap inflight_tasks_;
50
51 StatusCallback callback_;
52
53 base::WeakPtrFactory<ServiceWorkerDiskCacheMigrator> weak_factory_;
54
55 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDiskCacheMigrator);
56 };
57
58 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698