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

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: add DCHECKs 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
(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 friend class ServiceWorkerDiskCacheMigratorTest;
35 class Task;
36 class WrappedEntry;
37
38 using InflightTaskMap = IDMap<Task, IDMapOwnPointer>;
39
40 void OpenNextEntry();
41 void OnNextEntryOpened(scoped_ptr<WrappedEntry> entry, int result);
42 void RunPendingTask();
43 void OnEntryMigrated(InflightTaskMap::KeyType task_id,
44 ServiceWorkerStatusCode status);
45 void Complete(ServiceWorkerStatusCode status);
46
47 void set_max_number_of_inflight_tasks(size_t max_number) {
48 max_number_of_inflight_tasks_ = max_number;
49 }
50
51 scoped_ptr<disk_cache::Backend::Iterator> iterator_;
52 bool is_iterating_ = false;
53
54 ServiceWorkerDiskCache* src_;
55 ServiceWorkerDiskCache* dest_;
56
57 InflightTaskMap::KeyType next_task_id_ = 0;
58 InflightTaskMap inflight_tasks_;
59 scoped_ptr<Task> pending_task_;
60 size_t max_number_of_inflight_tasks_ = 10;
61
62 StatusCallback callback_;
63
64 base::WeakPtrFactory<ServiceWorkerDiskCacheMigrator> weak_factory_;
65
66 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDiskCacheMigrator);
67 };
68
69 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698