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

Unified Diff: base/android/auto_jobject.cc

Issue 7480016: Add AutoJObject and AutoGlobalJObject (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Updated base.gypi to exclude android directory for any non-Android OS Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/android/auto_jobject.h ('k') | base/base.gypi » ('j') | base/base.gypi » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/auto_jobject.cc
diff --git a/base/android/auto_jobject.cc b/base/android/auto_jobject.cc
new file mode 100644
index 0000000000000000000000000000000000000000..04acd28377cbf51cd4f77c3d88311865023f60ac
--- /dev/null
+++ b/base/android/auto_jobject.cc
@@ -0,0 +1,47 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/android/auto_jobject.h"
+
+#include <stddef.h>
+
+namespace base {
+namespace android {
+
+AutoJObject AutoJObject::FromLocalRef(JNIEnv* env, jobject obj) {
+ return AutoJObject(env, obj);
+}
+
+AutoJObject::AutoJObject(const AutoJObject& other)
+ : env_(other.env_),
+ obj_(other.obj_ ? other.env_->NewLocalRef(other.obj_) : NULL) {
+}
+
+AutoJObject::AutoJObject(JNIEnv* env, jobject obj)
+ : env_(env),
+ obj_(obj) {
+}
+
+AutoJObject::~AutoJObject() {
+ if (obj_)
+ env_->DeleteLocalRef(obj_);
+}
+
+JNIEnv* AutoJObject::env() const {
+ return env_;
+}
+
+jobject AutoJObject::obj() const {
+ return obj_;
+}
+
+jobject AutoJObject::Release() {
+ jobject obj = obj_;
+ obj_ = 0;
bulach 2011/07/26 18:23:04 nit: NULL
+ return obj;
+}
+
+} // namespace android
+} // namespace base
+
bulach 2011/07/26 18:23:04 nit: extra \n
« no previous file with comments | « base/android/auto_jobject.h ('k') | base/base.gypi » ('j') | base/base.gypi » ('J')

Powered by Google App Engine
This is Rietveld 408576698