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

Unified Diff: base/android/scoped_java_ref.h

Issue 2219923002: JNI: allow either JavaRef or bare objects in Java calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unreachable line 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_generator/testSingleJNIAdditionalImport.golden ('k') | base/android/scoped_java_ref.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 a1b4b13f6da0116e00e64c0db3a86770fb1441a6..ba98d22d383dce4114c748e1666b53b1ac833e50 100644
--- a/base/android/scoped_java_ref.h
+++ b/base/android/scoped_java_ref.h
@@ -54,11 +54,11 @@ class BASE_EXPORT JavaRef<jobject> {
jobject obj() const { return obj_; }
- bool is_null() const { return obj_ == NULL; }
+ bool is_null() const { return obj_ == nullptr; }
protected:
- // Initializes a NULL reference. Don't add anything else here; it's inlined.
- JavaRef() : obj_(NULL) {}
+ // Initializes a null reference. Don't add anything else here; it's inlined.
+ JavaRef() : obj_(nullptr) {}
// Takes ownership of the |obj| reference passed; requires it to be a local
// reference type.
@@ -144,7 +144,7 @@ class JavaParamRef : public JavaRef<T> {
template<typename T>
class ScopedJavaLocalRef : public JavaRef<T> {
public:
- ScopedJavaLocalRef() : env_(NULL) {}
+ ScopedJavaLocalRef() : env_(nullptr) {}
// Non-explicit copy constructor, to allow ScopedJavaLocalRef to be returned
// by value as this is the normal usage pattern.
@@ -153,9 +153,8 @@ class ScopedJavaLocalRef : public JavaRef<T> {
this->SetNewLocalRef(env_, other.obj());
}
- template<typename U>
- explicit ScopedJavaLocalRef(const U& other)
- : env_(NULL) {
+ template <typename U>
+ explicit ScopedJavaLocalRef(const U& other) : env_(nullptr) {
this->Reset(other);
}
@@ -187,7 +186,7 @@ class ScopedJavaLocalRef : public JavaRef<T> {
template<typename U>
void Reset(const U& other) {
- // If |env_| was not yet set (is still NULL) it will be attached to the
+ // If |env_| was not yet set (is still null) it will be attached to the
// current thread in SetNewLocalRef().
this->Reset(env_, other.obj());
}
@@ -255,7 +254,7 @@ class ScopedJavaGlobalRef : public JavaRef<T> {
template<typename U>
void Reset(const U& other) {
- this->Reset(NULL, other.obj());
+ this->Reset(nullptr, other.obj());
}
template<typename U>
@@ -278,6 +277,22 @@ class ScopedJavaGlobalRef : public JavaRef<T> {
}
};
+// Temporary type for parameters to Java functions, to allow incremental
+// migration from bare jobject to JavaRef. Don't use outside JNI generator.
+template <typename T>
+class JavaRefOrBare {
+ public:
+ JavaRefOrBare(std::nullptr_t) : obj_(nullptr) {}
+ JavaRefOrBare(const JavaRef<T>& ref) : obj_(ref.obj()) {}
+ JavaRefOrBare(T obj) : obj_(obj) {}
+ T obj() const { return obj_; }
+
+ private:
+ T obj_;
+
+ DISALLOW_COPY_AND_ASSIGN(JavaRefOrBare);
+};
+
} // namespace android
} // namespace base
« no previous file with comments | « base/android/jni_generator/testSingleJNIAdditionalImport.golden ('k') | base/android/scoped_java_ref.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698