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

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

Issue 2195123002: Only setup distillability mojo if needed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/dom_distiller/content/browser/distillability_driver.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
index 413e90786855d8bbc557ae9653ba4aaf93db8b33..c8c90932802982cd1c1a7452d7cce2fd8e39837f 100644
--- a/components/dom_distiller/content/browser/distillability_driver.cc
+++ b/components/dom_distiller/content/browser/distillability_driver.cc
@@ -25,7 +25,10 @@ class DistillabilityServiceImpl : public mojom::DistillabilityService {
: binding_(this, std::move(request)),
distillability_driver_(distillability_driver) {}
- ~DistillabilityServiceImpl() override {}
+ ~DistillabilityServiceImpl() override {
+ if (!distillability_driver_) return;
+ distillability_driver_->SetNeedsMojoSetup();
+ }
void NotifyIsDistillable(bool is_distillable, bool is_last_update) override {
if (!distillability_driver_) return;
@@ -40,6 +43,7 @@ class DistillabilityServiceImpl : public mojom::DistillabilityService {
DistillabilityDriver::DistillabilityDriver(
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
+ mojo_needs_setup_(true),
weak_factory_(this) {
if (!web_contents) return;
SetupMojoService(web_contents->GetMainFrame());
@@ -66,11 +70,20 @@ void DistillabilityDriver::OnDistillability(
m_delegate_.Run(distillable, is_last);
}
+void DistillabilityDriver::SetNeedsMojoSetup() {
+ mojo_needs_setup_ = true;
+}
+
void DistillabilityDriver::RenderFrameHostChanged(
content::RenderFrameHost* old_host,
content::RenderFrameHost* new_host) {
+ // This method is invoked if any of the active RenderFrameHosts are swapped.
+ // Only add the mojo service to the main frame host.
+ if (!web_contents() || web_contents()->GetMainFrame() != new_host) return;
+
// If the RenderFrameHost changes (this will happen if the user navigates to
// or from a native page), the service needs to be attached to that host.
+ mojo_needs_setup_ = true;
SetupMojoService(new_host);
// Clean up the service on the old host if possible.
if (!old_host) return;
@@ -86,11 +99,15 @@ void DistillabilityDriver::DidStartProvisionalLoadForFrame(
void DistillabilityDriver::SetupMojoService(
content::RenderFrameHost* frame_host) {
- if (!frame_host || !frame_host->GetInterfaceRegistry()) return;
+ if (!frame_host || !frame_host->GetInterfaceRegistry()
+ || !mojo_needs_setup_) {
+ return;
+ }
frame_host->GetInterfaceRegistry()->AddInterface(
base::Bind(&DistillabilityDriver::CreateDistillabilityService,
weak_factory_.GetWeakPtr()));
+ mojo_needs_setup_ = false;
}
} // namespace dom_distiller
« 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