Simplify ChildProcessLauncher
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_cache_scheduler.cc
blobfc842cafddabb22bc7a527d03b7a0a3a0abe8777
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.
5 #include "content/browser/service_worker/service_worker_cache_scheduler.h"
7 #include <string>
9 #include "base/logging.h"
11 namespace content {
13 ServiceWorkerCacheScheduler::ServiceWorkerCacheScheduler()
14 : operation_running_(false) {
17 ServiceWorkerCacheScheduler::~ServiceWorkerCacheScheduler() {
20 void ServiceWorkerCacheScheduler::ScheduleOperation(
21 const base::Closure& closure) {
22 pending_operations_.push_back(closure);
23 RunOperationIfIdle();
26 void ServiceWorkerCacheScheduler::CompleteOperationAndRunNext() {
27 DCHECK(operation_running_);
28 operation_running_ = false;
29 RunOperationIfIdle();
32 bool ServiceWorkerCacheScheduler::ScheduledOperations() const {
33 return operation_running_ || !pending_operations_.empty();
36 void ServiceWorkerCacheScheduler::RunOperationIfIdle() {
37 if (!operation_running_ && !pending_operations_.empty()) {
38 operation_running_ = true;
39 // TODO(jkarlin): Run multiple operations in parallel where allowed.
40 base::Closure closure = pending_operations_.front();
41 pending_operations_.pop_front();
42 closure.Run();
46 } // namespace content