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

Side by Side Diff: content/browser/android/interface_registry_android_impl.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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/android/interface_registry_android_impl.h"
6
7 #include <utility>
8
9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h"
11 #include "base/callback.h"
12 #include "base/memory/ptr_util.h"
13 #include "jni/InterfaceRegistry_jni.h"
14 #include "mojo/public/cpp/system/message_pipe.h"
15 #include "services/shell/public/cpp/interface_provider.h"
16 #include "services/shell/public/cpp/interface_registry.h"
17
18 using base::android::AttachCurrentThread;
19 using base::android::ConvertJavaStringToUTF8;
20 using base::android::ScopedJavaGlobalRef;
21
22 namespace content {
23
24 namespace {
25
26 // Callback passed to the wrapped InterfaceRegistry upon AddInterface(). The
27 // InterfaceRegistry will call it to create a registered Java impl.
28 void CreateImplAndAttach(
29 const ScopedJavaGlobalRef<jobject>& j_scoped_interface_registry,
30 const ScopedJavaGlobalRef<jobject>& j_scoped_manager,
31 const ScopedJavaGlobalRef<jobject>& j_scoped_factory,
32 mojo::ScopedMessagePipeHandle handle) {
33 JNIEnv* env = AttachCurrentThread();
34 Java_InterfaceRegistry_createImplAndAttach(
35 env, j_scoped_interface_registry.obj(), handle.release().value(),
36 j_scoped_manager.obj(), j_scoped_factory.obj());
37 }
38
39 } // namespace
40
41 // static
42 std::unique_ptr<InterfaceRegistryAndroid> InterfaceRegistryAndroid::Create(
43 shell::InterfaceRegistry* interface_registry) {
44 return base::WrapUnique(new InterfaceRegistryAndroidImpl(interface_registry));
45 }
46
47 // static
48 bool InterfaceRegistryAndroidImpl::Register(JNIEnv* env) {
49 return RegisterNativesImpl(env);
50 }
51
52 InterfaceRegistryAndroidImpl::~InterfaceRegistryAndroidImpl() {
53 Java_InterfaceRegistry_destroy(AttachCurrentThread(), obj_.obj());
54 }
55
56 // Constructor and destructor call into Java.
57 InterfaceRegistryAndroidImpl::InterfaceRegistryAndroidImpl(
58 shell::InterfaceRegistry* interface_registry)
59 : interface_registry_(interface_registry) {
60 JNIEnv* env = AttachCurrentThread();
61 obj_.Reset(
62 env,
63 Java_InterfaceRegistry_create(
64 env, reinterpret_cast<intptr_t>(this)).obj());
65 }
66
67 const base::android::ScopedJavaGlobalRef<jobject>&
68 InterfaceRegistryAndroidImpl::GetObj() {
69 return obj_;
70 }
71
72 // Methods called from Java.
73 void InterfaceRegistryAndroidImpl::AddInterface(
74 JNIEnv* env,
75 const JavaParamRef<jobject>& j_interface_registry,
76 const JavaParamRef<jobject>& j_manager,
77 const JavaParamRef<jobject>& j_factory,
78 const JavaParamRef<jstring>& j_name) {
79 std::string name(ConvertJavaStringToUTF8(env, j_name));
80
81 ScopedJavaGlobalRef<jobject> j_scoped_interface_registry;
82 j_scoped_interface_registry.Reset(env, j_interface_registry);
83
84 ScopedJavaGlobalRef<jobject> j_scoped_manager;
85 j_scoped_manager.Reset(env, j_manager);
86
87 ScopedJavaGlobalRef<jobject> j_scoped_factory;
88 j_scoped_factory.Reset(env, j_factory);
89
90 interface_registry_->AddInterface(
91 name, base::Bind(&CreateImplAndAttach, j_scoped_interface_registry,
92 j_scoped_manager, j_scoped_factory),
93 nullptr);
94 }
95
96 void InterfaceRegistryAndroidImpl::RemoveInterface(
97 JNIEnv* env,
98 const JavaParamRef<jobject>& j_interface_registry,
99 const JavaParamRef<jstring>& j_name) {
100 std::string name(ConvertJavaStringToUTF8(env, j_name));
101 interface_registry_->RemoveInterface(name);
102 }
103
104 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/interface_registry_android_impl.h ('k') | content/browser/android/service_registry_android_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698