OLD | NEW |
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 <cmath> | 7 #include <cmath> |
8 #include <string> | 8 #include <string> |
9 #include <type_traits> | 9 #include <type_traits> |
10 | 10 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // sync with ContentSuggestionsCategory in histograms.xml. | 71 // sync with ContentSuggestionsCategory in histograms.xml. |
72 enum HistogramCategories { | 72 enum HistogramCategories { |
73 EXPERIMENTAL, | 73 EXPERIMENTAL, |
74 RECENT_TABS, | 74 RECENT_TABS, |
75 DOWNLOADS, | 75 DOWNLOADS, |
76 BOOKMARKS, | 76 BOOKMARKS, |
77 PHYSICAL_WEB_PAGES, | 77 PHYSICAL_WEB_PAGES, |
78 FOREIGN_TABS, | 78 FOREIGN_TABS, |
79 ARTICLES, | 79 ARTICLES, |
80 READING_LIST, | 80 READING_LIST, |
| 81 BREAKING_NEWS, |
81 // Insert new values here! | 82 // Insert new values here! |
82 COUNT | 83 COUNT |
83 }; | 84 }; |
84 | 85 |
85 HistogramCategories GetHistogramCategory(Category category) { | 86 HistogramCategories GetHistogramCategory(Category category) { |
86 static_assert( | 87 static_assert( |
87 std::is_same<decltype(category.id()), | 88 std::is_same<decltype(category.id()), |
88 typename std::underlying_type<KnownCategories>::type>::value, | 89 typename std::underlying_type<KnownCategories>::type>::value, |
89 "KnownCategories must have the same underlying type as category.id()"); | 90 "KnownCategories must have the same underlying type as category.id()"); |
90 // Note: Since the underlying type of KnownCategories is int, it's legal to | 91 // Note: Since the underlying type of KnownCategories is int, it's legal to |
91 // cast from int to KnownCategories, even if the given value isn't listed in | 92 // cast from int to KnownCategories, even if the given value isn't listed in |
92 // the enumeration. The switch still makes sure that all known values are | 93 // the enumeration. The switch still makes sure that all known values are |
93 // listed here. | 94 // listed here. |
94 auto known_category = static_cast<KnownCategories>(category.id()); | 95 auto known_category = static_cast<KnownCategories>(category.id()); |
95 switch (known_category) { | 96 switch (known_category) { |
96 case KnownCategories::RECENT_TABS: | 97 case KnownCategories::RECENT_TABS: |
97 return HistogramCategories::RECENT_TABS; | 98 return HistogramCategories::RECENT_TABS; |
98 case KnownCategories::DOWNLOADS: | 99 case KnownCategories::DOWNLOADS: |
99 return HistogramCategories::DOWNLOADS; | 100 return HistogramCategories::DOWNLOADS; |
100 case KnownCategories::BOOKMARKS: | 101 case KnownCategories::BOOKMARKS: |
101 return HistogramCategories::BOOKMARKS; | 102 return HistogramCategories::BOOKMARKS; |
102 case KnownCategories::PHYSICAL_WEB_PAGES: | 103 case KnownCategories::PHYSICAL_WEB_PAGES: |
103 return HistogramCategories::PHYSICAL_WEB_PAGES; | 104 return HistogramCategories::PHYSICAL_WEB_PAGES; |
104 case KnownCategories::FOREIGN_TABS: | 105 case KnownCategories::FOREIGN_TABS: |
105 return HistogramCategories::FOREIGN_TABS; | 106 return HistogramCategories::FOREIGN_TABS; |
106 case KnownCategories::ARTICLES: | 107 case KnownCategories::ARTICLES: |
107 return HistogramCategories::ARTICLES; | 108 return HistogramCategories::ARTICLES; |
108 case KnownCategories::READING_LIST: | 109 case KnownCategories::READING_LIST: |
109 return HistogramCategories::READING_LIST; | 110 return HistogramCategories::READING_LIST; |
| 111 case KnownCategories::BREAKING_NEWS: |
| 112 return HistogramCategories::BREAKING_NEWS; |
110 case KnownCategories::LOCAL_CATEGORIES_COUNT: | 113 case KnownCategories::LOCAL_CATEGORIES_COUNT: |
111 case KnownCategories::REMOTE_CATEGORIES_OFFSET: | 114 case KnownCategories::REMOTE_CATEGORIES_OFFSET: |
112 NOTREACHED(); | 115 NOTREACHED(); |
113 return HistogramCategories::COUNT; | 116 return HistogramCategories::COUNT; |
114 } | 117 } |
115 // All other (unknown) categories go into a single "Experimental" bucket. | 118 // All other (unknown) categories go into a single "Experimental" bucket. |
116 return HistogramCategories::EXPERIMENTAL; | 119 return HistogramCategories::EXPERIMENTAL; |
117 } | 120 } |
118 | 121 |
119 // Each suffix here should correspond to an entry under histogram suffix | 122 // Each suffix here should correspond to an entry under histogram suffix |
(...skipping 10 matching lines...) Expand all Loading... |
130 case HistogramCategories::PHYSICAL_WEB_PAGES: | 133 case HistogramCategories::PHYSICAL_WEB_PAGES: |
131 return "PhysicalWeb"; | 134 return "PhysicalWeb"; |
132 case HistogramCategories::FOREIGN_TABS: | 135 case HistogramCategories::FOREIGN_TABS: |
133 return "ForeignTabs"; | 136 return "ForeignTabs"; |
134 case HistogramCategories::ARTICLES: | 137 case HistogramCategories::ARTICLES: |
135 return "Articles"; | 138 return "Articles"; |
136 case HistogramCategories::EXPERIMENTAL: | 139 case HistogramCategories::EXPERIMENTAL: |
137 return "Experimental"; | 140 return "Experimental"; |
138 case HistogramCategories::READING_LIST: | 141 case HistogramCategories::READING_LIST: |
139 return "ReadingList"; | 142 return "ReadingList"; |
| 143 case HistogramCategories::BREAKING_NEWS: |
| 144 return "BreakingNews"; |
140 case HistogramCategories::COUNT: | 145 case HistogramCategories::COUNT: |
141 NOTREACHED(); | 146 NOTREACHED(); |
142 break; | 147 break; |
143 } | 148 } |
144 return std::string(); | 149 return std::string(); |
145 } | 150 } |
146 | 151 |
147 std::string GetCategoryHistogramName(const char* base_name, Category category) { | 152 std::string GetCategoryHistogramName(const char* base_name, Category category) { |
148 return base::StringPrintf(kPerCategoryHistogramFormat, base_name, | 153 return base::StringPrintf(kPerCategoryHistogramFormat, base_name, |
149 GetCategorySuffix(category).c_str()); | 154 GetCategorySuffix(category).c_str()); |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 void RecordCategoryDismissed() { | 385 void RecordCategoryDismissed() { |
381 base::RecordAction(base::UserMetricsAction("Suggestions.Category.Dismissed")); | 386 base::RecordAction(base::UserMetricsAction("Suggestions.Category.Dismissed")); |
382 } | 387 } |
383 | 388 |
384 void RecordFetchAction() { | 389 void RecordFetchAction() { |
385 base::RecordAction(base::UserMetricsAction("Suggestions.Category.Fetch")); | 390 base::RecordAction(base::UserMetricsAction("Suggestions.Category.Fetch")); |
386 } | 391 } |
387 | 392 |
388 } // namespace metrics | 393 } // namespace metrics |
389 } // namespace ntp_snippets | 394 } // namespace ntp_snippets |
OLD | NEW |