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

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

Issue 2696223004: Desktop NTP: Add a UMA metric NewTabPage.TilesReceivedTime (Closed)
Patch Set: review Created 3 years, 10 months 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 26 matching lines...) Expand all
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 } // namespace 43 } // namespace
44 44
45 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPUserDataLogger); 45 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPUserDataLogger);
46 46
47 47 // Helper macro to log a load time to UMA. There's no good reason why we don't
48 // Log a time event for a given |histogram| at a given |value|. This 48 // use one of the standard UMA_HISTORAM_*_TIMES macros, but all their ranges are
49 // routine exists because regular histogram macros are cached thus can't be used 49 // different, and it's not worth changing all the existing histograms.
50 // if the name of the histogram will change at a given call site. 50 #define UMA_HISTOGRAM_LOAD_TIME(name, sample) \
51 void LogLoadTimeHistogram(const std::string& histogram, base::TimeDelta value) { 51 UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, \
52 base::HistogramBase* counter = base::Histogram::FactoryTimeGet( 52 base::TimeDelta::FromMilliseconds(1), \
53 histogram, 53 base::TimeDelta::FromSeconds(60), 100)
54 base::TimeDelta::FromMilliseconds(1),
55 base::TimeDelta::FromSeconds(60), 100,
56 base::Histogram::kUmaTargetedHistogramFlag);
57 if (counter)
58 counter->AddTime(value);
59 }
60
61 54
62 NTPUserDataLogger::~NTPUserDataLogger() {} 55 NTPUserDataLogger::~NTPUserDataLogger() {}
63 56
64 // static 57 // static
65 NTPUserDataLogger* NTPUserDataLogger::GetOrCreateFromWebContents( 58 NTPUserDataLogger* NTPUserDataLogger::GetOrCreateFromWebContents(
66 content::WebContents* content) { 59 content::WebContents* content) {
67 DCHECK(search::IsInstantNTP(content)); 60 DCHECK(search::IsInstantNTP(content));
68 61
69 // Calling CreateForWebContents when an instance is already attached has no 62 // Calling CreateForWebContents when an instance is already attached has no
70 // effect, so we can do this. 63 // effect, so we can do this.
(...skipping 15 matching lines...) Expand all
86 DVLOG(1) << "NTP URL changed from \"" << logger->ntp_url_ << "\" to \"" 79 DVLOG(1) << "NTP URL changed from \"" << logger->ntp_url_ << "\" to \""
87 << entry->GetURL() << "\""; 80 << entry->GetURL() << "\"";
88 logger->ntp_url_ = entry->GetURL(); 81 logger->ntp_url_ = entry->GetURL();
89 } 82 }
90 83
91 return logger; 84 return logger;
92 } 85 }
93 86
94 void NTPUserDataLogger::LogEvent(NTPLoggingEventType event, 87 void NTPUserDataLogger::LogEvent(NTPLoggingEventType event,
95 base::TimeDelta time) { 88 base::TimeDelta time) {
96 DCHECK_EQ(NTP_ALL_TILES_LOADED, event); 89 switch (event) {
97 EmitNtpStatistics(time); 90 case NTP_ALL_TILES_RECEIVED:
91 tiles_received_time_ = time;
92 break;
93 case NTP_ALL_TILES_LOADED:
94 EmitNtpStatistics(time);
95 break;
96 }
98 } 97 }
99 98
100 void NTPUserDataLogger::LogMostVisitedImpression( 99 void NTPUserDataLogger::LogMostVisitedImpression(
101 int position, 100 int position,
102 ntp_tiles::NTPTileSource tile_source) { 101 ntp_tiles::NTPTileSource tile_source) {
103 if ((position >= kNumMostVisited) || impression_was_logged_[position]) { 102 if ((position >= kNumMostVisited) || impression_was_logged_[position]) {
104 return; 103 return;
105 } 104 }
106 impression_was_logged_[position] = true; 105 impression_was_logged_[position] = true;
107 impression_tile_source_[position] = tile_source; 106 impression_tile_source_[position] = tile_source;
(...skipping 28 matching lines...) Expand all
136 NavigatedFromURLToURL(load_details.previous_url, 135 NavigatedFromURLToURL(load_details.previous_url,
137 load_details.entry->GetURL()); 136 load_details.entry->GetURL());
138 } 137 }
139 138
140 void NTPUserDataLogger::NavigatedFromURLToURL(const GURL& from, 139 void NTPUserDataLogger::NavigatedFromURLToURL(const GURL& from,
141 const GURL& to) { 140 const GURL& to) {
142 // User is returning to NTP, probably via the back button; reset stats. 141 // User is returning to NTP, probably via the back button; reset stats.
143 if (from.is_valid() && to.is_valid() && (to == ntp_url_)) { 142 if (from.is_valid() && to.is_valid() && (to == ntp_url_)) {
144 DVLOG(1) << "Returning to New Tab Page"; 143 DVLOG(1) << "Returning to New Tab Page";
145 impression_was_logged_.reset(); 144 impression_was_logged_.reset();
145 tiles_received_time_ = base::TimeDelta();
146 has_emitted_ = false; 146 has_emitted_ = false;
147 } 147 }
148 } 148 }
149 149
150 void NTPUserDataLogger::EmitNtpStatistics(base::TimeDelta load_time) { 150 void NTPUserDataLogger::EmitNtpStatistics(base::TimeDelta load_time) {
151 // We only send statistics once per page. 151 // We only send statistics once per page.
152 if (has_emitted_) 152 if (has_emitted_) {
153 return; 153 return;
154 }
154 155
155 DVLOG(1) << "Emitting NTP load time: " << load_time << ", " 156 DVLOG(1) << "Emitting NTP load time: " << load_time << ", "
156 << "number of tiles: " << impression_was_logged_.count(); 157 << "number of tiles: " << impression_was_logged_.count();
157 158
158 std::vector<ntp_tiles::metrics::TileImpression> tiles; 159 std::vector<ntp_tiles::metrics::TileImpression> tiles;
159 bool has_server_side_suggestions = false; 160 bool has_server_side_suggestions = false;
160 for (int i = 0; i < kNumMostVisited; i++) { 161 for (int i = 0; i < kNumMostVisited; i++) {
161 if (!impression_was_logged_[i]) { 162 if (!impression_was_logged_[i]) {
162 break; 163 break;
163 } 164 }
164 if (impression_tile_source_[i] == 165 if (impression_tile_source_[i] ==
165 ntp_tiles::NTPTileSource::SUGGESTIONS_SERVICE) { 166 ntp_tiles::NTPTileSource::SUGGESTIONS_SERVICE) {
166 has_server_side_suggestions = true; 167 has_server_side_suggestions = true;
167 } 168 }
168 // No URL passed since we're not interested in favicon-related Rappor 169 // No URL passed since we're not interested in favicon-related Rappor
169 // metrics. 170 // metrics.
170 tiles.emplace_back(impression_tile_source_[i], 171 tiles.emplace_back(impression_tile_source_[i],
171 ntp_tiles::metrics::THUMBNAIL, GURL()); 172 ntp_tiles::metrics::THUMBNAIL, GURL());
172 } 173 }
173 174
174 // Not interested in Rappor metrics. 175 // Not interested in Rappor metrics.
175 ntp_tiles::metrics::RecordPageImpression(tiles, /*rappor_service=*/nullptr); 176 ntp_tiles::metrics::RecordPageImpression(tiles, /*rappor_service=*/nullptr);
176 177
177 LogLoadTimeHistogram("NewTabPage.LoadTime", load_time); 178 UMA_HISTOGRAM_LOAD_TIME("NewTabPage.TilesReceivedTime", tiles_received_time_);
179 UMA_HISTOGRAM_LOAD_TIME("NewTabPage.LoadTime", load_time);
178 180
179 // Split between ML and MV. 181 // Split between ML (aka SuggestionsService) and MV (aka TopSites).
180 std::string type = has_server_side_suggestions ? "MostLikely" : "MostVisited"; 182 if (has_server_side_suggestions) {
181 LogLoadTimeHistogram("NewTabPage.LoadTime." + type, load_time); 183 UMA_HISTOGRAM_LOAD_TIME("NewTabPage.TilesReceivedTime.MostLikely",
184 tiles_received_time_);
185 UMA_HISTOGRAM_LOAD_TIME("NewTabPage.LoadTime.MostLikely", load_time);
186 } else {
187 UMA_HISTOGRAM_LOAD_TIME("NewTabPage.TilesReceivedTime.MostVisited",
188 tiles_received_time_);
189 UMA_HISTOGRAM_LOAD_TIME("NewTabPage.LoadTime.MostVisited", load_time);
190 }
182 191
183 // Split between Web and Local. 192 // Split between Web and Local.
184 std::string variant = ntp_url_.SchemeIsHTTPOrHTTPS() ? "Web" : "LocalNTP"; 193 if (ntp_url_.SchemeIsHTTPOrHTTPS()) {
185 LogLoadTimeHistogram("NewTabPage.LoadTime." + variant, load_time); 194 UMA_HISTOGRAM_LOAD_TIME("NewTabPage.TilesReceivedTime.Web",
195 tiles_received_time_);
196 UMA_HISTOGRAM_LOAD_TIME("NewTabPage.LoadTime.Web", load_time);
197 } else {
198 UMA_HISTOGRAM_LOAD_TIME("NewTabPage.TilesReceivedTime.LocalNTP",
199 tiles_received_time_);
200 UMA_HISTOGRAM_LOAD_TIME("NewTabPage.LoadTime.LocalNTP", load_time);
201 }
186 202
187 // Split between Startup and non-startup. 203 // Split between Startup and non-startup.
188 std::string status = during_startup_ ? "Startup" : "NewTab"; 204 if (during_startup_) {
189 LogLoadTimeHistogram("NewTabPage.LoadTime." + status, load_time); 205 UMA_HISTOGRAM_LOAD_TIME("NewTabPage.TilesReceivedTime.Startup",
206 tiles_received_time_);
207 UMA_HISTOGRAM_LOAD_TIME("NewTabPage.LoadTime.Startup", load_time);
208 } else {
209 UMA_HISTOGRAM_LOAD_TIME("NewTabPage.TilesReceivedTime.NewTab",
210 tiles_received_time_);
211 UMA_HISTOGRAM_LOAD_TIME("NewTabPage.LoadTime.NewTab", load_time);
212 }
190 213
191 has_emitted_ = true; 214 has_emitted_ = true;
192 during_startup_ = false; 215 during_startup_ = false;
193 } 216 }
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