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

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

Issue 1308413003: Inline constructors/destructor for JavaRef. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: also comment .cc file 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
« no previous file with comments | « no previous file | base/android/scoped_java_ref.cc » ('j') | 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
11 #include "base/base_export.h" 11 #include "base/base_export.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/logging.h"
13 14
14 namespace base { 15 namespace base {
15 namespace android { 16 namespace android {
16 17
17 // Creates a new local reference frame, in which at least a given number of 18 // Creates a new local reference frame, in which at least a given number of
18 // local references can be created. Note that local references already created 19 // local references can be created. Note that local references already created
19 // in previous local frames are still valid in the current local frame. 20 // in previous local frames are still valid in the current local frame.
20 class BASE_EXPORT ScopedJavaLocalFrame { 21 class BASE_EXPORT ScopedJavaLocalFrame {
21 public: 22 public:
22 explicit ScopedJavaLocalFrame(JNIEnv* env); 23 explicit ScopedJavaLocalFrame(JNIEnv* env);
(...skipping 15 matching lines...) Expand all
38 // other JavaRef<> template types. This allows you to e.g. pass 39 // other JavaRef<> template types. This allows you to e.g. pass
39 // ScopedJavaLocalRef<jstring> into a function taking const JavaRef<jobject>& 40 // ScopedJavaLocalRef<jstring> into a function taking const JavaRef<jobject>&
40 template<> 41 template<>
41 class BASE_EXPORT JavaRef<jobject> { 42 class BASE_EXPORT JavaRef<jobject> {
42 public: 43 public:
43 jobject obj() const { return obj_; } 44 jobject obj() const { return obj_; }
44 45
45 bool is_null() const { return obj_ == NULL; } 46 bool is_null() const { return obj_ == NULL; }
46 47
47 protected: 48 protected:
48 // Initializes a NULL reference. 49 // Initializes a NULL reference. Don't add anything else here; it's inlined.
49 JavaRef(); 50 JavaRef() : obj_(NULL) {}
50 51
51 // Takes ownership of the |obj| reference passed; requires it to be a local 52 // Takes ownership of the |obj| reference passed; requires it to be a local
52 // reference type. 53 // reference type.
54 #if DCHECK_IS_ON()
55 // Implementation contains a DCHECK; implement out-of-line when DCHECK_IS_ON.
53 JavaRef(JNIEnv* env, jobject obj); 56 JavaRef(JNIEnv* env, jobject obj);
57 #else
58 // Don't add anything else here; it's inlined.
59 JavaRef(JNIEnv* env, jobject obj) : obj_(obj) {}
60 #endif
54 61
55 ~JavaRef(); 62 // Don't add anything else here; it's inlined.
63 ~JavaRef() {}
56 64
57 // The following are implementation detail convenience methods, for 65 // The following are implementation detail convenience methods, for
58 // use by the sub-classes. 66 // use by the sub-classes.
59 JNIEnv* SetNewLocalRef(JNIEnv* env, jobject obj); 67 JNIEnv* SetNewLocalRef(JNIEnv* env, jobject obj);
60 void SetNewGlobalRef(JNIEnv* env, jobject obj); 68 void SetNewGlobalRef(JNIEnv* env, jobject obj);
61 void ResetLocalRef(JNIEnv* env); 69 void ResetLocalRef(JNIEnv* env);
62 void ResetGlobalRef(); 70 void ResetGlobalRef();
63 jobject ReleaseInternal(); 71 jobject ReleaseInternal();
64 72
65 private: 73 private:
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 // global reference when it is done with it. 216 // global reference when it is done with it.
209 T Release() { 217 T Release() {
210 return static_cast<T>(this->ReleaseInternal()); 218 return static_cast<T>(this->ReleaseInternal());
211 } 219 }
212 }; 220 };
213 221
214 } // namespace android 222 } // namespace android
215 } // namespace base 223 } // namespace base
216 224
217 #endif // BASE_ANDROID_SCOPED_JAVA_REF_H_ 225 #endif // BASE_ANDROID_SCOPED_JAVA_REF_H_
OLDNEW
« no previous file with comments | « no previous file | base/android/scoped_java_ref.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698