| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // reorder elements, only add new ones at the end (before COUNT), and keep in | 69 // reorder elements, only add new ones at the end (before COUNT), and keep in |
| 70 // sync with ContentSuggestionsCategory in histograms.xml. | 70 // sync with ContentSuggestionsCategory in histograms.xml. |
| 71 enum HistogramCategories { | 71 enum HistogramCategories { |
| 72 EXPERIMENTAL, | 72 EXPERIMENTAL, |
| 73 RECENT_TABS, | 73 RECENT_TABS, |
| 74 DOWNLOADS, | 74 DOWNLOADS, |
| 75 BOOKMARKS, | 75 BOOKMARKS, |
| 76 PHYSICAL_WEB_PAGES, | 76 PHYSICAL_WEB_PAGES, |
| 77 FOREIGN_TABS, | 77 FOREIGN_TABS, |
| 78 ARTICLES, | 78 ARTICLES, |
| 79 READING_LIST, |
| 79 // Insert new values here! | 80 // Insert new values here! |
| 80 COUNT | 81 COUNT |
| 81 }; | 82 }; |
| 82 | 83 |
| 83 HistogramCategories GetHistogramCategory(Category category) { | 84 HistogramCategories GetHistogramCategory(Category category) { |
| 84 static_assert( | 85 static_assert( |
| 85 std::is_same<decltype(category.id()), typename base::underlying_type< | 86 std::is_same<decltype(category.id()), typename base::underlying_type< |
| 86 KnownCategories>::type>::value, | 87 KnownCategories>::type>::value, |
| 87 "KnownCategories must have the same underlying type as category.id()"); | 88 "KnownCategories must have the same underlying type as category.id()"); |
| 88 // Note: Since the underlying type of KnownCategories is int, it's legal to | 89 // Note: Since the underlying type of KnownCategories is int, it's legal to |
| 89 // cast from int to KnownCategories, even if the given value isn't listed in | 90 // cast from int to KnownCategories, even if the given value isn't listed in |
| 90 // the enumeration. The switch still makes sure that all known values are | 91 // the enumeration. The switch still makes sure that all known values are |
| 91 // listed here. | 92 // listed here. |
| 92 auto known_category = static_cast<KnownCategories>(category.id()); | 93 auto known_category = static_cast<KnownCategories>(category.id()); |
| 93 switch (known_category) { | 94 switch (known_category) { |
| 94 case KnownCategories::RECENT_TABS: | 95 case KnownCategories::RECENT_TABS: |
| 95 return HistogramCategories::RECENT_TABS; | 96 return HistogramCategories::RECENT_TABS; |
| 96 case KnownCategories::DOWNLOADS: | 97 case KnownCategories::DOWNLOADS: |
| 97 return HistogramCategories::DOWNLOADS; | 98 return HistogramCategories::DOWNLOADS; |
| 98 case KnownCategories::BOOKMARKS: | 99 case KnownCategories::BOOKMARKS: |
| 99 return HistogramCategories::BOOKMARKS; | 100 return HistogramCategories::BOOKMARKS; |
| 100 case KnownCategories::PHYSICAL_WEB_PAGES: | 101 case KnownCategories::PHYSICAL_WEB_PAGES: |
| 101 return HistogramCategories::PHYSICAL_WEB_PAGES; | 102 return HistogramCategories::PHYSICAL_WEB_PAGES; |
| 102 case KnownCategories::FOREIGN_TABS: | 103 case KnownCategories::FOREIGN_TABS: |
| 103 return HistogramCategories::FOREIGN_TABS; | 104 return HistogramCategories::FOREIGN_TABS; |
| 104 case KnownCategories::ARTICLES: | 105 case KnownCategories::ARTICLES: |
| 105 return HistogramCategories::ARTICLES; | 106 return HistogramCategories::ARTICLES; |
| 107 case KnownCategories::READING_LIST: |
| 108 return HistogramCategories::READING_LIST; |
| 106 case KnownCategories::LOCAL_CATEGORIES_COUNT: | 109 case KnownCategories::LOCAL_CATEGORIES_COUNT: |
| 107 case KnownCategories::REMOTE_CATEGORIES_OFFSET: | 110 case KnownCategories::REMOTE_CATEGORIES_OFFSET: |
| 108 NOTREACHED(); | 111 NOTREACHED(); |
| 109 return HistogramCategories::COUNT; | 112 return HistogramCategories::COUNT; |
| 110 } | 113 } |
| 111 // All other (unknown) categories go into a single "Experimental" bucket. | 114 // All other (unknown) categories go into a single "Experimental" bucket. |
| 112 return HistogramCategories::EXPERIMENTAL; | 115 return HistogramCategories::EXPERIMENTAL; |
| 113 } | 116 } |
| 114 | 117 |
| 115 // Each suffix here should correspond to an entry under histogram suffix | 118 // Each suffix here should correspond to an entry under histogram suffix |
| 116 // ContentSuggestionCategory in histograms.xml. | 119 // ContentSuggestionCategory in histograms.xml. |
| 117 std::string GetCategorySuffix(Category category) { | 120 std::string GetCategorySuffix(Category category) { |
| 118 HistogramCategories histogram_category = GetHistogramCategory(category); | 121 HistogramCategories histogram_category = GetHistogramCategory(category); |
| 119 switch (histogram_category) { | 122 switch (histogram_category) { |
| 120 case HistogramCategories::RECENT_TABS: | 123 case HistogramCategories::RECENT_TABS: |
| 121 return "RecentTabs"; | 124 return "RecentTabs"; |
| 122 case HistogramCategories::DOWNLOADS: | 125 case HistogramCategories::DOWNLOADS: |
| 123 return "Downloads"; | 126 return "Downloads"; |
| 124 case HistogramCategories::BOOKMARKS: | 127 case HistogramCategories::BOOKMARKS: |
| 125 return "Bookmarks"; | 128 return "Bookmarks"; |
| 126 case HistogramCategories::PHYSICAL_WEB_PAGES: | 129 case HistogramCategories::PHYSICAL_WEB_PAGES: |
| 127 return "PhysicalWeb"; | 130 return "PhysicalWeb"; |
| 128 case HistogramCategories::FOREIGN_TABS: | 131 case HistogramCategories::FOREIGN_TABS: |
| 129 return "ForeignTabs"; | 132 return "ForeignTabs"; |
| 130 case HistogramCategories::ARTICLES: | 133 case HistogramCategories::ARTICLES: |
| 131 return "Articles"; | 134 return "Articles"; |
| 132 case HistogramCategories::EXPERIMENTAL: | 135 case HistogramCategories::EXPERIMENTAL: |
| 133 return "Experimental"; | 136 return "Experimental"; |
| 137 case HistogramCategories::READING_LIST: |
| 138 return "ReadingList"; |
| 134 case HistogramCategories::COUNT: | 139 case HistogramCategories::COUNT: |
| 135 NOTREACHED(); | 140 NOTREACHED(); |
| 136 break; | 141 break; |
| 137 } | 142 } |
| 138 return std::string(); | 143 return std::string(); |
| 139 } | 144 } |
| 140 | 145 |
| 141 std::string GetCategoryHistogramName(const char* base_name, Category category) { | 146 std::string GetCategoryHistogramName(const char* base_name, Category category) { |
| 142 return base::StringPrintf(kPerCategoryHistogramFormat, base_name, | 147 return base::StringPrintf(kPerCategoryHistogramFormat, base_name, |
| 143 GetCategorySuffix(category).c_str()); | 148 GetCategorySuffix(category).c_str()); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 } | 357 } |
| 353 | 358 |
| 354 void OnCategoryDismissed(Category category) { | 359 void OnCategoryDismissed(Category category) { |
| 355 UMA_HISTOGRAM_ENUMERATION(kHistogramCategoryDismissed, | 360 UMA_HISTOGRAM_ENUMERATION(kHistogramCategoryDismissed, |
| 356 GetHistogramCategory(category), | 361 GetHistogramCategory(category), |
| 357 HistogramCategories::COUNT); | 362 HistogramCategories::COUNT); |
| 358 } | 363 } |
| 359 | 364 |
| 360 } // namespace metrics | 365 } // namespace metrics |
| 361 } // namespace ntp_snippets | 366 } // namespace ntp_snippets |
| OLD | NEW |