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

Unified Diff: base/android/scoped_java_ref.cc

Issue 7828084: Refactor ScopedJavaRef (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: operator= docs Created 9 years, 3 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/scoped_java_ref.cc
diff --git a/base/android/scoped_java_ref.cc b/base/android/scoped_java_ref.cc
new file mode 100644
index 0000000000000000000000000000000000000000..da932f8ddd0753571ffbcaf54e9e90b614614441
--- /dev/null
+++ b/base/android/scoped_java_ref.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/scoped_java_ref.h"
+
+namespace base {
+namespace android {
+
+JavaRef<jobject>::JavaRef() : env_(NULL), obj_(NULL) {}
+
+JavaRef<jobject>::JavaRef(JNIEnv* env, jobject obj)
+ : env_(env),
+ obj_(obj) {
+ DCHECK_EQ(JNILocalRefType, env->GetObjectRefType(obj));
+}
+
+JavaRef<jobject>::~JavaRef() {
+}
+
+void JavaRef<jobject>::SetNewLocalRef(JNIEnv* env, jobject obj) {
+ if (obj)
+ obj = env->NewLocalRef(obj);
+ if (obj_)
+ env_->DeleteLocalRef(obj_);
+ env_ = env;
+ obj_ = obj;
+}
+
+void JavaRef<jobject>::SetNewGlobalRef(JNIEnv* env, jobject obj) {
+ if (obj)
+ obj = env->NewGlobalRef(obj);
+ if (obj_)
+ env_->DeleteGlobalRef(obj_);
+ env_ = env;
+ obj_ = obj;
+}
+
+jobject JavaRef<jobject>::ReleaseInternal() {
+ jobject obj = obj_;
+ env_ = NULL;
+ obj_ = NULL;
+ return obj;
+}
+
+} // namespace android
+} // namespace base

Powered by Google App Engine
This is Rietveld 408576698