Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / metrics / chrome_metrics_service_client.h
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.
4
5 #ifndef CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_
6 #define CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/thread_checker.h"
15 #include "chrome/browser/memory_details.h"
16 #include "chrome/browser/metrics/network_stats_uploader.h"
17 #include "chrome/browser/metrics/tracking_synchronizer_observer.h"
18 #include "components/metrics/metrics_service_client.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
21
22 class ChromeOSMetricsProvider;
23 class GoogleUpdateMetricsProviderWin;
24 class MetricsService;
25 class PluginMetricsProvider;
26 class PrefRegistrySimple;
27 class ProfilerMetricsProvider;
28
29 #if !defined(OS_CHROMEOS) && !defined(OS_IOS)
30 class SigninStatusMetricsProvider;
31 #endif
32
33 namespace base {
34 class FilePath;
35 }
36
37 namespace metrics {
38 class MetricsStateManager;
39 }
40
41 // ChromeMetricsServiceClient provides an implementation of MetricsServiceClient
42 // that depends on chrome/.
43 class ChromeMetricsServiceClient
44     : public metrics::MetricsServiceClient,
45       public chrome_browser_metrics::TrackingSynchronizerObserver,
46       public content::NotificationObserver {
47  public:
48   virtual ~ChromeMetricsServiceClient();
49
50   // Factory function.
51   static scoped_ptr<ChromeMetricsServiceClient> Create(
52       metrics::MetricsStateManager* state_manager,
53       PrefService* local_state);
54
55   // Registers local state prefs used by this class.
56   static void RegisterPrefs(PrefRegistrySimple* registry);
57
58   // metrics::MetricsServiceClient:
59   virtual void SetMetricsClientId(const std::string& client_id) OVERRIDE;
60   virtual bool IsOffTheRecordSessionActive() OVERRIDE;
61   virtual std::string GetApplicationLocale() OVERRIDE;
62   virtual bool GetBrand(std::string* brand_code) OVERRIDE;
63   virtual metrics::SystemProfileProto::Channel GetChannel() OVERRIDE;
64   virtual std::string GetVersionString() OVERRIDE;
65   virtual void OnLogUploadComplete() OVERRIDE;
66   virtual void StartGatheringMetrics(
67       const base::Closure& done_callback) OVERRIDE;
68   virtual void CollectFinalMetrics(const base::Closure& done_callback)
69       OVERRIDE;
70   virtual scoped_ptr<metrics::MetricsLogUploader> CreateUploader(
71       const std::string& server_url,
72       const std::string& mime_type,
73       const base::Callback<void(int)>& on_upload_complete) OVERRIDE;
74
75   MetricsService* metrics_service() { return metrics_service_.get(); }
76
77   void LogPluginLoadingError(const base::FilePath& plugin_path);
78
79  private:
80   explicit ChromeMetricsServiceClient(
81       metrics::MetricsStateManager* state_manager);
82
83   // Completes the two-phase initialization of ChromeMetricsServiceClient.
84   void Initialize();
85
86   // Callback that continues the init task by loading plugin information.
87   void OnInitTaskGotHardwareClass();
88
89   // Called after the Plugin init task has been completed that continues the
90   // init task by launching a task to gather Google Update statistics.
91   void OnInitTaskGotPluginInfo();
92
93   // Called after GoogleUpdate init task has been completed that continues the
94   // init task by loading profiler data.
95   void OnInitTaskGotGoogleUpdateData();
96
97   // TrackingSynchronizerObserver:
98   virtual void ReceivedProfilerData(
99       const tracked_objects::ProcessDataSnapshot& process_data,
100       int process_type) OVERRIDE;
101   virtual void FinishedReceivingProfilerData() OVERRIDE;
102
103   // Callbacks for various stages of final log info collection. Do not call
104   // these directly.
105   void OnMemoryDetailCollectionDone();
106   void OnHistogramSynchronizationDone();
107
108   // Records metrics about the switches present on the command line.
109   void RecordCommandLineMetrics();
110
111   // Registers |this| as an observer for notifications which indicate that a
112   // user is performing work. This is useful to allow some features to sleep,
113   // until the machine becomes active, such as precluding UMA uploads unless
114   // there was recent activity.
115   void RegisterForNotifications();
116
117   // content::NotificationObserver:
118   virtual void Observe(int type,
119                        const content::NotificationSource& source,
120                        const content::NotificationDetails& details) OVERRIDE;
121
122 #if defined(OS_WIN)
123   // Counts (and removes) the browser crash dump attempt signals left behind by
124   // any previous browser processes which generated a crash dump.
125   void CountBrowserCrashDumpAttempts();
126 #endif  // OS_WIN
127
128   base::ThreadChecker thread_checker_;
129
130   // Weak pointer to the MetricsStateManager.
131   metrics::MetricsStateManager* metrics_state_manager_;
132
133   // The MetricsService that |this| is a client of.
134   scoped_ptr<MetricsService> metrics_service_;
135
136   content::NotificationRegistrar registrar_;
137
138   // On ChromeOS, holds a weak pointer to the ChromeOSMetricsProvider instance
139   // that has been registered with MetricsService. On other platforms, is NULL.
140   ChromeOSMetricsProvider* chromeos_metrics_provider_;
141
142   NetworkStatsUploader network_stats_uploader_;
143
144   // Saved callback received from CollectFinalMetrics().
145   base::Closure collect_final_metrics_done_callback_;
146
147   // Indicates that collect final metrics step is running.
148   bool waiting_for_collect_final_metrics_step_;
149
150   // Number of async histogram fetch requests in progress.
151   int num_async_histogram_fetches_in_progress_;
152
153   // The ProfilerMetricsProvider instance that was registered with
154   // MetricsService. Has the same lifetime as |metrics_service_|.
155   ProfilerMetricsProvider* profiler_metrics_provider_;
156
157 #if defined(ENABLE_PLUGINS)
158   // The PluginMetricsProvider instance that was registered with
159   // MetricsService. Has the same lifetime as |metrics_service_|.
160   PluginMetricsProvider* plugin_metrics_provider_;
161 #endif
162
163 #if defined(OS_WIN)
164   // The GoogleUpdateMetricsProviderWin instance that was registered with
165   // MetricsService. Has the same lifetime as |metrics_service_|.
166   GoogleUpdateMetricsProviderWin* google_update_metrics_provider_;
167 #endif
168
169 #if !defined(OS_CHROMEOS) && !defined(OS_IOS)
170   // The SigninStatusMetricsProvider instance that was registered with
171   // MetricsService. Has the same lifetime as |metrics_service_|.
172   SigninStatusMetricsProvider* signin_status_metrics_provider_;
173 #endif
174
175   // Callback that is called when initial metrics gathering is complete.
176   base::Closure finished_gathering_initial_metrics_callback_;
177
178   // The MemoryGrowthTracker instance that tracks memory usage growth in
179   // MemoryDetails.
180   MemoryGrowthTracker memory_growth_tracker_;
181
182   base::WeakPtrFactory<ChromeMetricsServiceClient> weak_ptr_factory_;
183
184   DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceClient);
185 };
186
187 #endif  // CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_