Commit 76aad9a0 authored by treib's avatar treib Committed by Commit bot

Cleanup desktop NTP metrics recording, part 2

Followup to https://codereview.chromium.org/2429523002

- Remove NTP_*_SIDE_SUGGESTION (replaced by LogMostVisitedImpression calls)
- Cleanup tests

BUG=656646
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2435683003
Cr-Commit-Position: refs/heads/master@{#427086}
parent 8ab445a5
......@@ -16,10 +16,6 @@
* @const
*/
var LOG_TYPE = {
// A suggestion coming from the server was rendered.
NTP_SERVER_SIDE_SUGGESTION: 0,
// A suggestion coming from the client was rendered.
NTP_CLIENT_SIDE_SUGGESTION: 1,
// All NTP Tiles have finished loading (successfully or failing).
NTP_ALL_TILES_LOADED: 11,
};
......@@ -310,7 +306,6 @@ var addTile = function(args) {
data.faviconUrl = 'chrome-search://favicon/size/16@' +
window.devicePixelRatio + 'x/' + data.renderViewId + '/' + data.tid;
}
logEvent(LOG_TYPE.NTP_CLIENT_SIDE_SUGGESTION);
tiles.appendChild(renderTile(data));
} else if (args.url) {
// If a URL is passed: a server-side suggestion.
......@@ -319,7 +314,6 @@ var addTile = function(args) {
if (/^javascript:/i.test(args.url) ||
/^javascript:/i.test(args.thumbnailUrl))
return;
logEvent(LOG_TYPE.NTP_SERVER_SIDE_SUGGESTION);
tiles.appendChild(renderTile(args));
} else { // an empty tile
tiles.appendChild(renderTile(null));
......
......@@ -259,7 +259,7 @@ TEST_F(SearchIPCRouterTest, ProcessLogEventMsg) {
NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
SetupMockDelegateAndPolicy();
MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_CLIENT_SIDE_SUGGESTION, delta))
EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_ALL_TILES_LOADED, delta))
.Times(1);
EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
.WillOnce(testing::Return(true));
......@@ -267,7 +267,7 @@ TEST_F(SearchIPCRouterTest, ProcessLogEventMsg) {
content::WebContents* contents = web_contents();
OnMessageReceived(ChromeViewHostMsg_LogEvent(
contents->GetRoutingID(), GetSearchIPCRouterSeqNo(),
NTP_CLIENT_SIDE_SUGGESTION, delta));
NTP_ALL_TILES_LOADED, delta));
}
TEST_F(SearchIPCRouterTest, IgnoreLogEventMsg) {
......@@ -275,7 +275,7 @@ TEST_F(SearchIPCRouterTest, IgnoreLogEventMsg) {
NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
SetupMockDelegateAndPolicy();
MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_CLIENT_SIDE_SUGGESTION, delta))
EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_ALL_TILES_LOADED, delta))
.Times(0);
EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
.WillOnce(testing::Return(false));
......@@ -283,7 +283,7 @@ TEST_F(SearchIPCRouterTest, IgnoreLogEventMsg) {
content::WebContents* contents = web_contents();
OnMessageReceived(ChromeViewHostMsg_LogEvent(
contents->GetRoutingID(), GetSearchIPCRouterSeqNo(),
NTP_CLIENT_SIDE_SUGGESTION, delta));
NTP_ALL_TILES_LOADED, delta));
}
TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedImpressionMsg) {
......@@ -488,12 +488,12 @@ TEST_F(SearchIPCRouterTest, IgnoreMessageIfThePageIsNotActive) {
contents->GetRoutingID(), page_seq_no, OMNIBOX_FOCUS_VISIBLE));
base::TimeDelta delta = base::TimeDelta::FromMilliseconds(123);
EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_CLIENT_SIDE_SUGGESTION, delta))
EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_ALL_TILES_LOADED, delta))
.Times(0);
EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(0);
OnMessageReceived(
ChromeViewHostMsg_LogEvent(contents->GetRoutingID(), page_seq_no,
NTP_CLIENT_SIDE_SUGGESTION, delta));
NTP_ALL_TILES_LOADED, delta));
base::string16 text;
EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0);
......
......@@ -122,20 +122,8 @@ NTPUserDataLogger* NTPUserDataLogger::GetOrCreateFromWebContents(
void NTPUserDataLogger::LogEvent(NTPLoggingEventType event,
base::TimeDelta time) {
switch (event) {
case NTP_SERVER_SIDE_SUGGESTION:
has_server_side_suggestions_ = true;
number_of_tiles_++;
return;
case NTP_CLIENT_SIDE_SUGGESTION:
has_client_side_suggestions_ = true;
number_of_tiles_++;
return;
case NTP_ALL_TILES_LOADED:
EmitNtpStatistics(time);
return;
}
NOTREACHED();
DCHECK_EQ(NTP_ALL_TILES_LOADED, event);
EmitNtpStatistics(time);
}
void NTPUserDataLogger::LogMostVisitedImpression(
......@@ -145,6 +133,15 @@ void NTPUserDataLogger::LogMostVisitedImpression(
}
impression_was_logged_[position] = true;
switch (tile_source) {
case NTPLoggingTileSource::CLIENT:
has_client_side_suggestions_ = true;
break;
case NTPLoggingTileSource::SERVER:
has_server_side_suggestions_ = true;
break;
}
UMA_HISTOGRAM_ENUMERATION(kMostVisitedImpressionHistogramName, position,
kNumMostVisited);
......@@ -185,7 +182,6 @@ NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents)
: content::WebContentsObserver(contents),
has_server_side_suggestions_(false),
has_client_side_suggestions_(false),
number_of_tiles_(0),
has_emitted_(false),
during_startup_(!AfterStartupTaskUtils::IsBrowserStartupComplete()) {
// We record metrics about session data here because when this class typically
......@@ -209,7 +205,6 @@ void NTPUserDataLogger::NavigatedFromURLToURL(const GURL& from,
DVLOG(1) << "Returning to New Tab Page";
impression_was_logged_.reset();
has_emitted_ = false;
number_of_tiles_ = 0;
has_server_side_suggestions_ = false;
has_client_side_suggestions_ = false;
}
......@@ -219,8 +214,10 @@ void NTPUserDataLogger::EmitNtpStatistics(base::TimeDelta load_time) {
// We only send statistics once per page.
if (has_emitted_)
return;
size_t number_of_tiles = impression_was_logged_.count();
DVLOG(1) << "Emitting NTP load time: " << load_time << ", "
<< "number of tiles: " << number_of_tiles_;
<< "number of tiles: " << number_of_tiles;
LogLoadTimeHistogram("NewTabPage.LoadTime", load_time);
......@@ -236,12 +233,9 @@ void NTPUserDataLogger::EmitNtpStatistics(base::TimeDelta load_time) {
std::string status = during_startup_ ? "Startup" : "NewTab";
LogLoadTimeHistogram("NewTabPage.LoadTime." + status, load_time);
has_server_side_suggestions_ = false;
has_client_side_suggestions_ = false;
UMA_HISTOGRAM_CUSTOM_COUNTS(
"NewTabPage.NumberOfTiles", number_of_tiles_, 1, kNumMostVisited,
"NewTabPage.NumberOfTiles", number_of_tiles, 1, kNumMostVisited,
kNumMostVisited + 1);
number_of_tiles_ = 0;
has_emitted_ = true;
during_startup_ = false;
}
......@@ -84,10 +84,6 @@ class NTPUserDataLogger
// True if at least one iframe came from a client-side suggestion.
bool has_client_side_suggestions_;
// Total number of tiles rendered, no matter if it's a thumbnail, a gray tile
// or an external tile.
size_t number_of_tiles_;
// Whether we have already emitted NTP stats for this web contents.
bool has_emitted_;
......
......@@ -11,10 +11,10 @@
// Note: Keep in sync with browser/resources/local_ntp/most_visited_single.js
enum NTPLoggingEventType {
// A suggestion coming from the server was rendered.
NTP_SERVER_SIDE_SUGGESTION = 0,
// Deleted: NTP_SERVER_SIDE_SUGGESTION = 0,
// A suggestion coming from the client was rendered.
NTP_CLIENT_SIDE_SUGGESTION = 1,
// Deleted: NTP_CLIENT_SIDE_SUGGESTION = 1,
// Indicates a tile was rendered, no matter if it's a thumbnail, a gray tile
// or an external tile.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment