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. 4 5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_ 6 #define CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_ 7 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" 11 12 namespace content { 13 class WebContents; 14 } 15 16 // Helper class for logging data from the NTP. Attached to each NTP instance. 17 class NTPUserDataLogger 18 : public content::WebContentsObserver, 19 public content::WebContentsUserData<NTPUserDataLogger> { 20 public: 21 virtual ~NTPUserDataLogger(); 22 23 static NTPUserDataLogger* GetOrCreateFromWebContents( 24 content::WebContents* content); 25 26 // Logs the error percentage rate when loading thumbnail images for this NTP 27 // session to UMA histogram. Called when the user navigates to a URL. Only 28 // called for the instant NTP. 29 void EmitThumbnailErrorRate(); 30 31 // Logs a number of statistics regarding the NTP. Called when an NTP tab is 32 // about to be deactivated (be it by switching tabs, losing focus or closing 33 // the tab/shutting down Chrome), or when the user navigates to a URL. 34 void EmitNtpStatistics(); 35 36 // Called each time an event occurs on the NTP that requires a counter to be 37 // incremented. 38 void LogEvent(NTPLoggingEventType event); 39 40 // Logs an impression on one of the Most Visited tiles by a given provider. 41 void LogImpression(int position, const base::string16& provider); 42 43 // content::WebContentsObserver override 44 virtual void NavigationEntryCommitted( 45 const content::LoadCommittedDetails& load_details) OVERRIDE; 46 47 protected: 48 explicit NTPUserDataLogger(content::WebContents* contents); 49 50 // Returns the percent error given |events| occurrences and |errors| errors. 51 virtual size_t GetPercentError(size_t errors, size_t events) const; 52 53 private: 54 friend class content::WebContentsUserData<NTPUserDataLogger>; 55 56 // Total number of mouseovers for this NTP session. 57 size_t number_of_mouseovers_; 58 59 // Total number of attempts made to load thumbnail images for this NTP 60 // session. 61 size_t number_of_thumbnail_attempts_; 62 63 // Total number of errors that occurred when trying to load thumbnail images 64 // for this NTP session. When these errors occur a grey tile is shown instead 65 // of a thumbnail image. 66 size_t number_of_thumbnail_errors_; 67 68 // Total number of attempts made to load thumbnail images while providing a 69 // fallback thumbnail for this NTP session. 70 size_t number_of_fallback_thumbnails_requested_; 71 72 // Total number of errors that occurred while trying to load the primary 73 // thumbnail image and that caused a fallback to the secondary thumbnail. 74 size_t number_of_fallback_thumbnails_used_; 75 76 // Total number of tiles for which the visual appearance is handled externally 77 // by the page itself. 78 size_t number_of_external_tiles_; 79 80 // True if at least one iframe came from a server-side suggestion. In 81 // practice, either all the iframes are server-side suggestions or none are. 82 bool server_side_suggestions_; 83 84 // The URL of this New Tab Page - varies based on NTP version. 85 GURL ntp_url_; 86 87 DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger); 88 }; 89 90 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_ 91