Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 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 #include "webrtc/api/java/jni/jni_helpers.h" | 10 #include "webrtc/api/java/jni/jni_helpers.h" |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 // Scope Java local references to the lifetime of this object. Use in all C++ | 265 // Scope Java local references to the lifetime of this object. Use in all C++ |
| 266 // callbacks (i.e. entry points that don't originate in a Java callstack | 266 // callbacks (i.e. entry points that don't originate in a Java callstack |
| 267 // through a "native" method call). | 267 // through a "native" method call). |
| 268 ScopedLocalRefFrame::ScopedLocalRefFrame(JNIEnv* jni) : jni_(jni) { | 268 ScopedLocalRefFrame::ScopedLocalRefFrame(JNIEnv* jni) : jni_(jni) { |
| 269 RTC_CHECK(!jni_->PushLocalFrame(0)) << "Failed to PushLocalFrame"; | 269 RTC_CHECK(!jni_->PushLocalFrame(0)) << "Failed to PushLocalFrame"; |
| 270 } | 270 } |
| 271 ScopedLocalRefFrame::~ScopedLocalRefFrame() { | 271 ScopedLocalRefFrame::~ScopedLocalRefFrame() { |
| 272 jni_->PopLocalFrame(NULL); | 272 jni_->PopLocalFrame(NULL); |
| 273 } | 273 } |
| 274 | 274 |
| 275 // Creates an iterator representing the end of any collection. | |
| 276 Iterator::Iterator() : iterator_(NULL) {} | |
|
magjed_webrtc
2016/03/22 15:15:30
nit: Use nullptr instead of NULL. This file seems
skvlad
2016/03/23 00:29:27
Thanks. I've updated the entire file to use nullpt
| |
| 277 | |
| 278 // Creates an iterator pointing to the beginning of the specified collection. | |
| 279 Iterator::Iterator(JNIEnv* jni, jobject iterable) : jni_(jni) { | |
| 280 jclass j_class = GetObjectClass(jni, iterable); | |
| 281 jmethodID iterator_id = | |
| 282 GetMethodID(jni, j_class, "iterator", "()Ljava/util/Iterator;"); | |
| 283 iterator_ = jni->CallObjectMethod(iterable, iterator_id); | |
| 284 CHECK_EXCEPTION(jni) << "error during CallObjectMethod"; | |
| 285 RTC_CHECK(iterator_ != NULL); | |
| 286 | |
| 287 jclass iterator_class = GetObjectClass(jni, iterator_); | |
| 288 has_next_id_ = GetMethodID(jni, iterator_class, "hasNext", "()Z"); | |
| 289 next_id_ = GetMethodID(jni, iterator_class, "next", "()Ljava/lang/Object;"); | |
| 290 | |
| 291 // Start at the first element in the collection. | |
| 292 ++(*this); | |
| 293 } | |
| 294 | |
| 295 // Move constructor - necessary to be able to return iterator types from | |
| 296 // functions. | |
| 297 Iterator::Iterator(Iterator&& other) | |
| 298 : jni_(std::move(other.jni_)), | |
| 299 iterator_(std::move(other.iterator_)), | |
| 300 value_(std::move(other.value_)), | |
| 301 has_next_id_(std::move(other.has_next_id_)), | |
| 302 next_id_(std::move(other.next_id_)){}; | |
|
magjed_webrtc
2016/03/22 15:15:30
nit: space between '(' and '{'. Can you use 'git c
skvlad
2016/03/23 00:29:27
Done. Curiously, "git cl format" wants to remove t
| |
| 303 | |
| 304 // Advances the iterator one step. | |
| 305 Iterator& Iterator::operator++() { | |
| 306 if (iterator_ == NULL) { | |
| 307 // Can't iterate past the end. | |
| 308 return *this; | |
| 309 } | |
| 310 bool has_next = jni_->CallBooleanMethod(iterator_, has_next_id_); | |
| 311 CHECK_EXCEPTION(jni_) << "error during CallBooleanMethod"; | |
| 312 if (!has_next) { | |
|
magjed_webrtc
2016/03/22 15:15:30
You should probably set |value_| to nullptr here a
skvlad
2016/03/23 00:29:26
Done.
| |
| 313 iterator_ = NULL; | |
| 314 return *this; | |
| 315 } | |
| 316 | |
| 317 value_ = jni_->CallObjectMethod(iterator_, next_id_); | |
| 318 CHECK_EXCEPTION(jni_) << "error during CallObjectMethod"; | |
| 319 return *this; | |
| 320 } | |
| 321 | |
| 275 } // namespace webrtc_jni | 322 } // namespace webrtc_jni |
| OLD | NEW |