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

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: nit 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 web_contents()->GetMainFrame()->GetServiceRegistry()
wychen 2016/04/15 06:22:21 Would web_cotents() always be nullptr here? If the
mdjones 2016/04/15 21:04:09 Done.
48 ->RemoveService<DistillabilityService>();
49 content::WebContentsObserver::Observe(nullptr);
51 } 50 }
52 51
53 void DistillabilityDriver::CreateDistillabilityService( 52 void DistillabilityDriver::CreateDistillabilityService(
54 mojo::InterfaceRequest<DistillabilityService> request) { 53 mojo::InterfaceRequest<DistillabilityService> request) {
55 new DistillabilityServiceImpl(std::move(request), this); 54 new DistillabilityServiceImpl(std::move(request), this);
56 } 55 }
57 56
58 void DistillabilityDriver::SetDelegate( 57 void DistillabilityDriver::SetDelegate(
59 const base::Callback<void(bool, bool)>& delegate) { 58 const base::Callback<void(bool, bool)>& delegate) {
60 m_delegate_ = delegate; 59 m_delegate_ = delegate;
61 } 60 }
62 61
63 void DistillabilityDriver::OnDistillability( 62 void DistillabilityDriver::OnDistillability(
64 bool distillable, bool is_last) { 63 bool distillable, bool is_last) {
65 if (m_delegate_.is_null()) return; 64 if (m_delegate_.is_null()) return;
66 65
67 m_delegate_.Run(distillable, is_last); 66 m_delegate_.Run(distillable, is_last);
68 } 67 }
69 68
70 void DistillabilityDriver::RenderProcessGone( 69 void DistillabilityDriver::DidNavigateMainFrame(
71 base::TerminationStatus status) { 70 const content::LoadCommittedDetails& details,
72 CleanUp(); 71 const content::FrameNavigateParams& params) {
72 if (details.is_in_page) return;
73 SetupMojoService();
73 } 74 }
74 75
75 void DistillabilityDriver::CleanUp() { 76 void DistillabilityDriver::SetupMojoService() {
76 web_contents()->GetMainFrame()->GetServiceRegistry() 77 web_contents()->GetMainFrame()->GetServiceRegistry()->AddService(
77 ->RemoveService<DistillabilityService>(); 78 base::Bind(&DistillabilityDriver::CreateDistillabilityService,
78 content::WebContentsObserver::Observe(NULL); 79 weak_factory_.GetWeakPtr()));
79 } 80 }
80 81
81 } // namespace dom_distiller 82 } // 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