OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/android/build_info.h" | 5 #include "base/android/build_info.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/android/context_utils.h" | 9 #include "base/android/context_utils.h" |
10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
12 #include "base/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
15 #include "jni/BuildInfo_jni.h" | 15 #include "jni/BuildInfo_jni.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // The caller takes ownership of the returned const char*. | 19 // We are leaking these strings. |
20 const char* StrDupJString(const base::android::JavaRef<jstring>& java_string) { | 20 const char* StrDupJString(const base::android::JavaRef<jstring>& java_string) { |
| 21 // Some of the Java methods on BuildInfo can return null |
| 22 // (https://crbug.com/601081), which can't be represented as a std::string, so |
| 23 // use an empty string instead. |
| 24 // TODO(bauerb): Do this only for methods that can legitimately return null. |
| 25 if (java_string.is_null()) |
| 26 return ""; |
| 27 |
21 std::string str = ConvertJavaStringToUTF8(java_string); | 28 std::string str = ConvertJavaStringToUTF8(java_string); |
22 return strdup(str.c_str()); | 29 return strdup(str.c_str()); |
23 } | 30 } |
24 | 31 |
25 } // namespace | 32 } // namespace |
26 | 33 |
27 namespace base { | 34 namespace base { |
28 namespace android { | 35 namespace android { |
29 | 36 |
30 struct BuildInfoSingletonTraits { | 37 struct BuildInfoSingletonTraits { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 java_exception_info_ = nullptr; | 88 java_exception_info_ = nullptr; |
82 } | 89 } |
83 | 90 |
84 // static | 91 // static |
85 bool BuildInfo::RegisterBindings(JNIEnv* env) { | 92 bool BuildInfo::RegisterBindings(JNIEnv* env) { |
86 return RegisterNativesImpl(env); | 93 return RegisterNativesImpl(env); |
87 } | 94 } |
88 | 95 |
89 } // namespace android | 96 } // namespace android |
90 } // namespace base | 97 } // namespace base |
OLD | NEW |