| 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);
|
| }
|
|
|
|
|