| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTASK_H_ | 5 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTASK_H_ |
| 6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTASK_H_ | 6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTASK_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 void registerTask(WebTask*); | 34 void registerTask(WebTask*); |
| 35 void unregisterTask(WebTask*); | 35 void unregisterTask(WebTask*); |
| 36 void revokeAll(); | 36 void revokeAll(); |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 std::vector<WebTask*> m_tasks; | 39 std::vector<WebTask*> m_tasks; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 // A task containing an object pointer of class T. Derived classes should | 42 // A task containing an object pointer of class T. Derived classes should |
| 43 // override runIfValid() which in turn can safely invoke methods on the | 43 // override runIfValid() which in turn can safely invoke methods on the |
| 44 // m_object. The Class T must have "WebTaskList* taskList()". | 44 // m_object. The Class T must have "WebTaskList* mutable_task_list()". |
| 45 template<class T> | 45 template<class T> |
| 46 class WebMethodTask : public WebTask { | 46 class WebMethodTask : public WebTask { |
| 47 public: | 47 public: |
| 48 explicit WebMethodTask(T* object) | 48 explicit WebMethodTask(T* object) |
| 49 : WebTask(object->taskList()) | 49 : WebTask(object->mutable_task_list()) |
| 50 , m_object(object) | 50 , m_object(object) |
| 51 { | 51 { |
| 52 } | 52 } |
| 53 | 53 |
| 54 virtual ~WebMethodTask() { } | 54 virtual ~WebMethodTask() { } |
| 55 | 55 |
| 56 virtual void run() | 56 virtual void run() |
| 57 { | 57 { |
| 58 if (m_object) | 58 if (m_object) |
| 59 runIfValid(); | 59 runIfValid(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 virtual void cancel() | 62 virtual void cancel() |
| 63 { | 63 { |
| 64 m_object = 0; | 64 m_object = 0; |
| 65 m_taskList->unregisterTask(this); | 65 m_taskList->unregisterTask(this); |
| 66 m_taskList = 0; | 66 m_taskList = 0; |
| 67 } | 67 } |
| 68 | 68 |
| 69 virtual void runIfValid() = 0; | 69 virtual void runIfValid() = 0; |
| 70 | 70 |
| 71 protected: | 71 protected: |
| 72 T* m_object; | 72 T* m_object; |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 } // namespace content | 75 } // namespace content |
| 76 | 76 |
| 77 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTASK_H_ | 77 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTASK_H_ |
| OLD | NEW |