| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/browser/android/interface_registry_android_impl.h" | 5 #include "content/browser/android/interface_registry_android_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 // Callback passed to the wrapped InterfaceRegistry upon AddInterface(). The | 28 // Callback passed to the wrapped InterfaceRegistry upon AddInterface(). The |
| 29 // InterfaceRegistry will call it to create a registered Java impl. | 29 // InterfaceRegistry will call it to create a registered Java impl. |
| 30 void CreateImplAndAttach( | 30 void CreateImplAndAttach( |
| 31 const ScopedJavaGlobalRef<jobject>& j_scoped_interface_registry, | 31 const ScopedJavaGlobalRef<jobject>& j_scoped_interface_registry, |
| 32 const ScopedJavaGlobalRef<jobject>& j_scoped_manager, | 32 const ScopedJavaGlobalRef<jobject>& j_scoped_manager, |
| 33 const ScopedJavaGlobalRef<jobject>& j_scoped_factory, | 33 const ScopedJavaGlobalRef<jobject>& j_scoped_factory, |
| 34 mojo::ScopedMessagePipeHandle handle) { | 34 mojo::ScopedMessagePipeHandle handle) { |
| 35 JNIEnv* env = AttachCurrentThread(); | 35 JNIEnv* env = AttachCurrentThread(); |
| 36 Java_InterfaceRegistry_createImplAndAttach( | 36 Java_InterfaceRegistry_createImplAndAttach( |
| 37 env, j_scoped_interface_registry.obj(), handle.release().value(), | 37 env, j_scoped_interface_registry, handle.release().value(), |
| 38 j_scoped_manager.obj(), j_scoped_factory.obj()); | 38 j_scoped_manager, j_scoped_factory); |
| 39 } | 39 } |
| 40 | 40 |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 // static | 43 // static |
| 44 std::unique_ptr<InterfaceRegistryAndroid> InterfaceRegistryAndroid::Create( | 44 std::unique_ptr<InterfaceRegistryAndroid> InterfaceRegistryAndroid::Create( |
| 45 shell::InterfaceRegistry* interface_registry) { | 45 shell::InterfaceRegistry* interface_registry) { |
| 46 return base::WrapUnique(new InterfaceRegistryAndroidImpl(interface_registry)); | 46 return base::WrapUnique(new InterfaceRegistryAndroidImpl(interface_registry)); |
| 47 } | 47 } |
| 48 | 48 |
| 49 // static | 49 // static |
| 50 bool InterfaceRegistryAndroidImpl::Register(JNIEnv* env) { | 50 bool InterfaceRegistryAndroidImpl::Register(JNIEnv* env) { |
| 51 return RegisterNativesImpl(env); | 51 return RegisterNativesImpl(env); |
| 52 } | 52 } |
| 53 | 53 |
| 54 InterfaceRegistryAndroidImpl::~InterfaceRegistryAndroidImpl() { | 54 InterfaceRegistryAndroidImpl::~InterfaceRegistryAndroidImpl() { |
| 55 Java_InterfaceRegistry_destroy(AttachCurrentThread(), obj_.obj()); | 55 Java_InterfaceRegistry_destroy(AttachCurrentThread(), obj_); |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Constructor and destructor call into Java. | 58 // Constructor and destructor call into Java. |
| 59 InterfaceRegistryAndroidImpl::InterfaceRegistryAndroidImpl( | 59 InterfaceRegistryAndroidImpl::InterfaceRegistryAndroidImpl( |
| 60 shell::InterfaceRegistry* interface_registry) | 60 shell::InterfaceRegistry* interface_registry) |
| 61 : interface_registry_(interface_registry) { | 61 : interface_registry_(interface_registry) { |
| 62 JNIEnv* env = AttachCurrentThread(); | 62 JNIEnv* env = AttachCurrentThread(); |
| 63 obj_.Reset( | 63 obj_.Reset( |
| 64 env, | 64 env, |
| 65 Java_InterfaceRegistry_create( | 65 Java_InterfaceRegistry_create( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 101 |
| 102 void InterfaceRegistryAndroidImpl::RemoveInterface( | 102 void InterfaceRegistryAndroidImpl::RemoveInterface( |
| 103 JNIEnv* env, | 103 JNIEnv* env, |
| 104 const JavaParamRef<jobject>& j_interface_registry, | 104 const JavaParamRef<jobject>& j_interface_registry, |
| 105 const JavaParamRef<jstring>& j_name) { | 105 const JavaParamRef<jstring>& j_name) { |
| 106 std::string name(ConvertJavaStringToUTF8(env, j_name)); | 106 std::string name(ConvertJavaStringToUTF8(env, j_name)); |
| 107 interface_registry_->RemoveInterface(name); | 107 interface_registry_->RemoveInterface(name); |
| 108 } | 108 } |
| 109 | 109 |
| 110 } // namespace content | 110 } // namespace content |
| OLD | NEW |