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

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

Issue 1647803004: Move base to DEPS (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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 | « base/android/command_line_android.h ('k') | base/android/content_uri_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "base/android/command_line_android.h"
6
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"
12
13 using base::android::ConvertUTF8ToJavaString;
14 using base::android::ConvertJavaStringToUTF8;
15 using base::CommandLine;
16
17 namespace {
18
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);
30 }
31
32 } // namespace
33
34 static void Reset(JNIEnv* env, jclass clazz) {
35 CommandLine::Reset();
36 }
37
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);
41 }
42
43 static jstring GetSwitchValue(JNIEnv* env, jclass clazz, jstring jswitch) {
44 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch));
45 std::string value(CommandLine::ForCurrentProcess()->GetSwitchValueNative(
46 switch_string));
47 if (value.empty())
48 return 0;
49 // OK to release, JNI binding.
50 return ConvertUTF8ToJavaString(env, value).Release();
51 }
52
53 static void AppendSwitch(JNIEnv* env, jclass clazz, jstring jswitch) {
54 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch));
55 CommandLine::ForCurrentProcess()->AppendSwitch(switch_string);
56 }
57
58 static void AppendSwitchWithValue(JNIEnv* env, jclass clazz,
59 jstring jswitch, jstring jvalue) {
60 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch));
61 std::string value_string (ConvertJavaStringToUTF8(env, jvalue));
62 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switch_string,
63 value_string);
64 }
65
66 static void AppendSwitchesAndArguments(JNIEnv* env, jclass clazz,
67 jobjectArray array) {
68 AppendJavaStringArrayToCommandLine(env, array, false);
69 }
70
71 namespace base {
72 namespace android {
73
74 void InitNativeCommandLineFromJavaArray(JNIEnv* env, jobjectArray array) {
75 // TODO(port): Make an overload of Init() that takes StringVector rather than
76 // have to round-trip via AppendArguments.
77 CommandLine::Init(0, NULL);
78 AppendJavaStringArrayToCommandLine(env, array, true);
79 }
80
81 bool RegisterCommandLine(JNIEnv* env) {
82 return RegisterNativesImpl(env);
83 }
84
85 } // namespace android
86 } // namespace base
OLDNEW
« no previous file with comments | « base/android/command_line_android.h ('k') | base/android/content_uri_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698