OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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_DISK_CACHE_MIGRATOR_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISK_CACHE_MIGRATOR_H_ |
| 7 |
5 #include "content/browser/service_worker/service_worker_disk_cache.h" | 8 #include "content/browser/service_worker/service_worker_disk_cache.h" |
6 | 9 |
7 #include "base/id_map.h" | 10 #include "base/id_map.h" |
8 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
9 #include "content/browser/service_worker/service_worker_database.h" | 12 #include "content/browser/service_worker/service_worker_database.h" |
10 #include "content/common/service_worker/service_worker_status_code.h" | 13 #include "content/common/service_worker/service_worker_status_code.h" |
11 | 14 |
12 namespace content { | 15 namespace content { |
13 | 16 |
14 // This is used for migrating the ServiceWorkerDiskCache from the BlockFile | 17 // This is used for migrating the ServiceWorkerDiskCache from the BlockFile |
15 // backend to the Simple backend. The migrator iterates over resources in the | 18 // 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 | 19 // src DiskCache and copies them into the dest DiskCache one by one. This does |
17 // not delete the resources in the src DiskCache. | 20 // not delete the resources in the src DiskCache. |
18 // | 21 // |
19 // TODO(nhiroki): Remove this migrator after several milestones pass | 22 // TODO(nhiroki): Remove this migrator after several milestones pass |
20 // (http://crbug.com/487482) | 23 // (http://crbug.com/487482) |
21 class CONTENT_EXPORT ServiceWorkerDiskCacheMigrator { | 24 class CONTENT_EXPORT ServiceWorkerDiskCacheMigrator { |
22 public: | 25 public: |
23 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode)>; | 26 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode)>; |
24 | 27 |
25 ServiceWorkerDiskCacheMigrator(ServiceWorkerDiskCache* src, | 28 ServiceWorkerDiskCacheMigrator( |
26 ServiceWorkerDiskCache* dest); | 29 const base::FilePath& src_path, |
| 30 const base::FilePath& dest_path, |
| 31 int max_disk_cache_size, |
| 32 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread); |
27 ~ServiceWorkerDiskCacheMigrator(); | 33 ~ServiceWorkerDiskCacheMigrator(); |
28 | 34 |
29 // Returns SERVICE_WORKER_OK if all resources are successfully migrated. The | 35 // Returns SERVICE_WORKER_OK if all resources are successfully migrated. The |
30 // caller should delete the src DiskCache after migration. | 36 // caller should delete the src DiskCache after migration. |
31 void Start(const StatusCallback& callback); | 37 void Start(const StatusCallback& callback); |
32 | 38 |
33 private: | 39 private: |
34 friend class ServiceWorkerDiskCacheMigratorTest; | 40 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDiskCacheMigratorTest, |
| 41 ThrottleInflightTasks); |
| 42 |
35 class Task; | 43 class Task; |
36 class WrappedEntry; | 44 class WrappedEntry; |
37 | 45 |
38 using InflightTaskMap = IDMap<Task, IDMapOwnPointer>; | 46 using InflightTaskMap = IDMap<Task, IDMapOwnPointer>; |
39 | 47 |
| 48 void DidDeleteDestDirectory(bool deleted); |
| 49 void DidInitializeDiskCache(bool* is_failed, |
| 50 const base::Closure& barrier_closure, |
| 51 int result); |
| 52 void DidInitializeAllDiskCaches(bool* is_failed); |
| 53 |
40 void OpenNextEntry(); | 54 void OpenNextEntry(); |
41 void OnNextEntryOpened(scoped_ptr<WrappedEntry> entry, int result); | 55 void OnNextEntryOpened(scoped_ptr<WrappedEntry> entry, int result); |
42 void RunPendingTask(); | 56 void RunPendingTask(); |
43 void OnEntryMigrated(InflightTaskMap::KeyType task_id, | 57 void OnEntryMigrated(InflightTaskMap::KeyType task_id, |
44 ServiceWorkerStatusCode status); | 58 ServiceWorkerStatusCode status); |
45 void Complete(ServiceWorkerStatusCode status); | 59 void Complete(ServiceWorkerStatusCode status); |
46 | 60 |
47 void set_max_number_of_inflight_tasks(size_t max_number) { | 61 void set_max_number_of_inflight_tasks(size_t max_number) { |
48 max_number_of_inflight_tasks_ = max_number; | 62 max_number_of_inflight_tasks_ = max_number; |
49 } | 63 } |
50 | 64 |
51 scoped_ptr<disk_cache::Backend::Iterator> iterator_; | 65 scoped_ptr<disk_cache::Backend::Iterator> iterator_; |
52 bool is_iterating_ = false; | 66 bool is_iterating_ = false; |
53 | 67 |
54 ServiceWorkerDiskCache* src_; | 68 base::FilePath src_path_; |
55 ServiceWorkerDiskCache* dest_; | 69 base::FilePath dest_path_; |
| 70 scoped_ptr<ServiceWorkerDiskCache> src_; |
| 71 scoped_ptr<ServiceWorkerDiskCache> dest_; |
| 72 const int max_disk_cache_size_; |
| 73 scoped_refptr<base::SingleThreadTaskRunner> disk_cache_thread_; |
56 | 74 |
57 InflightTaskMap::KeyType next_task_id_ = 0; | 75 InflightTaskMap::KeyType next_task_id_ = 0; |
58 InflightTaskMap inflight_tasks_; | 76 InflightTaskMap inflight_tasks_; |
59 scoped_ptr<Task> pending_task_; | 77 scoped_ptr<Task> pending_task_; |
60 size_t max_number_of_inflight_tasks_ = 10; | 78 size_t max_number_of_inflight_tasks_ = 10; |
61 | 79 |
| 80 base::TimeTicks start_time_; |
| 81 size_t number_of_migrated_resources_ = 0; |
| 82 |
62 StatusCallback callback_; | 83 StatusCallback callback_; |
63 | 84 |
64 base::WeakPtrFactory<ServiceWorkerDiskCacheMigrator> weak_factory_; | 85 base::WeakPtrFactory<ServiceWorkerDiskCacheMigrator> weak_factory_; |
65 | 86 |
66 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDiskCacheMigrator); | 87 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDiskCacheMigrator); |
67 }; | 88 }; |
68 | 89 |
69 } // namespace content | 90 } // namespace content |
| 91 |
| 92 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISK_CACHE_MIGRATOR_H_ |
OLD | NEW |