Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(427)

Side by Side Diff: base/android/build_info.cc

Issue 1866023002: [Android] Handle null values in BuildInfo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698