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

Side by Side Diff: components/ntp_snippets/content_suggestions_metrics.cc

Issue 2337103003: [NTP Snippets] Metrics: switch over known categories (Closed)
Patch Set: base::underlying_type :-/ Created 4 years, 3 months 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
« no previous file with comments | « components/ntp_snippets/category_factory.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/ntp_snippets/content_suggestions_metrics.h" 5 #include "components/ntp_snippets/content_suggestions_metrics.h"
6 6
7 #include <string> 7 #include <string>
8 #include <type_traits>
8 9
9 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
10 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
11 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/template_util.h"
12 14
13 namespace ntp_snippets { 15 namespace ntp_snippets {
14 namespace metrics { 16 namespace metrics {
15 17
16 namespace { 18 namespace {
17 19
18 const int kMaxSuggestionsPerCategory = 10; 20 const int kMaxSuggestionsPerCategory = 10;
19 const int kMaxSuggestionsTotal = 50; 21 const int kMaxSuggestionsTotal = 50;
20 22
21 const char kHistogramCountOnNtpOpened[] = 23 const char kHistogramCountOnNtpOpened[] =
(...skipping 15 matching lines...) Expand all
37 const char kHistogramVisitDuration[] = 39 const char kHistogramVisitDuration[] =
38 "NewTabPage.ContentSuggestions.VisitDuration"; 40 "NewTabPage.ContentSuggestions.VisitDuration";
39 const char kHistogramMoreButtonShown[] = 41 const char kHistogramMoreButtonShown[] =
40 "NewTabPage.ContentSuggestions.MoreButtonShown"; 42 "NewTabPage.ContentSuggestions.MoreButtonShown";
41 const char kHistogramMoreButtonClicked[] = 43 const char kHistogramMoreButtonClicked[] =
42 "NewTabPage.ContentSuggestions.MoreButtonClicked"; 44 "NewTabPage.ContentSuggestions.MoreButtonClicked";
43 45
44 const char kPerCategoryHistogramFormat[] = "%s.%s"; 46 const char kPerCategoryHistogramFormat[] = "%s.%s";
45 47
46 std::string GetCategorySuffix(Category category) { 48 std::string GetCategorySuffix(Category category) {
47 // TODO(treib): Find a way to produce a compile error if a known category 49 static_assert(
48 // isn't listed here. 50 std::is_same<decltype(category.id()), typename base::underlying_type<
49 if (category.IsKnownCategory(KnownCategories::RECENT_TABS)) 51 KnownCategories>::type>::value,
50 return "RecentTabs"; 52 "KnownCategories must have the same underlying type as category.id()");
51 if (category.IsKnownCategory(KnownCategories::DOWNLOADS)) 53 // Note: Since the underlying type of KnownCategories is int, it's legal to
52 return "Downloads"; 54 // cast from int to KnownCategories, even if the given value isn't listed in
53 if (category.IsKnownCategory(KnownCategories::BOOKMARKS)) 55 // the enumeration. The switch still makes sure that all known values are
54 return "Bookmarks"; 56 // listed here.
55 if (category.IsKnownCategory(KnownCategories::ARTICLES)) 57 KnownCategories known_category = static_cast<KnownCategories>(category.id());
56 return "Articles"; 58 switch (known_category) {
57 // All other categories go into a single "Experimental" bucket. 59 case KnownCategories::RECENT_TABS:
60 return "RecentTabs";
61 case KnownCategories::DOWNLOADS:
62 return "Downloads";
63 case KnownCategories::BOOKMARKS:
64 return "Bookmarks";
65 case KnownCategories::PHYSICAL_WEB_PAGES:
66 return "PhysicalWeb";
67 case KnownCategories::ARTICLES:
68 return "Articles";
69 case KnownCategories::LOCAL_CATEGORIES_COUNT:
70 case KnownCategories::REMOTE_CATEGORIES_OFFSET:
71 NOTREACHED();
72 break;
73 }
74 // All other (unknown) categories go into a single "Experimental" bucket.
58 return "Experimental"; 75 return "Experimental";
59 } 76 }
60 77
61 std::string GetCategoryHistogramName(const char* base_name, Category category) { 78 std::string GetCategoryHistogramName(const char* base_name, Category category) {
62 return base::StringPrintf(kPerCategoryHistogramFormat, base_name, 79 return base::StringPrintf(kPerCategoryHistogramFormat, base_name,
63 GetCategorySuffix(category).c_str()); 80 GetCategorySuffix(category).c_str());
64 } 81 }
65 82
66 // This corresponds to UMA_HISTOGRAM_ENUMERATION, for use with dynamic histogram 83 // This corresponds to UMA_HISTOGRAM_ENUMERATION, for use with dynamic histogram
67 // names. 84 // names.
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 236
220 void OnMoreButtonClicked(Category category, int position) { 237 void OnMoreButtonClicked(Category category, int position) {
221 // The "more" card can appear in addition to the actual suggestions, so add 238 // The "more" card can appear in addition to the actual suggestions, so add
222 // one extra bucket to this histogram. 239 // one extra bucket to this histogram.
223 LogCategoryHistogramEnumeration(kHistogramMoreButtonClicked, category, 240 LogCategoryHistogramEnumeration(kHistogramMoreButtonClicked, category,
224 position, kMaxSuggestionsPerCategory + 1); 241 position, kMaxSuggestionsPerCategory + 1);
225 } 242 }
226 243
227 } // namespace metrics 244 } // namespace metrics
228 } // namespace ntp_snippets 245 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/category_factory.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698