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 "chrome/common/ntp_logging_events.h"
12 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/browser/web_contents_user_data.h"
19 // Helper class for logging data from the NTP. Attached to each NTP instance.
20 class NTPUserDataLogger
21 : public content::WebContentsObserver,
22 public content::WebContentsUserData<NTPUserDataLogger> {
24 ~NTPUserDataLogger() override;
26 static NTPUserDataLogger* GetOrCreateFromWebContents(
27 content::WebContents* content);
29 // Returns the name of the histogram that should be logged for an impression
30 // of a specified Most Visited |provider|.
31 static std::string GetMostVisitedImpressionHistogramNameForProvider(
32 const std::string& provider);
34 // Returns the name of the histogram that should be logged for a navigation
35 // to a specified Most Visited |provider|.
36 static std::string GetMostVisitedNavigationHistogramNameForProvider(
37 const std::string& provider);
39 // Logs a number of statistics regarding the NTP. Called when an NTP tab is
40 // about to be deactivated (be it by switching tabs, losing focus or closing
41 // the tab/shutting down Chrome), or when the user navigates to a URL.
42 void EmitNtpStatistics();
44 // Called each time an event occurs on the NTP that requires a counter to be
46 void LogEvent(NTPLoggingEventType event);
48 // Logs an impression on one of the Most Visited tiles by a given provider.
49 void LogMostVisitedImpression(int position, const base::string16& provider);
51 // Logs a navigation on one of the Most Visited tiles by a given provider.
52 void LogMostVisitedNavigation(int position, const base::string16& provider);
54 // content::WebContentsObserver override
55 void NavigationEntryCommitted(
56 const content::LoadCommittedDetails& load_details) override;
59 explicit NTPUserDataLogger(content::WebContents* contents);
62 friend class content::WebContentsUserData<NTPUserDataLogger>;
64 // True if at least one iframe came from a server-side suggestion. In
65 // practice, either all the iframes are server-side suggestions or none are.
66 bool has_server_side_suggestions_;
68 // Total number of tiles rendered, no matter if it's a thumbnail, a gray tile
69 // or an external tile.
70 size_t number_of_tiles_;
72 // Total number of tiles using a local thumbnail image for this NTP session.
73 size_t number_of_thumbnail_tiles_;
75 // Total number of tiles for which no thumbnail is specified and a gray tile
76 // with the domain is used as the main tile.
77 size_t number_of_gray_tiles_;
79 // Total number of tiles for which the visual appearance is handled externally
80 // by the page itself.
81 size_t number_of_external_tiles_;
83 // Total number of errors that occurred when trying to load thumbnail images
84 // for this NTP session. When these errors occur a grey tile is shown instead
85 // of a thumbnail image.
86 size_t number_of_thumbnail_errors_;
88 // The number of times a gray tile with the domain was used as the fallback
89 // for a failed thumbnail.
90 size_t number_of_gray_tile_fallbacks_;
92 // The number of times an external tile, for which the visual appearance is
93 // handled by the page itself, was the fallback for a failed thumbnail.
94 size_t number_of_external_tile_fallbacks_;
96 // Total number of mouseovers for this NTP session.
97 size_t number_of_mouseovers_;
99 // The URL of this New Tab Page - varies based on NTP version.
102 DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger);
105 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_