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_tiles/metrics.h" | 5 #include "components/ntp_tiles/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 void LogHistogramEvent(const std::string& histogram, | 37 void LogHistogramEvent(const std::string& histogram, |
38 int position, | 38 int position, |
39 int num_sites) { | 39 int num_sites) { |
40 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( | 40 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( |
41 histogram, 1, num_sites, num_sites + 1, | 41 histogram, 1, num_sites, num_sites + 1, |
42 base::Histogram::kUmaTargetedHistogramFlag); | 42 base::Histogram::kUmaTargetedHistogramFlag); |
43 if (counter) | 43 if (counter) |
44 counter->Add(position); | 44 counter->Add(position); |
45 } | 45 } |
46 | 46 |
47 std::string GetSourceHistogramName(NTPTileSource source) { | 47 std::string GetSourceHistogramName(TileSource source) { |
48 switch (source) { | 48 switch (source) { |
49 case NTPTileSource::TOP_SITES: | 49 case TileSource::TOP_SITES: |
50 return kHistogramClientName; | 50 return kHistogramClientName; |
51 case NTPTileSource::POPULAR: | 51 case TileSource::POPULAR: |
52 return kHistogramPopularName; | 52 return kHistogramPopularName; |
53 case NTPTileSource::WHITELIST: | 53 case TileSource::WHITELIST: |
54 return kHistogramWhitelistName; | 54 return kHistogramWhitelistName; |
55 case NTPTileSource::SUGGESTIONS_SERVICE: | 55 case TileSource::SUGGESTIONS_SERVICE: |
56 return kHistogramServerName; | 56 return kHistogramServerName; |
57 } | 57 } |
58 NOTREACHED(); | 58 NOTREACHED(); |
59 return std::string(); | 59 return std::string(); |
60 } | 60 } |
61 | 61 |
62 const char* GetIconTypeSuffix(MostVisitedTileType type) { | 62 const char* GetIconTypeSuffix(TileVisualType type) { |
63 switch (type) { | 63 switch (type) { |
64 case ICON_COLOR: | 64 case TileVisualType::ICON_COLOR: |
65 return kIconTypeSuffixColor; | 65 return kIconTypeSuffixColor; |
66 case ICON_DEFAULT: | 66 case TileVisualType::ICON_DEFAULT: |
67 return kIconTypeSuffixGray; | 67 return kIconTypeSuffixGray; |
68 case ICON_REAL: | 68 case TileVisualType::ICON_REAL: |
69 return kIconTypeSuffixReal; | 69 return kIconTypeSuffixReal; |
70 case NONE: // Fall through. | 70 case TileVisualType::NONE: // Fall through. |
71 case NUM_RECORDED_TILE_TYPES: // Fall through. | 71 case TileVisualType::NUM_RECORDED_TILE_TYPES: // Fall through. |
72 case THUMBNAIL: // Fall through. | 72 case TileVisualType::THUMBNAIL: // Fall through. |
73 case UNKNOWN_TILE_TYPE: | 73 case TileVisualType::UNKNOWN_TILE_TYPE: |
74 break; | 74 break; |
75 } | 75 } |
76 return nullptr; | 76 return nullptr; |
77 } | 77 } |
78 | 78 |
79 } // namespace | 79 } // namespace |
80 | 80 |
81 void RecordPageImpression(const std::vector<TileImpression>& tiles, | 81 void RecordPageImpression(const std::vector<TileImpression>& tiles, |
82 rappor::RapporService* rappor_service) { | 82 rappor::RapporService* rappor_service) { |
83 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.NumberOfTiles", tiles.size()); | 83 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.NumberOfTiles", tiles.size()); |
84 | 84 |
85 for (int index = 0; index < static_cast<int>(tiles.size()); index++) { | 85 for (int index = 0; index < static_cast<int>(tiles.size()); index++) { |
86 NTPTileSource source = tiles[index].source; | 86 TileSource source = tiles[index].source; |
87 MostVisitedTileType tile_type = tiles[index].type; | 87 TileVisualType tile_type = tiles[index].type; |
88 const GURL& url = tiles[index].url; | 88 const GURL& url = tiles[index].url; |
89 | 89 |
90 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SuggestionsImpression", index, | 90 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SuggestionsImpression", index, |
91 kMaxNumTiles); | 91 kMaxNumTiles); |
92 | 92 |
93 std::string source_name = GetSourceHistogramName(source); | 93 std::string source_name = GetSourceHistogramName(source); |
94 std::string impression_histogram = base::StringPrintf( | 94 std::string impression_histogram = base::StringPrintf( |
95 "NewTabPage.SuggestionsImpression.%s", source_name.c_str()); | 95 "NewTabPage.SuggestionsImpression.%s", source_name.c_str()); |
96 LogHistogramEvent(impression_histogram, index, kMaxNumTiles); | 96 LogHistogramEvent(impression_histogram, index, kMaxNumTiles); |
97 | 97 |
(...skipping 15 matching lines...) Expand all Loading... |
113 base::StringPrintf("NTP.SuggestionsImpressions.%s", icon_type_suffix), | 113 base::StringPrintf("NTP.SuggestionsImpressions.%s", icon_type_suffix), |
114 url); | 114 url); |
115 | 115 |
116 std::string icon_impression_histogram = base::StringPrintf( | 116 std::string icon_impression_histogram = base::StringPrintf( |
117 "NewTabPage.SuggestionsImpression.%s", icon_type_suffix); | 117 "NewTabPage.SuggestionsImpression.%s", icon_type_suffix); |
118 LogHistogramEvent(icon_impression_histogram, index, kMaxNumTiles); | 118 LogHistogramEvent(icon_impression_histogram, index, kMaxNumTiles); |
119 } | 119 } |
120 } | 120 } |
121 } | 121 } |
122 | 122 |
123 void RecordTileClick(int index, | 123 void RecordTileClick(int index, TileSource source, TileVisualType tile_type) { |
124 NTPTileSource source, | |
125 MostVisitedTileType tile_type) { | |
126 UMA_HISTOGRAM_ENUMERATION("NewTabPage.MostVisited", index, kMaxNumTiles); | 124 UMA_HISTOGRAM_ENUMERATION("NewTabPage.MostVisited", index, kMaxNumTiles); |
127 | 125 |
128 std::string histogram = base::StringPrintf( | 126 std::string histogram = base::StringPrintf( |
129 "NewTabPage.MostVisited.%s", GetSourceHistogramName(source).c_str()); | 127 "NewTabPage.MostVisited.%s", GetSourceHistogramName(source).c_str()); |
130 LogHistogramEvent(histogram, index, kMaxNumTiles); | 128 LogHistogramEvent(histogram, index, kMaxNumTiles); |
131 | 129 |
132 const char* icon_type_suffix = GetIconTypeSuffix(tile_type); | 130 const char* icon_type_suffix = GetIconTypeSuffix(tile_type); |
133 if (icon_type_suffix) { | 131 if (icon_type_suffix) { |
134 std::string icon_histogram = | 132 std::string icon_histogram = |
135 base::StringPrintf("NewTabPage.MostVisited.%s", icon_type_suffix); | 133 base::StringPrintf("NewTabPage.MostVisited.%s", icon_type_suffix); |
136 LogHistogramEvent(icon_histogram, index, kMaxNumTiles); | 134 LogHistogramEvent(icon_histogram, index, kMaxNumTiles); |
137 } | 135 } |
138 | 136 |
139 if (tile_type < NUM_RECORDED_TILE_TYPES) { | 137 if (tile_type < NUM_RECORDED_TILE_TYPES) { |
140 UMA_HISTOGRAM_ENUMERATION("NewTabPage.TileTypeClicked", tile_type, | 138 UMA_HISTOGRAM_ENUMERATION("NewTabPage.TileTypeClicked", tile_type, |
141 NUM_RECORDED_TILE_TYPES); | 139 NUM_RECORDED_TILE_TYPES); |
142 | 140 |
143 std::string histogram = | 141 std::string histogram = |
144 base::StringPrintf("NewTabPage.TileTypeClicked.%s", | 142 base::StringPrintf("NewTabPage.TileTypeClicked.%s", |
145 GetSourceHistogramName(source).c_str()); | 143 GetSourceHistogramName(source).c_str()); |
146 LogHistogramEvent(histogram, tile_type, NUM_RECORDED_TILE_TYPES); | 144 LogHistogramEvent(histogram, tile_type, NUM_RECORDED_TILE_TYPES); |
147 } | 145 } |
148 } | 146 } |
149 | 147 |
150 } // namespace metrics | 148 } // namespace metrics |
151 } // namespace ntp_tiles | 149 } // namespace ntp_tiles |
OLD | NEW |