Commit 008a7ae4 authored by Aran Gilman's avatar Aran Gilman Committed by Commit Bot

Clean up distillable_page_utils.h and related files.

This includes formatting the files with clang-format, adding and rewriting comments to make the code easier to understand, and adding/removing includes.

Change-Id: I91395c1974f8ad68a2fd0245c2362fe6d1803ddc
Reviewed-on: https://chromium-review.googlesource.com/c/1423091
Commit-Queue: Aran Gilman <gilmanmh@google.com>
Reviewed-by: default avatarMike Pinkerton <pinkerton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625436}
parent 48246c46
......@@ -4,6 +4,8 @@
#include "components/dom_distiller/content/browser/distillable_page_utils.h"
#include <string>
#include "base/bind.h"
#include "base/location.h"
#include "base/single_thread_task_runner.h"
......@@ -17,15 +19,18 @@
#include "components/dom_distiller/core/page_features.h"
#include "components/grit/components_resources.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/resource/resource_bundle.h"
namespace dom_distiller {
namespace {
void OnExtractFeaturesJsResult(const DistillablePageDetector* detector,
base::Callback<void(bool)> callback,
const base::Value* result) {
callback.Run(detector->Classify(CalculateDerivedFeaturesFromJSON(result)));
}
} // namespace
void IsDistillablePageForDetector(content::WebContents* web_contents,
......@@ -46,12 +51,12 @@ void IsDistillablePageForDetector(content::WebContents* web_contents,
base::Bind(OnExtractFeaturesJsResult, detector, callback));
}
void setDelegate(content::WebContents* web_contents,
void SetDelegate(content::WebContents* web_contents,
DistillabilityDelegate delegate) {
CHECK(web_contents);
DistillabilityDriver::CreateForWebContents(web_contents);
DistillabilityDriver *driver =
DistillabilityDriver* driver =
DistillabilityDriver::FromWebContents(web_contents);
CHECK(driver);
driver->SetDelegate(delegate);
......
......@@ -6,7 +6,10 @@
#define COMPONENTS_DOM_DISTILLER_CONTENT_BROWSER_DISTILLABLE_PAGE_UTILS_H_
#include "base/callback.h"
#include "content/public/browser/web_contents.h"
namespace content {
class WebContents;
} // namespace content
namespace dom_distiller {
......@@ -15,15 +18,22 @@ class DistillablePageDetector;
// Uses the provided DistillablePageDetector to detect if the page is
// distillable. The passed detector must be alive until after the callback is
// called.
//
// |web_contents| and |detector| must be non-null.
void IsDistillablePageForDetector(content::WebContents* web_contents,
const DistillablePageDetector* detector,
base::Callback<void(bool)> callback);
typedef base::RepeatingCallback<void(bool, bool, bool)> DistillabilityDelegate;
// Set the delegate to receive the result of whether the page is distillable.
void setDelegate(content::WebContents* web_contents,
//
// |web_contents| must be non-null.
using DistillabilityDelegate =
base::RepeatingCallback<void(bool /* is_distillable */,
bool /* is_last */,
bool /* is_mobile_friendly */)>;
void SetDelegate(content::WebContents* web_contents,
DistillabilityDelegate delegate);
}
} // namespace dom_distiller
#endif // COMPONENTS_DOM_DISTILLER_CONTENT_BROWSER_DISTILLABLE_PAGE_UTILS_H_
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include "base/bind.h"
#include "base/location.h"
#include "base/single_thread_task_runner.h"
......@@ -41,8 +39,8 @@ static void JNI_DistillablePageUtils_SetDelegate(
DistillabilityDelegate delegate = base::Bind(
OnIsPageDistillableUpdate, ScopedJavaGlobalRef<jobject>(env, callback));
setDelegate(web_contents, delegate);
SetDelegate(web_contents, delegate);
}
}
}
} // namespace android
} // namespace dom_distiller
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment