Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: chrome/browser/ui/webui/ntp/ntp_user_data_logger.cc

Issue 2544883006: Cleanup: Replace NTPLoggingTileSource by ntp_tiles::NTPTileSource (Closed)
Patch Set: tests Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" 5 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 22 matching lines...) Expand all
33 Profile::FromBrowserContext(contents->GetBrowserContext())); 33 Profile::FromBrowserContext(contents->GetBrowserContext()));
34 if (!sync) 34 if (!sync)
35 return; 35 return;
36 sync_sessions::SessionsSyncManager* sessions = 36 sync_sessions::SessionsSyncManager* sessions =
37 static_cast<sync_sessions::SessionsSyncManager*>( 37 static_cast<sync_sessions::SessionsSyncManager*>(
38 sync->GetSessionsSyncableService()); 38 sync->GetSessionsSyncableService());
39 sync_sessions::SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP( 39 sync_sessions::SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP(
40 sessions); 40 sessions);
41 } 41 }
42 42
43 ntp_tiles::NTPTileSource ConvertTileSource(NTPLoggingTileSource tile_source) {
44 switch (tile_source) {
45 case NTPLoggingTileSource::CLIENT:
46 return ntp_tiles::NTPTileSource::TOP_SITES;
47 case NTPLoggingTileSource::SERVER:
48 return ntp_tiles::NTPTileSource::SUGGESTIONS_SERVICE;
49 }
50 NOTREACHED();
51 return ntp_tiles::NTPTileSource::TOP_SITES;
52 }
53
54 } // namespace 43 } // namespace
55 44
56 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPUserDataLogger); 45 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPUserDataLogger);
57 46
58 47
59 // Log a time event for a given |histogram| at a given |value|. This 48 // Log a time event for a given |histogram| at a given |value|. This
60 // routine exists because regular histogram macros are cached thus can't be used 49 // routine exists because regular histogram macros are cached thus can't be used
61 // if the name of the histogram will change at a given call site. 50 // if the name of the histogram will change at a given call site.
62 void LogLoadTimeHistogram(const std::string& histogram, base::TimeDelta value) { 51 void LogLoadTimeHistogram(const std::string& histogram, base::TimeDelta value) {
63 base::HistogramBase* counter = base::Histogram::FactoryTimeGet( 52 base::HistogramBase* counter = base::Histogram::FactoryTimeGet(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 return logger; 91 return logger;
103 } 92 }
104 93
105 void NTPUserDataLogger::LogEvent(NTPLoggingEventType event, 94 void NTPUserDataLogger::LogEvent(NTPLoggingEventType event,
106 base::TimeDelta time) { 95 base::TimeDelta time) {
107 DCHECK_EQ(NTP_ALL_TILES_LOADED, event); 96 DCHECK_EQ(NTP_ALL_TILES_LOADED, event);
108 EmitNtpStatistics(time); 97 EmitNtpStatistics(time);
109 } 98 }
110 99
111 void NTPUserDataLogger::LogMostVisitedImpression( 100 void NTPUserDataLogger::LogMostVisitedImpression(
112 int position, NTPLoggingTileSource tile_source) { 101 int position,
102 ntp_tiles::NTPTileSource tile_source) {
113 if ((position >= kNumMostVisited) || impression_was_logged_[position]) { 103 if ((position >= kNumMostVisited) || impression_was_logged_[position]) {
114 return; 104 return;
115 } 105 }
116 impression_was_logged_[position] = true; 106 impression_was_logged_[position] = true;
117 impression_tile_source_[position] = tile_source; 107 impression_tile_source_[position] = tile_source;
118 } 108 }
119 109
120 void NTPUserDataLogger::LogMostVisitedNavigation( 110 void NTPUserDataLogger::LogMostVisitedNavigation(
121 int position, NTPLoggingTileSource tile_source) { 111 int position,
122 ntp_tiles::metrics::RecordTileClick(position, ConvertTileSource(tile_source), 112 ntp_tiles::NTPTileSource tile_source) {
113 ntp_tiles::metrics::RecordTileClick(position, tile_source,
123 ntp_tiles::metrics::THUMBNAIL); 114 ntp_tiles::metrics::THUMBNAIL);
124 115
125 // Records the action. This will be available as a time-stamped stream 116 // Records the action. This will be available as a time-stamped stream
126 // server-side and can be used to compute time-to-long-dwell. 117 // server-side and can be used to compute time-to-long-dwell.
127 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked")); 118 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked"));
128 } 119 }
129 120
130 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents) 121 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents)
131 : content::WebContentsObserver(contents), 122 : content::WebContentsObserver(contents),
132 impression_tile_source_(kNumMostVisited), 123 impression_tile_source_(kNumMostVisited),
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 << "number of tiles: " << impression_was_logged_.count(); 156 << "number of tiles: " << impression_was_logged_.count();
166 157
167 std::vector<std::pair<ntp_tiles::NTPTileSource, 158 std::vector<std::pair<ntp_tiles::NTPTileSource,
168 ntp_tiles::metrics::MostVisitedTileType>> 159 ntp_tiles::metrics::MostVisitedTileType>>
169 tiles; 160 tiles;
170 bool has_server_side_suggestions = false; 161 bool has_server_side_suggestions = false;
171 for (int i = 0; i < kNumMostVisited; i++) { 162 for (int i = 0; i < kNumMostVisited; i++) {
172 if (!impression_was_logged_[i]) { 163 if (!impression_was_logged_[i]) {
173 break; 164 break;
174 } 165 }
175 if (impression_tile_source_[i] == NTPLoggingTileSource::SERVER) { 166 if (impression_tile_source_[i] ==
167 ntp_tiles::NTPTileSource::SUGGESTIONS_SERVICE) {
176 has_server_side_suggestions = true; 168 has_server_side_suggestions = true;
177 } 169 }
178 tiles.emplace_back(ConvertTileSource(impression_tile_source_[i]), 170 tiles.emplace_back(impression_tile_source_[i],
179 ntp_tiles::metrics::THUMBNAIL); 171 ntp_tiles::metrics::THUMBNAIL);
180 } 172 }
181 ntp_tiles::metrics::RecordPageImpression(tiles); 173 ntp_tiles::metrics::RecordPageImpression(tiles);
182 174
183 LogLoadTimeHistogram("NewTabPage.LoadTime", load_time); 175 LogLoadTimeHistogram("NewTabPage.LoadTime", load_time);
184 176
185 // Split between ML and MV. 177 // Split between ML and MV.
186 std::string type = has_server_side_suggestions ? "MostLikely" : "MostVisited"; 178 std::string type = has_server_side_suggestions ? "MostLikely" : "MostVisited";
187 LogLoadTimeHistogram("NewTabPage.LoadTime." + type, load_time); 179 LogLoadTimeHistogram("NewTabPage.LoadTime." + type, load_time);
188 180
189 // Split between Web and Local. 181 // Split between Web and Local.
190 std::string variant = ntp_url_.SchemeIsHTTPOrHTTPS() ? "Web" : "LocalNTP"; 182 std::string variant = ntp_url_.SchemeIsHTTPOrHTTPS() ? "Web" : "LocalNTP";
191 LogLoadTimeHistogram("NewTabPage.LoadTime." + variant, load_time); 183 LogLoadTimeHistogram("NewTabPage.LoadTime." + variant, load_time);
192 184
193 // Split between Startup and non-startup. 185 // Split between Startup and non-startup.
194 std::string status = during_startup_ ? "Startup" : "NewTab"; 186 std::string status = during_startup_ ? "Startup" : "NewTab";
195 LogLoadTimeHistogram("NewTabPage.LoadTime." + status, load_time); 187 LogLoadTimeHistogram("NewTabPage.LoadTime." + status, load_time);
196 188
197 has_emitted_ = true; 189 has_emitted_ = true;
198 during_startup_ = false; 190 during_startup_ = false;
199 } 191 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/ntp_user_data_logger.h ('k') | chrome/browser/ui/webui/ntp/ntp_user_data_logger_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698