| 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/service_registry_android_impl.h" | 5 #include "content/browser/android/service_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 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 // static | 42 // static |
| 43 std::unique_ptr<ServiceRegistryAndroid> ServiceRegistryAndroid::Create( | 43 std::unique_ptr<ServiceRegistryAndroid> ServiceRegistryAndroid::Create( |
| 44 shell::InterfaceRegistry* interface_registry, | 44 shell::InterfaceRegistry* interface_registry, |
| 45 shell::InterfaceProvider* remote_interfaces) { | 45 shell::InterfaceProvider* remote_interfaces) { |
| 46 return base::WrapUnique(new ServiceRegistryAndroidImpl( | 46 return base::WrapUnique(new ServiceRegistryAndroidImpl( |
| 47 interface_registry, remote_interfaces)); | 47 interface_registry, remote_interfaces)); |
| 48 } | 48 } |
| 49 | 49 |
| 50 // static | 50 // static |
| 51 std::unique_ptr<ServiceRegistryAndroid> ServiceRegistryAndroid::Create( | |
| 52 ServiceRegistry* service_registry) { | |
| 53 return base::WrapUnique(new ServiceRegistryAndroidImpl(service_registry)); | |
| 54 } | |
| 55 | |
| 56 // static | |
| 57 bool ServiceRegistryAndroidImpl::Register(JNIEnv* env) { | 51 bool ServiceRegistryAndroidImpl::Register(JNIEnv* env) { |
| 58 return RegisterNativesImpl(env); | 52 return RegisterNativesImpl(env); |
| 59 } | 53 } |
| 60 | 54 |
| 61 ServiceRegistryAndroidImpl::~ServiceRegistryAndroidImpl() { | 55 ServiceRegistryAndroidImpl::~ServiceRegistryAndroidImpl() { |
| 62 Java_ServiceRegistry_destroy(AttachCurrentThread(), obj_.obj()); | 56 Java_ServiceRegistry_destroy(AttachCurrentThread(), obj_.obj()); |
| 63 } | 57 } |
| 64 | 58 |
| 65 // Constructor and destructor call into Java. | 59 // Constructor and destructor call into Java. |
| 66 ServiceRegistryAndroidImpl::ServiceRegistryAndroidImpl( | 60 ServiceRegistryAndroidImpl::ServiceRegistryAndroidImpl( |
| 67 shell::InterfaceRegistry* interface_registry, | 61 shell::InterfaceRegistry* interface_registry, |
| 68 shell::InterfaceProvider* remote_interfaces) | 62 shell::InterfaceProvider* remote_interfaces) |
| 69 : interface_registry_(interface_registry), | 63 : interface_registry_(interface_registry), |
| 70 remote_interfaces_(remote_interfaces) { | 64 remote_interfaces_(remote_interfaces) { |
| 71 JNIEnv* env = AttachCurrentThread(); | 65 JNIEnv* env = AttachCurrentThread(); |
| 72 obj_.Reset( | 66 obj_.Reset( |
| 73 env, | 67 env, |
| 74 Java_ServiceRegistry_create(env, reinterpret_cast<intptr_t>(this)).obj()); | 68 Java_ServiceRegistry_create(env, reinterpret_cast<intptr_t>(this)).obj()); |
| 75 } | 69 } |
| 76 | 70 |
| 77 ServiceRegistryAndroidImpl::ServiceRegistryAndroidImpl( | |
| 78 ServiceRegistry* service_registry) | |
| 79 : service_registry_(service_registry) { | |
| 80 JNIEnv* env = AttachCurrentThread(); | |
| 81 obj_.Reset( | |
| 82 env, | |
| 83 Java_ServiceRegistry_create(env, reinterpret_cast<intptr_t>(this)).obj()); | |
| 84 } | |
| 85 | |
| 86 | |
| 87 const base::android::ScopedJavaGlobalRef<jobject>& | 71 const base::android::ScopedJavaGlobalRef<jobject>& |
| 88 ServiceRegistryAndroidImpl::GetObj() { | 72 ServiceRegistryAndroidImpl::GetObj() { |
| 89 return obj_; | 73 return obj_; |
| 90 } | 74 } |
| 91 | 75 |
| 92 // Methods called from Java. | 76 // Methods called from Java. |
| 93 void ServiceRegistryAndroidImpl::AddService( | 77 void ServiceRegistryAndroidImpl::AddService( |
| 94 JNIEnv* env, | 78 JNIEnv* env, |
| 95 const JavaParamRef<jobject>& j_service_registry, | 79 const JavaParamRef<jobject>& j_service_registry, |
| 96 const JavaParamRef<jobject>& j_manager, | 80 const JavaParamRef<jobject>& j_manager, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 mojo::ScopedMessagePipeHandle handle((mojo::MessagePipeHandle(j_handle))); | 128 mojo::ScopedMessagePipeHandle handle((mojo::MessagePipeHandle(j_handle))); |
| 145 if (remote_interfaces_) | 129 if (remote_interfaces_) |
| 146 remote_interfaces_->GetInterface(name, std::move(handle)); | 130 remote_interfaces_->GetInterface(name, std::move(handle)); |
| 147 else if (service_registry_) | 131 else if (service_registry_) |
| 148 service_registry_->ConnectToRemoteService(name, std::move(handle)); | 132 service_registry_->ConnectToRemoteService(name, std::move(handle)); |
| 149 else | 133 else |
| 150 NOTREACHED(); | 134 NOTREACHED(); |
| 151 } | 135 } |
| 152 | 136 |
| 153 } // namespace content | 137 } // namespace content |
| OLD | NEW |