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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/dom_distiller/content/browser/distillability_driver.h"
6 #include "components/dom_distiller/content/common/distiller_messages.h"
7
8 #include "content/public/browser/render_frame_host.h"
9 #include "content/public/browser/web_contents_observer.h"
10 #include "content/public/browser/web_contents_user_data.h"
11
12 DEFINE_WEB_CONTENTS_USER_DATA_KEY(
13 dom_distiller::DistillabilityDriver);
14
15 namespace dom_distiller {
16
17 DistillabilityDriver::DistillabilityDriver(
18 content::WebContents* web_contents)
19 : content::WebContentsObserver(web_contents) {
20 }
21
22 DistillabilityDriver::~DistillabilityDriver() {
23 CleanUp();
24 }
25
26 void DistillabilityDriver::SetDelegate(
27 const base::Callback<void(bool, bool)>& delegate) {
28 m_delegate_ = delegate;
29 }
30
31 bool DistillabilityDriver::OnMessageReceived(const IPC::Message &msg,
32 content::RenderFrameHost* render_frame_host) {
33 bool handled = true;
34 IPC_BEGIN_MESSAGE_MAP(DistillabilityDriver, msg)
35 IPC_MESSAGE_HANDLER(FrameHostMsg_Distillability,
36 OnDistillability)
37 IPC_MESSAGE_UNHANDLED(handled = false)
38 IPC_END_MESSAGE_MAP()
39 return handled;
40 }
41
42 void DistillabilityDriver::OnDistillability(
43 bool distillable, bool is_last) {
44 if (m_delegate_.is_null()) return;
45
46 m_delegate_.Run(distillable, is_last);
47 }
48
49 void DistillabilityDriver::RenderProcessGone(
50 base::TerminationStatus status) {
51 CleanUp();
52 }
53
54 void DistillabilityDriver::CleanUp() {
55 content::WebContentsObserver::Observe(NULL);
56 }
57
58 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698