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

Side by Side Diff: components/dom_distiller/content/browser/distillability_driver.cc

Issue 1883023004: Reader Mode triggers after tab crash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@distillability-mojo
Patch Set: different lifecycle Created 4 years, 8 months 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
« no previous file with comments | « components/dom_distiller/content/browser/distillability_driver.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/dom_distiller/content/browser/distillability_driver.h" 5 #include "components/dom_distiller/content/browser/distillability_driver.h"
6 6
7 #include "content/public/browser/render_frame_host.h" 7 #include "content/public/browser/render_frame_host.h"
8 #include "content/public/browser/web_contents.h" 8 #include "content/public/browser/web_contents.h"
9 #include "content/public/browser/web_contents_observer.h" 9 #include "content/public/browser/web_contents_observer.h"
10 #include "content/public/browser/web_contents_user_data.h" 10 #include "content/public/browser/web_contents_user_data.h"
(...skipping 22 matching lines...) Expand all
33 33
34 private: 34 private:
35 mojo::StrongBinding<DistillabilityService> binding_; 35 mojo::StrongBinding<DistillabilityService> binding_;
36 DistillabilityDriver* distillability_driver_; 36 DistillabilityDriver* distillability_driver_;
37 }; 37 };
38 38
39 DistillabilityDriver::DistillabilityDriver( 39 DistillabilityDriver::DistillabilityDriver(
40 content::WebContents* web_contents) 40 content::WebContents* web_contents)
41 : content::WebContentsObserver(web_contents), 41 : content::WebContentsObserver(web_contents),
42 weak_factory_(this) { 42 weak_factory_(this) {
43 if (!web_contents) return; 43 SetupMojoService();
44 web_contents->GetMainFrame()->GetServiceRegistry()->AddService(
45 base::Bind(&DistillabilityDriver::CreateDistillabilityService,
46 weak_factory_.GetWeakPtr()));
47 } 44 }
48 45
49 DistillabilityDriver::~DistillabilityDriver() { 46 DistillabilityDriver::~DistillabilityDriver() {
50 CleanUp(); 47 content::WebContentsObserver::Observe(nullptr);
51 } 48 }
52 49
53 void DistillabilityDriver::CreateDistillabilityService( 50 void DistillabilityDriver::CreateDistillabilityService(
54 mojo::InterfaceRequest<DistillabilityService> request) { 51 mojo::InterfaceRequest<DistillabilityService> request) {
55 new DistillabilityServiceImpl(std::move(request), this); 52 new DistillabilityServiceImpl(std::move(request), this);
56 } 53 }
57 54
58 void DistillabilityDriver::SetDelegate( 55 void DistillabilityDriver::SetDelegate(
59 const base::Callback<void(bool, bool)>& delegate) { 56 const base::Callback<void(bool, bool)>& delegate) {
60 m_delegate_ = delegate; 57 m_delegate_ = delegate;
61 } 58 }
62 59
63 void DistillabilityDriver::OnDistillability( 60 void DistillabilityDriver::OnDistillability(
64 bool distillable, bool is_last) { 61 bool distillable, bool is_last) {
65 if (m_delegate_.is_null()) return; 62 if (m_delegate_.is_null()) return;
66 63
67 m_delegate_.Run(distillable, is_last); 64 m_delegate_.Run(distillable, is_last);
65
66 if (web_contents() && is_last) {
67 web_contents()->GetMainFrame()->GetServiceRegistry()
68 ->RemoveService<DistillabilityService>();
69 }
68 } 70 }
69 71
70 void DistillabilityDriver::RenderProcessGone( 72 void DistillabilityDriver::DidStartProvisionalLoadForFrame(
71 base::TerminationStatus status) { 73 content::RenderFrameHost* render_frame_host, const GURL& validated_url,
72 CleanUp(); 74 bool is_error_page, bool is_iframe_srcdoc) {
75 SetupMojoService();
73 } 76 }
74 77
75 void DistillabilityDriver::CleanUp() { 78 void DistillabilityDriver::SetupMojoService() {
76 if (!web_contents()) return; 79 if (!web_contents()) return;
77 web_contents()->GetMainFrame()->GetServiceRegistry() 80 web_contents()->GetMainFrame()->GetServiceRegistry()->AddService(
78 ->RemoveService<DistillabilityService>(); 81 base::Bind(&DistillabilityDriver::CreateDistillabilityService,
79 content::WebContentsObserver::Observe(NULL); 82 weak_factory_.GetWeakPtr()));
80 } 83 }
81 84
82 } // namespace dom_distiller 85 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « components/dom_distiller/content/browser/distillability_driver.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698