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

Side by Side Diff: chrome/browser/search/most_visited_iframe_source.cc

Issue 111423005: [Most Visited] Log suggestion provider to UMA (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years 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 | Annotate | Revision Log
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 "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";
28
29 // This macro is needed because the histogram name changes according to the
30 // provider, and UMA_HISTOGRAM_ENUMERATION caches a given histogram object at
Jered 2013/12/13 19:39:38 Where are you using UMA_HISTOGRAM_ENUMERATION here
Mathieu 2013/12/13 20:00:38 You're right, done. Made it a private function so
31 // call site, which will not work in this scenario.
32 #define MV_PROVIDER_CLICK_HISTOGRAM(position, provider) \
33 do { \
34 std::string histogram_name = \
35 MostVisitedIframeSource::GetHistogramNameForProvider(provider); \
36 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( \
37 histogram_name, 1, \
38 MostVisitedIframeSource::kNumMostVisited, \
39 MostVisitedIframeSource::kNumMostVisited + 1, \
40 base::Histogram::kUmaTargetedHistogramFlag); \
41 counter->Add(position); \
42 } while (0)
26 43
27 } // namespace 44 } // namespace
28 45
29 MostVisitedIframeSource::MostVisitedIframeSource() { 46 MostVisitedIframeSource::MostVisitedIframeSource() {
30 } 47 }
31 48
32 MostVisitedIframeSource::~MostVisitedIframeSource() { 49 MostVisitedIframeSource::~MostVisitedIframeSource() {
33 } 50 }
34 51
35 const int MostVisitedIframeSource::kNumMostVisited = 8; 52 const int MostVisitedIframeSource::kNumMostVisited = 8;
(...skipping 26 matching lines...) Expand all
62 } else if (path == kUtilJSPath) { 79 } else if (path == kUtilJSPath) {
63 SendResource(IDR_MOST_VISITED_UTIL_JS, callback); 80 SendResource(IDR_MOST_VISITED_UTIL_JS, callback);
64 } else if (path == kCommonCSSPath) { 81 } else if (path == kCommonCSSPath) {
65 SendResource(IDR_MOST_VISITED_IFRAME_CSS, callback); 82 SendResource(IDR_MOST_VISITED_IFRAME_CSS, callback);
66 } else if (path == kLogHTMLPath) { 83 } else if (path == kLogHTMLPath) {
67 // Log the clicked MostVisited element by position. 84 // Log the clicked MostVisited element by position.
68 std::string str_position; 85 std::string str_position;
69 int position; 86 int position;
70 if (net::GetValueForKeyInQuery(url, "pos", &str_position) && 87 if (net::GetValueForKeyInQuery(url, "pos", &str_position) &&
71 base::StringToInt(str_position, &position)) { 88 base::StringToInt(str_position, &position)) {
89 // Log the Most Visited click.
72 UMA_HISTOGRAM_ENUMERATION(kMostVisitedHistogramName, position, 90 UMA_HISTOGRAM_ENUMERATION(kMostVisitedHistogramName, position,
73 kNumMostVisited); 91 kNumMostVisited);
92 // If a specific provider is specified, log the metric specific to the
93 // provider.
94 std::string provider;
95 if (net::GetValueForKeyInQuery(url, "pr", &provider))
96 MV_PROVIDER_CLICK_HISTOGRAM(position, provider.c_str());
97
74 // Records the action. This will be available as a time-stamped stream 98 // 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. 99 // server-side and can be used to compute time-to-long-dwell.
76 content::RecordAction(content::UserMetricsAction("MostVisited_Clicked")); 100 content::RecordAction(content::UserMetricsAction("MostVisited_Clicked"));
77 } 101 }
78 callback.Run(NULL); 102 callback.Run(NULL);
79 } else { 103 } else {
80 callback.Run(NULL); 104 callback.Run(NULL);
81 } 105 }
82 } 106 }
83 107
84 bool MostVisitedIframeSource::ServesPath(const std::string& path) const { 108 bool MostVisitedIframeSource::ServesPath(const std::string& path) const {
85 return path == kTitleHTMLPath || path == kTitleCSSPath || 109 return path == kTitleHTMLPath || path == kTitleCSSPath ||
86 path == kTitleJSPath || path == kThumbnailHTMLPath || 110 path == kTitleJSPath || path == kThumbnailHTMLPath ||
87 path == kThumbnailCSSPath || path == kThumbnailJSPath || 111 path == kThumbnailCSSPath || path == kThumbnailJSPath ||
88 path == kUtilJSPath || path == kCommonCSSPath || path == kLogHTMLPath; 112 path == kUtilJSPath || path == kCommonCSSPath || path == kLogHTMLPath;
89 } 113 }
114
115 // static
116 std::string MostVisitedIframeSource::GetHistogramNameForProvider(
117 const char* provider) {
118 return base::StringPrintf(kMostVisitedHistogramWithProvider, provider);
119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698