Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / base / android / command_line_android.cc
blob3a2b1f2e2af2647103386ea4ab5b1eb06ada06f0
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
3 // found in the LICENSE file.
5 #include "base/android/command_line_android.h"
7 #include "base/android/jni_array.h"
8 #include "base/android/jni_string.h"
9 #include "base/command_line.h"
10 #include "base/logging.h"
11 #include "jni/CommandLine_jni.h"
13 using base::android::ConvertUTF8ToJavaString;
14 using base::android::ConvertJavaStringToUTF8;
15 using base::CommandLine;
17 namespace {
19 void AppendJavaStringArrayToCommandLine(JNIEnv* env,
20 jobjectArray array,
21 bool includes_program) {
22 std::vector<std::string> vec;
23 if (array)
24 base::android::AppendJavaStringArrayToStringVector(env, array, &vec);
25 if (!includes_program)
26 vec.insert(vec.begin(), "");
27 CommandLine extra_command_line(vec);
28 CommandLine::ForCurrentProcess()->AppendArguments(extra_command_line,
29 includes_program);
32 } // namespace
34 static void Reset(JNIEnv* env, jclass clazz) {
35 CommandLine::Reset();
38 static jboolean HasSwitch(JNIEnv* env, jclass clazz, jstring jswitch) {
39 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch));
40 return CommandLine::ForCurrentProcess()->HasSwitch(switch_string);
43 static ScopedJavaLocalRef<jstring> GetSwitchValue(JNIEnv* env,
44 jclass clazz,
45 jstring jswitch) {
46 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch));
47 std::string value(CommandLine::ForCurrentProcess()->GetSwitchValueNative(
48 switch_string));
49 if (value.empty())
50 return ScopedJavaLocalRef<jstring>();
51 return ConvertUTF8ToJavaString(env, value);
54 static void AppendSwitch(JNIEnv* env, jclass clazz, jstring jswitch) {
55 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch));
56 CommandLine::ForCurrentProcess()->AppendSwitch(switch_string);
59 static void AppendSwitchWithValue(JNIEnv* env, jclass clazz,
60 jstring jswitch, jstring jvalue) {
61 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch));
62 std::string value_string (ConvertJavaStringToUTF8(env, jvalue));
63 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switch_string,
64 value_string);
67 static void AppendSwitchesAndArguments(JNIEnv* env, jclass clazz,
68 jobjectArray array) {
69 AppendJavaStringArrayToCommandLine(env, array, false);
72 namespace base {
73 namespace android {
75 void InitNativeCommandLineFromJavaArray(JNIEnv* env, jobjectArray array) {
76 // TODO(port): Make an overload of Init() that takes StringVector rather than
77 // have to round-trip via AppendArguments.
78 CommandLine::Init(0, NULL);
79 AppendJavaStringArrayToCommandLine(env, array, true);
82 bool RegisterCommandLine(JNIEnv* env) {
83 return RegisterNativesImpl(env);
86 } // namespace android
87 } // namespace base