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

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

Issue 1434433002: Pass distillability updates from renderer to browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@model
Patch Set: address tsepez's comment Created 5 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/distillability_driver.cc
diff --git a/components/dom_distiller/content/browser/distillability_driver.cc b/components/dom_distiller/content/browser/distillability_driver.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8af458f5c0aad8be7e990a992191caf4e6b9b34d
--- /dev/null
+++ b/components/dom_distiller/content/browser/distillability_driver.cc
@@ -0,0 +1,58 @@
+// Copyright 2015 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 "components/dom_distiller/content/browser/distillability_driver.h"
+#include "components/dom_distiller/content/common/distiller_messages.h"
+
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "content/public/browser/web_contents_user_data.h"
+
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(
+ dom_distiller::DistillabilityDriver);
+
+namespace dom_distiller {
+
+DistillabilityDriver::DistillabilityDriver(
+ content::WebContents* web_contents)
+ : content::WebContentsObserver(web_contents) {
+}
+
+DistillabilityDriver::~DistillabilityDriver() {
+ CleanUp();
+}
+
+void DistillabilityDriver::SetDelegate(
+ const base::Callback<void(bool, bool)>& delegate) {
+ m_delegate_ = delegate;
+}
+
+bool DistillabilityDriver::OnMessageReceived(const IPC::Message &msg,
+ content::RenderFrameHost* render_frame_host) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(DistillabilityDriver, msg)
+ IPC_MESSAGE_HANDLER(FrameHostMsg_Distillability,
+ OnDistillability)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void DistillabilityDriver::OnDistillability(
+ bool distillable, bool is_last) {
+ if (m_delegate_.is_null()) return;
+
+ m_delegate_.Run(distillable, is_last);
+}
+
+void DistillabilityDriver::RenderProcessGone(
+ base::TerminationStatus status) {
+ CleanUp();
+}
+
+void DistillabilityDriver::CleanUp() {
+ content::WebContentsObserver::Observe(NULL);
+}
+
+} // namespace dom_distiller

Powered by Google App Engine
This is Rietveld 408576698