Home | History | Annotate | Download | only in ntp
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_
      6 #define CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_
      7 
      8 #include <string>
      9 
     10 #include "base/strings/string16.h"
     11 #include "chrome/common/ntp_logging_events.h"
     12 #include "content/public/browser/web_contents_observer.h"
     13 #include "content/public/browser/web_contents_user_data.h"
     14 
     15 namespace content {
     16 class WebContents;
     17 }
     18 
     19 // Helper class for logging data from the NTP. Attached to each NTP instance.
     20 class NTPUserDataLogger
     21     : public content::WebContentsObserver,
     22       public content::WebContentsUserData<NTPUserDataLogger> {
     23  public:
     24   virtual ~NTPUserDataLogger();
     25 
     26   static NTPUserDataLogger* GetOrCreateFromWebContents(
     27       content::WebContents* content);
     28 
     29   // Returns the name of the histogram that should be logged for an impression
     30   // of a specified Most Visited |provider|.
     31   static std::string GetMostVisitedImpressionHistogramNameForProvider(
     32       const std::string& provider);
     33 
     34   // Returns the name of the histogram that should be logged for a navigation
     35   // to a specified Most Visited |provider|.
     36   static std::string GetMostVisitedNavigationHistogramNameForProvider(
     37       const std::string& provider);
     38 
     39   // Logs a number of statistics regarding the NTP. Called when an NTP tab is
     40   // about to be deactivated (be it by switching tabs, losing focus or closing
     41   // the tab/shutting down Chrome), or when the user navigates to a URL.
     42   void EmitNtpStatistics();
     43 
     44   // Called each time an event occurs on the NTP that requires a counter to be
     45   // incremented.
     46   void LogEvent(NTPLoggingEventType event);
     47 
     48   // Logs an impression on one of the Most Visited tiles by a given provider.
     49   void LogMostVisitedImpression(int position, const base::string16& provider);
     50 
     51   // Logs a navigation on one of the Most Visited tiles by a given provider.
     52   void LogMostVisitedNavigation(int position, const base::string16& provider);
     53 
     54   // content::WebContentsObserver override
     55   virtual void NavigationEntryCommitted(
     56       const content::LoadCommittedDetails& load_details) OVERRIDE;
     57 
     58  protected:
     59   explicit NTPUserDataLogger(content::WebContents* contents);
     60 
     61  private:
     62   friend class content::WebContentsUserData<NTPUserDataLogger>;
     63 
     64   // True if at least one iframe came from a server-side suggestion. In
     65   // practice, either all the iframes are server-side suggestions or none are.
     66   bool has_server_side_suggestions_;
     67 
     68   // Total number of tiles rendered, no matter if it's a thumbnail, a gray tile
     69   // or an external tile.
     70   size_t number_of_tiles_;
     71 
     72   // Total number of tiles using a local thumbnail image for this NTP session.
     73   size_t number_of_thumbnail_tiles_;
     74 
     75   // Total number of tiles for which no thumbnail is specified and a gray tile
     76   // with the domain is used as the main tile.
     77   size_t number_of_gray_tiles_;
     78 
     79   // Total number of tiles for which the visual appearance is handled externally
     80   // by the page itself.
     81   size_t number_of_external_tiles_;
     82 
     83   // Total number of errors that occurred when trying to load thumbnail images
     84   // for this NTP session. When these errors occur a grey tile is shown instead
     85   // of a thumbnail image.
     86   size_t number_of_thumbnail_errors_;
     87 
     88   // The number of times a gray tile with the domain was used as the fallback
     89   // for a failed thumbnail.
     90   size_t number_of_gray_tile_fallbacks_;
     91 
     92   // The number of times an external tile, for which the visual appearance is
     93   // handled by the page itself, was the fallback for a failed thumbnail.
     94   size_t number_of_external_tile_fallbacks_;
     95 
     96   // Total number of mouseovers for this NTP session.
     97   size_t number_of_mouseovers_;
     98 
     99   // The URL of this New Tab Page - varies based on NTP version.
    100   GURL ntp_url_;
    101 
    102   DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger);
    103 };
    104 
    105 #endif  // CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_
    106