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

Unified Diff: components/offline_pages/core/task.cc

Issue 2359933007: [Offline pages] Introduces TaskQueue to serialize tasks that asynchronously access SQLStore (Closed)
Patch Set: Addressing feedback from Dmitry Created 4 years, 3 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
« no previous file with comments | « components/offline_pages/core/task.h ('k') | components/offline_pages/core/task_queue.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/offline_pages/core/task.cc
diff --git a/components/offline_pages/core/task.cc b/components/offline_pages/core/task.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1bf7a7d550326e41b2031c82b1593b93590f0feb
--- /dev/null
+++ b/components/offline_pages/core/task.cc
@@ -0,0 +1,43 @@
+// Copyright 2016 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 "components/offline_pages/core/task.h"
+
+#include "base/bind.h"
+#include "base/threading/thread_task_runner_handle.h"
+
+namespace offline_pages {
+
+Task::Task() {}
+
+Task::~Task() {}
+
+void Task::SetTaskCompletionCallbackForTesting(
+ scoped_refptr<base::SingleThreadTaskRunner> task_completion_runner,
+ const TaskCompletionCallback& task_completion_callback) {
+ SetTaskCompletionCallback(task_completion_runner, task_completion_callback);
+}
+
+void Task::SetTaskCompletionCallback(
+ scoped_refptr<base::SingleThreadTaskRunner> task_completion_runner,
+ const TaskCompletionCallback& task_completion_callback) {
+ // Attempts to enforce that SetTaskCompletionCallback is at most called once
+ // and enforces that reasonable values are set once that happens.
+ DCHECK(!task_completion_runner_);
+ DCHECK(task_completion_runner);
+ DCHECK(task_completion_callback_.is_null());
+ DCHECK(!task_completion_callback.is_null());
+ task_completion_runner_ = task_completion_runner;
+ task_completion_callback_ = task_completion_callback;
+}
+
+void Task::TaskComplete() {
+ if (task_completion_callback_.is_null() || !task_completion_runner_)
+ return;
+
+ task_completion_runner_->PostTask(
+ FROM_HERE, base::Bind(task_completion_callback_, this));
+}
+
+} // namespace offline_pages
« no previous file with comments | « components/offline_pages/core/task.h ('k') | components/offline_pages/core/task_queue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698