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

Side by Side Diff: webrtc/modules/utility/source/jvm_android.cc

Issue 1923133002: Replace the remaining scoped_ptr with unique_ptr in webrtc/modules/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Don't remove #include "scoped_ptr.h" from .h files Created 4 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 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 <android/log.h> 11 #include <android/log.h>
12 12
13 #include <memory>
14
13 #include "webrtc/modules/utility/include/jvm_android.h" 15 #include "webrtc/modules/utility/include/jvm_android.h"
14 16
15 #include "webrtc/base/checks.h" 17 #include "webrtc/base/checks.h"
16 18
17 #define TAG "JVM" 19 #define TAG "JVM"
18 #define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__) 20 #define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
19 #define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__) 21 #define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
20 22
21 namespace webrtc { 23 namespace webrtc {
22 24
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 : JavaClass(jni, clazz), jni_(jni) { 134 : JavaClass(jni, clazz), jni_(jni) {
133 ALOGD("NativeRegistration::ctor%s", GetThreadInfo().c_str()); 135 ALOGD("NativeRegistration::ctor%s", GetThreadInfo().c_str());
134 } 136 }
135 137
136 NativeRegistration::~NativeRegistration() { 138 NativeRegistration::~NativeRegistration() {
137 ALOGD("NativeRegistration::dtor%s", GetThreadInfo().c_str()); 139 ALOGD("NativeRegistration::dtor%s", GetThreadInfo().c_str());
138 jni_->UnregisterNatives(j_class_); 140 jni_->UnregisterNatives(j_class_);
139 CHECK_EXCEPTION(jni_) << "Error during UnregisterNatives"; 141 CHECK_EXCEPTION(jni_) << "Error during UnregisterNatives";
140 } 142 }
141 143
142 rtc::scoped_ptr<GlobalRef> NativeRegistration::NewObject( 144 std::unique_ptr<GlobalRef> NativeRegistration::NewObject(
143 const char* name, const char* signature, ...) { 145 const char* name, const char* signature, ...) {
144 ALOGD("NativeRegistration::NewObject%s", GetThreadInfo().c_str()); 146 ALOGD("NativeRegistration::NewObject%s", GetThreadInfo().c_str());
145 va_list args; 147 va_list args;
146 va_start(args, signature); 148 va_start(args, signature);
147 jobject obj = jni_->NewObjectV(j_class_, 149 jobject obj = jni_->NewObjectV(j_class_,
148 GetMethodID(jni_, j_class_, name, signature), 150 GetMethodID(jni_, j_class_, name, signature),
149 args); 151 args);
150 CHECK_EXCEPTION(jni_) << "Error during NewObjectV"; 152 CHECK_EXCEPTION(jni_) << "Error during NewObjectV";
151 va_end(args); 153 va_end(args);
152 return rtc::scoped_ptr<GlobalRef>(new GlobalRef(jni_, obj)); 154 return std::unique_ptr<GlobalRef>(new GlobalRef(jni_, obj));
153 } 155 }
154 156
155 // JavaClass implementation. 157 // JavaClass implementation.
156 jmethodID JavaClass::GetMethodId( 158 jmethodID JavaClass::GetMethodId(
157 const char* name, const char* signature) { 159 const char* name, const char* signature) {
158 return GetMethodID(jni_, j_class_, name, signature); 160 return GetMethodID(jni_, j_class_, name, signature);
159 } 161 }
160 162
161 jmethodID JavaClass::GetStaticMethodId( 163 jmethodID JavaClass::GetStaticMethodId(
162 const char* name, const char* signature) { 164 const char* name, const char* signature) {
(...skipping 11 matching lines...) Expand all
174 // JNIEnvironment implementation. 176 // JNIEnvironment implementation.
175 JNIEnvironment::JNIEnvironment(JNIEnv* jni) : jni_(jni) { 177 JNIEnvironment::JNIEnvironment(JNIEnv* jni) : jni_(jni) {
176 ALOGD("JNIEnvironment::ctor%s", GetThreadInfo().c_str()); 178 ALOGD("JNIEnvironment::ctor%s", GetThreadInfo().c_str());
177 } 179 }
178 180
179 JNIEnvironment::~JNIEnvironment() { 181 JNIEnvironment::~JNIEnvironment() {
180 ALOGD("JNIEnvironment::dtor%s", GetThreadInfo().c_str()); 182 ALOGD("JNIEnvironment::dtor%s", GetThreadInfo().c_str());
181 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 183 RTC_DCHECK(thread_checker_.CalledOnValidThread());
182 } 184 }
183 185
184 rtc::scoped_ptr<NativeRegistration> JNIEnvironment::RegisterNatives( 186 std::unique_ptr<NativeRegistration> JNIEnvironment::RegisterNatives(
185 const char* name, const JNINativeMethod *methods, int num_methods) { 187 const char* name, const JNINativeMethod *methods, int num_methods) {
186 ALOGD("JNIEnvironment::RegisterNatives(%s)", name); 188 ALOGD("JNIEnvironment::RegisterNatives(%s)", name);
187 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 189 RTC_DCHECK(thread_checker_.CalledOnValidThread());
188 jclass clazz = LookUpClass(name); 190 jclass clazz = LookUpClass(name);
189 jni_->RegisterNatives(clazz, methods, num_methods); 191 jni_->RegisterNatives(clazz, methods, num_methods);
190 CHECK_EXCEPTION(jni_) << "Error during RegisterNatives"; 192 CHECK_EXCEPTION(jni_) << "Error during RegisterNatives";
191 return rtc::scoped_ptr<NativeRegistration>( 193 return std::unique_ptr<NativeRegistration>(
192 new NativeRegistration(jni_, clazz)); 194 new NativeRegistration(jni_, clazz));
193 } 195 }
194 196
195 std::string JNIEnvironment::JavaToStdString(const jstring& j_string) { 197 std::string JNIEnvironment::JavaToStdString(const jstring& j_string) {
196 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 198 RTC_DCHECK(thread_checker_.CalledOnValidThread());
197 const char* jchars = jni_->GetStringUTFChars(j_string, nullptr); 199 const char* jchars = jni_->GetStringUTFChars(j_string, nullptr);
198 CHECK_EXCEPTION(jni_); 200 CHECK_EXCEPTION(jni_);
199 const int size = jni_->GetStringUTFLength(j_string); 201 const int size = jni_->GetStringUTFLength(j_string);
200 CHECK_EXCEPTION(jni_); 202 CHECK_EXCEPTION(jni_);
201 std::string ret(jchars, size); 203 std::string ret(jchars, size);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 LoadClasses(jni()); 235 LoadClasses(jni());
234 } 236 }
235 237
236 JVM::~JVM() { 238 JVM::~JVM() {
237 ALOGD("JVM::~JVM%s", GetThreadInfo().c_str()); 239 ALOGD("JVM::~JVM%s", GetThreadInfo().c_str());
238 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 240 RTC_DCHECK(thread_checker_.CalledOnValidThread());
239 FreeClassReferences(jni()); 241 FreeClassReferences(jni());
240 DeleteGlobalRef(jni(), context_); 242 DeleteGlobalRef(jni(), context_);
241 } 243 }
242 244
243 rtc::scoped_ptr<JNIEnvironment> JVM::environment() { 245 std::unique_ptr<JNIEnvironment> JVM::environment() {
244 ALOGD("JVM::environment%s", GetThreadInfo().c_str()); 246 ALOGD("JVM::environment%s", GetThreadInfo().c_str());
245 // The JNIEnv is used for thread-local storage. For this reason, we cannot 247 // The JNIEnv is used for thread-local storage. For this reason, we cannot
246 // share a JNIEnv between threads. If a piece of code has no other way to get 248 // share a JNIEnv between threads. If a piece of code has no other way to get
247 // its JNIEnv, we should share the JavaVM, and use GetEnv to discover the 249 // its JNIEnv, we should share the JavaVM, and use GetEnv to discover the
248 // thread's JNIEnv. (Assuming it has one, if not, use AttachCurrentThread). 250 // thread's JNIEnv. (Assuming it has one, if not, use AttachCurrentThread).
249 // See // http://developer.android.com/training/articles/perf-jni.html. 251 // See // http://developer.android.com/training/articles/perf-jni.html.
250 JNIEnv* jni = GetEnv(jvm_); 252 JNIEnv* jni = GetEnv(jvm_);
251 if (!jni) { 253 if (!jni) {
252 ALOGE("AttachCurrentThread() has not been called on this thread."); 254 ALOGE("AttachCurrentThread() has not been called on this thread.");
253 return rtc::scoped_ptr<JNIEnvironment>(); 255 return std::unique_ptr<JNIEnvironment>();
254 } 256 }
255 return rtc::scoped_ptr<JNIEnvironment>(new JNIEnvironment(jni)); 257 return std::unique_ptr<JNIEnvironment>(new JNIEnvironment(jni));
256 } 258 }
257 259
258 JavaClass JVM::GetClass(const char* name) { 260 JavaClass JVM::GetClass(const char* name) {
259 ALOGD("JVM::GetClass(%s)%s", name, GetThreadInfo().c_str()); 261 ALOGD("JVM::GetClass(%s)%s", name, GetThreadInfo().c_str());
260 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 262 RTC_DCHECK(thread_checker_.CalledOnValidThread());
261 return JavaClass(jni(), LookUpClass(name)); 263 return JavaClass(jni(), LookUpClass(name));
262 } 264 }
263 265
264 } // namespace webrtc 266 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/utility/include/process_thread.h ('k') | webrtc/modules/utility/source/process_thread_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698