summaryrefslogtreecommitdiffstats
path: root/base/android/scoped_java_ref.cc
diff options
context:
space:
mode:
authorreveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-08 01:01:50 +0000
committerreveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-08 01:01:50 +0000
commitb3fd32d3fc22b996f0bc5dd284331cc4bab156ff (patch)
tree6884b68590ac2acd99c691903f98ac3a72340154 /base/android/scoped_java_ref.cc
parentd48dc9bb8bdcff277771769c6da5b15338394245 (diff)
downloadchromium_src-b3fd32d3fc22b996f0bc5dd284331cc4bab156ff.zip
chromium_src-b3fd32d3fc22b996f0bc5dd284331cc4bab156ff.tar.gz
chromium_src-b3fd32d3fc22b996f0bc5dd284331cc4bab156ff.tar.bz2
base: Add ScopedJavaLocalFrame class.
This class can be used to create a local reference frame. A local reference frame ensures that some amount of local references can be created and forces all references created in the frame to be releases when exiting the frame. BUG=360069 TBR=darin Review URL: https://codereview.chromium.org/225283008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262273 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/android/scoped_java_ref.cc')
-rw-r--r--base/android/scoped_java_ref.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/base/android/scoped_java_ref.cc b/base/android/scoped_java_ref.cc
index 21b466e..bb6f503 100644
--- a/base/android/scoped_java_ref.cc
+++ b/base/android/scoped_java_ref.cc
@@ -9,6 +9,24 @@
namespace base {
namespace android {
+namespace {
+
+const int kDefaultLocalFrameCapacity = 16;
+
+} // namespace
+
+ScopedJavaLocalFrame::ScopedJavaLocalFrame(JNIEnv* env) : env_(env) {
+ int failed = env_->PushLocalFrame(kDefaultLocalFrameCapacity);
+ DCHECK(!failed);
+}
+
+ScopedJavaLocalFrame::ScopedJavaLocalFrame(JNIEnv* env, int capacity)
+ : env_(env) {
+ int failed = env_->PushLocalFrame(capacity);
+ DCHECK(!failed);
+}
+
+ScopedJavaLocalFrame::~ScopedJavaLocalFrame() { env_->PopLocalFrame(NULL); }
JavaRef<jobject>::JavaRef() : obj_(NULL) {}