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

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

Issue 110533009: Import TestRunner library into chromium. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 7 years 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/WebScopedPtr.h ('k') | content/shell/renderer/test_runner/WebTask.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/shell/renderer/test_runner/WebTask.h
diff --git a/content/shell/renderer/test_runner/WebTask.h b/content/shell/renderer/test_runner/WebTask.h
new file mode 100644
index 0000000000000000000000000000000000000000..3f8a23468dded7512d2967d114502da026f1f7df
--- /dev/null
+++ b/content/shell/renderer/test_runner/WebTask.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 WebTask_h
+#define WebTask_h
+
+#include <vector>
+
+namespace WebTestRunner {
+
+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* m_taskList;
+};
+
+class WebTaskList {
+public:
+ WebTaskList();
+ ~WebTaskList();
+ void registerTask(WebTask*);
+ void unregisterTask(WebTask*);
+ void revokeAll();
+
+private:
+ std::vector<WebTask*> m_tasks;
+};
+
+// A task containing an object pointer of class T. Derived classes should
+// override runIfValid() which in turn can safely invoke methods on the
+// m_object. The Class T must have "WebTaskList* taskList()".
+template<class T>
+class WebMethodTask : public WebTask {
+public:
+ explicit WebMethodTask(T* object)
+ : WebTask(object->taskList())
+ , m_object(object)
+ {
+ }
+
+ virtual ~WebMethodTask() { }
+
+ virtual void run()
+ {
+ if (m_object)
+ runIfValid();
+ }
+
+ virtual void cancel()
+ {
+ m_object = 0;
+ m_taskList->unregisterTask(this);
+ m_taskList = 0;
+ }
+
+ virtual void runIfValid() = 0;
+
+protected:
+ T* m_object;
+};
+
+}
+
+#endif // WebTask_h
« no previous file with comments | « content/shell/renderer/test_runner/WebScopedPtr.h ('k') | content/shell/renderer/test_runner/WebTask.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698