File: ntp_user_data_logger.h

package info (click to toggle)
chromium-browser 41.0.2272.118-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 2,189,132 kB
  • sloc: cpp: 9,691,462; ansic: 3,341,451; python: 712,689; asm: 518,779; xml: 208,926; java: 169,820; sh: 119,353; perl: 68,907; makefile: 28,311; yacc: 13,305; objc: 11,385; tcl: 3,186; cs: 2,225; sql: 2,217; lex: 2,215; lisp: 1,349; pascal: 1,256; awk: 407; ruby: 155; sed: 53; php: 14; exp: 11
file content (105 lines) | stat: -rw-r--r-- 3,964 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_
#define CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_

#include <string>

#include "base/strings/string16.h"
#include "chrome/common/ntp_logging_events.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"

namespace content {
class WebContents;
}

// Helper class for logging data from the NTP. Attached to each NTP instance.
class NTPUserDataLogger
    : public content::WebContentsObserver,
      public content::WebContentsUserData<NTPUserDataLogger> {
 public:
  ~NTPUserDataLogger() override;

  static NTPUserDataLogger* GetOrCreateFromWebContents(
      content::WebContents* content);

  // Returns the name of the histogram that should be logged for an impression
  // of a specified Most Visited |provider|.
  static std::string GetMostVisitedImpressionHistogramNameForProvider(
      const std::string& provider);

  // Returns the name of the histogram that should be logged for a navigation
  // to a specified Most Visited |provider|.
  static std::string GetMostVisitedNavigationHistogramNameForProvider(
      const std::string& provider);

  // 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();

  // Called each time an event occurs on the NTP that requires a counter to be
  // incremented.
  void LogEvent(NTPLoggingEventType event);

  // Logs an impression on one of the Most Visited tiles by a given provider.
  void LogMostVisitedImpression(int position, const base::string16& provider);

  // Logs a navigation on one of the Most Visited tiles by a given provider.
  void LogMostVisitedNavigation(int position, const base::string16& provider);

  // content::WebContentsObserver override
  void NavigationEntryCommitted(
      const content::LoadCommittedDetails& load_details) override;

 protected:
  explicit NTPUserDataLogger(content::WebContents* contents);

 private:
  friend class content::WebContentsUserData<NTPUserDataLogger>;

  // True if at least one iframe came from a server-side suggestion. In
  // practice, either all the iframes are server-side suggestions or none are.
  bool has_server_side_suggestions_;

  // Total number of tiles rendered, no matter if it's a thumbnail, a gray tile
  // or an external tile.
  size_t number_of_tiles_;

  // Total number of tiles using a local thumbnail image for this NTP session.
  size_t number_of_thumbnail_tiles_;

  // Total number of tiles for which no thumbnail is specified and a gray tile
  // with the domain is used as the main tile.
  size_t number_of_gray_tiles_;

  // Total number of tiles for which the visual appearance is handled externally
  // by the page itself.
  size_t number_of_external_tiles_;

  // Total number of errors that occurred when trying to load thumbnail images
  // for this NTP session. When these errors occur a grey tile is shown instead
  // of a thumbnail image.
  size_t number_of_thumbnail_errors_;

  // The number of times a gray tile with the domain was used as the fallback
  // for a failed thumbnail.
  size_t number_of_gray_tile_fallbacks_;

  // The number of times an external tile, for which the visual appearance is
  // handled by the page itself, was the fallback for a failed thumbnail.
  size_t number_of_external_tile_fallbacks_;

  // Total number of mouseovers for this NTP session.
  size_t number_of_mouseovers_;

  // The URL of this New Tab Page - varies based on NTP version.
  GURL ntp_url_;

  DISALLOW_COPY_AND_ASSIGN(NTPUserDataLogger);
};

#endif  // CHROME_BROWSER_UI_WEBUI_NTP_NTP_USER_DATA_LOGGER_H_