OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/android/global_object_registry.h" |
| 6 |
| 7 namespace base { |
| 8 namespace android { |
| 9 |
| 10 GlobalObjectRegistry::GlobalObjectRegistry() {} |
| 11 // static |
| 12 GlobalObjectRegistry* GlobalObjectRegistry::GetInstance() { |
| 13 static GlobalObjectRegistry* instance; |
| 14 if (!instance) |
| 15 instance = new GlobalObjectRegistry(); |
| 16 return instance; |
| 17 } |
| 18 |
| 19 void GlobalObjectRegistry::Set(Key key, const JavaRef<jobject>& java_object) { |
| 20 DCHECK(mappings_.find(key) == mappings_.end()); |
| 21 mappings_[key] = ScopedJavaGlobalRef<jobject>(java_object); |
| 22 } |
| 23 |
| 24 ScopedJavaLocalRef<jobject> GlobalObjectRegistry::Take(Key key) { |
| 25 auto iter = mappings_.find(key); |
| 26 if (iter == mappings_.end()) |
| 27 return ScopedJavaLocalRef<jobject>(); |
| 28 |
| 29 ScopedJavaLocalRef<jobject> result(iter->second); |
| 30 mappings_.erase(iter); |
| 31 return result; |
| 32 } |
| 33 |
| 34 } // namespace android |
| 35 } // namespace base |
OLD | NEW |