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

Side by Side Diff: base/android/scoped_java_ref.h

Issue 1481033002: jni: Allow nullptr to be converted to JavaParamRef. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add std:: prefix to make clang happy Created 5 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_ANDROID_SCOPED_JAVA_REF_H_ 5 #ifndef BASE_ANDROID_SCOPED_JAVA_REF_H_
6 #define BASE_ANDROID_SCOPED_JAVA_REF_H_ 6 #define BASE_ANDROID_SCOPED_JAVA_REF_H_
7 7
8 #include <jni.h> 8 #include <jni.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 // Method parameters should not be deleted, and so this class exists purely to 99 // Method parameters should not be deleted, and so this class exists purely to
100 // wrap them as a JavaRef<T> in the JNI binding generator. Do not create 100 // wrap them as a JavaRef<T> in the JNI binding generator. Do not create
101 // instances manually. 101 // instances manually.
102 template<typename T> 102 template<typename T>
103 class JavaParamRef : public JavaRef<T> { 103 class JavaParamRef : public JavaRef<T> {
104 public: 104 public:
105 // Assumes that |obj| is a parameter passed to a JNI method from Java. 105 // Assumes that |obj| is a parameter passed to a JNI method from Java.
106 // Does not assume ownership as parameters should not be deleted. 106 // Does not assume ownership as parameters should not be deleted.
107 JavaParamRef(JNIEnv* env, T obj) : JavaRef<T>(env, obj) {} 107 JavaParamRef(JNIEnv* env, T obj) : JavaRef<T>(env, obj) {}
108 108
109 // Allow nullptr to be converted to JavaParamRef. Some unit tests call JNI
110 // methods directly from C++ and pass null for objects which are not actually
111 // used by the implementation (e.g. the caller object); allow this to keep
112 // working.
113 JavaParamRef(std::nullptr_t) : JavaRef<T>() {}
114
109 ~JavaParamRef() {} 115 ~JavaParamRef() {}
110 116
111 // TODO(torne): remove this cast once we're using JavaRef consistently. 117 // TODO(torne): remove this cast once we're using JavaRef consistently.
112 // http://crbug.com/506850 118 // http://crbug.com/506850
113 operator T() const { return JavaRef<T>::obj(); } 119 operator T() const { return JavaRef<T>::obj(); }
114 120
115 private: 121 private:
116 DISALLOW_COPY_AND_ASSIGN(JavaParamRef); 122 DISALLOW_COPY_AND_ASSIGN(JavaParamRef);
117 }; 123 };
118 124
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 // is *not* a transfer of ownership and Release() should not be used. 260 // is *not* a transfer of ownership and Release() should not be used.
255 T Release() { 261 T Release() {
256 return static_cast<T>(this->ReleaseInternal()); 262 return static_cast<T>(this->ReleaseInternal());
257 } 263 }
258 }; 264 };
259 265
260 } // namespace android 266 } // namespace android
261 } // namespace base 267 } // namespace base
262 268
263 #endif // BASE_ANDROID_SCOPED_JAVA_REF_H_ 269 #endif // BASE_ANDROID_SCOPED_JAVA_REF_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698