| OLD | NEW |
| 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 "chrome/browser/search/most_visited_iframe_source.h" | 5 #include "chrome/browser/search/most_visited_iframe_source.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
| 11 #include "content/public/browser/user_metrics.h" | 11 #include "content/public/browser/user_metrics.h" |
| 12 #include "grit/browser_resources.h" | 12 #include "grit/browser_resources.h" |
| 13 #include "net/base/url_util.h" | 13 #include "net/base/url_util.h" |
| 14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const char kTitleHTMLPath[] = "/title.html"; | 18 const char kTitleHTMLPath[] = "/title.html"; |
| 19 const char kTitleCSSPath[] = "/title.css"; | 19 const char kTitleCSSPath[] = "/title.css"; |
| 20 const char kTitleJSPath[] = "/title.js"; | 20 const char kTitleJSPath[] = "/title.js"; |
| 21 const char kThumbnailHTMLPath[] = "/thumbnail.html"; | 21 const char kThumbnailHTMLPath[] = "/thumbnail.html"; |
| 22 const char kThumbnailCSSPath[] = "/thumbnail.css"; | 22 const char kThumbnailCSSPath[] = "/thumbnail.css"; |
| 23 const char kThumbnailJSPath[] = "/thumbnail.js"; | 23 const char kThumbnailJSPath[] = "/thumbnail.js"; |
| 24 const char kUtilJSPath[] = "/util.js"; | 24 const char kUtilJSPath[] = "/util.js"; |
| 25 const char kCommonCSSPath[] = "/common.css"; | 25 const char kCommonCSSPath[] = "/common.css"; |
| 26 const char kLogHTMLPath[] = "/log.html"; | |
| 27 const char kMostVisitedHistogramWithProvider[] = "NewTabPage.MostVisited.%s"; | 26 const char kMostVisitedHistogramWithProvider[] = "NewTabPage.MostVisited.%s"; |
| 28 | 27 |
| 29 } // namespace | 28 } // namespace |
| 30 | 29 |
| 31 MostVisitedIframeSource::MostVisitedIframeSource() { | 30 MostVisitedIframeSource::MostVisitedIframeSource() { |
| 32 } | 31 } |
| 33 | 32 |
| 34 MostVisitedIframeSource::~MostVisitedIframeSource() { | 33 MostVisitedIframeSource::~MostVisitedIframeSource() { |
| 35 } | 34 } |
| 36 | 35 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 59 SendResource(IDR_MOST_VISITED_THUMBNAIL_HTML, callback); | 58 SendResource(IDR_MOST_VISITED_THUMBNAIL_HTML, callback); |
| 60 } else if (path == kThumbnailCSSPath) { | 59 } else if (path == kThumbnailCSSPath) { |
| 61 SendResource(IDR_MOST_VISITED_THUMBNAIL_CSS, callback); | 60 SendResource(IDR_MOST_VISITED_THUMBNAIL_CSS, callback); |
| 62 } else if (path == kThumbnailJSPath) { | 61 } else if (path == kThumbnailJSPath) { |
| 63 SendJSWithOrigin(IDR_MOST_VISITED_THUMBNAIL_JS, render_process_id, | 62 SendJSWithOrigin(IDR_MOST_VISITED_THUMBNAIL_JS, render_process_id, |
| 64 render_frame_id, callback); | 63 render_frame_id, callback); |
| 65 } else if (path == kUtilJSPath) { | 64 } else if (path == kUtilJSPath) { |
| 66 SendResource(IDR_MOST_VISITED_UTIL_JS, callback); | 65 SendResource(IDR_MOST_VISITED_UTIL_JS, callback); |
| 67 } else if (path == kCommonCSSPath) { | 66 } else if (path == kCommonCSSPath) { |
| 68 SendResource(IDR_MOST_VISITED_IFRAME_CSS, callback); | 67 SendResource(IDR_MOST_VISITED_IFRAME_CSS, callback); |
| 69 } else if (path == kLogHTMLPath) { | |
| 70 // Log the clicked MostVisited element by position. | |
| 71 std::string str_position; | |
| 72 int position; | |
| 73 if (net::GetValueForKeyInQuery(url, "pos", &str_position) && | |
| 74 base::StringToInt(str_position, &position)) { | |
| 75 // Log the Most Visited click. | |
| 76 UMA_HISTOGRAM_ENUMERATION(kMostVisitedHistogramName, position, | |
| 77 kNumMostVisited); | |
| 78 // If a specific provider is specified, log the metric specific to the | |
| 79 // provider. | |
| 80 std::string provider; | |
| 81 if (net::GetValueForKeyInQuery(url, "pr", &provider)) | |
| 82 LogMostVisitedProviderClick(position, provider); | |
| 83 | |
| 84 // Records the action. This will be available as a time-stamped stream | |
| 85 // server-side and can be used to compute time-to-long-dwell. | |
| 86 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked")); | |
| 87 } | |
| 88 callback.Run(NULL); | |
| 89 } else { | 68 } else { |
| 90 callback.Run(NULL); | 69 callback.Run(NULL); |
| 91 } | 70 } |
| 92 } | 71 } |
| 93 | 72 |
| 94 bool MostVisitedIframeSource::ServesPath(const std::string& path) const { | 73 bool MostVisitedIframeSource::ServesPath(const std::string& path) const { |
| 95 return path == kTitleHTMLPath || path == kTitleCSSPath || | 74 return path == kTitleHTMLPath || path == kTitleCSSPath || |
| 96 path == kTitleJSPath || path == kThumbnailHTMLPath || | 75 path == kTitleJSPath || path == kThumbnailHTMLPath || |
| 97 path == kThumbnailCSSPath || path == kThumbnailJSPath || | 76 path == kThumbnailCSSPath || path == kThumbnailJSPath || |
| 98 path == kUtilJSPath || path == kCommonCSSPath || path == kLogHTMLPath; | 77 path == kUtilJSPath || path == kCommonCSSPath; |
| 99 } | 78 } |
| 100 | |
| 101 void MostVisitedIframeSource::LogMostVisitedProviderClick( | |
| 102 int position, | |
| 103 const std::string& provider) { | |
| 104 std::string histogram_name = | |
| 105 MostVisitedIframeSource::GetHistogramNameForProvider(provider); | |
| 106 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( | |
| 107 histogram_name, 1, | |
| 108 MostVisitedIframeSource::kNumMostVisited, | |
| 109 MostVisitedIframeSource::kNumMostVisited + 1, | |
| 110 base::Histogram::kUmaTargetedHistogramFlag); | |
| 111 counter->Add(position); | |
| 112 } | |
| 113 | |
| 114 // static | |
| 115 std::string MostVisitedIframeSource::GetHistogramNameForProvider( | |
| 116 const std::string& provider) { | |
| 117 return base::StringPrintf(kMostVisitedHistogramWithProvider, | |
| 118 provider.c_str()); | |
| 119 } | |
| OLD | NEW |