Index: base/android/global_object_registry.h |
diff --git a/base/android/global_object_registry.h b/base/android/global_object_registry.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9cff32b314b62c10da9d3f8929d0948f9b123a61 |
--- /dev/null |
+++ b/base/android/global_object_registry.h |
@@ -0,0 +1,47 @@ |
+// 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. |
+ |
+#ifndef BASE_ANDROID_GLOBAL_OBJECT_REGISTRY_H_ |
+#define BASE_ANDROID_GLOBAL_OBJECT_REGISTRY_H_ |
+ |
+#include <stdint.h> |
+ |
+#include <map> |
+ |
+#include "base/android/scoped_java_ref.h" |
+#include "build/build_config.h" |
+ |
+namespace base { |
+namespace android { |
+ |
+// The GlobalObjectRegistry is a singleton object used to store and retrieve |
+// Java objects from native code. It is useful during child process creation and |
+// is used somehow similarlty to the way GlobalDescriptors is used to deal with |
+// file descriptors. |
+// It might make sense in the future to merge this class and GlobalDescriptors |
+// into a unique ProcessInitiContext class. |
+class BASE_EXPORT GlobalObjectRegistry final { |
+ public: |
+ typedef uint32_t Key; |
+ |
+ // Returns the singleton instance of GlobalObjectRegistry. |
+ static GlobalObjectRegistry* GetInstance(); |
+ |
+ // Stores |java_object| and associates it with |key|. |
+ void Set(Key key, const JavaRef<jobject>& java_object); |
+ |
+ ScopedJavaLocalRef<jobject> Take(Key key); |
+ |
+ private: |
+ GlobalObjectRegistry(); |
+ |
+ std::map<Key, ScopedJavaGlobalRef<jobject>> mappings_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(GlobalObjectRegistry); |
+}; |
+ |
+} // namespace android |
+} // namespace base |
+ |
+#endif // BASE_ANDROID_GLOBAL_OBJECT_REGISTRY_H_ |