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

Unified Diff: components/offline_pages/core/test_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/test_task.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/offline_pages/core/test_task.cc
diff --git a/components/offline_pages/core/test_task.cc b/components/offline_pages/core/test_task.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cd0ade91ffb02cfb7051bf408574d799bf3e96c0
--- /dev/null
+++ b/components/offline_pages/core/test_task.cc
@@ -0,0 +1,58 @@
+// 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/test_task.h"
+
+#include "base/bind.h"
+
+namespace offline_pages {
+
+ConsumedResource::ConsumedResource() {}
+
+ConsumedResource::~ConsumedResource() {}
+
+void ConsumedResource::Step(const base::Closure& step_callback) {
+ next_step_ = step_callback;
+}
+
+void ConsumedResource::CompleteStep() {
+ base::Closure temp_ = next_step_;
+ next_step_.Reset();
+ temp_.Run();
+}
+
+TestTask::TestTask(ConsumedResource* resource)
+ : resource_(resource),
+ state_(TaskState::NOT_STARTED),
+ leave_early_(false) {}
+
+TestTask::TestTask(ConsumedResource* resource, bool leave_early)
+ : resource_(resource),
+ state_(TaskState::NOT_STARTED),
+ leave_early_(leave_early) {}
+
+TestTask::~TestTask() {}
+
+// Run is Step 1 in our case.
+void TestTask::Run() {
+ state_ = TaskState::STEP_1;
+ resource_->Step(base::Bind(&TestTask::Step2, base::Unretained(this)));
+}
+
+void TestTask::Step2() {
+ if (leave_early_) {
+ LastStep();
+ return;
+ }
+ state_ = TaskState::STEP_2;
+ resource_->Step(base::Bind(&TestTask::LastStep, base::Unretained(this)));
+}
+
+// This is step 3, but we conclude here.
+void TestTask::LastStep() {
+ state_ = TaskState::COMPLETED;
+ TaskComplete();
+}
+
+} // namespace offline_pages
« no previous file with comments | « components/offline_pages/core/test_task.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698