Use libaddressinput revision 265.
[chromium-blink-merge.git] / base / android / command_line_android.cc
blob895ffab4f959cd340433bc7091fbe93ec8ee7f50
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;
16 namespace {
18 void AppendJavaStringArrayToCommandLine(JNIEnv* env,
19 jobjectArray array,
20 bool includes_program) {
21 std::vector<std::string> vec;
22 if (array)
23 base::android::AppendJavaStringArrayToStringVector(env, array, &vec);
24 if (!includes_program)
25 vec.insert(vec.begin(), "");
26 CommandLine extra_command_line(vec);
27 CommandLine::ForCurrentProcess()->AppendArguments(extra_command_line,
28 includes_program);
31 } // namespace
33 static void Reset(JNIEnv* env, jclass clazz) {
34 CommandLine::Reset();
37 static jboolean HasSwitch(JNIEnv* env, jclass clazz, jstring jswitch) {
38 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch));
39 return CommandLine::ForCurrentProcess()->HasSwitch(switch_string);
42 static jstring GetSwitchValue(JNIEnv* env, jclass clazz, jstring jswitch) {
43 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch));
44 std::string value(CommandLine::ForCurrentProcess()->GetSwitchValueNative(
45 switch_string));
46 if (value.empty())
47 return 0;
48 // OK to release, JNI binding.
49 return ConvertUTF8ToJavaString(env, value).Release();
52 static void AppendSwitch(JNIEnv* env, jclass clazz, jstring jswitch) {
53 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch));
54 CommandLine::ForCurrentProcess()->AppendSwitch(switch_string);
57 static void AppendSwitchWithValue(JNIEnv* env, jclass clazz,
58 jstring jswitch, jstring jvalue) {
59 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch));
60 std::string value_string (ConvertJavaStringToUTF8(env, jvalue));
61 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switch_string,
62 value_string);
65 static void AppendSwitchesAndArguments(JNIEnv* env, jclass clazz,
66 jobjectArray array) {
67 AppendJavaStringArrayToCommandLine(env, array, false);
70 namespace base {
71 namespace android {
73 void InitNativeCommandLineFromJavaArray(JNIEnv* env, jobjectArray array) {
74 // TODO(port): Make an overload of Init() that takes StringVector rather than
75 // have to round-trip via AppendArguments.
76 CommandLine::Init(0, NULL);
77 AppendJavaStringArrayToCommandLine(env, array, true);
80 bool RegisterCommandLine(JNIEnv* env) {
81 return RegisterNativesImpl(env);
84 } // namespace android
85 } // namespace base