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. In
67 // practice, either all the iframes are server-side suggestions or none are.
68 bool has_server_side_suggestions_
;
70 // Total number of tiles rendered, no matter if it's a thumbnail, a gray tile
71 // or an external tile.
72 size_t number_of_tiles_
;
74 // Total number of tiles using a local thumbnail image for this NTP session.
75 size_t number_of_thumbnail_tiles_
;
77 // Total number of tiles for which no thumbnail is specified and a gray tile
78 // with the domain is used as the main tile.
79 size_t number_of_gray_tiles_
;
81 // Total number of tiles for which the visual appearance is handled externally
82 // by the page itself.
83 size_t number_of_external_tiles_
;
85 // Total number of errors that occurred when trying to load thumbnail images
86 // for this NTP session. When these errors occur a grey tile is shown instead
87 // of a thumbnail image.
88 size_t number_of_thumbnail_errors_
;
90 // The number of times a gray tile with the domain was used as the fallback
91 // for a failed thumbnail.
92 size_t number_of_gray_tile_fallbacks_
;
94 // The number of times an external tile, for which the visual appearance is
95 // handled by the page itself, was the fallback for a failed thumbnail.
96 size_t number_of_external_tile_fallbacks_
;
98 // Total number of mouseovers for this NTP session.
99 size_t number_of_mouseovers_
;
101 // Time from navigation start it took to load the NTP in milliseconds.
102 base::TimeDelta load_time_
;
104 // Whether we have already emitted NTP stats for this web contents.
107 // The URL of this New Tab Page - varies based on NTP version.
110 DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger
);
113 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_