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 #include "content/browser/service_worker/service_worker_cache_scheduler.h" | 5 #include "content/browser/cache_storage/cache_storage_scheduler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 | 12 |
13 ServiceWorkerCacheScheduler::ServiceWorkerCacheScheduler() | 13 CacheStorageScheduler::CacheStorageScheduler() : operation_running_(false) { |
14 : operation_running_(false) { | |
15 } | 14 } |
16 | 15 |
17 ServiceWorkerCacheScheduler::~ServiceWorkerCacheScheduler() { | 16 CacheStorageScheduler::~CacheStorageScheduler() { |
18 } | 17 } |
19 | 18 |
20 void ServiceWorkerCacheScheduler::ScheduleOperation( | 19 void CacheStorageScheduler::ScheduleOperation(const base::Closure& closure) { |
21 const base::Closure& closure) { | |
22 pending_operations_.push_back(closure); | 20 pending_operations_.push_back(closure); |
23 RunOperationIfIdle(); | 21 RunOperationIfIdle(); |
24 } | 22 } |
25 | 23 |
26 void ServiceWorkerCacheScheduler::CompleteOperationAndRunNext() { | 24 void CacheStorageScheduler::CompleteOperationAndRunNext() { |
27 DCHECK(operation_running_); | 25 DCHECK(operation_running_); |
28 operation_running_ = false; | 26 operation_running_ = false; |
29 RunOperationIfIdle(); | 27 RunOperationIfIdle(); |
30 } | 28 } |
31 | 29 |
32 bool ServiceWorkerCacheScheduler::ScheduledOperations() const { | 30 bool CacheStorageScheduler::ScheduledOperations() const { |
33 return operation_running_ || !pending_operations_.empty(); | 31 return operation_running_ || !pending_operations_.empty(); |
34 } | 32 } |
35 | 33 |
36 void ServiceWorkerCacheScheduler::RunOperationIfIdle() { | 34 void CacheStorageScheduler::RunOperationIfIdle() { |
37 if (!operation_running_ && !pending_operations_.empty()) { | 35 if (!operation_running_ && !pending_operations_.empty()) { |
38 operation_running_ = true; | 36 operation_running_ = true; |
39 // TODO(jkarlin): Run multiple operations in parallel where allowed. | 37 // TODO(jkarlin): Run multiple operations in parallel where allowed. |
40 base::Closure closure = pending_operations_.front(); | 38 base::Closure closure = pending_operations_.front(); |
41 pending_operations_.pop_front(); | 39 pending_operations_.pop_front(); |
42 closure.Run(); | 40 closure.Run(); |
43 } | 41 } |
44 } | 42 } |
45 | 43 |
46 } // namespace content | 44 } // namespace content |
OLD | NEW |