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

Unified Diff: components/dom_distiller/content/browser/distillable_page_utils_android.cc

Issue 2538463002: android: Don't pass ScopedJavaGlobalRef pointers. (Closed)
Patch Set: timeouts are very annoying Created 4 years, 1 month 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: components/dom_distiller/content/browser/distillable_page_utils_android.cc
diff --git a/components/dom_distiller/content/browser/distillable_page_utils_android.cc b/components/dom_distiller/content/browser/distillable_page_utils_android.cc
index f0890f68c60ada3b450830b227d46d06620162bd..68430f6d964ade53aaa85c42e84aebb8982204c5 100644
--- a/components/dom_distiller/content/browser/distillable_page_utils_android.cc
+++ b/components/dom_distiller/content/browser/distillable_page_utils_android.cc
@@ -15,25 +15,23 @@
#include "jni/DistillablePageUtils_jni.h"
using base::android::JavaParamRef;
+using base::android::JavaRef;
using base::android::ScopedJavaGlobalRef;
namespace dom_distiller {
namespace android {
namespace {
-void OnIsPageDistillableResult(
- std::unique_ptr<ScopedJavaGlobalRef<jobject>> callback_holder,
- bool isDistillable) {
+void OnIsPageDistillableResult(const JavaRef<jobject>& callback,
+ bool isDistillable) {
Java_DistillablePageUtils_callOnIsPageDistillableResult(
- base::android::AttachCurrentThread(), callback_holder->obj(),
- isDistillable);
+ base::android::AttachCurrentThread(), callback, isDistillable);
}
-void OnIsPageDistillableUpdate(
- ScopedJavaGlobalRef<jobject>* callback_holder,
- bool isDistillable, bool isLast) {
+void OnIsPageDistillableUpdate(const JavaRef<jobject>& callback,
+ bool isDistillable,
+ bool isLast) {
Java_DistillablePageUtils_callOnIsPageDistillableUpdate(
- base::android::AttachCurrentThread(), callback_holder->obj(),
- isDistillable, isLast);
+ base::android::AttachCurrentThread(), callback, isDistillable, isLast);
}
} // namespace
@@ -44,19 +42,17 @@ static void IsPageDistillable(JNIEnv* env,
const JavaParamRef<jobject>& callback) {
content::WebContents* web_contents(
content::WebContents::FromJavaWebContents(webContents));
- std::unique_ptr<ScopedJavaGlobalRef<jobject>> callback_holder(
- new ScopedJavaGlobalRef<jobject>());
- callback_holder->Reset(env, callback);
if (!web_contents) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(OnIsPageDistillableResult,
- base::Passed(&callback_holder), false));
+ FROM_HERE,
+ base::Bind(OnIsPageDistillableResult,
+ ScopedJavaGlobalRef<jobject>(env, callback), false));
return;
}
- IsDistillablePage(
- web_contents, is_mobile_optimized,
- base::Bind(OnIsPageDistillableResult, base::Passed(&callback_holder)));
+ IsDistillablePage(web_contents, is_mobile_optimized,
+ base::Bind(OnIsPageDistillableResult,
+ ScopedJavaGlobalRef<jobject>(env, callback)));
}
static void SetDelegate(JNIEnv* env,
@@ -69,13 +65,8 @@ static void SetDelegate(JNIEnv* env,
return;
}
- // TODO(wychen): check memory management
- ScopedJavaGlobalRef<jobject>* callback_holder(
- new ScopedJavaGlobalRef<jobject>());
- callback_holder->Reset(env, callback);
-
- DistillabilityDelegate delegate =
- base::Bind(OnIsPageDistillableUpdate, base::Owned(callback_holder));
+ DistillabilityDelegate delegate = base::Bind(
+ OnIsPageDistillableUpdate, ScopedJavaGlobalRef<jobject>(env, callback));
setDelegate(web_contents, delegate);
}
« no previous file with comments | « chrome/browser/android/preferences/pref_service_bridge.cc ('k') | content/browser/android/app_web_message_port_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698