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

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

Issue 10536066: android content shell bringup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync and merge Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « base/android/jni_array.h ('k') | base/android/jni_generator/jni_generator.py » ('j') | 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/jni_array.h" 5 #include "base/android/jni_array.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 CheckException(env); 60 CheckException(env);
61 61
62 for (size_t i = 0; i < v.size(); ++i) { 62 for (size_t i = 0; i < v.size(); ++i) {
63 ScopedJavaLocalRef<jstring> item = ConvertUTF16ToJavaString(env, v[i]); 63 ScopedJavaLocalRef<jstring> item = ConvertUTF16ToJavaString(env, v[i]);
64 env->SetObjectArrayElement(joa, i, item.obj()); 64 env->SetObjectArrayElement(joa, i, item.obj());
65 } 65 }
66 return ScopedJavaLocalRef<jobjectArray>(env, joa); 66 return ScopedJavaLocalRef<jobjectArray>(env, joa);
67 } 67 }
68 68
69 void AppendJavaStringArrayToStringVector(JNIEnv* env, 69 void AppendJavaStringArrayToStringVector(JNIEnv* env,
70 const JavaRef<jobjectArray>& array, 70 jobjectArray array,
71 std::vector<string16>* out) { 71 std::vector<string16>* out) {
72 DCHECK(out); 72 DCHECK(out);
73 if (array.is_null()) 73 if (!array)
74 return; 74 return;
75 jsize len = env->GetArrayLength(array.obj()); 75 jsize len = env->GetArrayLength(array);
76 for (jsize i = 0; i < len; ++i) { 76 for (jsize i = 0; i < len; ++i) {
77 ScopedJavaLocalRef<jstring> str(env, 77 ScopedJavaLocalRef<jstring> str(env,
78 static_cast<jstring>(env->GetObjectArrayElement(array.obj(), i))); 78 static_cast<jstring>(env->GetObjectArrayElement(array, i)));
79 out->push_back(ConvertJavaStringToUTF16(str)); 79 out->push_back(ConvertJavaStringToUTF16(str));
80 } 80 }
81 } 81 }
82 82
83 void AppendJavaByteArrayToByteVector(JNIEnv* env, 83 void AppendJavaByteArrayToByteVector(JNIEnv* env,
84 jbyteArray byte_array, 84 jbyteArray byte_array,
85 std::vector<uint8>* out) { 85 std::vector<uint8>* out) {
86 DCHECK(out); 86 DCHECK(out);
87 if (!byte_array) 87 if (!byte_array)
88 return; 88 return;
89 jsize len = env->GetArrayLength(byte_array); 89 jsize len = env->GetArrayLength(byte_array);
90 jbyte* bytes = env->GetByteArrayElements(byte_array, NULL); 90 jbyte* bytes = env->GetByteArrayElements(byte_array, NULL);
91 out->insert(out->end(), bytes, bytes + len); 91 out->insert(out->end(), bytes, bytes + len);
92 env->ReleaseByteArrayElements(byte_array, bytes, JNI_ABORT); 92 env->ReleaseByteArrayElements(byte_array, bytes, JNI_ABORT);
93 } 93 }
94 94
95 void JavaByteArrayToByteVector(JNIEnv* env, 95 void JavaByteArrayToByteVector(JNIEnv* env,
96 jbyteArray byte_array, 96 jbyteArray byte_array,
97 std::vector<uint8>* out) { 97 std::vector<uint8>* out) {
98 DCHECK(out); 98 DCHECK(out);
99 out->clear(); 99 out->clear();
100 AppendJavaByteArrayToByteVector(env, byte_array, out); 100 AppendJavaByteArrayToByteVector(env, byte_array, out);
101 } 101 }
102 102
103 } // namespace android 103 } // namespace android
104 } // namespace base 104 } // namespace base
OLDNEW
« no previous file with comments | « base/android/jni_array.h ('k') | base/android/jni_generator/jni_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698