summaryrefslogtreecommitdiffstats
path: root/components/dom_distiller
diff options
context:
space:
mode:
authoryfriedman@chromium.org <yfriedman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-24 22:07:51 +0000
committeryfriedman@chromium.org <yfriedman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-24 22:07:51 +0000
commitfb688daf52cef3bb041634888583ee2c28c8af66 (patch)
tree17e1870fa1705d9102769fcfc3b504c553f07e04 /components/dom_distiller
parentaf60c4ec56a067a980d2a7096996655bdc1f3648 (diff)
downloadchromium_src-fb688daf52cef3bb041634888583ee2c28c8af66.zip
chromium_src-fb688daf52cef3bb041634888583ee2c28c8af66.tar.gz
chromium_src-fb688daf52cef3bb041634888583ee2c28c8af66.tar.bz2
[dom_distiller] Improve distillation speed.
Wait for DOMContentLoaded instead of the full page to load. Also, stop page loading at this time. With this change, distillation results are calculated sooner and network traffic is reduced as unneeded subresources aren't fetched. The downside is that this may break some pages which are using Javascript to write the main document although this uncommon for document-centric pages. Also adds some logs to see when the distiller is running: (e.g. out/Debug/chrome --enable-dom-distiller --vmodule="*distiller*=1") BUG=288015 NOTRY=true R=cjhopman@chromium.org Review URL: https://codereview.chromium.org/209333002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@259030 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/dom_distiller')
-rw-r--r--components/dom_distiller/content/distiller_page_web_contents.cc18
-rw-r--r--components/dom_distiller/content/distiller_page_web_contents.h6
-rw-r--r--components/dom_distiller/core/page_distiller.cc9
3 files changed, 18 insertions, 15 deletions
diff --git a/components/dom_distiller/content/distiller_page_web_contents.cc b/components/dom_distiller/content/distiller_page_web_contents.cc
index 2333d03..9cf8388 100644
--- a/components/dom_distiller/content/distiller_page_web_contents.cc
+++ b/components/dom_distiller/content/distiller_page_web_contents.cc
@@ -35,9 +35,9 @@ DistillerPageWebContents::~DistillerPageWebContents() {
void DistillerPageWebContents::InitImpl() {
DCHECK(browser_context_);
- web_contents_.reset(
- content::WebContents::Create(
- content::WebContents::CreateParams(browser_context_)));
+ content::WebContents::CreateParams create_params(browser_context_);
+ create_params.initially_hidden = true;
+ web_contents_.reset(content::WebContents::Create(create_params));
}
void DistillerPageWebContents::LoadURLImpl(const GURL& gurl) {
@@ -57,14 +57,12 @@ void DistillerPageWebContents::ExecuteJavaScriptImpl(
web_contents_->GetLastCommittedURL()));
}
-void DistillerPageWebContents::DidFinishLoad(int64 frame_id,
- const GURL& validated_url,
- bool is_main_frame,
- RenderViewHost* render_view_host) {
- // TODO(shashishekhar): Find a better way to detect when it is safe to run the
- // distillation script. Waiting for the entire page to load is really slow.
- if (is_main_frame) {
+void DistillerPageWebContents::DocumentLoadedInFrame(
+ int64 frame_id,
+ RenderViewHost* render_view_host) {
+ if (frame_id == web_contents_->GetMainFrame()->GetRoutingID()) {
content::WebContentsObserver::Observe(NULL);
+ web_contents_->Stop();
OnLoadURLDone();
}
}
diff --git a/components/dom_distiller/content/distiller_page_web_contents.h b/components/dom_distiller/content/distiller_page_web_contents.h
index 8d8bf3e..c6b94fc 100644
--- a/components/dom_distiller/content/distiller_page_web_contents.h
+++ b/components/dom_distiller/content/distiller_page_web_contents.h
@@ -46,10 +46,8 @@ class DistillerPageWebContents : public DistillerPage,
virtual ~DistillerPageWebContents();
// content::WebContentsObserver implementation.
- virtual void DidFinishLoad(int64 frame_id,
- const GURL& validated_url,
- bool is_main_frame,
- RenderViewHost* render_view_host) OVERRIDE;
+ virtual void DocumentLoadedInFrame(int64 frame_id,
+ RenderViewHost* render_view_host) OVERRIDE;
virtual void DidFailLoad(int64 frame_id,
const GURL& validated_url,
diff --git a/components/dom_distiller/core/page_distiller.cc b/components/dom_distiller/core/page_distiller.cc
index 9116b47..db941ab 100644
--- a/components/dom_distiller/core/page_distiller.cc
+++ b/components/dom_distiller/core/page_distiller.cc
@@ -40,11 +40,15 @@ void PageDistiller::DistillPage(const GURL& url,
LoadURL(url);
}
-void PageDistiller::LoadURL(const GURL& url) { distiller_page_->LoadURL(url); }
+void PageDistiller::LoadURL(const GURL& url) {
+ DVLOG(1) << "Loading for distillation: " << url.spec();
+ distiller_page_->LoadURL(url);
+}
void PageDistiller::OnLoadURLDone() { GetDistilledContent(); }
void PageDistiller::GetDistilledContent() {
+ DVLOG(1) << "Beginning distillation";
std::string script = ResourceBundle::GetSharedInstance()
.GetRawDataResource(IDR_DISTILLER_JS)
.as_string();
@@ -53,6 +57,9 @@ void PageDistiller::GetDistilledContent() {
void PageDistiller::OnExecuteJavaScriptDone(const GURL& page_url,
const base::Value* value) {
+ DVLOG(1) << "Distillation complete; extracting resources for "
+ << page_url.spec();
+
scoped_ptr<DistilledPageInfo> page_info(new DistilledPageInfo());
std::string result;
const base::ListValue* result_list = NULL;