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

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: clean 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";
26 27
28 #define MV_CLICK_HISTOGRAM(position, provider) \
Alexei Svitkine (slow) 2013/12/12 22:15:44 Add a comment that mentions why this can't use the
Mathieu 2013/12/13 15:01:38 Done.
29 do { \
30 std::string histogram_name = provider ? \
31 base::StringPrintf( \
32 MostVisitedIframeSource::kMostVisitedHistogramWithProvider, \
33 provider) : MostVisitedIframeSource::kMostVisitedHistogramName; \
Alexei Svitkine (slow) 2013/12/12 22:15:44 Shouldn't you log the non-suffixed histogram too e
Mathieu 2013/12/13 15:01:38 I was combining both in this macro and passing NUL
34 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( \
35 histogram_name, 1, MostVisitedIframeSource::kNumMostVisited, \
36 MostVisitedIframeSource::kNumMostVisited + 1, \
37 base::Histogram::kUmaTargetedHistogramFlag); \
38 counter->Add(position); \
39 } while (0)
40
27 } // namespace 41 } // namespace
28 42
29 MostVisitedIframeSource::MostVisitedIframeSource() { 43 MostVisitedIframeSource::MostVisitedIframeSource() {
30 } 44 }
31 45
32 MostVisitedIframeSource::~MostVisitedIframeSource() { 46 MostVisitedIframeSource::~MostVisitedIframeSource() {
33 } 47 }
34 48
35 const int MostVisitedIframeSource::kNumMostVisited = 8; 49 const int MostVisitedIframeSource::kNumMostVisited = 8;
36 const char MostVisitedIframeSource::kMostVisitedHistogramName[] = 50 const char MostVisitedIframeSource::kMostVisitedHistogramName[] =
37 "NewTabPage.MostVisited"; 51 "NewTabPage.MostVisited";
52 const char MostVisitedIframeSource::kMostVisitedHistogramWithProvider[] =
53 "NewTabPage.MostVisited.%s";
38 54
39 std::string MostVisitedIframeSource::GetSource() const { 55 std::string MostVisitedIframeSource::GetSource() const {
40 return chrome::kChromeSearchMostVisitedHost; 56 return chrome::kChromeSearchMostVisitedHost;
41 } 57 }
42 58
43 void MostVisitedIframeSource::StartDataRequest( 59 void MostVisitedIframeSource::StartDataRequest(
44 const std::string& path_and_query, 60 const std::string& path_and_query,
45 int render_process_id, 61 int render_process_id,
46 int render_view_id, 62 int render_view_id,
47 const content::URLDataSource::GotDataCallback& callback) { 63 const content::URLDataSource::GotDataCallback& callback) {
(...skipping 14 matching lines...) Expand all
62 } else if (path == kUtilJSPath) { 78 } else if (path == kUtilJSPath) {
63 SendResource(IDR_MOST_VISITED_UTIL_JS, callback); 79 SendResource(IDR_MOST_VISITED_UTIL_JS, callback);
64 } else if (path == kCommonCSSPath) { 80 } else if (path == kCommonCSSPath) {
65 SendResource(IDR_MOST_VISITED_IFRAME_CSS, callback); 81 SendResource(IDR_MOST_VISITED_IFRAME_CSS, callback);
66 } else if (path == kLogHTMLPath) { 82 } else if (path == kLogHTMLPath) {
67 // Log the clicked MostVisited element by position. 83 // Log the clicked MostVisited element by position.
68 std::string str_position; 84 std::string str_position;
69 int position; 85 int position;
70 if (net::GetValueForKeyInQuery(url, "pos", &str_position) && 86 if (net::GetValueForKeyInQuery(url, "pos", &str_position) &&
71 base::StringToInt(str_position, &position)) { 87 base::StringToInt(str_position, &position)) {
72 UMA_HISTOGRAM_ENUMERATION(kMostVisitedHistogramName, position, 88 // Log the Most Visited click.
73 kNumMostVisited); 89 MV_CLICK_HISTOGRAM(position, NULL);
90 // If a specific provider is specified, log the metric specific to the
91 // provider.
92 std::string provider;
93 if (net::GetValueForKeyInQuery(url, "pr", &provider)) {
Alexei Svitkine (slow) 2013/12/12 22:15:44 Nit: {} not needed.
Mathieu 2013/12/13 15:01:38 Done.
94 MV_CLICK_HISTOGRAM(position, provider.c_str());
95 }
74 // Records the action. This will be available as a time-stamped stream 96 // 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. 97 // server-side and can be used to compute time-to-long-dwell.
76 content::RecordAction(content::UserMetricsAction("MostVisited_Clicked")); 98 content::RecordAction(content::UserMetricsAction("MostVisited_Clicked"));
77 } 99 }
78 callback.Run(NULL); 100 callback.Run(NULL);
79 } else { 101 } else {
80 callback.Run(NULL); 102 callback.Run(NULL);
81 } 103 }
82 } 104 }
83 105
84 bool MostVisitedIframeSource::ServesPath(const std::string& path) const { 106 bool MostVisitedIframeSource::ServesPath(const std::string& path) const {
85 return path == kTitleHTMLPath || path == kTitleCSSPath || 107 return path == kTitleHTMLPath || path == kTitleCSSPath ||
86 path == kTitleJSPath || path == kThumbnailHTMLPath || 108 path == kTitleJSPath || path == kThumbnailHTMLPath ||
87 path == kThumbnailCSSPath || path == kThumbnailJSPath || 109 path == kThumbnailCSSPath || path == kThumbnailJSPath ||
88 path == kUtilJSPath || path == kCommonCSSPath || path == kLogHTMLPath; 110 path == kUtilJSPath || path == kCommonCSSPath || path == kLogHTMLPath;
89 } 111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698