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

Side by Side Diff: content/browser/service_worker/service_worker_cache_scheduler.cc

Issue 867903005: [ServiceWorkerCache] Serialize ServiceWorkerCacheStorage operations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments from PS3 Created 5 years, 10 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_cache_scheduler.h"
6
7 #include <string>
8
9 #include "base/logging.h"
10
11 namespace content {
12
13 ServiceWorkerCacheScheduler::ServiceWorkerCacheScheduler()
14 : operation_running_(false) {
15 }
16
17 ServiceWorkerCacheScheduler::~ServiceWorkerCacheScheduler() {
18 }
19
20 void ServiceWorkerCacheScheduler::ScheduleOperation(
21 const base::Closure& closure) {
22 pending_operations_.push_back(closure);
23 RunOperationIfIdle();
24 }
25
26 void ServiceWorkerCacheScheduler::CompleteOperationAndRunNext() {
27 DCHECK(!pending_operations_.empty());
28 operation_running_ = false;
29 pending_operations_.pop_front();
30 RunOperationIfIdle();
31 }
32
33 bool ServiceWorkerCacheScheduler::Empty() const {
34 return pending_operations_.empty();
35 }
36
37 void ServiceWorkerCacheScheduler::RunOperationIfIdle() {
38 DCHECK(!operation_running_ || !pending_operations_.empty());
39
40 if (!operation_running_ && !pending_operations_.empty()) {
41 operation_running_ = true;
42 // TODO(jkarlin): Run multiple operations in parallel where allowed.
43 pending_operations_.front().Run();
44 }
45 }
46
47 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698