Commit b744ad3d authored by wychen's avatar wychen Committed by Commit bot

Record start up latency of DOM distiller viewer

BUG=617701

Review-Url: https://codereview.chromium.org/2011213002
Cr-Commit-Position: refs/heads/master@{#398115}
parent 861acbc2
...@@ -108,7 +108,8 @@ void SelfDeletingRequestDelegate::TakeViewerHandle( ...@@ -108,7 +108,8 @@ void SelfDeletingRequestDelegate::TakeViewerHandle(
void StartNavigationToDistillerViewer(content::WebContents* web_contents, void StartNavigationToDistillerViewer(content::WebContents* web_contents,
const GURL& url) { const GURL& url) {
GURL viewer_url = dom_distiller::url_utils::GetDistillerViewUrlFromUrl( GURL viewer_url = dom_distiller::url_utils::GetDistillerViewUrlFromUrl(
dom_distiller::kDomDistillerScheme, url); dom_distiller::kDomDistillerScheme, url,
(base::TimeTicks::Now() - base::TimeTicks()).InMilliseconds());
content::NavigationController::LoadURLParams params(viewer_url); content::NavigationController::LoadURLParams params(viewer_url);
params.transition_type = ui::PAGE_TRANSITION_AUTO_BOOKMARK; params.transition_type = ui::PAGE_TRANSITION_AUTO_BOOKMARK;
web_contents->GetController().LoadURLWithParams(params); web_contents->GetController().LoadURLWithParams(params);
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "base/memory/ref_counted_memory.h" #include "base/memory/ref_counted_memory.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/metrics/user_metrics.h" #include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -157,6 +157,15 @@ void DomDistillerViewerSource::RequestViewerHandle::DidFinishLoad( ...@@ -157,6 +157,15 @@ void DomDistillerViewerSource::RequestViewerHandle::DidFinishLoad(
return; return;
} }
int64_t start_time_ms = url_utils::GetTimeFromDistillerUrl(validated_url);
if (start_time_ms > 0) {
base::TimeTicks start_time =
base::TimeDelta::FromMilliseconds(start_time_ms) + base::TimeTicks();
base::TimeDelta latency = base::TimeTicks::Now() - start_time;
UMA_HISTOGRAM_TIMES("DomDistiller.Time.ViewerLoading", latency);
}
// No SendJavaScript() calls allowed before |buffer_| is run and cleared. // No SendJavaScript() calls allowed before |buffer_| is run and cleared.
waiting_for_page_ready_ = false; waiting_for_page_ready_ = false;
if (!buffer_.empty()) { if (!buffer_.empty()) {
......
...@@ -9,6 +9,7 @@ namespace dom_distiller { ...@@ -9,6 +9,7 @@ namespace dom_distiller {
const char kDomDistillerScheme[] = "chrome-distiller"; const char kDomDistillerScheme[] = "chrome-distiller";
const char kEntryIdKey[] = "entry_id"; const char kEntryIdKey[] = "entry_id";
const char kUrlKey[] = "url"; const char kUrlKey[] = "url";
const char kTimeKey[] = "time";
const char kViewerCssPath[] = "dom_distiller_viewer.css"; const char kViewerCssPath[] = "dom_distiller_viewer.css";
const char kViewerLoadingImagePath[] = "dom_distiller_material_spinner.svg"; const char kViewerLoadingImagePath[] = "dom_distiller_material_spinner.svg";
const char kViewerSaveFontScalingPath[] = "savefontscaling/"; const char kViewerSaveFontScalingPath[] = "savefontscaling/";
......
...@@ -10,6 +10,7 @@ namespace dom_distiller { ...@@ -10,6 +10,7 @@ namespace dom_distiller {
extern const char kDomDistillerScheme[]; extern const char kDomDistillerScheme[];
extern const char kEntryIdKey[]; extern const char kEntryIdKey[];
extern const char kUrlKey[]; extern const char kUrlKey[];
extern const char kTimeKey[];
extern const char kViewerCssPath[]; extern const char kViewerCssPath[];
extern const char kViewerLoadingImagePath[]; extern const char kViewerLoadingImagePath[];
extern const char kViewerSaveFontScalingPath[]; extern const char kViewerSaveFontScalingPath[];
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <string> #include <string>
#include "base/guid.h" #include "base/guid.h"
#include "base/strings/string_number_conversions.h"
#include "components/dom_distiller/core/url_constants.h" #include "components/dom_distiller/core/url_constants.h"
#include "grit/components_resources.h" #include "grit/components_resources.h"
#include "net/base/url_util.h" #include "net/base/url_util.h"
...@@ -30,8 +31,13 @@ const GURL GetDistillerViewUrlFromEntryId(const std::string& scheme, ...@@ -30,8 +31,13 @@ const GURL GetDistillerViewUrlFromEntryId(const std::string& scheme,
} }
const GURL GetDistillerViewUrlFromUrl(const std::string& scheme, const GURL GetDistillerViewUrlFromUrl(const std::string& scheme,
const GURL& view_url) { const GURL& view_url,
int64_t start_time_ms) {
GURL url(scheme + "://" + base::GenerateGUID()); GURL url(scheme + "://" + base::GenerateGUID());
if (start_time_ms > 0) {
url = net::AppendOrReplaceQueryParameter(url, kTimeKey,
base::IntToString(start_time_ms));
}
return net::AppendOrReplaceQueryParameter(url, kUrlKey, view_url.spec()); return net::AppendOrReplaceQueryParameter(url, kUrlKey, view_url.spec());
} }
...@@ -45,6 +51,21 @@ const GURL GetOriginalUrlFromDistillerUrl(const GURL& url) { ...@@ -45,6 +51,21 @@ const GURL GetOriginalUrlFromDistillerUrl(const GURL& url) {
return GURL(original_url_str); return GURL(original_url_str);
} }
int64_t GetTimeFromDistillerUrl(const GURL& url) {
if (!dom_distiller::url_utils::IsDistilledPage(url))
return 0;
std::string time_str;
if (!net::GetValueForKeyInQuery(url, kTimeKey, &time_str))
return 0;
int64_t time_int = 0;
if (!base::StringToInt64(time_str, &time_int))
return 0;
return time_int;
}
std::string GetValueForKeyInUrl(const GURL& url, const std::string& key) { std::string GetValueForKeyInUrl(const GURL& url, const std::string& key) {
if (!url.is_valid()) if (!url.is_valid())
return ""; return "";
......
...@@ -19,12 +19,17 @@ const GURL GetDistillerViewUrlFromEntryId(const std::string& scheme, ...@@ -19,12 +19,17 @@ const GURL GetDistillerViewUrlFromEntryId(const std::string& scheme,
// Returns the URL for viewing distilled content for a URL. // Returns the URL for viewing distilled content for a URL.
const GURL GetDistillerViewUrlFromUrl(const std::string& scheme, const GURL GetDistillerViewUrlFromUrl(const std::string& scheme,
const GURL& view_url); const GURL& view_url,
int64_t start_time_ms = 0);
// Returns the original URL from the distilled URL. // Returns the original URL from the distilled URL.
// If the URL is not distilled, it is returned as is. // If the URL is not distilled, it is returned as is.
const GURL GetOriginalUrlFromDistillerUrl(const GURL& distilled_url); const GURL GetOriginalUrlFromDistillerUrl(const GURL& distilled_url);
// Returns the starting time from the distilled URL.
// Returns 0 when not available or on error.
int64_t GetTimeFromDistillerUrl(const GURL& url);
// Returns the value of the query parameter for the given |key| for a given URL. // Returns the value of the query parameter for the given |key| for a given URL.
// If the URL is invalid or if the key is not found, returns an empty string. // If the URL is invalid or if the key is not found, returns an empty string.
// If there are multiple keys found in the URL, returns the value for the first // If there are multiple keys found in the URL, returns the value for the first
......
...@@ -43,7 +43,7 @@ TEST(DomDistillerUrlUtilsTest, TestGetValueForKeyInUrlPathQuery) { ...@@ -43,7 +43,7 @@ TEST(DomDistillerUrlUtilsTest, TestGetValueForKeyInUrlPathQuery) {
std::string ThroughDistiller(const std::string& url) { std::string ThroughDistiller(const std::string& url) {
return GetOriginalUrlFromDistillerUrl( return GetOriginalUrlFromDistillerUrl(
GetDistillerViewUrlFromUrl(kDomDistillerScheme, GURL(url))).spec(); GetDistillerViewUrlFromUrl(kDomDistillerScheme, GURL(url), 123)).spec();
} }
std::string GetOriginalUrlFromDistillerUrl(const std::string& url) { std::string GetOriginalUrlFromDistillerUrl(const std::string& url) {
......
...@@ -10079,6 +10079,13 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. ...@@ -10079,6 +10079,13 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary> </summary>
</histogram> </histogram>
<histogram name="DomDistiller.Time.ViewerLoading" units="ms">
<owner>wychen@chromium.org</owner>
<summary>
Records the time from the Reader Mode panel opening to the viewer loaded.
</summary>
</histogram>
<histogram name="DomDistiller.Time.ViewingReaderModePanel" units="ms"> <histogram name="DomDistiller.Time.ViewingReaderModePanel" units="ms">
<owner>mdjones@chromium.org</owner> <owner>mdjones@chromium.org</owner>
<summary> <summary>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment