Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_TASK_H_ | |
| 6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_TASK_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 namespace content { | |
| 11 | |
| 12 class WebTaskList; | |
| 13 | |
| 14 // WebTask represents a task which can run by WebTestDelegate::postTask() or | |
| 15 // WebTestDelegate::postDelayedTask(). | |
| 16 class WebTask { | |
| 17 public: | |
| 18 explicit WebTask(WebTaskList*); | |
| 19 virtual ~WebTask(); | |
| 20 | |
| 21 // The main code of this task. | |
| 22 // An implementation of run() should return immediately if cancel() was | |
| 23 // called. | |
| 24 virtual void run() = 0; | |
| 25 virtual void cancel() = 0; | |
| 26 | |
| 27 protected: | |
| 28 WebTaskList* task_list_; | |
| 29 }; | |
| 30 | |
| 31 class WebTaskList { | |
| 32 public: | |
| 33 WebTaskList(); | |
| 34 ~WebTaskList(); | |
| 35 void RegisterTask(WebTask*); | |
| 36 void UnregisterTask(WebTask*); | |
| 37 void RevokeAll(); | |
| 38 | |
| 39 private: | |
| 40 std::vector<WebTask*> tasks_; | |
| 41 }; | |
|
jochen (gone - plz use gerrit)
2014/09/12 07:47:03
disallow copy/assign
Abhishek
2014/09/12 08:00:09
Done.
| |
| 42 | |
| 43 // A task containing an object pointer of class T. Derived classes should | |
| 44 // override RunIfValid() which in turn can safely invoke methods on the | |
| 45 // object_. The Class T must have "WebTaskList* mutable_task_list()". | |
| 46 template <class T> | |
| 47 class WebMethodTask : public WebTask { | |
| 48 public: | |
| 49 explicit WebMethodTask(T* object) | |
| 50 : WebTask(object->mutable_task_list()), object_(object) {} | |
| 51 | |
| 52 virtual ~WebMethodTask() {} | |
| 53 | |
| 54 virtual void run() { | |
| 55 if (object_) | |
| 56 RunIfValid(); | |
| 57 } | |
| 58 | |
| 59 virtual void cancel() { | |
| 60 object_ = 0; | |
| 61 task_list_->UnregisterTask(this); | |
| 62 task_list_ = 0; | |
| 63 } | |
| 64 | |
| 65 virtual void RunIfValid() = 0; | |
| 66 | |
| 67 protected: | |
| 68 T* object_; | |
| 69 }; | |
| 70 | |
| 71 } // namespace content | |
| 72 | |
| 73 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_TASK_H_ | |
| OLD | NEW |