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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/android/interface_registry_android_impl.cc
diff --git a/content/browser/android/interface_registry_android_impl.cc b/content/browser/android/interface_registry_android_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d02169203c166f6db4ff41ec267ae9bffdad1cce
--- /dev/null
+++ b/content/browser/android/interface_registry_android_impl.cc
@@ -0,0 +1,104 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/android/interface_registry_android_impl.h"
+
+#include <utility>
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_string.h"
+#include "base/callback.h"
+#include "base/memory/ptr_util.h"
+#include "jni/InterfaceRegistry_jni.h"
+#include "mojo/public/cpp/system/message_pipe.h"
+#include "services/shell/public/cpp/interface_provider.h"
+#include "services/shell/public/cpp/interface_registry.h"
+
+using base::android::AttachCurrentThread;
+using base::android::ConvertJavaStringToUTF8;
+using base::android::ScopedJavaGlobalRef;
+
+namespace content {
+
+namespace {
+
+// Callback passed to the wrapped InterfaceRegistry upon AddInterface(). The
+// InterfaceRegistry will call it to create a registered Java impl.
+void CreateImplAndAttach(
+ const ScopedJavaGlobalRef<jobject>& j_scoped_interface_registry,
+ const ScopedJavaGlobalRef<jobject>& j_scoped_manager,
+ const ScopedJavaGlobalRef<jobject>& j_scoped_factory,
+ mojo::ScopedMessagePipeHandle handle) {
+ JNIEnv* env = AttachCurrentThread();
+ Java_InterfaceRegistry_createImplAndAttach(
+ env, j_scoped_interface_registry.obj(), handle.release().value(),
+ j_scoped_manager.obj(), j_scoped_factory.obj());
+}
+
+} // namespace
+
+// static
+std::unique_ptr<InterfaceRegistryAndroid> InterfaceRegistryAndroid::Create(
+ shell::InterfaceRegistry* interface_registry) {
+ return base::WrapUnique(new InterfaceRegistryAndroidImpl(interface_registry));
+}
+
+// static
+bool InterfaceRegistryAndroidImpl::Register(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+InterfaceRegistryAndroidImpl::~InterfaceRegistryAndroidImpl() {
+ Java_InterfaceRegistry_destroy(AttachCurrentThread(), obj_.obj());
+}
+
+// Constructor and destructor call into Java.
+InterfaceRegistryAndroidImpl::InterfaceRegistryAndroidImpl(
+ shell::InterfaceRegistry* interface_registry)
+ : interface_registry_(interface_registry) {
+ JNIEnv* env = AttachCurrentThread();
+ obj_.Reset(
+ env,
+ Java_InterfaceRegistry_create(
+ env, reinterpret_cast<intptr_t>(this)).obj());
+}
+
+const base::android::ScopedJavaGlobalRef<jobject>&
+InterfaceRegistryAndroidImpl::GetObj() {
+ return obj_;
+}
+
+// Methods called from Java.
+void InterfaceRegistryAndroidImpl::AddInterface(
+ JNIEnv* env,
+ const JavaParamRef<jobject>& j_interface_registry,
+ const JavaParamRef<jobject>& j_manager,
+ const JavaParamRef<jobject>& j_factory,
+ const JavaParamRef<jstring>& j_name) {
+ std::string name(ConvertJavaStringToUTF8(env, j_name));
+
+ ScopedJavaGlobalRef<jobject> j_scoped_interface_registry;
+ j_scoped_interface_registry.Reset(env, j_interface_registry);
+
+ ScopedJavaGlobalRef<jobject> j_scoped_manager;
+ j_scoped_manager.Reset(env, j_manager);
+
+ ScopedJavaGlobalRef<jobject> j_scoped_factory;
+ j_scoped_factory.Reset(env, j_factory);
+
+ interface_registry_->AddInterface(
+ name, base::Bind(&CreateImplAndAttach, j_scoped_interface_registry,
+ j_scoped_manager, j_scoped_factory),
+ nullptr);
+}
+
+void InterfaceRegistryAndroidImpl::RemoveInterface(
+ JNIEnv* env,
+ const JavaParamRef<jobject>& j_interface_registry,
+ const JavaParamRef<jstring>& j_name) {
+ std::string name(ConvertJavaStringToUTF8(env, j_name));
+ interface_registry_->RemoveInterface(name);
+}
+
+} // namespace content
« 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