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

Unified Diff: base/android/auto_global_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
Index: base/android/auto_global_jobject.cc
diff --git a/base/android/auto_global_jobject.cc b/base/android/auto_global_jobject.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1aa5415c5a9f6ba713c3d8912e07342eab7f1faa
--- /dev/null
+++ b/base/android/auto_global_jobject.cc
@@ -0,0 +1,54 @@
+// 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_global_jobject.h"
+
+#include <stddef.h>
+
+namespace base {
+namespace android {
+
+AutoGlobalJObject AutoGlobalJObject::FromLocalRef(JNIEnv* env, jobject obj) {
+ return AutoGlobalJObject(AutoJObject::FromLocalRef(env, obj));
+}
+
+AutoGlobalJObject::AutoGlobalJObject(const AutoJObject& obj)
+ : env_(obj.env()),
+ obj_(obj.env()->NewGlobalRef(obj.obj())) {
+}
+
+AutoGlobalJObject::AutoGlobalJObject()
+ : env_(NULL),
+ obj_(NULL) {
+}
+
+AutoGlobalJObject::AutoGlobalJObject(const AutoGlobalJObject& other)
+ : env_(NULL),
+ obj_(NULL) {
+ Reset(other);
+}
+
+AutoGlobalJObject::~AutoGlobalJObject() {
+ Reset();
+}
+
+void AutoGlobalJObject::Reset() {
+ if (env_ && obj_)
+ env_->DeleteGlobalRef(obj_);
+ env_ = NULL;
+ obj_ = NULL;
+}
+
+void AutoGlobalJObject::Reset(const AutoGlobalJObject& other) {
+ Reset();
+ env_ = other.env_;
+ obj_ = other.env_ ? other.env_->NewGlobalRef(other.obj_) : NULL;
+}
+
+jobject AutoGlobalJObject::obj() const {
+ return obj_;
+}
+
+} // namespace android
+} // namespace base

Powered by Google App Engine
This is Rietveld 408576698