| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/android/java/jni_helper.h" | 5 #include "content/browser/android/java/jni_helper.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 return strcmp(jni_signature, other.jni_signature) < 0; | 37 return strcmp(jni_signature, other.jni_signature) < 0; |
| 38 } | 38 } |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 typedef std::map<MethodIdentifier, jmethodID> MethodIDMap; | 41 typedef std::map<MethodIdentifier, jmethodID> MethodIDMap; |
| 42 | 42 |
| 43 const base::subtle::AtomicWord kUnlocked = 0; | 43 const base::subtle::AtomicWord kUnlocked = 0; |
| 44 const base::subtle::AtomicWord kLocked = 1; | 44 const base::subtle::AtomicWord kLocked = 1; |
| 45 base::subtle::AtomicWord g_method_id_map_lock = kUnlocked; | 45 base::subtle::AtomicWord g_method_id_map_lock = kUnlocked; |
| 46 | 46 |
| 47 base::LazyInstance<MethodIDMap> g_method_id_map = LAZY_INSTANCE_INITIALIZER; | 47 base::LazyInstance<MethodIDMap>::DestructorAtExit g_method_id_map = |
| 48 LAZY_INSTANCE_INITIALIZER; |
| 48 | 49 |
| 49 } // namespace | 50 } // namespace |
| 50 | 51 |
| 51 jmethodID GetMethodIDFromClassName(JNIEnv* env, | 52 jmethodID GetMethodIDFromClassName(JNIEnv* env, |
| 52 const char* class_name, | 53 const char* class_name, |
| 53 const char* method, | 54 const char* method, |
| 54 const char* jni_signature) { | 55 const char* jni_signature) { |
| 55 MethodIdentifier key; | 56 MethodIdentifier key; |
| 56 key.class_name = class_name; | 57 key.class_name = class_name; |
| 57 key.method = method; | 58 key.method = method; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // Another thread may have populated the map already. | 91 // Another thread may have populated the map already. |
| 91 std::pair<MethodIDMap::const_iterator, bool> result = | 92 std::pair<MethodIDMap::const_iterator, bool> result = |
| 92 map->insert(std::make_pair(key, id)); | 93 map->insert(std::make_pair(key, id)); |
| 93 DCHECK_EQ(id, result.first->second); | 94 DCHECK_EQ(id, result.first->second); |
| 94 base::subtle::Release_Store(&g_method_id_map_lock, kUnlocked); | 95 base::subtle::Release_Store(&g_method_id_map_lock, kUnlocked); |
| 95 | 96 |
| 96 return id; | 97 return id; |
| 97 } | 98 } |
| 98 | 99 |
| 99 } // namespace content | 100 } // namespace content |
| OLD | NEW |