This source file includes following definitions.
- GetOrCreateFromWebContents
- GetMostVisitedImpressionHistogramNameForProvider
- GetMostVisitedNavigationHistogramNameForProvider
- EmitNtpStatistics
- LogEvent
- LogMostVisitedImpression
- LogMostVisitedNavigation
- NavigationEntryCommitted
- number_of_mouseovers_
#include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h"
#include "base/metrics/histogram.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/search/most_visited_iframe_source.h"
#include "chrome/browser/search/search.h"
#include "chrome/common/search_urls.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
#define UMA_HISTOGRAM_NTP_TILES(name, sample) \
UMA_HISTOGRAM_CUSTOM_COUNTS(name, sample, 0, 8, 9)
namespace {
enum SuggestionsType {
CLIENT_SIDE = 0,
SERVER_SIDE = 1,
SUGGESTIONS_TYPE_COUNT = 2
};
const int kNumMostVisited = 8;
const char kMostVisitedImpressionHistogramName[] =
"NewTabPage.SuggestionsImpression";
const char kMostVisitedImpressionHistogramWithProvider[] =
"NewTabPage.SuggestionsImpression.%s";
const char kMostVisitedNavigationHistogramName[] =
"NewTabPage.MostVisited";
const char kMostVisitedNavigationHistogramWithProvider[] =
"NewTabPage.MostVisited.%s";
}
DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPUserDataLogger);
NTPUserDataLogger::~NTPUserDataLogger() {}
NTPUserDataLogger* NTPUserDataLogger::GetOrCreateFromWebContents(
content::WebContents* content) {
NTPUserDataLogger::CreateForWebContents(content);
NTPUserDataLogger* logger = NTPUserDataLogger::FromWebContents(content);
const content::NavigationEntry* entry =
content->GetController().GetVisibleEntry();
if (entry)
logger->ntp_url_ = entry->GetURL();
return logger;
}
std::string NTPUserDataLogger::GetMostVisitedImpressionHistogramNameForProvider(
const std::string& provider) {
return base::StringPrintf(kMostVisitedImpressionHistogramWithProvider,
provider.c_str());
}
std::string NTPUserDataLogger::GetMostVisitedNavigationHistogramNameForProvider(
const std::string& provider) {
return base::StringPrintf(kMostVisitedNavigationHistogramWithProvider,
provider.c_str());
}
void NTPUserDataLogger::EmitNtpStatistics() {
UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers", number_of_mouseovers_);
number_of_mouseovers_ = 0;
if (number_of_tiles_ > 0) {
UMA_HISTOGRAM_ENUMERATION(
"NewTabPage.SuggestionsType",
has_server_side_suggestions_ ? SERVER_SIDE : CLIENT_SIDE,
SUGGESTIONS_TYPE_COUNT);
has_server_side_suggestions_ = false;
UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfTiles", number_of_tiles_);
number_of_tiles_ = 0;
UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfThumbnailTiles",
number_of_thumbnail_tiles_);
number_of_thumbnail_tiles_ = 0;
UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfGrayTiles",
number_of_gray_tiles_);
number_of_gray_tiles_ = 0;
UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfExternalTiles",
number_of_external_tiles_);
number_of_external_tiles_ = 0;
UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfThumbnailErrors",
number_of_thumbnail_errors_);
number_of_thumbnail_errors_ = 0;
UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfGrayTileFallbacks",
number_of_gray_tile_fallbacks_);
number_of_gray_tile_fallbacks_ = 0;
UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfExternalTileFallbacks",
number_of_external_tile_fallbacks_);
number_of_external_tile_fallbacks_ = 0;
}
}
void NTPUserDataLogger::LogEvent(NTPLoggingEventType event) {
switch (event) {
case NTP_SERVER_SIDE_SUGGESTION:
has_server_side_suggestions_ = true;
break;
case NTP_CLIENT_SIDE_SUGGESTION:
DCHECK(!has_server_side_suggestions_);
break;
case NTP_TILE:
number_of_tiles_++;
break;
case NTP_THUMBNAIL_TILE:
number_of_thumbnail_tiles_++;
break;
case NTP_GRAY_TILE:
number_of_gray_tiles_++;
break;
case NTP_EXTERNAL_TILE:
number_of_external_tiles_++;
break;
case NTP_THUMBNAIL_ERROR:
number_of_thumbnail_errors_++;
break;
case NTP_GRAY_TILE_FALLBACK:
number_of_gray_tile_fallbacks_++;
break;
case NTP_EXTERNAL_TILE_FALLBACK:
number_of_external_tile_fallbacks_++;
break;
case NTP_MOUSEOVER:
number_of_mouseovers_++;
break;
default:
NOTREACHED();
}
}
void NTPUserDataLogger::LogMostVisitedImpression(
int position, const base::string16& provider) {
UMA_HISTOGRAM_ENUMERATION(kMostVisitedImpressionHistogramName, position,
kNumMostVisited);
if (!provider.empty()) {
base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
GetMostVisitedImpressionHistogramNameForProvider(
base::UTF16ToUTF8(provider)),
1,
kNumMostVisited,
kNumMostVisited + 1,
base::Histogram::kUmaTargetedHistogramFlag);
counter->Add(position);
}
}
void NTPUserDataLogger::LogMostVisitedNavigation(
int position, const base::string16& provider) {
UMA_HISTOGRAM_ENUMERATION(kMostVisitedNavigationHistogramName, position,
kNumMostVisited);
if (!provider.empty()) {
base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
GetMostVisitedNavigationHistogramNameForProvider(
base::UTF16ToUTF8(provider)),
1,
kNumMostVisited,
kNumMostVisited + 1,
base::Histogram::kUmaTargetedHistogramFlag);
counter->Add(position);
}
content::RecordAction(base::UserMetricsAction("MostVisited_Clicked"));
}
void NTPUserDataLogger::NavigationEntryCommitted(
const content::LoadCommittedDetails& load_details) {
if (!load_details.previous_url.is_valid())
return;
if (search::MatchesOriginAndPath(ntp_url_, load_details.previous_url)) {
EmitNtpStatistics();
}
}
NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents)
: content::WebContentsObserver(contents),
has_server_side_suggestions_(false),
number_of_tiles_(0),
number_of_thumbnail_tiles_(0),
number_of_gray_tiles_(0),
number_of_external_tiles_(0),
number_of_thumbnail_errors_(0),
number_of_gray_tile_fallbacks_(0),
number_of_external_tile_fallbacks_(0),
number_of_mouseovers_(0) {
}