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

Unified Diff: content/public/browser/android/service_registry_android.cc

Issue 1831173002: Scaffolding for Android implementation of PaymentRequest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo
Patch Set: Cleanup Created 4 years, 8 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/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

Powered by Google App Engine
This is Rietveld 408576698