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

Unified Diff: base/android/scoped_java_ref.h

Issue 2268553002: Small improvements to JNI references. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Learn about, and then fix, the most vexing parse. :) Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/android/jni_weak_ref.cc ('k') | base/android/scoped_java_ref_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/scoped_java_ref.h
diff --git a/base/android/scoped_java_ref.h b/base/android/scoped_java_ref.h
index ba98d22d383dce4114c748e1666b53b1ac833e50..cf8edc984626f8fd61564d876b137980f8b2d5f1 100644
--- a/base/android/scoped_java_ref.h
+++ b/base/android/scoped_java_ref.h
@@ -9,6 +9,7 @@
#include <stddef.h>
#include <type_traits>
+#include <utility>
#include "base/base_export.h"
#include "base/logging.h"
@@ -70,6 +71,8 @@ class BASE_EXPORT JavaRef<jobject> {
JavaRef(JNIEnv* env, jobject obj) : obj_(obj) {}
#endif
+ void swap(JavaRef& other) { std::swap(obj_, other.obj_); }
+
// The following are implementation detail convenience methods, for
// use by the sub-classes.
JNIEnv* SetNewLocalRef(JNIEnv* env, jobject obj);
@@ -153,6 +156,10 @@ class ScopedJavaLocalRef : public JavaRef<T> {
this->SetNewLocalRef(env_, other.obj());
}
+ ScopedJavaLocalRef(ScopedJavaLocalRef<T>&& other) : env_(other.env_) {
+ this->swap(other);
+ }
+
template <typename U>
explicit ScopedJavaLocalRef(const U& other) : env_(nullptr) {
this->Reset(other);
@@ -172,6 +179,11 @@ class ScopedJavaLocalRef : public JavaRef<T> {
this->Reset(other);
}
+ void operator=(ScopedJavaLocalRef<T>&& other) {
+ env_ = other.env_;
+ this->swap(other);
+ }
+
void Reset() {
this->ResetLocalRef(env_);
}
@@ -231,6 +243,8 @@ class ScopedJavaGlobalRef : public JavaRef<T> {
this->Reset(other);
}
+ ScopedJavaGlobalRef(ScopedJavaGlobalRef<T>&& other) { this->swap(other); }
+
ScopedJavaGlobalRef(JNIEnv* env, T obj) { this->Reset(env, obj); }
template<typename U>
@@ -248,6 +262,8 @@ class ScopedJavaGlobalRef : public JavaRef<T> {
this->Reset(other);
}
+ void operator=(ScopedJavaGlobalRef<T>&& other) { this->swap(other); }
+
void Reset() {
this->ResetGlobalRef();
}
« no previous file with comments | « base/android/jni_weak_ref.cc ('k') | base/android/scoped_java_ref_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698