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

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

Issue 2191033002: Split ServiceRegistryAndroid into InterfaceRegistryAndroid and InterfaceProviderAndroid (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 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
« no previous file with comments | « content/shell/android/java/src/org/chromium/content_shell/ShellMojoTestUtils.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/interface_provider_android.h"
16 #include "content/public/browser/android/interface_registry_android.h"
16 #include "jni/ShellMojoTestUtils_jni.h" 17 #include "jni/ShellMojoTestUtils_jni.h"
17 #include "services/shell/public/cpp/interface_provider.h" 18 #include "services/shell/public/cpp/interface_provider.h"
18 #include "services/shell/public/cpp/interface_registry.h" 19 #include "services/shell/public/cpp/interface_registry.h"
19 20
20 namespace { 21 namespace {
21 22
22 struct TestEnvironment { 23 struct TestEnvironment {
23 base::MessageLoop message_loop; 24 base::MessageLoop message_loop;
24 std::vector<std::unique_ptr<shell::InterfaceRegistry>> registries; 25 std::vector<std::unique_ptr<shell::InterfaceRegistry>> registries;
25 std::vector<std::unique_ptr<shell::InterfaceProvider>> providers; 26 std::vector<std::unique_ptr<shell::InterfaceProvider>> providers;
26 ScopedVector<content::ServiceRegistryAndroid> wrappers; 27 std::vector<std::unique_ptr<content::InterfaceRegistryAndroid>>
28 registry_wrappers;
29 std::vector<std::unique_ptr<content::InterfaceProviderAndroid>>
30 provider_wrappers;
27 }; 31 };
28 32
29 } // namespace 33 } // namespace
30 34
31 namespace content { 35 namespace content {
32 36
33 static jlong SetupTestEnvironment(JNIEnv* env, 37 static jlong SetupTestEnvironment(JNIEnv* env,
34 const JavaParamRef<jclass>& jcaller) { 38 const JavaParamRef<jclass>& jcaller) {
35 return reinterpret_cast<intptr_t>(new TestEnvironment()); 39 return reinterpret_cast<intptr_t>(new TestEnvironment());
36 } 40 }
37 41
38 static void TearDownTestEnvironment(JNIEnv* env, 42 static void TearDownTestEnvironment(JNIEnv* env,
39 const JavaParamRef<jclass>& jcaller, 43 const JavaParamRef<jclass>& jcaller,
40 jlong test_environment) { 44 jlong test_environment) {
41 delete reinterpret_cast<TestEnvironment*>(test_environment); 45 delete reinterpret_cast<TestEnvironment*>(test_environment);
42 } 46 }
43 47
44 static ScopedJavaLocalRef<jobject> CreateServiceRegistryPair( 48 static ScopedJavaLocalRef<jobject> CreateInterfaceRegistryAndProvider(
45 JNIEnv* env, 49 JNIEnv* env,
46 const JavaParamRef<jclass>& jcaller, 50 const JavaParamRef<jclass>& jcaller,
47 jlong native_test_environment) { 51 jlong native_test_environment) {
48 TestEnvironment* test_environment = 52 TestEnvironment* test_environment =
49 reinterpret_cast<TestEnvironment*>(native_test_environment); 53 reinterpret_cast<TestEnvironment*>(native_test_environment);
50 54
51 std::unique_ptr<shell::InterfaceRegistry> registry_a( 55 std::unique_ptr<shell::InterfaceRegistry> registry(
52 new shell::InterfaceRegistry(nullptr)); 56 new shell::InterfaceRegistry(nullptr));
53 std::unique_ptr<shell::InterfaceRegistry> registry_b( 57 std::unique_ptr<shell::InterfaceProvider> provider(
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); 58 new shell::InterfaceProvider);
59 59
60 shell::mojom::InterfaceProviderPtr a_to_b; 60 shell::mojom::InterfaceProviderPtr provider_proxy;
61 shell::mojom::InterfaceProviderRequest a_to_b_request = 61 shell::mojom::InterfaceProviderRequest provider_request =
62 mojo::GetProxy(&a_to_b); 62 mojo::GetProxy(&provider_proxy);
63 provider_a->Bind(std::move(a_to_b)); 63 provider->Bind(std::move(provider_proxy));
64 registry_b->Bind(std::move(a_to_b_request)); 64 registry->Bind(std::move(provider_request));
65 65
66 shell::mojom::InterfaceProviderPtr b_to_a; 66 std::unique_ptr<content::InterfaceRegistryAndroid> registry_android(
67 shell::mojom::InterfaceProviderRequest b_to_a_request = 67 InterfaceRegistryAndroid::Create(registry.get()));
68 mojo::GetProxy(&b_to_a); 68 std::unique_ptr<content::InterfaceProviderAndroid> provider_android(
69 provider_b->Bind(std::move(b_to_a)); 69 InterfaceProviderAndroid::Create(provider.get()));
70 registry_a->Bind(std::move(b_to_a_request));
71 70
72 content::ServiceRegistryAndroid* wrapper_a = 71 ScopedJavaLocalRef<jobject> obj = Java_ShellMojoTestUtils_makePair(
73 ServiceRegistryAndroid::Create(registry_a.get(), 72 env, registry_android->GetObj().obj(), provider_android->GetObj().obj());
74 provider_a.get()).release();
75 test_environment->wrappers.push_back(wrapper_a);
76 content::ServiceRegistryAndroid* wrapper_b =
77 ServiceRegistryAndroid::Create(registry_b.get(),
78 provider_b.get()).release();
79 test_environment->wrappers.push_back(wrapper_b);
80 73
81 test_environment->registries.push_back(std::move(registry_a)); 74 test_environment->registry_wrappers.push_back(std::move(registry_android));
82 test_environment->providers.push_back(std::move(provider_a)); 75 test_environment->provider_wrappers.push_back(std::move(provider_android));
83 test_environment->registries.push_back(std::move(registry_b)); 76 test_environment->registries.push_back(std::move(registry));
84 test_environment->providers.push_back(std::move(provider_b)); 77 test_environment->providers.push_back(std::move(provider));
85 78
86 return Java_ShellMojoTestUtils_makePair(env, wrapper_a->GetObj().obj(), 79 return obj;
87 wrapper_b->GetObj().obj());
88 } 80 }
89 81
90 static void RunLoop(JNIEnv* env, 82 static void RunLoop(JNIEnv* env,
91 const JavaParamRef<jclass>& jcaller, 83 const JavaParamRef<jclass>& jcaller,
92 jlong timeout_ms) { 84 jlong timeout_ms) {
93 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 85 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
94 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), 86 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
95 base::TimeDelta::FromMilliseconds(timeout_ms)); 87 base::TimeDelta::FromMilliseconds(timeout_ms));
96 base::RunLoop run_loop; 88 base::RunLoop run_loop;
97 run_loop.Run(); 89 run_loop.Run();
98 } 90 }
99 91
100 bool RegisterShellMojoTestUtils(JNIEnv* env) { 92 bool RegisterShellMojoTestUtils(JNIEnv* env) {
101 return RegisterNativesImpl(env); 93 return RegisterNativesImpl(env);
102 } 94 }
103 95
104 } // namespace content 96 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/android/java/src/org/chromium/content_shell/ShellMojoTestUtils.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698