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 #include <stdint.h> | 5 #include <stdint.h> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 }, | 847 }, |
848 base::SequencedTaskRunnerHandle::Get(), run_loop.QuitClosure(), | 848 base::SequencedTaskRunnerHandle::Get(), run_loop.QuitClosure(), |
849 thread_safe_ptr); | 849 thread_safe_ptr); |
850 other_thread.message_loop()->task_runner()->PostTask(FROM_HERE, run_method); | 850 other_thread.message_loop()->task_runner()->PostTask(FROM_HERE, run_method); |
851 | 851 |
852 // Block until the method callback is called on the background thread. | 852 // Block until the method callback is called on the background thread. |
853 run_loop.Run(); | 853 run_loop.Run(); |
854 } | 854 } |
855 | 855 |
856 TEST_F(InterfacePtrTest, BindLaterThreadSafeInterfacePointer) { | 856 TEST_F(InterfacePtrTest, BindLaterThreadSafeInterfacePointer) { |
857 // Create a ThreadSafeInterfacePtr that we'll bind from a different thread. | |
858 scoped_refptr<math::ThreadSafeCalculatorPtr> thread_safe_ptr = | |
859 math::ThreadSafeCalculatorPtr::CreateUnbound(); | |
860 ASSERT_TRUE(thread_safe_ptr); | |
861 | |
862 // Create and start the thread from where we'll bind the interface pointer. | 857 // Create and start the thread from where we'll bind the interface pointer. |
863 base::Thread other_thread("service test thread"); | 858 base::Thread other_thread("service test thread"); |
864 other_thread.Start(); | 859 other_thread.Start(); |
865 const scoped_refptr<base::SingleThreadTaskRunner>& other_thread_task_runner = | 860 const scoped_refptr<base::SingleThreadTaskRunner>& other_thread_task_runner = |
866 other_thread.message_loop()->task_runner(); | 861 other_thread.message_loop()->task_runner(); |
| 862 |
| 863 // Create a ThreadSafeInterfacePtr that we'll bind from a different thread. |
| 864 scoped_refptr<math::ThreadSafeCalculatorPtr> thread_safe_ptr = |
| 865 math::ThreadSafeCalculatorPtr::CreateUnbound(other_thread_task_runner); |
| 866 ASSERT_TRUE(thread_safe_ptr); |
| 867 |
867 MathCalculatorImpl* math_calc_impl = nullptr; | 868 MathCalculatorImpl* math_calc_impl = nullptr; |
868 { | 869 { |
869 base::RunLoop run_loop; | 870 base::RunLoop run_loop; |
870 auto run_method = base::Bind( | 871 auto run_method = base::Bind( |
871 [](const scoped_refptr<base::TaskRunner>& main_task_runner, | 872 [](const scoped_refptr<base::TaskRunner>& main_task_runner, |
872 const base::Closure& quit_closure, | 873 const base::Closure& quit_closure, |
873 const scoped_refptr<math::ThreadSafeCalculatorPtr>& thread_safe_ptr, | 874 const scoped_refptr<math::ThreadSafeCalculatorPtr>& thread_safe_ptr, |
874 MathCalculatorImpl** math_calc_impl) { | 875 MathCalculatorImpl** math_calc_impl) { |
875 math::CalculatorPtr ptr; | 876 math::CalculatorPtr ptr; |
876 // In real life, the implementation would have a legitimate owner. | 877 // In real life, the implementation would have a legitimate owner. |
(...skipping 24 matching lines...) Expand all Loading... |
901 other_thread_task_runner->DeleteSoon(FROM_HERE, math_calc_impl); | 902 other_thread_task_runner->DeleteSoon(FROM_HERE, math_calc_impl); |
902 | 903 |
903 // Reset the pointer now so the InterfacePtr associated resources can be | 904 // Reset the pointer now so the InterfacePtr associated resources can be |
904 // deleted before the background thread's message loop is invalidated. | 905 // deleted before the background thread's message loop is invalidated. |
905 thread_safe_ptr = nullptr; | 906 thread_safe_ptr = nullptr; |
906 } | 907 } |
907 | 908 |
908 } // namespace | 909 } // namespace |
909 } // namespace test | 910 } // namespace test |
910 } // namespace mojo | 911 } // namespace mojo |
OLD | NEW |