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

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 <bitset>
10 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
Marc Treib 2016/07/15 10:04:46 nit: empty line between <> and "" includes
sfiera 2016/07/15 10:26:00 Done.
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/time/time.h" 13 #include "base/time/time.h"
13 #include "chrome/common/search/ntp_logging_events.h" 14 #include "chrome/common/search/ntp_logging_events.h"
15 #include "content/public/browser/web_contents_observer.h"
14 #include "content/public/browser/web_contents_user_data.h" 16 #include "content/public/browser/web_contents_user_data.h"
15 17
16 namespace content { 18 namespace content {
17 class WebContents; 19 class WebContents;
18 } 20 }
19 21
20 // Helper class for logging data from the NTP. Attached to each NTP instance. 22 // Helper class for logging data from the NTP. Attached to each NTP instance.
21 class NTPUserDataLogger 23 class NTPUserDataLogger
22 : public content::WebContentsUserData<NTPUserDataLogger> { 24 : public content::WebContentsObserver,
25 public content::WebContentsUserData<NTPUserDataLogger> {
23 public: 26 public:
24 ~NTPUserDataLogger() override; 27 ~NTPUserDataLogger() override;
25 28
29 // Gets the associated NTPUserDataLogger, creating it if necessary.
30 //
31 // MUST be called only when the NTP is active.
26 static NTPUserDataLogger* GetOrCreateFromWebContents( 32 static NTPUserDataLogger* GetOrCreateFromWebContents(
27 content::WebContents* content); 33 content::WebContents* content);
28 34
29 // Called when an event occurs on the NTP that requires a counter to be 35 // Called when an event occurs on the NTP that requires a counter to be
30 // incremented. |time| is the delta time in ms from navigation start until 36 // incremented. |time| is the delta time in ms from navigation start until
31 // this event happened. 37 // this event happened.
32 void LogEvent(NTPLoggingEventType event, base::TimeDelta time); 38 void LogEvent(NTPLoggingEventType event, base::TimeDelta time);
33 39
34 // Logs an impression on one of the NTP tiles by a given source. 40 // Logs an impression on one of the NTP tiles by a given source.
35 void LogMostVisitedImpression(int position, NTPLoggingTileSource tile_source); 41 void LogMostVisitedImpression(int position, NTPLoggingTileSource tile_source);
36 42
37 // Logs a navigation on one of the NTP tiles by a given source. 43 // Logs a navigation on one of the NTP tiles by a given source.
38 void LogMostVisitedNavigation(int position, NTPLoggingTileSource tile_source); 44 void LogMostVisitedNavigation(int position, NTPLoggingTileSource tile_source);
39 45
40 protected: 46 protected:
41 explicit NTPUserDataLogger(content::WebContents* contents); 47 explicit NTPUserDataLogger(content::WebContents* contents);
42 48
43 private: 49 private:
44 friend class content::WebContentsUserData<NTPUserDataLogger>; 50 friend class content::WebContentsUserData<NTPUserDataLogger>;
45 51
46 FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest, 52 FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest,
47 OnMostVisitedItemsChangedFromServer); 53 OnMostVisitedItemsChangedFromServer);
48 FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest, 54 FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest,
49 OnMostVisitedItemsChangedFromClient); 55 OnMostVisitedItemsChangedFromClient);
50 FRIEND_TEST_ALL_PREFIXES(NTPUserDataLoggerTest, 56 FRIEND_TEST_ALL_PREFIXES(NTPUserDataLoggerTest,
51 TestLogging); 57 TestLogging);
52 58
59 // content::WebContentsObserver override
60 void NavigationEntryCommitted(
61 const content::LoadCommittedDetails& load_details) override;
62
53 // Logs a number of statistics regarding the NTP. Called when an NTP tab is 63 // Logs a number of statistics regarding the NTP. Called when an NTP tab is
54 // about to be deactivated (be it by switching tabs, losing focus or closing 64 // about to be deactivated (be it by switching tabs, losing focus or closing
55 // the tab/shutting down Chrome), or when the user navigates to a URL. 65 // the tab/shutting down Chrome), or when the user navigates to a URL.
56 void EmitNtpStatistics(base::TimeDelta load_time); 66 void EmitNtpStatistics(base::TimeDelta load_time);
57 67
68 // Records whether we have yet logged an impression for the tile at a given
69 // index. A typical NTP will log 8 impressions, but could record fewer for new
70 // users that haven't built up a history yet.
71 //
72 // If something happens that causes the NTP to pull tiles from different
73 // sources, such as logging in (switching from client to server tiles), then
Marc Treib 2016/07/15 10:04:46 nit: s/logging/signing (that's the usual nomenclat
sfiera 2016/07/15 10:26:00 Done.
74 // only the impressions for the first source will be logged, leaving the
75 // number of impressions for a source slightly out-of-sync with navigations.
76 std::bitset<8> impression_was_logged_;
Marc Treib 2016/07/15 10:04:46 Please use the kNumMostVisited constant instead of
sfiera 2016/07/15 10:26:00 Done.
77
58 // True if at least one iframe came from a server-side suggestion. 78 // True if at least one iframe came from a server-side suggestion.
59 bool has_server_side_suggestions_; 79 bool has_server_side_suggestions_;
60 80
61 // True if at least one iframe came from a client-side suggestion. 81 // True if at least one iframe came from a client-side suggestion.
62 bool has_client_side_suggestions_; 82 bool has_client_side_suggestions_;
63 83
64 // Total number of tiles rendered, no matter if it's a thumbnail, a gray tile 84 // Total number of tiles rendered, no matter if it's a thumbnail, a gray tile
65 // or an external tile. 85 // or an external tile.
66 size_t number_of_tiles_; 86 size_t number_of_tiles_;
67 87
68 // Whether we have already emitted NTP stats for this web contents. 88 // Whether we have already emitted NTP stats for this web contents.
69 bool has_emitted_; 89 bool has_emitted_;
70 90
71 // Are stats being logged during Chrome startup? 91 // Are stats being logged during Chrome startup?
72 bool during_startup_; 92 bool during_startup_;
73 93
74 // The URL of this New Tab Page - varies based on NTP version. 94 // The URL of this New Tab Page - varies based on NTP version.
75 GURL ntp_url_; 95 GURL ntp_url_;
76 96
77 DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger); 97 DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger);
78 }; 98 };
79 99
80 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_ 100 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698