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

Side by Side Diff: components/dom_distiller/content/distiller_page_web_contents.cc

Issue 1143173009: Add UMA histogram DomDistiller.Time.RunJavaScript (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/distiller_page_web_contents.h" 5 #include "components/dom_distiller/content/distiller_page_web_contents.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/metrics/histogram.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
10 #include "components/dom_distiller/content/web_contents_main_frame_observer.h" 11 #include "components/dom_distiller/content/web_contents_main_frame_observer.h"
11 #include "components/dom_distiller/core/distiller_page.h" 12 #include "components/dom_distiller/core/distiller_page.h"
12 #include "components/dom_distiller/core/dom_distiller_service.h" 13 #include "components/dom_distiller/core/dom_distiller_service.h"
13 #include "content/public/browser/browser_context.h" 14 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/navigation_controller.h" 15 #include "content/public/browser/navigation_controller.h"
15 #include "content/public/browser/render_frame_host.h" 16 #include "content/public/browser/render_frame_host.h"
16 #include "content/public/browser/render_view_host.h" 17 #include "content/public/browser/render_view_host.h"
17 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
18 #include "content/public/browser/web_contents_observer.h" 19 #include "content/public/browser/web_contents_observer.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 void DistillerPageWebContents::DidFailLoad( 158 void DistillerPageWebContents::DidFailLoad(
158 content::RenderFrameHost* render_frame_host, 159 content::RenderFrameHost* render_frame_host,
159 const GURL& validated_url, 160 const GURL& validated_url,
160 int error_code, 161 int error_code,
161 const base::string16& error_description) { 162 const base::string16& error_description) {
162 if (!render_frame_host->GetParent()) { 163 if (!render_frame_host->GetParent()) {
163 content::WebContentsObserver::Observe(NULL); 164 content::WebContentsObserver::Observe(NULL);
164 DCHECK(state_ == LOADING_PAGE || state_ == EXECUTING_JAVASCRIPT); 165 DCHECK(state_ == LOADING_PAGE || state_ == EXECUTING_JAVASCRIPT);
165 state_ = PAGELOAD_FAILED; 166 state_ = PAGELOAD_FAILED;
166 scoped_ptr<base::Value> empty = base::Value::CreateNullValue(); 167 scoped_ptr<base::Value> empty = base::Value::CreateNullValue();
167 OnWebContentsDistillationDone(GURL(), empty.get()); 168 OnWebContentsDistillationDone(GURL(), base::TimeTicks(), empty.get());
168 } 169 }
169 } 170 }
170 171
171 void DistillerPageWebContents::ExecuteJavaScript() { 172 void DistillerPageWebContents::ExecuteJavaScript() {
172 content::RenderFrameHost* frame = 173 content::RenderFrameHost* frame =
173 source_page_handle_->web_contents()->GetMainFrame(); 174 source_page_handle_->web_contents()->GetMainFrame();
174 DCHECK(frame); 175 DCHECK(frame);
175 DCHECK_EQ(LOADING_PAGE, state_); 176 DCHECK_EQ(LOADING_PAGE, state_);
176 state_ = EXECUTING_JAVASCRIPT; 177 state_ = EXECUTING_JAVASCRIPT;
177 content::WebContentsObserver::Observe(NULL); 178 content::WebContentsObserver::Observe(NULL);
178 // Stop any pending navigation since the intent is to distill the current 179 // Stop any pending navigation since the intent is to distill the current
179 // page. 180 // page.
180 source_page_handle_->web_contents()->Stop(); 181 source_page_handle_->web_contents()->Stop();
181 DVLOG(1) << "Beginning distillation"; 182 DVLOG(1) << "Beginning distillation";
182 frame->ExecuteJavaScript( 183 frame->ExecuteJavaScript(
183 base::UTF8ToUTF16(script_), 184 base::UTF8ToUTF16(script_),
184 base::Bind(&DistillerPageWebContents::OnWebContentsDistillationDone, 185 base::Bind(&DistillerPageWebContents::OnWebContentsDistillationDone,
185 base::Unretained(this), 186 base::Unretained(this),
186 source_page_handle_->web_contents()->GetLastCommittedURL())); 187 source_page_handle_->web_contents()->GetLastCommittedURL(),
188 base::TimeTicks::Now()));
187 } 189 }
188 190
189 void DistillerPageWebContents::OnWebContentsDistillationDone( 191 void DistillerPageWebContents::OnWebContentsDistillationDone(
190 const GURL& page_url, 192 const GURL& page_url,
193 const base::TimeTicks& javascript_start,
191 const base::Value* value) { 194 const base::Value* value) {
192 DCHECK(state_ == IDLE || state_ == LOADING_PAGE || // TODO(nyquist): 493795. 195 DCHECK(state_ == IDLE || state_ == LOADING_PAGE || // TODO(nyquist): 493795.
193 state_ == PAGELOAD_FAILED || state_ == EXECUTING_JAVASCRIPT); 196 state_ == PAGELOAD_FAILED || state_ == EXECUTING_JAVASCRIPT);
194 state_ = IDLE; 197 state_ = IDLE;
198
199 if (!javascript_start.is_null()) {
200 base::TimeDelta javascript_time = base::TimeTicks::Now() - javascript_start;
201 UMA_HISTOGRAM_TIMES("DomDistiller.Time.RunJavaScript", javascript_time);
202 DVLOG(1) << "DomDistiller.Time.RunJavaScript = " << javascript_time;
203 }
204
195 DistillerPage::OnDistillationDone(page_url, value); 205 DistillerPage::OnDistillationDone(page_url, value);
196 } 206 }
197 207
198 } // namespace dom_distiller 208 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « components/dom_distiller/content/distiller_page_web_contents.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698