OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/command_line_android.h" | 5 #include "base/android/command_line_android.h" |
6 | 6 |
7 #include "base/android/jni_array.h" | 7 #include "base/android/jni_array.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 static void Reset(JNIEnv* env, jclass clazz) { | 34 static void Reset(JNIEnv* env, jclass clazz) { |
35 CommandLine::Reset(); | 35 CommandLine::Reset(); |
36 } | 36 } |
37 | 37 |
38 static jboolean HasSwitch(JNIEnv* env, jclass clazz, jstring jswitch) { | 38 static jboolean HasSwitch(JNIEnv* env, jclass clazz, jstring jswitch) { |
39 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch)); | 39 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch)); |
40 return CommandLine::ForCurrentProcess()->HasSwitch(switch_string); | 40 return CommandLine::ForCurrentProcess()->HasSwitch(switch_string); |
41 } | 41 } |
42 | 42 |
43 static jstring GetSwitchValue(JNIEnv* env, jclass clazz, jstring jswitch) { | 43 static ScopedJavaLocalRef<jstring> GetSwitchValue(JNIEnv* env, |
| 44 jclass clazz, |
| 45 jstring jswitch) { |
44 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch)); | 46 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch)); |
45 std::string value(CommandLine::ForCurrentProcess()->GetSwitchValueNative( | 47 std::string value(CommandLine::ForCurrentProcess()->GetSwitchValueNative( |
46 switch_string)); | 48 switch_string)); |
47 if (value.empty()) | 49 if (value.empty()) |
48 return 0; | 50 return ScopedJavaLocalRef<jstring>(); |
49 // OK to release, JNI binding. | 51 return ConvertUTF8ToJavaString(env, value); |
50 return ConvertUTF8ToJavaString(env, value).Release(); | |
51 } | 52 } |
52 | 53 |
53 static void AppendSwitch(JNIEnv* env, jclass clazz, jstring jswitch) { | 54 static void AppendSwitch(JNIEnv* env, jclass clazz, jstring jswitch) { |
54 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch)); | 55 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch)); |
55 CommandLine::ForCurrentProcess()->AppendSwitch(switch_string); | 56 CommandLine::ForCurrentProcess()->AppendSwitch(switch_string); |
56 } | 57 } |
57 | 58 |
58 static void AppendSwitchWithValue(JNIEnv* env, jclass clazz, | 59 static void AppendSwitchWithValue(JNIEnv* env, jclass clazz, |
59 jstring jswitch, jstring jvalue) { | 60 jstring jswitch, jstring jvalue) { |
60 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch)); | 61 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch)); |
(...skipping 16 matching lines...) Expand all Loading... |
77 CommandLine::Init(0, NULL); | 78 CommandLine::Init(0, NULL); |
78 AppendJavaStringArrayToCommandLine(env, array, true); | 79 AppendJavaStringArrayToCommandLine(env, array, true); |
79 } | 80 } |
80 | 81 |
81 bool RegisterCommandLine(JNIEnv* env) { | 82 bool RegisterCommandLine(JNIEnv* env) { |
82 return RegisterNativesImpl(env); | 83 return RegisterNativesImpl(env); |
83 } | 84 } |
84 | 85 |
85 } // namespace android | 86 } // namespace android |
86 } // namespace base | 87 } // namespace base |
OLD | NEW |