| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| 13 #include "base/macros.h" | 11 #include "base/macros.h" |
| 14 #include "base/strings/string16.h" | |
| 15 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 16 #include "chrome/common/search/ntp_logging_events.h" | 13 #include "chrome/common/search/ntp_logging_events.h" |
| 17 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
| 18 #include "content/public/browser/web_contents_user_data.h" | 15 #include "content/public/browser/web_contents_user_data.h" |
| 19 | 16 |
| 20 namespace content { | 17 namespace content { |
| 21 class WebContents; | 18 class WebContents; |
| 22 } | 19 } |
| 23 | 20 |
| 24 // Helper class for logging data from the NTP. Attached to each NTP instance. | 21 // Helper class for logging data from the NTP. Attached to each NTP instance. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 35 // incremented. |time| is the delta time in ms from navigation start until | 32 // incremented. |time| is the delta time in ms from navigation start until |
| 36 // this event happened. | 33 // this event happened. |
| 37 void LogEvent(NTPLoggingEventType event, base::TimeDelta time); | 34 void LogEvent(NTPLoggingEventType event, base::TimeDelta time); |
| 38 | 35 |
| 39 // Logs an impression on one of the NTP tiles by a given source. | 36 // Logs an impression on one of the NTP tiles by a given source. |
| 40 void LogMostVisitedImpression(int position, NTPLoggingTileSource tile_source); | 37 void LogMostVisitedImpression(int position, NTPLoggingTileSource tile_source); |
| 41 | 38 |
| 42 // Logs a navigation on one of the NTP tiles by a given source. | 39 // Logs a navigation on one of the NTP tiles by a given source. |
| 43 void LogMostVisitedNavigation(int position, NTPLoggingTileSource tile_source); | 40 void LogMostVisitedNavigation(int position, NTPLoggingTileSource tile_source); |
| 44 | 41 |
| 45 // content::WebContentsObserver override | |
| 46 void NavigationEntryCommitted( | |
| 47 const content::LoadCommittedDetails& load_details) override; | |
| 48 | |
| 49 // Called when the tab is closed. Logs statistics. | 42 // Called when the tab is closed. Logs statistics. |
| 50 void TabDeactivated(); | 43 void TabDeactivated(); |
| 51 | 44 |
| 52 // Called when the set of most visited sites changes. Flushes statistics. | 45 // Called when the set of most visited sites changes. Flushes statistics. |
| 53 void MostVisitedItemsChanged(); | 46 void MostVisitedItemsChanged(); |
| 54 | 47 |
| 55 protected: | 48 protected: |
| 56 explicit NTPUserDataLogger(content::WebContents* contents); | 49 explicit NTPUserDataLogger(content::WebContents* contents); |
| 57 | 50 |
| 58 private: | 51 private: |
| 59 friend class content::WebContentsUserData<NTPUserDataLogger>; | 52 friend class content::WebContentsUserData<NTPUserDataLogger>; |
| 60 | 53 |
| 61 FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest, | 54 FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest, |
| 62 OnMostVisitedItemsChangedFromServer); | 55 OnMostVisitedItemsChangedFromServer); |
| 63 FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest, | 56 FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest, |
| 64 OnMostVisitedItemsChangedFromClient); | 57 OnMostVisitedItemsChangedFromClient); |
| 65 FRIEND_TEST_ALL_PREFIXES(NTPUserDataLoggerTest, | 58 FRIEND_TEST_ALL_PREFIXES(NTPUserDataLoggerTest, |
| 66 TestLogging); | 59 TestLogging); |
| 67 | 60 |
| 61 // content::WebContentsObserver override |
| 62 void NavigationEntryCommitted( |
| 63 const content::LoadCommittedDetails& load_details) override; |
| 64 |
| 68 // To clarify at the call site whether we are calling EmitNtpStatistics() for | 65 // To clarify at the call site whether we are calling EmitNtpStatistics() for |
| 69 // a good reason (CLOSED, NAVIGATED_AWAY) or a questionable one (MV_CHANGED, | 66 // a good reason (CLOSED, NAVIGATED_AWAY) or a questionable one (MV_CHANGED, |
| 70 // INTERNAL_FLUSH). | 67 // INTERNAL_FLUSH). |
| 71 // TODO(sfiera): remove MV_CHANGED, INTERNAL_FLUSH. | 68 // TODO(sfiera): remove MV_CHANGED, INTERNAL_FLUSH. |
| 72 enum class EmitReason { CLOSED, NAVIGATED_AWAY, MV_CHANGED, INTERNAL_FLUSH }; | 69 enum class EmitReason { CLOSED, NAVIGATED_AWAY, MV_CHANGED, INTERNAL_FLUSH }; |
| 73 | 70 |
| 74 // Logs a number of statistics regarding the NTP. Called when an NTP tab is | 71 // Logs a number of statistics regarding the NTP. Called when an NTP tab is |
| 75 // about to be deactivated (be it by switching tabs, losing focus or closing | 72 // about to be deactivated (be it by switching tabs, losing focus or closing |
| 76 // the tab/shutting down Chrome), or when the user navigates to a URL. | 73 // the tab/shutting down Chrome), or when the user navigates to a URL. |
| 77 void EmitNtpStatistics(EmitReason reason); | 74 void EmitNtpStatistics(EmitReason reason); |
| 78 | 75 |
| 79 // True if at least one iframe came from a server-side suggestion. | 76 // True if at least one iframe came from a server-side suggestion. |
| 80 bool has_server_side_suggestions_; | 77 bool has_server_side_suggestions_; |
| 81 | 78 |
| 82 // True if at least one iframe came from a client-side suggestion. | 79 // True if at least one iframe came from a client-side suggestion. |
| 83 bool has_client_side_suggestions_; | 80 bool has_client_side_suggestions_; |
| 84 | 81 |
| 85 // Total number of tiles rendered, no matter if it's a thumbnail, a gray tile | 82 // Total number of tiles rendered, no matter if it's a thumbnail, a gray tile |
| 86 // or an external tile. | 83 // or an external tile. |
| 87 size_t number_of_tiles_; | 84 size_t number_of_tiles_; |
| 88 | 85 |
| 89 // Total number of tiles using a local thumbnail image for this NTP session. | |
| 90 size_t number_of_thumbnail_tiles_; | |
| 91 | |
| 92 // Total number of tiles for which no thumbnail is specified and a gray tile | |
| 93 // with the domain is used as the main tile. | |
| 94 size_t number_of_gray_tiles_; | |
| 95 | |
| 96 // Total number of tiles for which the visual appearance is handled externally | |
| 97 // by the page itself. | |
| 98 size_t number_of_external_tiles_; | |
| 99 | |
| 100 // Total number of errors that occurred when trying to load thumbnail images | |
| 101 // for this NTP session. When these errors occur a grey tile is shown instead | |
| 102 // of a thumbnail image. | |
| 103 size_t number_of_thumbnail_errors_; | |
| 104 | |
| 105 // The number of times a gray tile with the domain was used as the fallback | |
| 106 // for a failed thumbnail. | |
| 107 size_t number_of_gray_tile_fallbacks_; | |
| 108 | |
| 109 // The number of times an external tile, for which the visual appearance is | |
| 110 // handled by the page itself, was the fallback for a failed thumbnail. | |
| 111 size_t number_of_external_tile_fallbacks_; | |
| 112 | |
| 113 // Time from navigation start it took to load the NTP in milliseconds. | 86 // Time from navigation start it took to load the NTP in milliseconds. |
| 114 base::TimeDelta load_time_; | 87 base::TimeDelta load_time_; |
| 115 | 88 |
| 116 // Whether we have already emitted NTP stats for this web contents. | 89 // Whether we have already emitted NTP stats for this web contents. |
| 117 bool has_emitted_; | 90 bool has_emitted_; |
| 118 | 91 |
| 119 // Are stats being logged during Chrome startup? | 92 // Are stats being logged during Chrome startup? |
| 120 bool during_startup_; | 93 bool during_startup_; |
| 121 | 94 |
| 122 // The URL of this New Tab Page - varies based on NTP version. | 95 // The URL of this New Tab Page - varies based on NTP version. |
| 123 GURL ntp_url_; | 96 GURL ntp_url_; |
| 124 | 97 |
| 125 DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger); | 98 DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger); |
| 126 }; | 99 }; |
| 127 | 100 |
| 128 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_ | 101 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_ |
| OLD | NEW |