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

Side by Side Diff: webrtc/examples/android/media_demo/jni/jni_helpers.cc

Issue 1430023005: Remove ICU usage from jni_helpers.cc. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Once more with feeling. Created 5 years, 1 month 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 | « webrtc/build/webrtc.gni ('k') | webrtc/webrtc_examples.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/examples/android/media_demo/jni/jni_helpers.h" 11 #include "webrtc/examples/android/media_demo/jni/jni_helpers.h"
12 12
13 #include <limits> 13 #include <limits>
14 14
15 #include "unicode/unistr.h"
16
17 using icu::UnicodeString;
18
19 jmethodID GetMethodID(JNIEnv* jni, jclass c, const std::string& name, 15 jmethodID GetMethodID(JNIEnv* jni, jclass c, const std::string& name,
20 const char* signature) { 16 const char* signature) {
21 jmethodID m = jni->GetMethodID(c, name.c_str(), signature); 17 jmethodID m = jni->GetMethodID(c, name.c_str(), signature);
22 CHECK_JNI_EXCEPTION(jni, "error during GetMethodID"); 18 CHECK_JNI_EXCEPTION(jni, "error during GetMethodID");
23 return m; 19 return m;
24 } 20 }
25 21
26 jlong jlongFromPointer(void* ptr) { 22 jlong jlongFromPointer(void* ptr) {
27 CHECK(sizeof(intptr_t) <= sizeof(jlong), "Time to rethink the use of jlongs"); 23 CHECK(sizeof(intptr_t) <= sizeof(jlong), "Time to rethink the use of jlongs");
28 // Going through intptr_t to be obvious about the definedness of the 24 // Going through intptr_t to be obvious about the definedness of the
29 // conversion from pointer to integral type. intptr_t to jlong is a standard 25 // conversion from pointer to integral type. intptr_t to jlong is a standard
30 // widening by the COMPILE_ASSERT above. 26 // widening by the COMPILE_ASSERT above.
31 jlong ret = reinterpret_cast<intptr_t>(ptr); 27 jlong ret = reinterpret_cast<intptr_t>(ptr);
32 CHECK(reinterpret_cast<void*>(ret) == ptr, 28 CHECK(reinterpret_cast<void*>(ret) == ptr,
33 "jlong does not convert back to pointer"); 29 "jlong does not convert back to pointer");
34 return ret; 30 return ret;
35 } 31 }
36 32
37 // Given a (UTF-16) jstring return a new UTF-8 native string. 33 // Given a (UTF-16) jstring return a new UTF-8 native string.
38 std::string JavaToStdString(JNIEnv* jni, const jstring& j_string) { 34 std::string JavaToStdString(JNIEnv* jni, const jstring& j_string) {
39 const jchar* jchars = jni->GetStringChars(j_string, NULL); 35 const char* chars = jni->GetStringUTFChars(j_string, NULL);
40 CHECK_JNI_EXCEPTION(jni, "Error during GetStringChars"); 36 CHECK_JNI_EXCEPTION(jni, "Error during GetStringUTFChars");
41 UnicodeString ustr(jchars, jni->GetStringLength(j_string)); 37 std::string str(chars, jni->GetStringUTFLength(j_string));
42 CHECK_JNI_EXCEPTION(jni, "Error during GetStringLength"); 38 CHECK_JNI_EXCEPTION(jni, "Error during GetStringUTFLength");
43 jni->ReleaseStringChars(j_string, jchars); 39 jni->ReleaseStringUTFChars(j_string, chars);
44 CHECK_JNI_EXCEPTION(jni, "Error during ReleaseStringChars"); 40 CHECK_JNI_EXCEPTION(jni, "Error during ReleaseStringUTFChars");
45 std::string ret; 41 return str;
46 return ustr.toUTF8String(ret);
47 } 42 }
48 43
49 ClassReferenceHolder::ClassReferenceHolder(JNIEnv* jni, const char** classes, 44 ClassReferenceHolder::ClassReferenceHolder(JNIEnv* jni, const char** classes,
50 int size) { 45 int size) {
51 for (int i = 0; i < size; ++i) { 46 for (int i = 0; i < size; ++i) {
52 LoadClass(jni, classes[i]); 47 LoadClass(jni, classes[i]);
53 } 48 }
54 } 49 }
55 ClassReferenceHolder::~ClassReferenceHolder() { 50 ClassReferenceHolder::~ClassReferenceHolder() {
56 CHECK(classes_.empty(), "Must call FreeReferences() before dtor!"); 51 CHECK(classes_.empty(), "Must call FreeReferences() before dtor!");
(...skipping 16 matching lines...) Expand all
73 void ClassReferenceHolder::LoadClass(JNIEnv* jni, const std::string& name) { 68 void ClassReferenceHolder::LoadClass(JNIEnv* jni, const std::string& name) {
74 jclass localRef = jni->FindClass(name.c_str()); 69 jclass localRef = jni->FindClass(name.c_str());
75 CHECK_JNI_EXCEPTION(jni, "Could not load class"); 70 CHECK_JNI_EXCEPTION(jni, "Could not load class");
76 CHECK(localRef, name.c_str()); 71 CHECK(localRef, name.c_str());
77 jclass globalRef = reinterpret_cast<jclass>(jni->NewGlobalRef(localRef)); 72 jclass globalRef = reinterpret_cast<jclass>(jni->NewGlobalRef(localRef));
78 CHECK_JNI_EXCEPTION(jni, "error during NewGlobalRef"); 73 CHECK_JNI_EXCEPTION(jni, "error during NewGlobalRef");
79 CHECK(globalRef, name.c_str()); 74 CHECK(globalRef, name.c_str());
80 bool inserted = classes_.insert(std::make_pair(name, globalRef)).second; 75 bool inserted = classes_.insert(std::make_pair(name, globalRef)).second;
81 CHECK(inserted, "Duplicate class name"); 76 CHECK(inserted, "Duplicate class name");
82 } 77 }
OLDNEW
« no previous file with comments | « webrtc/build/webrtc.gni ('k') | webrtc/webrtc_examples.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698