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

Unified 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: Nits Created 5 years, 11 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_cache_scheduler.cc
diff --git a/content/browser/service_worker/service_worker_cache_scheduler.cc b/content/browser/service_worker/service_worker_cache_scheduler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..694c5821f3f6c4123606e53b58f4096a1a03e494
--- /dev/null
+++ b/content/browser/service_worker/service_worker_cache_scheduler.cc
@@ -0,0 +1,47 @@
+// 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_cache_scheduler.h"
+
+#include <string>
+
+#include "base/logging.h"
+
+namespace content {
+
+ServiceWorkerCacheScheduler::ServiceWorkerCacheScheduler()
+ : operation_running_(false) {
+}
+
+ServiceWorkerCacheScheduler::~ServiceWorkerCacheScheduler() {
+}
+
+void ServiceWorkerCacheScheduler::ScheduleOperation(
+ const base::Closure& closure) {
+ pending_operations_.push_back(closure);
+ RunOperationIfIdle();
+}
+
+void ServiceWorkerCacheScheduler::CompleteOperationAndRunNext() {
+ DCHECK(!pending_operations_.empty());
+ operation_running_ = false;
+ pending_operations_.pop_front();
+ RunOperationIfIdle();
+}
+
+bool ServiceWorkerCacheScheduler::Empty() const {
+ return pending_operations_.empty();
+}
+
+void ServiceWorkerCacheScheduler::RunOperationIfIdle() {
+ DCHECK(!operation_running_ || !pending_operations_.empty());
+
+ if (!operation_running_ && !pending_operations_.empty()) {
+ operation_running_ = true;
+ // TODO(jkarlin): Run multiple operations in parallel where allowed.
+ pending_operations_.front().Run();
+ }
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698