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

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

Issue 2544883006: Cleanup: Replace NTPLoggingTileSource by ntp_tiles::NTPTileSource (Closed)
Patch Set: tests Created 4 years 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 "content/public/browser/web_contents_observer.h" 17 #include "content/public/browser/web_contents_observer.h"
17 #include "content/public/browser/web_contents_user_data.h" 18 #include "content/public/browser/web_contents_user_data.h"
18 19
19 namespace content { 20 namespace content {
20 class WebContents; 21 class WebContents;
21 } 22 }
22 23
23 // 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.
24 class NTPUserDataLogger 25 class NTPUserDataLogger
25 : public content::WebContentsObserver, 26 : public content::WebContentsObserver,
26 public content::WebContentsUserData<NTPUserDataLogger> { 27 public content::WebContentsUserData<NTPUserDataLogger> {
27 public: 28 public:
28 ~NTPUserDataLogger() override; 29 ~NTPUserDataLogger() override;
29 30
30 // Gets the associated NTPUserDataLogger, creating it if necessary. 31 // Gets the associated NTPUserDataLogger, creating it if necessary.
31 // 32 //
32 // MUST be called only when the NTP is active. 33 // MUST be called only when the NTP is active.
33 static NTPUserDataLogger* GetOrCreateFromWebContents( 34 static NTPUserDataLogger* GetOrCreateFromWebContents(
34 content::WebContents* content); 35 content::WebContents* content);
35 36
36 // 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
37 // incremented. |time| is the delta time from navigation start until this 38 // incremented. |time| is the delta time from navigation start until this
38 // event happened. 39 // event happened.
39 void LogEvent(NTPLoggingEventType event, base::TimeDelta time); 40 void LogEvent(NTPLoggingEventType event, base::TimeDelta time);
40 41
41 // 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.
42 void LogMostVisitedImpression(int position, NTPLoggingTileSource tile_source); 43 void LogMostVisitedImpression(int position,
44 ntp_tiles::NTPTileSource tile_source);
43 45
44 // 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.
45 void LogMostVisitedNavigation(int position, NTPLoggingTileSource tile_source); 47 void LogMostVisitedNavigation(int position,
48 ntp_tiles::NTPTileSource tile_source);
46 49
47 protected: 50 protected:
48 explicit NTPUserDataLogger(content::WebContents* contents); 51 explicit NTPUserDataLogger(content::WebContents* contents);
49 52
50 private: 53 private:
51 friend class content::WebContentsUserData<NTPUserDataLogger>; 54 friend class content::WebContentsUserData<NTPUserDataLogger>;
52 55
53 FRIEND_TEST_ALL_PREFIXES(NTPUserDataLoggerTest, TestLogMostVisitedImpression); 56 FRIEND_TEST_ALL_PREFIXES(NTPUserDataLoggerTest, TestLogMostVisitedImpression);
54 FRIEND_TEST_ALL_PREFIXES(NTPUserDataLoggerTest, TestNumberOfTiles); 57 FRIEND_TEST_ALL_PREFIXES(NTPUserDataLoggerTest, TestNumberOfTiles);
55 58
(...skipping 17 matching lines...) Expand all
73 // users that haven't built up a history yet. 76 // users that haven't built up a history yet.
74 // 77 //
75 // If something happens that causes the NTP to pull tiles from different 78 // If something happens that causes the NTP to pull tiles from different
76 // sources, such as signing in (switching from client to server tiles), then 79 // sources, such as signing in (switching from client to server tiles), then
77 // only the impressions for the first source will be logged, leaving the 80 // only the impressions for the first source will be logged, leaving the
78 // number of impressions for a source slightly out-of-sync with navigations. 81 // number of impressions for a source slightly out-of-sync with navigations.
79 std::bitset<kNumMostVisited> impression_was_logged_; 82 std::bitset<kNumMostVisited> impression_was_logged_;
80 83
81 // Stores the tile source for each impression. Entries are only valid if the 84 // Stores the tile source for each impression. Entries are only valid if the
82 // corresponding entry in |impression_was_logged_| is true. 85 // corresponding entry in |impression_was_logged_| is true.
83 std::vector<NTPLoggingTileSource> impression_tile_source_; 86 std::vector<ntp_tiles::NTPTileSource> impression_tile_source_;
84 87
85 // Whether we have already emitted NTP stats for this web contents. 88 // Whether we have already emitted NTP stats for this web contents.
86 bool has_emitted_; 89 bool has_emitted_;
87 90
88 // Are stats being logged during Chrome startup? 91 // Are stats being logged during Chrome startup?
89 bool during_startup_; 92 bool during_startup_;
90 93
91 // 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.
92 GURL ntp_url_; 95 GURL ntp_url_;
93 96
94 DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger); 97 DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger);
95 }; 98 };
96 99
97 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_ 100 #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