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_
8 #include "chrome/common/ntp_logging_events.h"
9 #include "content/public/browser/web_contents_observer.h"
10 #include "content/public/browser/web_contents_user_data.h"
13 // Helper class for logging data from the NTP. Attached to each NTP instance.
14 class NTPUserDataLogger
15 : public content::WebContentsObserver,
16 public content::WebContentsUserData<NTPUserDataLogger> {
18 virtual ~NTPUserDataLogger();
20 // To be set after initialization of this class. Used to determine whether a
21 // tab visibility change event or navigation event comes from the NTP.
22 void set_ntp_url(const GURL& url) {
26 const GURL& ntp_url() const { return ntp_url_; }
28 // Logs the error percentage rate when loading thumbnail images for this NTP
29 // session to UMA histogram. Called when the user navigates to a URL.
30 void EmitThumbnailErrorRate();
32 // Logs total number of mouseovers per NTP session to UMA histogram. Called
33 // when an NTP tab is about to be deactivated (be it by switching tabs, losing
34 // focus or closing the tab/shutting down Chrome), or when the user navigates
36 void EmitMouseoverCount();
38 // Called each time an event occurs on the NTP that requires a counter to be
40 void LogEvent(NTPLoggingEventType event);
42 // content::WebContentsObserver override
43 virtual void NavigationEntryCommitted(
44 const content::LoadCommittedDetails& load_details) OVERRIDE;
47 explicit NTPUserDataLogger(content::WebContents* contents);
49 // Returns the percent error given |events| occurrences and |errors| errors.
50 virtual size_t GetPercentError(size_t errors, size_t events) const;
53 friend class content::WebContentsUserData<NTPUserDataLogger>;
55 // Total number of mouseovers for this NTP session.
56 size_t number_of_mouseovers_;
58 // Total number of attempts made to load thumbnail images for this NTP
60 size_t number_of_thumbnail_attempts_;
62 // Total number of errors that occurred when trying to load thumbnail images
63 // for this NTP session. When these errors occur a grey tile is shown instead
64 // of a thumbnail image.
65 size_t number_of_thumbnail_errors_;
67 // Total number of attempts made to load thumbnail images while providing a
68 // fallback thumbnail for this NTP session.
69 size_t number_of_fallback_thumbnails_requested_;
71 // Total number of errors that occurred while trying to load the primary
72 // thumbnail image and that caused a fallback to the secondary thumbnail.
73 size_t number_of_fallback_thumbnails_used_;
75 // The URL of this New Tab Page - varies based on NTP version.
78 DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger);
81 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_