- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / ntp / ntp_user_data_logger.h
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 "chrome/common/ntp_logging_events.h"
9 #include "content/public/browser/web_contents_observer.h"
10 #include "content/public/browser/web_contents_user_data.h"
11
12
13 // Helper class for logging data from the NTP. Attached to each NTP instance.
14 class NTPUserDataLogger
15     : public content::WebContentsObserver,
16       public content::WebContentsUserData<NTPUserDataLogger> {
17  public:
18   virtual ~NTPUserDataLogger();
19
20   // To be set after initialization of this class. Used to determine whether a
21   // tab visibility change event or navigation event comes from the NTP.
22   void set_ntp_url(const GURL& url) {
23     ntp_url_ = url;
24   }
25
26   const GURL& ntp_url() const { return ntp_url_; }
27
28   // Logs the error percentage rate when loading thumbnail images for this NTP
29   // session to UMA histogram. Called when the user navigates to a URL.
30   void EmitThumbnailErrorRate();
31
32   // Logs total number of mouseovers per NTP session to UMA histogram. Called
33   // when an NTP tab is about to be deactivated (be it by switching tabs, losing
34   // focus or closing the tab/shutting down Chrome), or when the user navigates
35   // to a URL.
36   void EmitMouseoverCount();
37
38   // Called each time an event occurs on the NTP that requires a counter to be
39   // incremented.
40   void LogEvent(NTPLoggingEventType event);
41
42   // content::WebContentsObserver override
43   virtual void NavigationEntryCommitted(
44       const content::LoadCommittedDetails& load_details) OVERRIDE;
45
46  protected:
47   explicit NTPUserDataLogger(content::WebContents* contents);
48
49   // Returns the percent error given |events| occurrences and |errors| errors.
50   virtual size_t GetPercentError(size_t errors, size_t events) const;
51
52  private:
53   friend class content::WebContentsUserData<NTPUserDataLogger>;
54
55   // Total number of mouseovers for this NTP session.
56   size_t number_of_mouseovers_;
57
58   // Total number of attempts made to load thumbnail images for this NTP
59   // session.
60   size_t number_of_thumbnail_attempts_;
61
62   // Total number of errors that occurred when trying to load thumbnail images
63   // for this NTP session. When these errors occur a grey tile is shown instead
64   // of a thumbnail image.
65   size_t number_of_thumbnail_errors_;
66
67   // Total number of attempts made to load thumbnail images while providing a
68   // fallback thumbnail for this NTP session.
69   size_t number_of_fallback_thumbnails_requested_;
70
71   // Total number of errors that occurred while trying to load the primary
72   // thumbnail image and that caused a fallback to the secondary thumbnail.
73   size_t number_of_fallback_thumbnails_used_;
74
75   // The URL of this New Tab Page - varies based on NTP version.
76   GURL ntp_url_;
77
78   DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger);
79 };
80
81 #endif  // CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_