Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_ |
| 7 | 7 |
| 8 #include "base/gtest_prod_util.h" | |
| 8 #include "chrome/common/ntp_logging_events.h" | 9 #include "chrome/common/ntp_logging_events.h" |
| 9 #include "content/public/browser/web_contents_observer.h" | 10 #include "content/public/browser/web_contents_observer.h" |
| 10 #include "content/public/browser/web_contents_user_data.h" | 11 #include "content/public/browser/web_contents_user_data.h" |
| 11 | 12 |
| 12 namespace content { | 13 namespace content { |
| 13 class WebContents; | 14 class WebContents; |
| 14 } | 15 } |
| 15 | 16 |
| 16 // Helper class for logging data from the NTP. Attached to each NTP instance. | 17 // Helper class for logging data from the NTP. Attached to each NTP instance. |
| 17 class NTPUserDataLogger | 18 class NTPUserDataLogger |
| 18 : public content::WebContentsObserver, | 19 : public content::WebContentsObserver, |
| 19 public content::WebContentsUserData<NTPUserDataLogger> { | 20 public content::WebContentsUserData<NTPUserDataLogger> { |
| 20 public: | 21 public: |
| 21 virtual ~NTPUserDataLogger(); | 22 virtual ~NTPUserDataLogger(); |
| 22 | 23 |
| 23 static NTPUserDataLogger* GetOrCreateFromWebContents( | 24 static NTPUserDataLogger* GetOrCreateFromWebContents( |
| 24 content::WebContents* content); | 25 content::WebContents* content); |
| 25 | 26 |
| 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 | 27 // 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 | 28 // 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. | 29 // the tab/shutting down Chrome), or when the user navigates to a URL. |
| 34 void EmitNtpStatistics(); | 30 void EmitNtpStatistics(); |
| 35 | 31 |
| 36 // Called each time an event occurs on the NTP that requires a counter to be | 32 // Called each time an event occurs on the NTP that requires a counter to be |
| 37 // incremented. | 33 // incremented. |
| 38 void LogEvent(NTPLoggingEventType event); | 34 void LogEvent(NTPLoggingEventType event); |
| 39 | 35 |
| 40 // Logs an impression on one of the Most Visited tiles by a given provider. | 36 // Logs an impression on one of the Most Visited tiles by a given provider. |
| 41 void LogImpression(int position, const base::string16& provider); | 37 void LogImpression(int position, const base::string16& provider); |
| 42 | 38 |
| 43 // content::WebContentsObserver override | 39 // content::WebContentsObserver override |
| 44 virtual void NavigationEntryCommitted( | 40 virtual void NavigationEntryCommitted( |
| 45 const content::LoadCommittedDetails& load_details) OVERRIDE; | 41 const content::LoadCommittedDetails& load_details) OVERRIDE; |
| 46 | 42 |
| 47 protected: | 43 protected: |
| 44 FRIEND_TEST_ALL_PREFIXES(NTPUserDataLoggerTest, TestLogging); | |
|
Evan Stade
2014/01/09 00:45:42
if this is just for the constructor, I'd prefer yo
beaudoin
2014/01/15 23:39:56
Done.
| |
| 48 explicit NTPUserDataLogger(content::WebContents* contents); | 45 explicit NTPUserDataLogger(content::WebContents* contents); |
| 49 | 46 |
| 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: | 47 private: |
| 54 friend class content::WebContentsUserData<NTPUserDataLogger>; | 48 friend class content::WebContentsUserData<NTPUserDataLogger>; |
| 55 | 49 |
| 56 // Total number of mouseovers for this NTP session. | 50 // Total number of mouseovers for this NTP session. |
| 57 size_t number_of_mouseovers_; | 51 size_t number_of_mouseovers_; |
| 58 | 52 |
| 53 // Total number of tiles rendered, no matter if it's a thumbnail, a gray tile | |
| 54 // or an external tile. | |
| 55 size_t number_of_tiles_; | |
| 56 | |
| 59 // Total number of attempts made to load thumbnail images for this NTP | 57 // Total number of attempts made to load thumbnail images for this NTP |
| 60 // session. | 58 // session. |
| 61 size_t number_of_thumbnail_attempts_; | 59 size_t number_of_thumbnail_attempts_; |
| 62 | 60 |
| 63 // Total number of errors that occurred when trying to load thumbnail images | 61 // 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 | 62 // for this NTP session. When these errors occur a grey tile is shown instead |
| 65 // of a thumbnail image. | 63 // of a thumbnail image. |
| 66 size_t number_of_thumbnail_errors_; | 64 size_t number_of_thumbnail_errors_; |
| 67 | 65 |
| 68 // Total number of attempts made to load thumbnail images while providing a | 66 // The number of times a gray tile with the domain was used as the fallback |
| 69 // fallback thumbnail for this NTP session. | 67 // for a failed thumbnail. |
| 70 size_t number_of_fallback_thumbnails_requested_; | 68 size_t number_of_gray_tile_fallbacks_; |
| 71 | 69 |
| 72 // Total number of errors that occurred while trying to load the primary | 70 // The number of times an external tile, for which the visual appearance is |
| 73 // thumbnail image and that caused a fallback to the secondary thumbnail. | 71 // handled by the page itself, was the fallback for a failed thumbnail. |
| 74 size_t number_of_fallback_thumbnails_used_; | 72 size_t number_of_external_fallbacks_; |
| 75 | 73 |
| 76 // Total number of tiles for which the visual appearance is handled externally | 74 // Total number of tiles for which the visual appearance is handled externally |
| 77 // by the page itself. | 75 // by the page itself. |
| 78 size_t number_of_external_tiles_; | 76 size_t number_of_external_tiles_; |
| 79 | 77 |
| 78 // Total number of tiles for which no thumbnail is specified and a gray tile | |
| 79 // with the domain is used as the main tile. | |
| 80 size_t number_of_gray_tiles_; | |
|
Evan Stade
2014/01/09 00:45:42
can you make the order of these member variables m
beaudoin
2014/01/15 23:39:56
I cleaned the enums up, used more uniform names an
| |
| 81 | |
| 80 // True if at least one iframe came from a server-side suggestion. In | 82 // 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. | 83 // practice, either all the iframes are server-side suggestions or none are. |
| 82 bool server_side_suggestions_; | 84 bool server_side_suggestions_; |
| 83 | 85 |
| 84 // The URL of this New Tab Page - varies based on NTP version. | 86 // The URL of this New Tab Page - varies based on NTP version. |
| 85 GURL ntp_url_; | 87 GURL ntp_url_; |
| 86 | 88 |
| 87 DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger); | 89 DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger); |
| 88 }; | 90 }; |
| 89 | 91 |
| 90 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_ | 92 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_ |
| OLD | NEW |