Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/browser/ui/webui/ntp/ntp_user_data_logger.h

Issue 2124903003: Record impressions/navigations only once per tile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "chrome/common/search/ntp_logging_events.h" 13 #include "chrome/common/search/ntp_logging_events.h"
14 #include "content/public/browser/web_contents_observer.h" 14 #include "content/public/browser/web_contents_observer.h"
15 #include "content/public/browser/web_contents_user_data.h" 15 #include "content/public/browser/web_contents_user_data.h"
16 16
17 namespace content { 17 namespace content {
18 class WebContents; 18 class WebContents;
19 } 19 }
20 20
21 // 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.
22 class NTPUserDataLogger 22 class NTPUserDataLogger
23 : public content::WebContentsObserver, 23 : public content::WebContentsObserver,
24 public content::WebContentsUserData<NTPUserDataLogger> { 24 public content::WebContentsUserData<NTPUserDataLogger> {
25 public: 25 public:
26 ~NTPUserDataLogger() override; 26 ~NTPUserDataLogger() override;
27 27
28 // Gets the associated NTPUserDataLogger, creating it if necessary.
29 //
30 // MUST be called only when the NTP is active.
Marc Treib 2016/07/12 08:17:46 Can we DCHECK this? search::IsInstantNTP might be
sfiera 2016/07/14 14:11:08 DCHECK added.
28 static NTPUserDataLogger* GetOrCreateFromWebContents( 31 static NTPUserDataLogger* GetOrCreateFromWebContents(
29 content::WebContents* content); 32 content::WebContents* content);
30 33
31 // Called when an event occurs on the NTP that requires a counter to be 34 // Called when an event occurs on the NTP that requires a counter to be
32 // incremented. |time| is the delta time in ms from navigation start until 35 // incremented. |time| is the delta time in ms from navigation start until
33 // this event happened. 36 // this event happened.
34 void LogEvent(NTPLoggingEventType event, base::TimeDelta time); 37 void LogEvent(NTPLoggingEventType event, base::TimeDelta time);
35 38
36 // Logs an impression on one of the NTP tiles by a given source. 39 // Logs an impression on one of the NTP tiles by a given source.
37 void LogMostVisitedImpression(int position, NTPLoggingTileSource tile_source); 40 void LogMostVisitedImpression(int position, NTPLoggingTileSource tile_source);
38 41
39 // Logs a navigation on one of the NTP tiles by a given source. 42 // Logs a navigation on one of the NTP tiles by a given source.
40 void LogMostVisitedNavigation(int position, NTPLoggingTileSource tile_source); 43 void LogMostVisitedNavigation(int position, NTPLoggingTileSource tile_source);
41 44
42 // Called when the tab is closed. Logs statistics. 45 // Called when the tab is closed. Logs statistics.
43 void TabDeactivated(); 46 void TabDeactivated();
44 47
45 // Called when the set of most visited sites changes. Flushes statistics.
46 void MostVisitedItemsChanged();
47
48 protected: 48 protected:
49 explicit NTPUserDataLogger(content::WebContents* contents); 49 explicit NTPUserDataLogger(content::WebContents* contents);
50 50
51 private: 51 private:
52 friend class content::WebContentsUserData<NTPUserDataLogger>; 52 friend class content::WebContentsUserData<NTPUserDataLogger>;
53 53
54 FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest, 54 FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest,
55 OnMostVisitedItemsChangedFromServer); 55 OnMostVisitedItemsChangedFromServer);
56 FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest, 56 FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest,
57 OnMostVisitedItemsChangedFromClient); 57 OnMostVisitedItemsChangedFromClient);
58 FRIEND_TEST_ALL_PREFIXES(NTPUserDataLoggerTest, 58 FRIEND_TEST_ALL_PREFIXES(NTPUserDataLoggerTest,
59 TestLogging); 59 TestLogging);
60 60
61 // content::WebContentsObserver override 61 // content::WebContentsObserver override
62 void NavigationEntryCommitted( 62 void NavigationEntryCommitted(
63 const content::LoadCommittedDetails& load_details) override; 63 const content::LoadCommittedDetails& load_details) override;
64 64
65 // 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
66 // a good reason (CLOSED, NAVIGATED_AWAY) or a questionable one (MV_CHANGED, 66 // a good reason (CLOSED, NAVIGATED_AWAY) or a questionable one
67 // INTERNAL_FLUSH). 67 // (INTERNAL_FLUSH).
68 // TODO(sfiera): remove MV_CHANGED, INTERNAL_FLUSH. 68 // TODO(sfiera): remove INTERNAL_FLUSH.
69 enum class EmitReason { CLOSED, NAVIGATED_AWAY, MV_CHANGED, INTERNAL_FLUSH }; 69 enum class EmitReason { CLOSED, NAVIGATED_AWAY, INTERNAL_FLUSH };
70 70
71 // 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
72 // 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
73 // 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.
74 void EmitNtpStatistics(EmitReason reason); 74 void EmitNtpStatistics(EmitReason reason);
75 75
76 // Records whether we have yet logged an impression for the tile at a given
77 // index. A typical NTP will log 8 impressions, but could record fewer for new
78 // users that haven't built up a history yet.
79 //
80 // If something happens that causes the NTP to pull tiles from different
81 // sources, such as logging in (switching from client to server tiles), then
82 // only the impressions for the first source will be logged, leaving the
83 // number of impressions for a source slightly out-of-sync with navigations.
84 std::vector<bool> impression_was_logged_;
85
76 // True if at least one iframe came from a server-side suggestion. 86 // True if at least one iframe came from a server-side suggestion.
77 bool has_server_side_suggestions_; 87 bool has_server_side_suggestions_;
78 88
79 // True if at least one iframe came from a client-side suggestion. 89 // True if at least one iframe came from a client-side suggestion.
80 bool has_client_side_suggestions_; 90 bool has_client_side_suggestions_;
81 91
82 // Total number of tiles rendered, no matter if it's a thumbnail, a gray tile 92 // Total number of tiles rendered, no matter if it's a thumbnail, a gray tile
83 // or an external tile. 93 // or an external tile.
84 size_t number_of_tiles_; 94 size_t number_of_tiles_;
85 95
86 // Time from navigation start it took to load the NTP in milliseconds. 96 // Time from navigation start it took to load the NTP in milliseconds.
87 base::TimeDelta load_time_; 97 base::TimeDelta load_time_;
88 98
89 // Whether we have already emitted NTP stats for this web contents. 99 // Whether we have already emitted NTP stats for this web contents.
90 bool has_emitted_; 100 bool has_emitted_;
91 101
92 // Are stats being logged during Chrome startup? 102 // Are stats being logged during Chrome startup?
93 bool during_startup_; 103 bool during_startup_;
94 104
95 // The URL of this New Tab Page - varies based on NTP version. 105 // The URL of this New Tab Page - varies based on NTP version.
96 GURL ntp_url_; 106 GURL ntp_url_;
97 107
98 DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger); 108 DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger);
99 }; 109 };
100 110
101 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_ 111 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698