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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_
6 #define CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_
10 #include "base/strings/string16.h"
11 #include "base/time/time.h"
12 #include "chrome/common/ntp_logging_events.h"
13 #include "content/public/browser/web_contents_observer.h"
14 #include "content/public/browser/web_contents_user_data.h"
20 // Helper class for logging data from the NTP. Attached to each NTP instance.
21 class NTPUserDataLogger
22 : public content::WebContentsObserver
,
23 public content::WebContentsUserData
<NTPUserDataLogger
> {
25 ~NTPUserDataLogger() override
;
27 static NTPUserDataLogger
* GetOrCreateFromWebContents(
28 content::WebContents
* content
);
30 // Returns the name of the histogram that should be logged for an impression
31 // of a specified Most Visited |provider|.
32 static std::string
GetMostVisitedImpressionHistogramNameForProvider(
33 const std::string
& provider
);
35 // Returns the name of the histogram that should be logged for a navigation
36 // to a specified Most Visited |provider|.
37 static std::string
GetMostVisitedNavigationHistogramNameForProvider(
38 const std::string
& provider
);
40 // Logs a number of statistics regarding the NTP. Called when an NTP tab is
41 // about to be deactivated (be it by switching tabs, losing focus or closing
42 // the tab/shutting down Chrome), or when the user navigates to a URL.
43 void EmitNtpStatistics();
45 // Called when an event occurs on the NTP that requires a counter to be
46 // incremented. |time| is the delta time in ms from navigation start until
47 // this event happened.
48 void LogEvent(NTPLoggingEventType event
, base::TimeDelta time
);
50 // Logs an impression on one of the Most Visited tiles by a given provider.
51 void LogMostVisitedImpression(int position
, const base::string16
& provider
);
53 // Logs a navigation on one of the Most Visited tiles by a given provider.
54 void LogMostVisitedNavigation(int position
, const base::string16
& provider
);
56 // content::WebContentsObserver override
57 void NavigationEntryCommitted(
58 const content::LoadCommittedDetails
& load_details
) override
;
61 explicit NTPUserDataLogger(content::WebContents
* contents
);
64 friend class content::WebContentsUserData
<NTPUserDataLogger
>;
66 // True if at least one iframe came from a server-side suggestion.
67 bool has_server_side_suggestions_
;
69 // True if at least one iframe came from a client-side suggestion.
70 bool has_client_side_suggestions_
;
72 // Total number of tiles rendered, no matter if it's a thumbnail, a gray tile
73 // or an external tile.
74 size_t number_of_tiles_
;
76 // Total number of tiles using a local thumbnail image for this NTP session.
77 size_t number_of_thumbnail_tiles_
;
79 // Total number of tiles for which no thumbnail is specified and a gray tile
80 // with the domain is used as the main tile.
81 size_t number_of_gray_tiles_
;
83 // Total number of tiles for which the visual appearance is handled externally
84 // by the page itself.
85 size_t number_of_external_tiles_
;
87 // Total number of errors that occurred when trying to load thumbnail images
88 // for this NTP session. When these errors occur a grey tile is shown instead
89 // of a thumbnail image.
90 size_t number_of_thumbnail_errors_
;
92 // The number of times a gray tile with the domain was used as the fallback
93 // for a failed thumbnail.
94 size_t number_of_gray_tile_fallbacks_
;
96 // The number of times an external tile, for which the visual appearance is
97 // handled by the page itself, was the fallback for a failed thumbnail.
98 size_t number_of_external_tile_fallbacks_
;
100 // Total number of mouseovers for this NTP session.
101 size_t number_of_mouseovers_
;
103 // Time from navigation start it took to load the NTP in milliseconds.
104 base::TimeDelta load_time_
;
106 // Whether we have already emitted NTP stats for this web contents.
109 // Are stats being logged during Chrome startup?
110 bool during_startup_
;
112 // The URL of this New Tab Page - varies based on NTP version.
115 DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger
);
118 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_