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

Unified Diff: components/test_runner/web_task.h

Issue 1852603002: Replacing most of web_task.h with base::Closure + base::WeakPtrFactory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-mocks-to-test-runner
Patch Set: Rebasing... Created 4 years, 8 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/test_runner/test_runner.cc ('k') | components/test_runner/web_task.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/test_runner/web_task.h
diff --git a/components/test_runner/web_task.h b/components/test_runner/web_task.h
index 3fb4d2d4304b9640287906a4d9f4ccc6b2585fc6..d8470a2c5eb7e43b20b1d34f24631a1e70c76275 100644
--- a/components/test_runner/web_task.h
+++ b/components/test_runner/web_task.h
@@ -5,72 +5,24 @@
#ifndef COMPONENTS_TEST_RUNNER_WEB_TASK_H_
#define COMPONENTS_TEST_RUNNER_WEB_TASK_H_
-#include <vector>
-
+#include "base/callback.h"
#include "base/macros.h"
#include "third_party/WebKit/public/platform/WebTaskRunner.h"
namespace test_runner {
-class WebTaskList;
-
-// WebTask represents a task which can run by WebTestDelegate::postTask() or
-// WebTestDelegate::postDelayedTask().
-class WebTask : public blink::WebTaskRunner::Task {
+// blink::WebTaskRunner::Task that wraps a base::Closure.
+class WebCallbackTask : public blink::WebTaskRunner::Task {
public:
- explicit WebTask(WebTaskList*);
- ~WebTask() override;
+ WebCallbackTask(const base::Closure& callback);
+ ~WebCallbackTask() override;
- // The main code of this task.
- // An implementation of run() should return immediately if cancel() was
- // called.
- void run() override = 0;
- virtual void cancel() = 0;
-
- protected:
- WebTaskList* task_list_;
-};
-
-class WebTaskList {
- public:
- WebTaskList();
- ~WebTaskList();
- void RegisterTask(WebTask*);
- void UnregisterTask(WebTask*);
- void RevokeAll();
+ void run() override;
private:
- std::vector<WebTask*> tasks_;
-
- DISALLOW_COPY_AND_ASSIGN(WebTaskList);
-};
-
-// A task containing an object pointer of class T. Derived classes should
-// override RunIfValid() which in turn can safely invoke methods on the
-// object_. The Class T must have "WebTaskList* mutable_task_list()".
-template <class T>
-class WebMethodTask : public WebTask {
- public:
- explicit WebMethodTask(T* object)
- : WebTask(object->mutable_task_list()), object_(object) {}
-
- virtual ~WebMethodTask() {}
-
- void run() override {
- if (object_)
- RunIfValid();
- }
-
- void cancel() override {
- object_ = 0;
- task_list_->UnregisterTask(this);
- task_list_ = 0;
- }
-
- virtual void RunIfValid() = 0;
+ base::Closure callback_;
- protected:
- T* object_;
+ DISALLOW_COPY_AND_ASSIGN(WebCallbackTask);
};
} // namespace test_runner
« no previous file with comments | « components/test_runner/test_runner.cc ('k') | components/test_runner/web_task.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698