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 #ifndef BASE_ANDROID_GLOBAL_OBJECT_REGISTRY_H_ |
| 6 #define BASE_ANDROID_GLOBAL_OBJECT_REGISTRY_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <map> |
| 11 |
| 12 #include "base/android/scoped_java_ref.h" |
| 13 #include "build/build_config.h" |
| 14 |
| 15 namespace base { |
| 16 namespace android { |
| 17 |
| 18 // The GlobalObjectRegistry is a singleton object used to store and retrieve |
| 19 // Java objects from native code. It is useful during child process creation and |
| 20 // is used somehow similarlty to the way GlobalDescriptors is used to deal with |
| 21 // file descriptors. |
| 22 // It might make sense in the future to merge this class and GlobalDescriptors |
| 23 // into a unique ProcessInitiContext class. |
| 24 class BASE_EXPORT GlobalObjectRegistry final { |
| 25 public: |
| 26 typedef uint32_t Key; |
| 27 |
| 28 // Returns the singleton instance of GlobalObjectRegistry. |
| 29 static GlobalObjectRegistry* GetInstance(); |
| 30 |
| 31 // Stores |java_object| and associates it with |key|. |
| 32 void Set(Key key, const JavaRef<jobject>& java_object); |
| 33 |
| 34 ScopedJavaLocalRef<jobject> Take(Key key); |
| 35 |
| 36 private: |
| 37 GlobalObjectRegistry(); |
| 38 |
| 39 std::map<Key, ScopedJavaGlobalRef<jobject>> mappings_; |
| 40 |
| 41 DISALLOW_COPY_AND_ASSIGN(GlobalObjectRegistry); |
| 42 }; |
| 43 |
| 44 } // namespace android |
| 45 } // namespace base |
| 46 |
| 47 #endif // BASE_ANDROID_GLOBAL_OBJECT_REGISTRY_H_ |
OLD | NEW |