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

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

Issue 1288183004: jni_generator: Make all object-returning natives return ScopedJavaLocalRef. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add some newlines for readability Created 5 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
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 "base/memory/scoped_vector.h" 7 #include "base/memory/scoped_vector.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "content/browser/mojo/service_registry_android.h" 10 #include "content/browser/mojo/service_registry_android.h"
(...skipping 15 matching lines...) Expand all
26 static jlong SetupTestEnvironment(JNIEnv* env, jclass jcaller) { 26 static jlong SetupTestEnvironment(JNIEnv* env, jclass jcaller) {
27 return reinterpret_cast<intptr_t>(new TestEnvironment()); 27 return reinterpret_cast<intptr_t>(new TestEnvironment());
28 } 28 }
29 29
30 static void TearDownTestEnvironment(JNIEnv* env, 30 static void TearDownTestEnvironment(JNIEnv* env,
31 jclass jcaller, 31 jclass jcaller,
32 jlong test_environment) { 32 jlong test_environment) {
33 delete reinterpret_cast<TestEnvironment*>(test_environment); 33 delete reinterpret_cast<TestEnvironment*>(test_environment);
34 } 34 }
35 35
36 static jobject CreateServiceRegistryPair(JNIEnv* env, 36 static ScopedJavaLocalRef<jobject> CreateServiceRegistryPair(
37 jclass jcaller, 37 JNIEnv* env,
38 jlong native_test_environment) { 38 jclass jcaller,
39 jlong native_test_environment) {
39 TestEnvironment* test_environment = 40 TestEnvironment* test_environment =
40 reinterpret_cast<TestEnvironment*>(native_test_environment); 41 reinterpret_cast<TestEnvironment*>(native_test_environment);
41 42
42 content::ServiceRegistryImpl* registry_a = new ServiceRegistryImpl(); 43 content::ServiceRegistryImpl* registry_a = new ServiceRegistryImpl();
43 test_environment->registries.push_back(registry_a); 44 test_environment->registries.push_back(registry_a);
44 content::ServiceRegistryImpl* registry_b = new ServiceRegistryImpl(); 45 content::ServiceRegistryImpl* registry_b = new ServiceRegistryImpl();
45 test_environment->registries.push_back(registry_b); 46 test_environment->registries.push_back(registry_b);
46 47
47 mojo::ServiceProviderPtr exposed_services_a; 48 mojo::ServiceProviderPtr exposed_services_a;
48 registry_a->Bind(GetProxy(&exposed_services_a)); 49 registry_a->Bind(GetProxy(&exposed_services_a));
49 registry_b->BindRemoteServiceProvider(exposed_services_a.Pass()); 50 registry_b->BindRemoteServiceProvider(exposed_services_a.Pass());
50 51
51 mojo::ServiceProviderPtr exposed_services_b; 52 mojo::ServiceProviderPtr exposed_services_b;
52 registry_b->Bind(GetProxy(&exposed_services_b)); 53 registry_b->Bind(GetProxy(&exposed_services_b));
53 registry_a->BindRemoteServiceProvider(exposed_services_b.Pass()); 54 registry_a->BindRemoteServiceProvider(exposed_services_b.Pass());
54 55
55 content::ServiceRegistryAndroid* wrapper_a = 56 content::ServiceRegistryAndroid* wrapper_a =
56 new ServiceRegistryAndroid(registry_a); 57 new ServiceRegistryAndroid(registry_a);
57 test_environment->wrappers.push_back(wrapper_a); 58 test_environment->wrappers.push_back(wrapper_a);
58 content::ServiceRegistryAndroid* wrapper_b = 59 content::ServiceRegistryAndroid* wrapper_b =
59 new ServiceRegistryAndroid(registry_b); 60 new ServiceRegistryAndroid(registry_b);
60 test_environment->wrappers.push_back(wrapper_b); 61 test_environment->wrappers.push_back(wrapper_b);
61 62
62 return Java_ShellMojoTestUtils_makePair(env, wrapper_a->GetObj().obj(), 63 return Java_ShellMojoTestUtils_makePair(env, wrapper_a->GetObj().obj(),
63 wrapper_b->GetObj().obj()).Release(); 64 wrapper_b->GetObj().obj());
64 } 65 }
65 66
66 static void RunLoop(JNIEnv* env, jclass jcaller, jlong timeout_ms) { 67 static void RunLoop(JNIEnv* env, jclass jcaller, jlong timeout_ms) {
67 base::MessageLoop::current()->PostDelayedTask( 68 base::MessageLoop::current()->PostDelayedTask(
68 FROM_HERE, 69 FROM_HERE,
69 base::MessageLoop::QuitClosure(), 70 base::MessageLoop::QuitClosure(),
70 base::TimeDelta::FromMilliseconds(timeout_ms)); 71 base::TimeDelta::FromMilliseconds(timeout_ms));
71 base::RunLoop run_loop; 72 base::RunLoop run_loop;
72 run_loop.Run(); 73 run_loop.Run();
73 } 74 }
74 75
75 bool RegisterShellMojoTestUtils(JNIEnv* env) { 76 bool RegisterShellMojoTestUtils(JNIEnv* env) {
76 return RegisterNativesImpl(env); 77 return RegisterNativesImpl(env);
77 } 78 }
78 79
79 } // namespace content 80 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698