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(); |
} |