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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/ntp_snippets/content_suggestions_metrics.cc
diff --git a/components/ntp_snippets/content_suggestions_metrics.cc b/components/ntp_snippets/content_suggestions_metrics.cc
index 5d4fbe169ad5a462da482bcc432b02bbbaa3b785..b83522a73a3d6a7768dbff941e392f829b0d8eac 100644
--- a/components/ntp_snippets/content_suggestions_metrics.cc
+++ b/components/ntp_snippets/content_suggestions_metrics.cc
@@ -5,10 +5,12 @@
#include "components/ntp_snippets/content_suggestions_metrics.h"
#include <string>
+#include <type_traits>
#include "base/metrics/histogram.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/stringprintf.h"
+#include "base/template_util.h"
namespace ntp_snippets {
namespace metrics {
@@ -44,17 +46,32 @@ const char kHistogramMoreButtonClicked[] =
const char kPerCategoryHistogramFormat[] = "%s.%s";
std::string GetCategorySuffix(Category category) {
- // TODO(treib): Find a way to produce a compile error if a known category
- // isn't listed here.
- if (category.IsKnownCategory(KnownCategories::RECENT_TABS))
- return "RecentTabs";
- if (category.IsKnownCategory(KnownCategories::DOWNLOADS))
- return "Downloads";
- if (category.IsKnownCategory(KnownCategories::BOOKMARKS))
- return "Bookmarks";
- if (category.IsKnownCategory(KnownCategories::ARTICLES))
- return "Articles";
- // All other categories go into a single "Experimental" bucket.
+ static_assert(
+ std::is_same<decltype(category.id()), typename base::underlying_type<
+ KnownCategories>::type>::value,
+ "KnownCategories must have the same underlying type as category.id()");
+ // Note: Since the underlying type of KnownCategories is int, it's legal to
+ // cast from int to KnownCategories, even if the given value isn't listed in
+ // the enumeration. The switch still makes sure that all known values are
+ // listed here.
+ KnownCategories known_category = static_cast<KnownCategories>(category.id());
+ switch (known_category) {
+ case KnownCategories::RECENT_TABS:
+ return "RecentTabs";
+ case KnownCategories::DOWNLOADS:
+ return "Downloads";
+ case KnownCategories::BOOKMARKS:
+ return "Bookmarks";
+ case KnownCategories::PHYSICAL_WEB_PAGES:
+ return "PhysicalWeb";
+ case KnownCategories::ARTICLES:
+ return "Articles";
+ case KnownCategories::LOCAL_CATEGORIES_COUNT:
+ case KnownCategories::REMOTE_CATEGORIES_OFFSET:
+ NOTREACHED();
+ break;
+ }
+ // All other (unknown) categories go into a single "Experimental" bucket.
return "Experimental";
}
« 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