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

Unified Diff: content/shell/renderer/test_runner/web_task.h

Issue 566833002: Update WebTask in chromium c++ style (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: resolved build error Created 6 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 | « content/shell/renderer/test_runner/test_runner.cc ('k') | content/shell/renderer/test_runner/web_task.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/shell/renderer/test_runner/web_task.h
diff --git a/content/shell/renderer/test_runner/web_task.h b/content/shell/renderer/test_runner/web_task.h
new file mode 100644
index 0000000000000000000000000000000000000000..437e7b8c276448d1f3dc05b3146490420b89f8e7
--- /dev/null
+++ b/content/shell/renderer/test_runner/web_task.h
@@ -0,0 +1,77 @@
+// Copyright 2013 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.
+
+#ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_TASK_H_
+#define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_TASK_H_
+
+#include <vector>
+
+#include "base/macros.h"
+
+namespace content {
+
+class WebTaskList;
+
+// WebTask represents a task which can run by WebTestDelegate::postTask() or
+// WebTestDelegate::postDelayedTask().
+class WebTask {
+ public:
+ explicit WebTask(WebTaskList*);
+ virtual ~WebTask();
+
+ // The main code of this task.
+ // An implementation of run() should return immediately if cancel() was
+ // called.
+ virtual void run() = 0;
+ virtual void cancel() = 0;
+
+ protected:
+ WebTaskList* task_list_;
+};
+
+class WebTaskList {
+ public:
+ WebTaskList();
+ ~WebTaskList();
+ void RegisterTask(WebTask*);
+ void UnregisterTask(WebTask*);
+ void RevokeAll();
+
+ 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() {}
+
+ virtual void run() {
+ if (object_)
+ RunIfValid();
+ }
+
+ virtual void cancel() {
+ object_ = 0;
+ task_list_->UnregisterTask(this);
+ task_list_ = 0;
+ }
+
+ virtual void RunIfValid() = 0;
+
+ protected:
+ T* object_;
+};
+
+} // namespace content
+
+#endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_TASK_H_
« no previous file with comments | « content/shell/renderer/test_runner/test_runner.cc ('k') | content/shell/renderer/test_runner/web_task.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698