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

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

Issue 7491099: Update base/android to use new ScopedJava(Global)Reference (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Also fix license headers Created 9 years, 4 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/path_utils.cc » ('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 2011 Google Inc. All Rights Reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Author: michaelbai@google.com (Tao Bai) 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
3 4
4 #include "base/android/jni_array.h" 5 #include "base/android/jni_array.h"
5 6
6 #include "base/android/auto_jobject.h"
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/scoped_java_reference.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
9 10
10 namespace base { 11 namespace base {
11 namespace android { 12 namespace android {
12 13
13 jbyteArray ToJavaByteArray(JNIEnv* env, 14 jbyteArray ToJavaByteArray(JNIEnv* env,
14 const unsigned char* bytes, 15 const unsigned char* bytes,
15 size_t len) { 16 size_t len) {
16 jbyteArray byte_array = env->NewByteArray(len); 17 jbyteArray byte_array = env->NewByteArray(len);
17 if (!byte_array) { 18 if (!byte_array) {
(...skipping 12 matching lines...) Expand all
30 jobjectArray ToJavaArrayOfByteArray(JNIEnv* env, 31 jobjectArray ToJavaArrayOfByteArray(JNIEnv* env,
31 const std::vector<std::string>& v) { 32 const std::vector<std::string>& v) {
32 size_t count = v.size(); 33 size_t count = v.size();
33 DCHECK_GT(count, 0U); 34 DCHECK_GT(count, 0U);
34 jclass byte_array_class = env->FindClass("[B"); 35 jclass byte_array_class = env->FindClass("[B");
35 jobjectArray joa = env->NewObjectArray(count, byte_array_class, NULL); 36 jobjectArray joa = env->NewObjectArray(count, byte_array_class, NULL);
36 if (joa == NULL) 37 if (joa == NULL)
37 return NULL; 38 return NULL;
38 39
39 for (size_t i = 0; i < count; ++i) { 40 for (size_t i = 0; i < count; ++i) {
40 AutoJObject byte_array = AutoJObject::FromLocalRef(env, ToJavaByteArray(env, 41 ScopedJavaReference<jobject> byte_array(env, ToJavaByteArray(env,
41 reinterpret_cast<const uint8*>(v[i].data()), v[i].length())); 42 reinterpret_cast<const uint8*>(v[i].data()), v[i].length()));
42 if (!byte_array.obj()) { 43 if (!byte_array.obj()) {
43 env->DeleteLocalRef(joa); 44 env->DeleteLocalRef(joa);
44 return NULL; 45 return NULL;
45 } 46 }
46 env->SetObjectArrayElement(joa, i, byte_array.obj()); 47 env->SetObjectArrayElement(joa, i, byte_array.obj());
47 } 48 }
48 return joa; 49 return joa;
49 } 50 }
50 51
51 } // namespace android 52 } // namespace android
52 } // namespace base 53 } // namespace base
OLDNEW
« no previous file with comments | « base/android/jni_array.h ('k') | base/android/path_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698