| 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/location.h" |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/single_thread_task_runner.h" |
| 11 #include "ppapi/c/pp_errors.h" | 13 #include "ppapi/c/pp_errors.h" |
| 12 #include "ppapi/proxy/ppapi_proxy_test.h" | 14 #include "ppapi/proxy/ppapi_proxy_test.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 16 |
| 15 namespace ppapi { | 17 namespace ppapi { |
| 16 | 18 |
| 17 namespace { | 19 namespace { |
| 18 | 20 |
| 19 class TestParameter { | 21 class TestParameter { |
| 20 public: | 22 public: |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 void SetUpTestOnMainThread() override { | 108 void SetUpTestOnMainThread() override { |
| 107 ProxyAutoLock auto_lock; | 109 ProxyAutoLock auto_lock; |
| 108 | 110 |
| 109 main_thread_callback_.reset( | 111 main_thread_callback_.reset( |
| 110 ThreadAwareCallback<CallbackFunc>::Create(&MainThreadCallbackBody)); | 112 ThreadAwareCallback<CallbackFunc>::Create(&MainThreadCallbackBody)); |
| 111 } | 113 } |
| 112 | 114 |
| 113 void SetUpTestOnSecondaryThread() override { | 115 void SetUpTestOnSecondaryThread() override { |
| 114 { | 116 { |
| 115 ProxyAutoLock auto_lock; | 117 ProxyAutoLock auto_lock; |
| 116 main_thread_message_loop_proxy_->PostTask( | 118 main_thread_task_runner_->PostTask( |
| 117 FROM_HERE, | 119 FROM_HERE, base::Bind(&ThreadAwareCallbackAbortTest::DeleteCallback, |
| 118 base::Bind(&ThreadAwareCallbackAbortTest::DeleteCallback, | 120 base::Unretained(this))); |
| 119 base::Unretained(this))); | |
| 120 // |main_thread_callback_| is still valid, even if DeleteCallback() can be | 121 // |main_thread_callback_| is still valid, even if DeleteCallback() can be |
| 121 // called before this following statement. That is because |auto_lock| is | 122 // called before this following statement. That is because |auto_lock| is |
| 122 // still held by this method, which prevents DeleteCallback() from | 123 // still held by this method, which prevents DeleteCallback() from |
| 123 // deleting the callback. | 124 // deleting the callback. |
| 124 main_thread_callback_->RunOnTargetThread(this); | 125 main_thread_callback_->RunOnTargetThread(this); |
| 125 } | 126 } |
| 126 | 127 |
| 127 PostQuitForSecondaryThread(); | 128 PostQuitForSecondaryThread(); |
| 128 PostQuitForMainThread(); | 129 PostQuitForMainThread(); |
| 129 } | 130 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 1, &double_arg, &bool_arg, object_arg, object_arg); | 191 1, &double_arg, &bool_arg, object_arg, object_arg); |
| 191 | 192 |
| 192 EXPECT_EQ(6, called_num); | 193 EXPECT_EQ(6, called_num); |
| 193 } | 194 } |
| 194 | 195 |
| 195 TEST_F(ThreadAwareCallbackMultiThreadTest, RunOnTargetThread) { RunTest(); } | 196 TEST_F(ThreadAwareCallbackMultiThreadTest, RunOnTargetThread) { RunTest(); } |
| 196 | 197 |
| 197 TEST_F(ThreadAwareCallbackAbortTest, NotRunIfAborted) { RunTest(); } | 198 TEST_F(ThreadAwareCallbackAbortTest, NotRunIfAborted) { RunTest(); } |
| 198 | 199 |
| 199 } // namespace ppapi | 200 } // namespace ppapi |
| OLD | NEW |