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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_disk_cache_migrator.h
diff --git a/content/browser/service_worker/service_worker_disk_cache_migrator.h b/content/browser/service_worker/service_worker_disk_cache_migrator.h
new file mode 100644
index 0000000000000000000000000000000000000000..f1503c85383f5fd821b3a50e254b14425cd9eab9
--- /dev/null
+++ b/content/browser/service_worker/service_worker_disk_cache_migrator.h
@@ -0,0 +1,58 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/service_worker/service_worker_disk_cache.h"
+
+#include "base/id_map.h"
+#include "base/memory/scoped_ptr.h"
+#include "content/browser/service_worker/service_worker_database.h"
+#include "content/common/service_worker/service_worker_status_code.h"
+
+namespace content {
+
+// This is used for migrating the ServiceWorkerDiskCache from the BlockFile
+// backend to the Simple backend. The migrator iterates over resources in the
+// src DiskCache and copies them into the dest DiskCache one by one. This does
+// not delete the resources in the src DiskCache.
+//
+// TODO(nhiroki): Remove this migrator after several milestones pass
+// (http://crbug.com/487482)
+class CONTENT_EXPORT ServiceWorkerDiskCacheMigrator {
+ public:
+ using StatusCallback = base::Callback<void(ServiceWorkerStatusCode)>;
+
+ ServiceWorkerDiskCacheMigrator(ServiceWorkerDiskCache* src,
+ ServiceWorkerDiskCache* dest);
+ ~ServiceWorkerDiskCacheMigrator();
+
+ // Returns SERVICE_WORKER_OK if all resources are successfully migrated. The
+ // caller should delete the src DiskCache after migration.
+ void Start(const StatusCallback& callback);
+
+ private:
+ class Task;
+
+ using InflightTaskMap = IDMap<Task, IDMapOwnPointer>;
+
+ void ContinueMigratingResources();
+ void OnOpenNextEntry(disk_cache::Entry** entry, int result);
+ void OnResourceMigrated(InflightTaskMap::KeyType task_id,
+ ServiceWorkerStatusCode status);
+ void Complete(ServiceWorkerStatusCode status);
+
+ scoped_ptr<disk_cache::Backend::Iterator> iterator_;
+ ServiceWorkerDiskCache* src_;
+ ServiceWorkerDiskCache* dest_;
+
+ InflightTaskMap::KeyType next_task_id_ = 0;
+ InflightTaskMap inflight_tasks_;
+
+ StatusCallback callback_;
+
+ base::WeakPtrFactory<ServiceWorkerDiskCacheMigrator> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDiskCacheMigrator);
+};
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698