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