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 <string> | 7 #include <string> |
8 #include <type_traits> | 8 #include <type_traits> |
9 | 9 |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 "NewTabPage.ContentSuggestions.MenuOpenedScore"; | 38 "NewTabPage.ContentSuggestions.MenuOpenedScore"; |
39 const char kHistogramVisitDuration[] = | 39 const char kHistogramVisitDuration[] = |
40 "NewTabPage.ContentSuggestions.VisitDuration"; | 40 "NewTabPage.ContentSuggestions.VisitDuration"; |
41 const char kHistogramMoreButtonShown[] = | 41 const char kHistogramMoreButtonShown[] = |
42 "NewTabPage.ContentSuggestions.MoreButtonShown"; | 42 "NewTabPage.ContentSuggestions.MoreButtonShown"; |
43 const char kHistogramMoreButtonClicked[] = | 43 const char kHistogramMoreButtonClicked[] = |
44 "NewTabPage.ContentSuggestions.MoreButtonClicked"; | 44 "NewTabPage.ContentSuggestions.MoreButtonClicked"; |
45 | 45 |
46 const char kPerCategoryHistogramFormat[] = "%s.%s"; | 46 const char kPerCategoryHistogramFormat[] = "%s.%s"; |
47 | 47 |
| 48 // Each suffix here should correspond to an entry under histogram suffix |
| 49 // ContentSuggestionCategory in histograms.xml. |
48 std::string GetCategorySuffix(Category category) { | 50 std::string GetCategorySuffix(Category category) { |
49 static_assert( | 51 static_assert( |
50 std::is_same<decltype(category.id()), typename base::underlying_type< | 52 std::is_same<decltype(category.id()), typename base::underlying_type< |
51 KnownCategories>::type>::value, | 53 KnownCategories>::type>::value, |
52 "KnownCategories must have the same underlying type as category.id()"); | 54 "KnownCategories must have the same underlying type as category.id()"); |
53 // Note: Since the underlying type of KnownCategories is int, it's legal to | 55 // Note: Since the underlying type of KnownCategories is int, it's legal to |
54 // cast from int to KnownCategories, even if the given value isn't listed in | 56 // cast from int to KnownCategories, even if the given value isn't listed in |
55 // the enumeration. The switch still makes sure that all known values are | 57 // the enumeration. The switch still makes sure that all known values are |
56 // listed here. | 58 // listed here. |
57 KnownCategories known_category = static_cast<KnownCategories>(category.id()); | 59 KnownCategories known_category = static_cast<KnownCategories>(category.id()); |
58 switch (known_category) { | 60 switch (known_category) { |
59 case KnownCategories::RECENT_TABS: | 61 case KnownCategories::RECENT_TABS: |
60 return "RecentTabs"; | 62 return "RecentTabs"; |
61 case KnownCategories::DOWNLOADS: | 63 case KnownCategories::DOWNLOADS: |
62 return "Downloads"; | 64 return "Downloads"; |
63 case KnownCategories::BOOKMARKS: | 65 case KnownCategories::BOOKMARKS: |
64 return "Bookmarks"; | 66 return "Bookmarks"; |
65 case KnownCategories::PHYSICAL_WEB_PAGES: | 67 case KnownCategories::PHYSICAL_WEB_PAGES: |
66 return "PhysicalWeb"; | 68 return "PhysicalWeb"; |
| 69 case KnownCategories::FOREIGN_TABS: |
| 70 return "ForeignTabs"; |
67 case KnownCategories::ARTICLES: | 71 case KnownCategories::ARTICLES: |
68 return "Articles"; | 72 return "Articles"; |
69 case KnownCategories::LOCAL_CATEGORIES_COUNT: | 73 case KnownCategories::LOCAL_CATEGORIES_COUNT: |
70 case KnownCategories::REMOTE_CATEGORIES_OFFSET: | 74 case KnownCategories::REMOTE_CATEGORIES_OFFSET: |
71 NOTREACHED(); | 75 NOTREACHED(); |
72 break; | 76 break; |
73 } | 77 } |
74 // All other (unknown) categories go into a single "Experimental" bucket. | 78 // All other (unknown) categories go into a single "Experimental" bucket. |
75 return "Experimental"; | 79 return "Experimental"; |
76 } | 80 } |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 240 |
237 void OnMoreButtonClicked(Category category, int position) { | 241 void OnMoreButtonClicked(Category category, int position) { |
238 // The "more" card can appear in addition to the actual suggestions, so add | 242 // The "more" card can appear in addition to the actual suggestions, so add |
239 // one extra bucket to this histogram. | 243 // one extra bucket to this histogram. |
240 LogCategoryHistogramEnumeration(kHistogramMoreButtonClicked, category, | 244 LogCategoryHistogramEnumeration(kHistogramMoreButtonClicked, category, |
241 position, kMaxSuggestionsPerCategory + 1); | 245 position, kMaxSuggestionsPerCategory + 1); |
242 } | 246 } |
243 | 247 |
244 } // namespace metrics | 248 } // namespace metrics |
245 } // namespace ntp_snippets | 249 } // namespace ntp_snippets |
OLD | NEW |