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 |