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

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

Issue 2790463003: ntp_tiles: Cleanup enum names (Closed)
Patch Set: add back histogram enums Created 3 years, 8 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 <bitset>
11 11
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "chrome/common/search/ntp_logging_events.h" 15 #include "chrome/common/search/ntp_logging_events.h"
16 #include "components/ntp_tiles/ntp_tile_source.h" 16 #include "components/ntp_tiles/tile_source.h"
17 #include "content/public/browser/web_contents_observer.h" 17 #include "content/public/browser/web_contents_observer.h"
18 #include "content/public/browser/web_contents_user_data.h" 18 #include "content/public/browser/web_contents_user_data.h"
19 19
20 namespace content { 20 namespace content {
21 class WebContents; 21 class WebContents;
22 } 22 }
23 23
24 // Helper class for logging data from the NTP. Attached to each NTP instance. 24 // Helper class for logging data from the NTP. Attached to each NTP instance.
25 class NTPUserDataLogger 25 class NTPUserDataLogger
26 : public content::WebContentsObserver, 26 : public content::WebContentsObserver,
27 public content::WebContentsUserData<NTPUserDataLogger> { 27 public content::WebContentsUserData<NTPUserDataLogger> {
28 public: 28 public:
29 ~NTPUserDataLogger() override; 29 ~NTPUserDataLogger() override;
30 30
31 // Gets the associated NTPUserDataLogger, creating it if necessary. 31 // Gets the associated NTPUserDataLogger, creating it if necessary.
32 // 32 //
33 // MUST be called only when the NTP is active. 33 // MUST be called only when the NTP is active.
34 static NTPUserDataLogger* GetOrCreateFromWebContents( 34 static NTPUserDataLogger* GetOrCreateFromWebContents(
35 content::WebContents* content); 35 content::WebContents* content);
36 36
37 // Called when an event occurs on the NTP that requires a counter to be 37 // Called when an event occurs on the NTP that requires a counter to be
38 // incremented. |time| is the delta time from navigation start until this 38 // incremented. |time| is the delta time from navigation start until this
39 // event happened. 39 // event happened.
40 void LogEvent(NTPLoggingEventType event, base::TimeDelta time); 40 void LogEvent(NTPLoggingEventType event, base::TimeDelta time);
41 41
42 // Logs an impression on one of the NTP tiles by a given source. 42 // Logs an impression on one of the NTP tiles by a given source.
43 void LogMostVisitedImpression(int position, 43 void LogMostVisitedImpression(int position,
44 ntp_tiles::NTPTileSource tile_source); 44 ntp_tiles::TileSource tile_source);
45 45
46 // Logs a navigation on one of the NTP tiles by a given source. 46 // Logs a navigation on one of the NTP tiles by a given source.
47 void LogMostVisitedNavigation(int position, 47 void LogMostVisitedNavigation(int position,
48 ntp_tiles::NTPTileSource tile_source); 48 ntp_tiles::TileSource tile_source);
49 49
50 protected: 50 protected:
51 explicit NTPUserDataLogger(content::WebContents* contents); 51 explicit NTPUserDataLogger(content::WebContents* contents);
52 52
53 private: 53 private:
54 friend class content::WebContentsUserData<NTPUserDataLogger>; 54 friend class content::WebContentsUserData<NTPUserDataLogger>;
55 55
56 FRIEND_TEST_ALL_PREFIXES(NTPUserDataLoggerTest, TestLogMostVisitedImpression); 56 FRIEND_TEST_ALL_PREFIXES(NTPUserDataLoggerTest, TestLogMostVisitedImpression);
57 FRIEND_TEST_ALL_PREFIXES(NTPUserDataLoggerTest, TestNumberOfTiles); 57 FRIEND_TEST_ALL_PREFIXES(NTPUserDataLoggerTest, TestNumberOfTiles);
58 FRIEND_TEST_ALL_PREFIXES(NTPUserDataLoggerTest, TestLoadTime); 58 FRIEND_TEST_ALL_PREFIXES(NTPUserDataLoggerTest, TestLoadTime);
(...skipping 18 matching lines...) Expand all
77 // users that haven't built up a history yet. 77 // users that haven't built up a history yet.
78 // 78 //
79 // If something happens that causes the NTP to pull tiles from different 79 // If something happens that causes the NTP to pull tiles from different
80 // sources, such as signing in (switching from client to server tiles), then 80 // sources, such as signing in (switching from client to server tiles), then
81 // only the impressions for the first source will be logged, leaving the 81 // only the impressions for the first source will be logged, leaving the
82 // number of impressions for a source slightly out-of-sync with navigations. 82 // number of impressions for a source slightly out-of-sync with navigations.
83 std::bitset<kNumMostVisited> impression_was_logged_; 83 std::bitset<kNumMostVisited> impression_was_logged_;
84 84
85 // Stores the tile source for each impression. Entries are only valid if the 85 // Stores the tile source for each impression. Entries are only valid if the
86 // corresponding entry in |impression_was_logged_| is true. 86 // corresponding entry in |impression_was_logged_| is true.
87 std::vector<ntp_tiles::NTPTileSource> impression_tile_source_; 87 std::vector<ntp_tiles::TileSource> impression_tile_source_;
88 88
89 // The time we received the NTP_ALL_TILES_RECEIVED event. 89 // The time we received the NTP_ALL_TILES_RECEIVED event.
90 base::TimeDelta tiles_received_time_; 90 base::TimeDelta tiles_received_time_;
91 91
92 // Whether we have already emitted NTP stats for this web contents. 92 // Whether we have already emitted NTP stats for this web contents.
93 bool has_emitted_; 93 bool has_emitted_;
94 94
95 // Are stats being logged during Chrome startup? 95 // Are stats being logged during Chrome startup?
96 bool during_startup_; 96 bool during_startup_;
97 97
98 // The URL of this New Tab Page - varies based on NTP version. 98 // The URL of this New Tab Page - varies based on NTP version.
99 GURL ntp_url_; 99 GURL ntp_url_;
100 100
101 DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger); 101 DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger);
102 }; 102 };
103 103
104 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_ 104 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_tab_helper_unittest.cc ('k') | chrome/browser/ui/webui/ntp/ntp_user_data_logger.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698