Remove listening of OMNIBOX_OPENED_URL from metrics code
[chromium-blink-merge.git] / chrome / browser / metrics / chrome_metrics_service_client.h
blob1500649d9317d51157831c99676e95d9c0162dd7
1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_
6 #define CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/containers/scoped_ptr_map.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/threading/thread_checker.h"
16 #include "chrome/browser/metrics/metrics_memory_details.h"
17 #include "components/metrics/metrics_service_client.h"
18 #include "components/metrics/profiler/tracking_synchronizer_observer.h"
19 #include "components/omnibox/browser/omnibox_event_global_tracker.h"
20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h"
23 class ChromeOSMetricsProvider;
24 class GoogleUpdateMetricsProviderWin;
25 class PluginMetricsProvider;
26 class PrefRegistrySimple;
27 class PrefService;
28 class ProcessResourceUsage;
30 #if !defined(OS_CHROMEOS) && !defined(OS_IOS)
31 class SigninStatusMetricsProvider;
32 #endif
34 namespace base {
35 class FilePath;
36 } // namespace base
38 namespace metrics {
39 class DriveMetricsProvider;
40 class MetricsService;
41 class MetricsStateManager;
42 class ProfilerMetricsProvider;
43 } // namespace metrics
45 // ChromeMetricsServiceClient provides an implementation of MetricsServiceClient
46 // that depends on chrome/.
47 class ChromeMetricsServiceClient
48 : public metrics::MetricsServiceClient,
49 public metrics::TrackingSynchronizerObserver,
50 public content::NotificationObserver {
51 public:
52 ~ChromeMetricsServiceClient() override;
54 // Factory function.
55 static scoped_ptr<ChromeMetricsServiceClient> Create(
56 metrics::MetricsStateManager* state_manager,
57 PrefService* local_state);
59 // Registers local state prefs used by this class.
60 static void RegisterPrefs(PrefRegistrySimple* registry);
62 // metrics::MetricsServiceClient:
63 void SetMetricsClientId(const std::string& client_id) override;
64 void OnRecordingDisabled() override;
65 bool IsOffTheRecordSessionActive() override;
66 int32 GetProduct() override;
67 std::string GetApplicationLocale() override;
68 bool GetBrand(std::string* brand_code) override;
69 metrics::SystemProfileProto::Channel GetChannel() override;
70 std::string GetVersionString() override;
71 void OnLogUploadComplete() override;
72 void StartGatheringMetrics(const base::Closure& done_callback) override;
73 void CollectFinalMetrics(const base::Closure& done_callback) override;
74 scoped_ptr<metrics::MetricsLogUploader> CreateUploader(
75 const base::Callback<void(int)>& on_upload_complete) override;
76 base::TimeDelta GetStandardUploadInterval() override;
77 base::string16 GetRegistryBackupKey() override;
79 metrics::MetricsService* metrics_service() { return metrics_service_.get(); }
81 void LogPluginLoadingError(const base::FilePath& plugin_path);
83 private:
84 explicit ChromeMetricsServiceClient(
85 metrics::MetricsStateManager* state_manager);
87 // Completes the two-phase initialization of ChromeMetricsServiceClient.
88 void Initialize();
90 // Callback that continues the init task by loading plugin information.
91 void OnInitTaskGotHardwareClass();
93 // Called after the Plugin init task has been completed that continues the
94 // init task by launching a task to gather Google Update statistics.
95 void OnInitTaskGotPluginInfo();
97 // Called after GoogleUpdate init task has been completed that continues the
98 // init task by loading profiler data.
99 void OnInitTaskGotGoogleUpdateData();
101 // Called after WebCache statistics have been received from a renderer
102 // process.
103 void OnWebCacheStatsRefresh(int host_id);
105 // TrackingSynchronizerObserver:
106 void ReceivedProfilerData(
107 const metrics::ProfilerDataAttributes& attributes,
108 const tracked_objects::ProcessDataPhaseSnapshot& process_data_phase,
109 const metrics::ProfilerEvents& past_profiler_events) override;
110 void FinishedReceivingProfilerData() override;
112 // Callbacks for various stages of final log info collection. Do not call
113 // these directly.
114 void OnMemoryDetailCollectionDone();
115 void OnHistogramSynchronizationDone();
117 // Records metrics about the switches present on the command line.
118 void RecordCommandLineMetrics();
120 // Registers |this| as an observer for notifications which indicate that a
121 // user is performing work. This is useful to allow some features to sleep,
122 // until the machine becomes active, such as precluding UMA uploads unless
123 // there was recent activity.
124 void RegisterForNotifications();
126 // content::NotificationObserver:
127 void Observe(int type,
128 const content::NotificationSource& source,
129 const content::NotificationDetails& details) override;
131 // Called when a URL is opened from the Omnibox.
132 void OnURLOpenedFromOmnibox(OmniboxLog* log);
134 #if defined(OS_WIN)
135 // Counts (and removes) the browser crash dump attempt signals left behind by
136 // any previous browser processes which generated a crash dump.
137 void CountBrowserCrashDumpAttempts();
138 #endif // OS_WIN
140 base::ThreadChecker thread_checker_;
142 // Weak pointer to the MetricsStateManager.
143 metrics::MetricsStateManager* metrics_state_manager_;
145 // The MetricsService that |this| is a client of.
146 scoped_ptr<metrics::MetricsService> metrics_service_;
148 content::NotificationRegistrar registrar_;
150 // On ChromeOS, holds a weak pointer to the ChromeOSMetricsProvider instance
151 // that has been registered with MetricsService. On other platforms, is NULL.
152 ChromeOSMetricsProvider* chromeos_metrics_provider_;
154 // Saved callback received from CollectFinalMetrics().
155 base::Closure collect_final_metrics_done_callback_;
157 // Indicates that collect final metrics step is running.
158 bool waiting_for_collect_final_metrics_step_;
160 // Number of async histogram fetch requests in progress.
161 int num_async_histogram_fetches_in_progress_;
163 // The ProfilerMetricsProvider instance that was registered with
164 // MetricsService. Has the same lifetime as |metrics_service_|.
165 metrics::ProfilerMetricsProvider* profiler_metrics_provider_;
167 #if defined(ENABLE_PLUGINS)
168 // The PluginMetricsProvider instance that was registered with
169 // MetricsService. Has the same lifetime as |metrics_service_|.
170 PluginMetricsProvider* plugin_metrics_provider_;
171 #endif
173 #if defined(OS_WIN)
174 // The GoogleUpdateMetricsProviderWin instance that was registered with
175 // MetricsService. Has the same lifetime as |metrics_service_|.
176 GoogleUpdateMetricsProviderWin* google_update_metrics_provider_;
177 #endif
179 // The DriveMetricsProvider instance that was registered with MetricsService.
180 // Has the same lifetime as |metrics_service_|.
181 metrics::DriveMetricsProvider* drive_metrics_provider_;
183 // Callback that is called when initial metrics gathering is complete.
184 base::Closure finished_gathering_initial_metrics_callback_;
186 // The MemoryGrowthTracker instance that tracks memory usage growth in
187 // MemoryDetails.
188 MemoryGrowthTracker memory_growth_tracker_;
190 // Callback to determine whether or not a cellular network is currently being
191 // used.
192 base::Callback<void(bool*)> cellular_callback_;
194 // Time of this object's creation.
195 const base::TimeTicks start_time_;
197 // Map of ProcessResourceUsage from render process host IDs.
198 base::ScopedPtrMap<int, scoped_ptr<ProcessResourceUsage>>
199 host_resource_usage_map_;
201 // Subscription for receiving callbacks that a URL was opened from the
202 // omnibox.
203 scoped_ptr<base::CallbackList<void(OmniboxLog*)>::Subscription>
204 omnibox_url_opened_subscription_;
206 base::WeakPtrFactory<ChromeMetricsServiceClient> weak_ptr_factory_;
208 DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceClient);
211 #endif // CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_