Index: content/public/browser/android/service_registry_android.cc |
diff --git a/content/browser/mojo/service_registry_android.cc b/content/public/browser/android/service_registry_android.cc |
similarity index 84% |
rename from content/browser/mojo/service_registry_android.cc |
rename to content/public/browser/android/service_registry_android.cc |
index 0e80e0842b589da6f1d7a33379291e7aa26df091..b6316f52065b0dcca2ab390766c29e741d33919a 100644 |
--- a/content/browser/mojo/service_registry_android.cc |
+++ b/content/public/browser/android/service_registry_android.cc |
@@ -2,14 +2,13 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "content/browser/mojo/service_registry_android.h" |
+#include "content/public/browser/android/service_registry_android.h" |
#include <utility> |
#include "base/android/jni_android.h" |
#include "base/android/jni_string.h" |
#include "base/callback.h" |
-#include "content/common/mojo/service_registry_impl.h" |
#include "jni/ServiceRegistry_jni.h" |
using base::android::AttachCurrentThread; |
@@ -20,6 +19,8 @@ namespace content { |
namespace { |
+const char kServiceRegistryAndroidKey[] = "service_registry_android"; |
+ |
// Callback passed to the wrapped ServiceRegistry upon AddService(). The |
// ServiceRegistry will call it to create a registered Java service |
void CreateImplAndAttach( |
@@ -42,14 +43,19 @@ bool ServiceRegistryAndroid::Register(JNIEnv* env) { |
return RegisterNativesImpl(env); |
} |
-// Constructor and destructor call into Java. |
-ServiceRegistryAndroid::ServiceRegistryAndroid( |
- ServiceRegistryImpl* service_registry) |
- : service_registry_(service_registry) { |
- JNIEnv* env = AttachCurrentThread(); |
- obj_.Reset( |
- env, |
- Java_ServiceRegistry_create(env, reinterpret_cast<intptr_t>(this)).obj()); |
+// static |
+ServiceRegistryAndroid* ServiceRegistryAndroid::From( |
+ ServiceRegistry* registry) { |
+ ServiceRegistryAndroid* registry_android = |
+ static_cast<ServiceRegistryAndroid*>( |
+ registry->GetUserData(kServiceRegistryAndroidKey)); |
+ |
+ if (!registry_android) { |
+ registry_android = new ServiceRegistryAndroid(registry); |
+ registry->SetUserData(kServiceRegistryAndroidKey, registry_android); |
+ } |
+ |
+ return registry_android; |
} |
ServiceRegistryAndroid::~ServiceRegistryAndroid() { |
@@ -99,4 +105,14 @@ void ServiceRegistryAndroid::ConnectToRemoteService( |
service_registry_->ConnectToRemoteService(name, std::move(handle)); |
} |
+// Constructor and destructor call into Java. |
+ServiceRegistryAndroid::ServiceRegistryAndroid( |
+ ServiceRegistry* service_registry) |
+ : service_registry_(service_registry) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ obj_.Reset( |
+ env, |
+ Java_ServiceRegistry_create(env, reinterpret_cast<intptr_t>(this)).obj()); |
+} |
+ |
} // namespace content |