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

Unified Diff: base/android/global_object_registry.cc

Issue 2735113003: Changing SpawnChild to return a struct.
Patch Set: Created 3 years, 9 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: base/android/global_object_registry.cc
diff --git a/base/android/global_object_registry.cc b/base/android/global_object_registry.cc
new file mode 100644
index 0000000000000000000000000000000000000000..371bb0374f95597f9cc631f692260dac36ee0d71
--- /dev/null
+++ b/base/android/global_object_registry.cc
@@ -0,0 +1,35 @@
+// Copyright 2017 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 "base/android/global_object_registry.h"
+
+namespace base {
+namespace android {
+
+GlobalObjectRegistry::GlobalObjectRegistry() {}
+// static
+GlobalObjectRegistry* GlobalObjectRegistry::GetInstance() {
+ static GlobalObjectRegistry* instance;
+ if (!instance)
+ instance = new GlobalObjectRegistry();
+ return instance;
+}
+
+void GlobalObjectRegistry::Set(Key key, const JavaRef<jobject>& java_object) {
+ DCHECK(mappings_.find(key) == mappings_.end());
+ mappings_[key] = ScopedJavaGlobalRef<jobject>(java_object);
+}
+
+ScopedJavaLocalRef<jobject> GlobalObjectRegistry::Take(Key key) {
+ auto iter = mappings_.find(key);
+ if (iter == mappings_.end())
+ return ScopedJavaLocalRef<jobject>();
+
+ ScopedJavaLocalRef<jobject> result(iter->second);
+ mappings_.erase(iter);
+ return result;
+}
+
+} // namespace android
+} // namespace base
« no previous file with comments | « base/android/global_object_registry.h ('k') | base/android/java/src/org/chromium/base/IParcelableChannel.aidl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698