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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/webui/ntp/ntp_user_data_logger.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/ntp/ntp_user_data_logger.h
diff --git a/chrome/browser/ui/webui/ntp/ntp_user_data_logger.h b/chrome/browser/ui/webui/ntp/ntp_user_data_logger.h
index bb96075e7331873169a20da3c905616ab4cc7247..6187e3734cf83e1e6bb2424831af892b035dd0ca 100644
--- a/chrome/browser/ui/webui/ntp/ntp_user_data_logger.h
+++ b/chrome/browser/ui/webui/ntp/ntp_user_data_logger.h
@@ -7,10 +7,13 @@
#include <stddef.h>
+#include <bitset>
+
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/time/time.h"
#include "chrome/common/search/ntp_logging_events.h"
+#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
namespace content {
@@ -19,10 +22,14 @@ class WebContents;
// Helper class for logging data from the NTP. Attached to each NTP instance.
class NTPUserDataLogger
- : public content::WebContentsUserData<NTPUserDataLogger> {
+ : public content::WebContentsObserver,
+ public content::WebContentsUserData<NTPUserDataLogger> {
public:
~NTPUserDataLogger() override;
+ // Gets the associated NTPUserDataLogger, creating it if necessary.
+ //
+ // MUST be called only when the NTP is active.
static NTPUserDataLogger* GetOrCreateFromWebContents(
content::WebContents* content);
@@ -49,12 +56,34 @@ class NTPUserDataLogger
OnMostVisitedItemsChangedFromClient);
FRIEND_TEST_ALL_PREFIXES(NTPUserDataLoggerTest,
TestLogging);
+ FRIEND_TEST_ALL_PREFIXES(NTPUserDataLoggerTest, TestLogMostVisitedImpression);
+ FRIEND_TEST_ALL_PREFIXES(NTPUserDataLoggerTest, TestNumberOfTiles);
+
+ // Number of Most Visited elements on the NTP for logging purposes.
+ static const int kNumMostVisited = 8;
+
+ // content::WebContentsObserver override
+ void NavigationEntryCommitted(
+ const content::LoadCommittedDetails& load_details) override;
+
+ // Implementation of NavigationEntryCommitted; separate for test.
+ void NavigatedFromURLToURL(const GURL& from, const GURL& to);
// Logs a number of statistics regarding the NTP. Called when an NTP tab is
// about to be deactivated (be it by switching tabs, losing focus or closing
// the tab/shutting down Chrome), or when the user navigates to a URL.
void EmitNtpStatistics(base::TimeDelta load_time);
+ // Records whether we have yet logged an impression for the tile at a given
+ // index. A typical NTP will log 8 impressions, but could record fewer for new
+ // users that haven't built up a history yet.
+ //
+ // If something happens that causes the NTP to pull tiles from different
+ // sources, such as signing in (switching from client to server tiles), then
+ // only the impressions for the first source will be logged, leaving the
+ // number of impressions for a source slightly out-of-sync with navigations.
+ std::bitset<kNumMostVisited> impression_was_logged_;
+
// True if at least one iframe came from a server-side suggestion.
bool has_server_side_suggestions_;
« no previous file with comments | « no previous file | 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