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"; | |
28 | 26 |
29 } // namespace | 27 } // namespace |
30 | 28 |
31 MostVisitedIframeSource::MostVisitedIframeSource() { | 29 MostVisitedIframeSource::MostVisitedIframeSource() { |
32 } | 30 } |
33 | 31 |
34 MostVisitedIframeSource::~MostVisitedIframeSource() { | 32 MostVisitedIframeSource::~MostVisitedIframeSource() { |
35 } | 33 } |
36 | 34 |
37 const int MostVisitedIframeSource::kNumMostVisited = 8; | 35 const int MostVisitedIframeSource::kNumMostVisited = 8; |
(...skipping 21 matching lines...) Expand all Loading... |
59 SendResource(IDR_MOST_VISITED_THUMBNAIL_HTML, callback); | 57 SendResource(IDR_MOST_VISITED_THUMBNAIL_HTML, callback); |
60 } else if (path == kThumbnailCSSPath) { | 58 } else if (path == kThumbnailCSSPath) { |
61 SendResource(IDR_MOST_VISITED_THUMBNAIL_CSS, callback); | 59 SendResource(IDR_MOST_VISITED_THUMBNAIL_CSS, callback); |
62 } else if (path == kThumbnailJSPath) { | 60 } else if (path == kThumbnailJSPath) { |
63 SendJSWithOrigin(IDR_MOST_VISITED_THUMBNAIL_JS, render_process_id, | 61 SendJSWithOrigin(IDR_MOST_VISITED_THUMBNAIL_JS, render_process_id, |
64 render_frame_id, callback); | 62 render_frame_id, callback); |
65 } else if (path == kUtilJSPath) { | 63 } else if (path == kUtilJSPath) { |
66 SendResource(IDR_MOST_VISITED_UTIL_JS, callback); | 64 SendResource(IDR_MOST_VISITED_UTIL_JS, callback); |
67 } else if (path == kCommonCSSPath) { | 65 } else if (path == kCommonCSSPath) { |
68 SendResource(IDR_MOST_VISITED_IFRAME_CSS, callback); | 66 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 { | 67 } else { |
90 callback.Run(NULL); | 68 callback.Run(NULL); |
91 } | 69 } |
92 } | 70 } |
93 | 71 |
94 bool MostVisitedIframeSource::ServesPath(const std::string& path) const { | 72 bool MostVisitedIframeSource::ServesPath(const std::string& path) const { |
95 return path == kTitleHTMLPath || path == kTitleCSSPath || | 73 return path == kTitleHTMLPath || path == kTitleCSSPath || |
96 path == kTitleJSPath || path == kThumbnailHTMLPath || | 74 path == kTitleJSPath || path == kThumbnailHTMLPath || |
97 path == kThumbnailCSSPath || path == kThumbnailJSPath || | 75 path == kThumbnailCSSPath || path == kThumbnailJSPath || |
98 path == kUtilJSPath || path == kCommonCSSPath || path == kLogHTMLPath; | 76 path == kUtilJSPath || path == kCommonCSSPath; |
99 } | 77 } |
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 |