| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/shell/browser/shell_mojo_test_utils_android.h" | 5 #include "content/shell/browser/shell_mojo_test_utils_android.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "content/browser/mojo/service_registry_android.h" | |
| 13 #include "content/common/mojo/service_registry_impl.h" | 12 #include "content/common/mojo/service_registry_impl.h" |
| 13 #include "content/public/browser/android/service_registry_android.h" |
| 14 #include "jni/ShellMojoTestUtils_jni.h" | 14 #include "jni/ShellMojoTestUtils_jni.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 struct TestEnvironment { | 18 struct TestEnvironment { |
| 19 base::MessageLoop message_loop; | 19 base::MessageLoop message_loop; |
| 20 ScopedVector<content::ServiceRegistryImpl> registries; | 20 ScopedVector<content::ServiceRegistryImpl> registries; |
| 21 ScopedVector<content::ServiceRegistryAndroid> wrappers; | |
| 22 }; | 21 }; |
| 23 | 22 |
| 24 } // namespace | 23 } // namespace |
| 25 | 24 |
| 26 namespace content { | 25 namespace content { |
| 27 | 26 |
| 28 static jlong SetupTestEnvironment(JNIEnv* env, | 27 static jlong SetupTestEnvironment(JNIEnv* env, |
| 29 const JavaParamRef<jclass>& jcaller) { | 28 const JavaParamRef<jclass>& jcaller) { |
| 30 return reinterpret_cast<intptr_t>(new TestEnvironment()); | 29 return reinterpret_cast<intptr_t>(new TestEnvironment()); |
| 31 } | 30 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 49 test_environment->registries.push_back(registry_b); | 48 test_environment->registries.push_back(registry_b); |
| 50 | 49 |
| 51 mojo::shell::mojom::InterfaceProviderPtr exposed_services_a; | 50 mojo::shell::mojom::InterfaceProviderPtr exposed_services_a; |
| 52 registry_a->Bind(GetProxy(&exposed_services_a)); | 51 registry_a->Bind(GetProxy(&exposed_services_a)); |
| 53 registry_b->BindRemoteServiceProvider(std::move(exposed_services_a)); | 52 registry_b->BindRemoteServiceProvider(std::move(exposed_services_a)); |
| 54 | 53 |
| 55 mojo::shell::mojom::InterfaceProviderPtr exposed_services_b; | 54 mojo::shell::mojom::InterfaceProviderPtr exposed_services_b; |
| 56 registry_b->Bind(GetProxy(&exposed_services_b)); | 55 registry_b->Bind(GetProxy(&exposed_services_b)); |
| 57 registry_a->BindRemoteServiceProvider(std::move(exposed_services_b)); | 56 registry_a->BindRemoteServiceProvider(std::move(exposed_services_b)); |
| 58 | 57 |
| 59 content::ServiceRegistryAndroid* wrapper_a = | 58 return Java_ShellMojoTestUtils_makePair( |
| 60 new ServiceRegistryAndroid(registry_a); | 59 env, ServiceRegistryAndroid::From(registry_a)->GetObj().obj(), |
| 61 test_environment->wrappers.push_back(wrapper_a); | 60 ServiceRegistryAndroid::From(registry_b)->GetObj().obj()); |
| 62 content::ServiceRegistryAndroid* wrapper_b = | |
| 63 new ServiceRegistryAndroid(registry_b); | |
| 64 test_environment->wrappers.push_back(wrapper_b); | |
| 65 | |
| 66 return Java_ShellMojoTestUtils_makePair(env, wrapper_a->GetObj().obj(), | |
| 67 wrapper_b->GetObj().obj()); | |
| 68 } | 61 } |
| 69 | 62 |
| 70 static void RunLoop(JNIEnv* env, | 63 static void RunLoop(JNIEnv* env, |
| 71 const JavaParamRef<jclass>& jcaller, | 64 const JavaParamRef<jclass>& jcaller, |
| 72 jlong timeout_ms) { | 65 jlong timeout_ms) { |
| 73 base::MessageLoop::current()->PostDelayedTask( | 66 base::MessageLoop::current()->PostDelayedTask( |
| 74 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 67 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 75 base::TimeDelta::FromMilliseconds(timeout_ms)); | 68 base::TimeDelta::FromMilliseconds(timeout_ms)); |
| 76 base::RunLoop run_loop; | 69 base::RunLoop run_loop; |
| 77 run_loop.Run(); | 70 run_loop.Run(); |
| 78 } | 71 } |
| 79 | 72 |
| 80 bool RegisterShellMojoTestUtils(JNIEnv* env) { | 73 bool RegisterShellMojoTestUtils(JNIEnv* env) { |
| 81 return RegisterNativesImpl(env); | 74 return RegisterNativesImpl(env); |
| 82 } | 75 } |
| 83 | 76 |
| 84 } // namespace content | 77 } // namespace content |
| OLD | NEW |