Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(480)

Side by Side Diff: content/shell/browser/shell_mojo_test_utils_android.cc

Issue 2099063002: Migrate RenderProcessHost, ChildThread to InterfaceRegistry/Provider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/location.h" 9 #include "base/location.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
15 #include "content/public/browser/android/service_registry_android.h" 15 #include "content/public/browser/android/service_registry_android.h"
16 #include "content/public/common/service_registry.h"
17 #include "jni/ShellMojoTestUtils_jni.h" 16 #include "jni/ShellMojoTestUtils_jni.h"
17 #include "services/shell/public/cpp/interface_provider.h"
18 #include "services/shell/public/cpp/interface_registry.h"
18 19
19 namespace { 20 namespace {
20 21
21 struct TestEnvironment { 22 struct TestEnvironment {
22 base::MessageLoop message_loop; 23 base::MessageLoop message_loop;
23 ScopedVector<content::ServiceRegistry> registries; 24 std::vector<std::unique_ptr<shell::InterfaceRegistry>> registries;
25 std::vector<std::unique_ptr<shell::InterfaceProvider>> providers;
24 ScopedVector<content::ServiceRegistryAndroid> wrappers; 26 ScopedVector<content::ServiceRegistryAndroid> wrappers;
25 }; 27 };
26 28
27 } // namespace 29 } // namespace
28 30
29 namespace content { 31 namespace content {
30 32
31 static jlong SetupTestEnvironment(JNIEnv* env, 33 static jlong SetupTestEnvironment(JNIEnv* env,
32 const JavaParamRef<jclass>& jcaller) { 34 const JavaParamRef<jclass>& jcaller) {
33 return reinterpret_cast<intptr_t>(new TestEnvironment()); 35 return reinterpret_cast<intptr_t>(new TestEnvironment());
34 } 36 }
35 37
36 static void TearDownTestEnvironment(JNIEnv* env, 38 static void TearDownTestEnvironment(JNIEnv* env,
37 const JavaParamRef<jclass>& jcaller, 39 const JavaParamRef<jclass>& jcaller,
38 jlong test_environment) { 40 jlong test_environment) {
39 delete reinterpret_cast<TestEnvironment*>(test_environment); 41 delete reinterpret_cast<TestEnvironment*>(test_environment);
40 } 42 }
41 43
42 static ScopedJavaLocalRef<jobject> CreateServiceRegistryPair( 44 static ScopedJavaLocalRef<jobject> CreateServiceRegistryPair(
43 JNIEnv* env, 45 JNIEnv* env,
44 const JavaParamRef<jclass>& jcaller, 46 const JavaParamRef<jclass>& jcaller,
45 jlong native_test_environment) { 47 jlong native_test_environment) {
46 TestEnvironment* test_environment = 48 TestEnvironment* test_environment =
47 reinterpret_cast<TestEnvironment*>(native_test_environment); 49 reinterpret_cast<TestEnvironment*>(native_test_environment);
48 50
49 content::ServiceRegistry* registry_a = ServiceRegistry::Create(); 51 std::unique_ptr<shell::InterfaceRegistry> registry_a(
50 test_environment->registries.push_back(registry_a); 52 new shell::InterfaceRegistry(nullptr));
51 content::ServiceRegistry* registry_b = ServiceRegistry::Create(); 53 std::unique_ptr<shell::InterfaceRegistry> registry_b(
52 test_environment->registries.push_back(registry_b); 54 new shell::InterfaceRegistry(nullptr));
55 std::unique_ptr<shell::InterfaceProvider> provider_a(
56 new shell::InterfaceProvider);
57 std::unique_ptr<shell::InterfaceProvider> provider_b(
58 new shell::InterfaceProvider);
53 59
54 shell::mojom::InterfaceProviderPtr exposed_services_a; 60 shell::mojom::InterfaceProviderPtr a_to_b;
55 registry_a->Bind(GetProxy(&exposed_services_a)); 61 shell::mojom::InterfaceProviderRequest a_to_b_request =
56 mojo::FuseInterface(registry_b->TakeRemoteRequest(), 62 mojo::GetProxy(&a_to_b);
57 exposed_services_a.PassInterface()); 63 provider_a->Bind(std::move(a_to_b));
64 registry_b->Bind(std::move(a_to_b_request));
58 65
59 shell::mojom::InterfaceProviderPtr exposed_services_b; 66 shell::mojom::InterfaceProviderPtr b_to_a;
60 registry_b->Bind(GetProxy(&exposed_services_b)); 67 shell::mojom::InterfaceProviderRequest b_to_a_request =
61 mojo::FuseInterface(registry_a->TakeRemoteRequest(), 68 mojo::GetProxy(&b_to_a);
62 exposed_services_b.PassInterface()); 69 provider_b->Bind(std::move(b_to_a));
70 registry_a->Bind(std::move(b_to_a_request));
63 71
64 content::ServiceRegistryAndroid* wrapper_a = 72 content::ServiceRegistryAndroid* wrapper_a =
65 ServiceRegistryAndroid::Create(registry_a).release(); 73 ServiceRegistryAndroid::Create(registry_a.get(),
74 provider_a.get()).release();
66 test_environment->wrappers.push_back(wrapper_a); 75 test_environment->wrappers.push_back(wrapper_a);
67 content::ServiceRegistryAndroid* wrapper_b = 76 content::ServiceRegistryAndroid* wrapper_b =
68 ServiceRegistryAndroid::Create(registry_b).release(); 77 ServiceRegistryAndroid::Create(registry_b.get(),
78 provider_b.get()).release();
69 test_environment->wrappers.push_back(wrapper_b); 79 test_environment->wrappers.push_back(wrapper_b);
70 80
81 test_environment->registries.push_back(std::move(registry_a));
82 test_environment->providers.push_back(std::move(provider_a));
83 test_environment->registries.push_back(std::move(registry_b));
84 test_environment->providers.push_back(std::move(provider_b));
85
71 return Java_ShellMojoTestUtils_makePair(env, wrapper_a->GetObj().obj(), 86 return Java_ShellMojoTestUtils_makePair(env, wrapper_a->GetObj().obj(),
72 wrapper_b->GetObj().obj()); 87 wrapper_b->GetObj().obj());
73 } 88 }
74 89
75 static void RunLoop(JNIEnv* env, 90 static void RunLoop(JNIEnv* env,
76 const JavaParamRef<jclass>& jcaller, 91 const JavaParamRef<jclass>& jcaller,
77 jlong timeout_ms) { 92 jlong timeout_ms) {
78 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 93 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
79 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), 94 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
80 base::TimeDelta::FromMilliseconds(timeout_ms)); 95 base::TimeDelta::FromMilliseconds(timeout_ms));
81 base::RunLoop run_loop; 96 base::RunLoop run_loop;
82 run_loop.Run(); 97 run_loop.Run();
83 } 98 }
84 99
85 bool RegisterShellMojoTestUtils(JNIEnv* env) { 100 bool RegisterShellMojoTestUtils(JNIEnv* env) {
86 return RegisterNativesImpl(env); 101 return RegisterNativesImpl(env);
87 } 102 }
88 103
89 } // namespace content 104 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698