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

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

Issue 1294333002: Fix wrong usages of ScopedJavaLocalRef::Release(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comment to Release() explaining it should not be used to call java methods Created 5 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 unified diff | Download patch
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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 this->Reset(env_, other.obj()); 147 this->Reset(env_, other.obj());
148 } 148 }
149 149
150 template<typename U> 150 template<typename U>
151 void Reset(JNIEnv* env, U obj) { 151 void Reset(JNIEnv* env, U obj) {
152 implicit_cast<T>(obj); // Ensure U is assignable to T 152 implicit_cast<T>(obj); // Ensure U is assignable to T
153 env_ = this->SetNewLocalRef(env, obj); 153 env_ = this->SetNewLocalRef(env, obj);
154 } 154 }
155 155
156 // Releases the local reference to the caller. The caller *must* delete the 156 // Releases the local reference to the caller. The caller *must* delete the
157 // local reference when it is done with it. 157 // local reference when it is done with it. Note that calling a Java method
158 // is *not* a transfer of ownership and Release() should not be used.
158 T Release() { 159 T Release() {
159 return static_cast<T>(this->ReleaseInternal()); 160 return static_cast<T>(this->ReleaseInternal());
160 } 161 }
161 162
162 private: 163 private:
163 // This class is only good for use on the thread it was created on so 164 // This class is only good for use on the thread it was created on so
164 // it's safe to cache the non-threadsafe JNIEnv* inside this object. 165 // it's safe to cache the non-threadsafe JNIEnv* inside this object.
165 JNIEnv* env_; 166 JNIEnv* env_;
166 }; 167 };
167 168
(...skipping 30 matching lines...) Expand all
198 this->Reset(NULL, other.obj()); 199 this->Reset(NULL, other.obj());
199 } 200 }
200 201
201 template<typename U> 202 template<typename U>
202 void Reset(JNIEnv* env, U obj) { 203 void Reset(JNIEnv* env, U obj) {
203 implicit_cast<T>(obj); // Ensure U is assignable to T 204 implicit_cast<T>(obj); // Ensure U is assignable to T
204 this->SetNewGlobalRef(env, obj); 205 this->SetNewGlobalRef(env, obj);
205 } 206 }
206 207
207 // Releases the global reference to the caller. The caller *must* delete the 208 // Releases the global reference to the caller. The caller *must* delete the
208 // global reference when it is done with it. 209 // global reference when it is done with it. Note that calling a Java method
210 // is *not* a transfer of ownership and Release() should not be used.
209 T Release() { 211 T Release() {
210 return static_cast<T>(this->ReleaseInternal()); 212 return static_cast<T>(this->ReleaseInternal());
211 } 213 }
212 }; 214 };
213 215
214 } // namespace android 216 } // namespace android
215 } // namespace base 217 } // namespace base
216 218
217 #endif // BASE_ANDROID_SCOPED_JAVA_REF_H_ 219 #endif // BASE_ANDROID_SCOPED_JAVA_REF_H_
OLDNEW
« no previous file with comments | « base/android/java_handler_thread.cc ('k') | chrome/browser/android/history_report/history_report_jni_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698