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

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

Issue 225283008: base: Add ScopedJavaLocalFrame class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Set kDefaultLocalFrameCapacity to 16. 512 is much higher than necessary and might fail. Created 6 years, 8 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 | Annotate | Revision Log
« 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 13
14 namespace base { 14 namespace base {
15 namespace android { 15 namespace android {
16 16
17 // 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 // in previous local frames are still valid in the current local frame.
20 class BASE_EXPORT ScopedJavaLocalFrame {
21 public:
22 explicit ScopedJavaLocalFrame(JNIEnv* env);
23 ScopedJavaLocalFrame(JNIEnv* env, int capacity);
24 ~ScopedJavaLocalFrame();
25
26 private:
27 // This class is only good for use on the thread it was created on so
28 // it's safe to cache the non-threadsafe JNIEnv* inside this object.
29 JNIEnv* env_;
30
31 DISALLOW_COPY_AND_ASSIGN(ScopedJavaLocalFrame);
32 };
33
17 // Forward declare the generic java reference template class. 34 // Forward declare the generic java reference template class.
18 template<typename T> class JavaRef; 35 template<typename T> class JavaRef;
19 36
20 // Template specialization of JavaRef, which acts as the base class for all 37 // Template specialization of JavaRef, which acts as the base class for all
21 // other JavaRef<> template types. This allows you to e.g. pass 38 // other JavaRef<> template types. This allows you to e.g. pass
22 // ScopedJavaLocalRef<jstring> into a function taking const JavaRef<jobject>& 39 // ScopedJavaLocalRef<jstring> into a function taking const JavaRef<jobject>&
23 template<> 40 template<>
24 class BASE_EXPORT JavaRef<jobject> { 41 class BASE_EXPORT JavaRef<jobject> {
25 public: 42 public:
26 jobject obj() const { return obj_; } 43 jobject obj() const { return obj_; }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 // global reference when it is done with it. 206 // global reference when it is done with it.
190 T Release() { 207 T Release() {
191 return static_cast<T>(this->ReleaseInternal()); 208 return static_cast<T>(this->ReleaseInternal());
192 } 209 }
193 }; 210 };
194 211
195 } // namespace android 212 } // namespace android
196 } // namespace base 213 } // namespace base
197 214
198 #endif // BASE_ANDROID_SCOPED_JAVA_REF_H_ 215 #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