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 | 8 |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 26 matching lines...) Expand all Loading... | |
37 const char kHistogramVisitDuration[] = | 37 const char kHistogramVisitDuration[] = |
38 "NewTabPage.ContentSuggestions.VisitDuration"; | 38 "NewTabPage.ContentSuggestions.VisitDuration"; |
39 const char kHistogramMoreButtonShown[] = | 39 const char kHistogramMoreButtonShown[] = |
40 "NewTabPage.ContentSuggestions.MoreButtonShown"; | 40 "NewTabPage.ContentSuggestions.MoreButtonShown"; |
41 const char kHistogramMoreButtonClicked[] = | 41 const char kHistogramMoreButtonClicked[] = |
42 "NewTabPage.ContentSuggestions.MoreButtonClicked"; | 42 "NewTabPage.ContentSuggestions.MoreButtonClicked"; |
43 | 43 |
44 const char kPerCategoryHistogramFormat[] = "%s.%s"; | 44 const char kPerCategoryHistogramFormat[] = "%s.%s"; |
45 | 45 |
46 std::string GetCategorySuffix(Category category) { | 46 std::string GetCategorySuffix(Category category) { |
47 // TODO(treib): Find a way to produce a compile error if a known category | 47 if (category.IsAnyKnownCategory()) { |
48 // isn't listed here. | 48 KnownCategories known_category = |
49 if (category.IsKnownCategory(KnownCategories::RECENT_TABS)) | 49 static_cast<KnownCategories>(category.id()); |
50 return "RecentTabs"; | 50 switch (known_category) { |
jkrcal
2016/09/13 16:08:05
Way better, thanks!
| |
51 if (category.IsKnownCategory(KnownCategories::DOWNLOADS)) | 51 case KnownCategories::RECENT_TABS: |
52 return "Downloads"; | 52 return "RecentTabs"; |
53 if (category.IsKnownCategory(KnownCategories::BOOKMARKS)) | 53 case KnownCategories::DOWNLOADS: |
54 return "Bookmarks"; | 54 return "Downloads"; |
55 if (category.IsKnownCategory(KnownCategories::ARTICLES)) | 55 case KnownCategories::BOOKMARKS: |
56 return "Articles"; | 56 return "Bookmarks"; |
57 // All other categories go into a single "Experimental" bucket. | 57 case KnownCategories::PHYSICAL_WEB_PAGES: |
58 return "PhysicalWeb"; | |
59 case KnownCategories::ARTICLES: | |
60 return "Articles"; | |
61 case KnownCategories::LOCAL_CATEGORIES_COUNT: | |
62 case KnownCategories::REMOTE_CATEGORIES_OFFSET: | |
63 NOTREACHED(); | |
64 break; | |
65 } | |
66 } | |
67 // All other (unknown) categories go into a single "Experimental" bucket. | |
58 return "Experimental"; | 68 return "Experimental"; |
59 } | 69 } |
60 | 70 |
61 std::string GetCategoryHistogramName(const char* base_name, Category category) { | 71 std::string GetCategoryHistogramName(const char* base_name, Category category) { |
62 return base::StringPrintf(kPerCategoryHistogramFormat, base_name, | 72 return base::StringPrintf(kPerCategoryHistogramFormat, base_name, |
63 GetCategorySuffix(category).c_str()); | 73 GetCategorySuffix(category).c_str()); |
64 } | 74 } |
65 | 75 |
66 // This corresponds to UMA_HISTOGRAM_ENUMERATION, for use with dynamic histogram | 76 // This corresponds to UMA_HISTOGRAM_ENUMERATION, for use with dynamic histogram |
67 // names. | 77 // names. |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 | 229 |
220 void OnMoreButtonClicked(Category category, int position) { | 230 void OnMoreButtonClicked(Category category, int position) { |
221 // The "more" card can appear in addition to the actual suggestions, so add | 231 // The "more" card can appear in addition to the actual suggestions, so add |
222 // one extra bucket to this histogram. | 232 // one extra bucket to this histogram. |
223 LogCategoryHistogramEnumeration(kHistogramMoreButtonClicked, category, | 233 LogCategoryHistogramEnumeration(kHistogramMoreButtonClicked, category, |
224 position, kMaxSuggestionsPerCategory + 1); | 234 position, kMaxSuggestionsPerCategory + 1); |
225 } | 235 } |
226 | 236 |
227 } // namespace metrics | 237 } // namespace metrics |
228 } // namespace ntp_snippets | 238 } // namespace ntp_snippets |
OLD | NEW |