blob: d3c38b4e4b23ff0f0cb0dbd2bb1c0b190069f76b [file] [log] [blame]
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_
#define CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_
#include <stddef.h>
#include <string>
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "base/time/time.h"
#include "chrome/common/ntp_logging_events.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
namespace content {
class WebContents;
}
// Helper class for logging data from the NTP. Attached to each NTP instance.
class NTPUserDataLogger
: public content::WebContentsObserver,
public content::WebContentsUserData<NTPUserDataLogger> {
public:
~NTPUserDataLogger() override;
static NTPUserDataLogger* GetOrCreateFromWebContents(
content::WebContents* content);
// Returns the name of the histogram that should be logged for an impression
// of a specified Most Visited |provider|.
static std::string GetMostVisitedImpressionHistogramNameForProvider(
const std::string& provider);
// Returns the name of the histogram that should be logged for a navigation
// to a specified Most Visited |provider|.
static std::string GetMostVisitedNavigationHistogramNameForProvider(
const std::string& provider);
// Logs a number of statistics regarding the NTP. Called when an NTP tab is
// about to be deactivated (be it by switching tabs, losing focus or closing
// the tab/shutting down Chrome), or when the user navigates to a URL.
void EmitNtpStatistics();
// Called when an event occurs on the NTP that requires a counter to be
// incremented. |time| is the delta time in ms from navigation start until
// this event happened.
void LogEvent(NTPLoggingEventType event, base::TimeDelta time);
// Logs an impression on one of the Most Visited tiles by a given provider.
void LogMostVisitedImpression(int position, const base::string16& provider);
// Logs a navigation on one of the Most Visited tiles by a given provider.
void LogMostVisitedNavigation(int position, const base::string16& provider);
// content::WebContentsObserver override
void NavigationEntryCommitted(
const content::LoadCommittedDetails& load_details) override;
protected:
explicit NTPUserDataLogger(content::WebContents* contents);
private:
friend class content::WebContentsUserData<NTPUserDataLogger>;
FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest,
OnMostVisitedItemsChangedFromServer);
FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest,
OnMostVisitedItemsChangedFromClient);
// True if at least one iframe came from a server-side suggestion.
bool has_server_side_suggestions_;
// 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_;
// Total number of tiles using a local thumbnail image for this NTP session.
size_t number_of_thumbnail_tiles_;
// Total number of tiles for which no thumbnail is specified and a gray tile
// with the domain is used as the main tile.
size_t number_of_gray_tiles_;
// Total number of tiles for which the visual appearance is handled externally
// by the page itself.
size_t number_of_external_tiles_;
// Total number of errors that occurred when trying to load thumbnail images
// for this NTP session. When these errors occur a grey tile is shown instead
// of a thumbnail image.
size_t number_of_thumbnail_errors_;
// The number of times a gray tile with the domain was used as the fallback
// for a failed thumbnail.
size_t number_of_gray_tile_fallbacks_;
// The number of times an external tile, for which the visual appearance is
// handled by the page itself, was the fallback for a failed thumbnail.
size_t number_of_external_tile_fallbacks_;
// Total number of mouseovers for this NTP session.
size_t number_of_mouseovers_;
// Time from navigation start it took to load the NTP in milliseconds.
base::TimeDelta load_time_;
// Whether we have already emitted NTP stats for this web contents.
bool has_emitted_;
// Are stats being logged during Chrome startup?
bool during_startup_;
// The URL of this New Tab Page - varies based on NTP version.
GURL ntp_url_;
DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger);
};
#endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_