Move MetricsLog into the Metrics component.
[chromium-blink-merge.git] / chrome / browser / metrics / chrome_metrics_service_client.h
blob63bf92e06503d9c43fa3e3aef322217ffc41ea8c
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/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/thread_checker.h"
15 #include "chrome/browser/metrics/network_stats_uploader.h"
16 #include "components/metrics/metrics_service_client.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
20 class ChromeOSMetricsProvider;
21 class MetricsService;
23 namespace metrics {
24 class MetricsStateManager;
27 // ChromeMetricsServiceClient provides an implementation of MetricsServiceClient
28 // that depends on chrome/.
29 class ChromeMetricsServiceClient : public metrics::MetricsServiceClient,
30 public content::NotificationObserver {
31 public:
32 virtual ~ChromeMetricsServiceClient();
34 // Factory function.
35 static scoped_ptr<ChromeMetricsServiceClient> Create(
36 metrics::MetricsStateManager* state_manager,
37 PrefService* local_state);
39 // metrics::MetricsServiceClient:
40 virtual void SetClientID(const std::string& client_id) OVERRIDE;
41 virtual bool IsOffTheRecordSessionActive() OVERRIDE;
42 virtual std::string GetApplicationLocale() OVERRIDE;
43 virtual bool GetBrand(std::string* brand_code) OVERRIDE;
44 virtual metrics::SystemProfileProto::Channel GetChannel() OVERRIDE;
45 virtual std::string GetVersionString() OVERRIDE;
46 virtual int64 GetInstallDate() OVERRIDE;
47 virtual void OnLogUploadComplete() OVERRIDE;
48 virtual void StartGatheringMetrics(
49 const base::Closure& done_callback) OVERRIDE;
50 virtual void CollectFinalMetrics(const base::Closure& done_callback)
51 OVERRIDE;
52 virtual scoped_ptr<metrics::MetricsLogUploader> CreateUploader(
53 const std::string& server_url,
54 const std::string& mime_type,
55 const base::Callback<void(int)>& on_upload_complete) OVERRIDE;
57 MetricsService* metrics_service() { return metrics_service_.get(); }
59 private:
60 explicit ChromeMetricsServiceClient(
61 metrics::MetricsStateManager* state_manager);
63 // Completes the two-phase initialization of ChromeMetricsServiceClient.
64 void Initialize();
66 // Callbacks for various stages of final log info collection. Do not call
67 // these directly.
68 void OnMemoryDetailCollectionDone();
69 void OnHistogramSynchronizationDone();
71 // Records metrics about the switches present on the command line.
72 void RecordCommandLineMetrics();
74 // Registers |this| as an observer for notifications which indicate that a
75 // user is performing work. This is useful to allow some features to sleep,
76 // until the machine becomes active, such as precluding UMA uploads unless
77 // there was recent activity.
78 void RegisterForNotifications();
80 // content::NotificationObserver:
81 virtual void Observe(int type,
82 const content::NotificationSource& source,
83 const content::NotificationDetails& details) OVERRIDE;
85 #if defined(OS_WIN)
86 // Counts (and removes) the browser crash dump attempt signals left behind by
87 // any previous browser processes which generated a crash dump.
88 void CountBrowserCrashDumpAttempts();
89 #endif // OS_WIN
91 base::ThreadChecker thread_checker_;
93 // Weak pointer to the MetricsStateManager.
94 metrics::MetricsStateManager* metrics_state_manager_;
96 // The MetricsService that |this| is a client of.
97 scoped_ptr<MetricsService> metrics_service_;
99 content::NotificationRegistrar registrar_;
101 // On ChromeOS, holds a weak pointer to the ChromeOSMetricsProvider instance
102 // that has been registered with MetricsService. On other platforms, is NULL.
103 ChromeOSMetricsProvider* chromeos_metrics_provider_;
105 NetworkStatsUploader network_stats_uploader_;
107 // Saved callback received from CollectFinalMetrics().
108 base::Closure collect_final_metrics_done_callback_;
110 // Indicates that collect final metrics step is running.
111 bool waiting_for_collect_final_metrics_step_;
113 // Number of async histogram fetch requests in progress.
114 int num_async_histogram_fetches_in_progress_;
116 base::WeakPtrFactory<ChromeMetricsServiceClient> weak_ptr_factory_;
118 DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceClient);
121 #endif // CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_