OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ppapi/shared_impl/thread_aware_callback.h" | 5 #include "ppapi/shared_impl/thread_aware_callback.h" |
6 | 6 |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 // even when requested from a different thread. | 51 // even when requested from a different thread. |
52 class ThreadAwareCallbackMultiThreadTest | 52 class ThreadAwareCallbackMultiThreadTest |
53 : public proxy::PluginProxyMultiThreadTest { | 53 : public proxy::PluginProxyMultiThreadTest { |
54 public: | 54 public: |
55 ThreadAwareCallbackMultiThreadTest() : main_thread_callback_called_(false) {} | 55 ThreadAwareCallbackMultiThreadTest() : main_thread_callback_called_(false) {} |
56 virtual ~ThreadAwareCallbackMultiThreadTest() { | 56 virtual ~ThreadAwareCallbackMultiThreadTest() { |
57 CHECK(main_thread_callback_called_); | 57 CHECK(main_thread_callback_called_); |
58 } | 58 } |
59 | 59 |
60 // proxy::PluginProxyMultiThreadTest implementation. | 60 // proxy::PluginProxyMultiThreadTest implementation. |
61 virtual void SetUpTestOnMainThread() OVERRIDE { | 61 virtual void SetUpTestOnMainThread() override { |
62 ProxyAutoLock auto_lock; | 62 ProxyAutoLock auto_lock; |
63 | 63 |
64 main_thread_callback_.reset( | 64 main_thread_callback_.reset( |
65 ThreadAwareCallback<CallbackFunc>::Create(&MainThreadCallbackBody)); | 65 ThreadAwareCallback<CallbackFunc>::Create(&MainThreadCallbackBody)); |
66 } | 66 } |
67 | 67 |
68 virtual void SetUpTestOnSecondaryThread() OVERRIDE { | 68 virtual void SetUpTestOnSecondaryThread() override { |
69 { | 69 { |
70 ProxyAutoLock auto_lock; | 70 ProxyAutoLock auto_lock; |
71 main_thread_callback_->RunOnTargetThread(this); | 71 main_thread_callback_->RunOnTargetThread(this); |
72 } | 72 } |
73 | 73 |
74 PostQuitForSecondaryThread(); | 74 PostQuitForSecondaryThread(); |
75 PostQuitForMainThread(); | 75 PostQuitForMainThread(); |
76 } | 76 } |
77 | 77 |
78 private: | 78 private: |
(...skipping 17 matching lines...) Expand all Loading... |
96 }; | 96 }; |
97 | 97 |
98 // Test that when a ThreadAwareCallback instance is destroyed, pending tasks to | 98 // Test that when a ThreadAwareCallback instance is destroyed, pending tasks to |
99 // run the callback will be ignored. | 99 // run the callback will be ignored. |
100 class ThreadAwareCallbackAbortTest : public proxy::PluginProxyMultiThreadTest { | 100 class ThreadAwareCallbackAbortTest : public proxy::PluginProxyMultiThreadTest { |
101 public: | 101 public: |
102 ThreadAwareCallbackAbortTest() {} | 102 ThreadAwareCallbackAbortTest() {} |
103 virtual ~ThreadAwareCallbackAbortTest() {} | 103 virtual ~ThreadAwareCallbackAbortTest() {} |
104 | 104 |
105 // proxy::PluginProxyMultiThreadTest implementation. | 105 // proxy::PluginProxyMultiThreadTest implementation. |
106 virtual void SetUpTestOnMainThread() OVERRIDE { | 106 virtual void SetUpTestOnMainThread() override { |
107 ProxyAutoLock auto_lock; | 107 ProxyAutoLock auto_lock; |
108 | 108 |
109 main_thread_callback_.reset( | 109 main_thread_callback_.reset( |
110 ThreadAwareCallback<CallbackFunc>::Create(&MainThreadCallbackBody)); | 110 ThreadAwareCallback<CallbackFunc>::Create(&MainThreadCallbackBody)); |
111 } | 111 } |
112 | 112 |
113 virtual void SetUpTestOnSecondaryThread() OVERRIDE { | 113 virtual void SetUpTestOnSecondaryThread() override { |
114 { | 114 { |
115 ProxyAutoLock auto_lock; | 115 ProxyAutoLock auto_lock; |
116 main_thread_message_loop_proxy_->PostTask( | 116 main_thread_message_loop_proxy_->PostTask( |
117 FROM_HERE, | 117 FROM_HERE, |
118 base::Bind(&ThreadAwareCallbackAbortTest::DeleteCallback, | 118 base::Bind(&ThreadAwareCallbackAbortTest::DeleteCallback, |
119 base::Unretained(this))); | 119 base::Unretained(this))); |
120 // |main_thread_callback_| is still valid, even if DeleteCallback() can be | 120 // |main_thread_callback_| is still valid, even if DeleteCallback() can be |
121 // called before this following statement. That is because |auto_lock| is | 121 // called before this following statement. That is because |auto_lock| is |
122 // still held by this method, which prevents DeleteCallback() from | 122 // still held by this method, which prevents DeleteCallback() from |
123 // deleting the callback. | 123 // deleting the callback. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 1, &double_arg, &bool_arg, object_arg, object_arg); | 190 1, &double_arg, &bool_arg, object_arg, object_arg); |
191 | 191 |
192 EXPECT_EQ(6, called_num); | 192 EXPECT_EQ(6, called_num); |
193 } | 193 } |
194 | 194 |
195 TEST_F(ThreadAwareCallbackMultiThreadTest, RunOnTargetThread) { RunTest(); } | 195 TEST_F(ThreadAwareCallbackMultiThreadTest, RunOnTargetThread) { RunTest(); } |
196 | 196 |
197 TEST_F(ThreadAwareCallbackAbortTest, NotRunIfAborted) { RunTest(); } | 197 TEST_F(ThreadAwareCallbackAbortTest, NotRunIfAborted) { RunTest(); } |
198 | 198 |
199 } // namespace ppapi | 199 } // namespace ppapi |
OLD | NEW |