blob: e21dde60965e282844d51312ccf55f212b646262 [file] [log] [blame]
[email protected]5bdaa2d2014-05-19 14:59:511// 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"
[email protected]4b4892b2014-05-22 15:06:1511#include "base/callback.h"
12#include "base/memory/weak_ptr.h"
[email protected]d7ea39e2014-05-22 03:59:1813#include "base/threading/thread_checker.h"
[email protected]73929422014-05-22 08:19:0514#include "chrome/browser/metrics/network_stats_uploader.h"
[email protected]5bdaa2d2014-05-19 14:59:5115#include "components/metrics/metrics_service_client.h"
[email protected]d7ea39e2014-05-22 03:59:1816#include "content/public/browser/notification_observer.h"
17#include "content/public/browser/notification_registrar.h"
18
19class MetricsService;
[email protected]5bdaa2d2014-05-19 14:59:5120
21// ChromeMetricsServiceClient provides an implementation of MetricsServiceClient
22// that depends on chrome/.
[email protected]d7ea39e2014-05-22 03:59:1823class ChromeMetricsServiceClient : public metrics::MetricsServiceClient,
24 public content::NotificationObserver {
[email protected]5bdaa2d2014-05-19 14:59:5125 public:
26 ChromeMetricsServiceClient();
27 virtual ~ChromeMetricsServiceClient();
28
29 // metrics::MetricsServiceClient:
30 virtual void SetClientID(const std::string& client_id) OVERRIDE;
31 virtual bool IsOffTheRecordSessionActive() OVERRIDE;
32 virtual std::string GetApplicationLocale() OVERRIDE;
33 virtual bool GetBrand(std::string* brand_code) OVERRIDE;
34 virtual metrics::SystemProfileProto::Channel GetChannel() OVERRIDE;
35 virtual std::string GetVersionString() OVERRIDE;
[email protected]73929422014-05-22 08:19:0536 virtual void OnLogUploadComplete() OVERRIDE;
[email protected]4b4892b2014-05-22 15:06:1537 virtual void CollectFinalMetrics(const base::Closure& done_callback)
38 OVERRIDE;
[email protected]5bdaa2d2014-05-19 14:59:5139
[email protected]d7ea39e2014-05-22 03:59:1840 // Stores a weak pointer to the given |service|.
41 // TODO(isherman): Fix the memory ownership model so that this method is not
42 // needed: http://crbug.com/375248
43 void set_service(MetricsService* service) { service_ = service; }
44
[email protected]5bdaa2d2014-05-19 14:59:5145 private:
[email protected]4b4892b2014-05-22 15:06:1546 // Callbacks for various stages of final log info collection. Do not call
47 // these directly.
48 void OnMemoryDetailCollectionDone();
49 void OnHistogramSynchronizationDone();
50
[email protected]daed87e2014-05-22 19:41:2251 // Records metrics about the switches present on the command line.
52 void RecordCommandLineMetrics();
53
[email protected]d7ea39e2014-05-22 03:59:1854 // Registers |this| as an observer for notifications which indicate that a
55 // user is performing work. This is useful to allow some features to sleep,
56 // until the machine becomes active, such as precluding UMA uploads unless
57 // there was recent activity.
58 void RegisterForNotifications();
59
60 // content::NotificationObserver:
61 virtual void Observe(int type,
62 const content::NotificationSource& source,
63 const content::NotificationDetails& details) OVERRIDE;
64
[email protected]4b4892b2014-05-22 15:06:1565 base::ThreadChecker thread_checker_;
66
[email protected]d7ea39e2014-05-22 03:59:1867 // The MetricsService that |this| is a client of. Weak pointer.
68 MetricsService* service_;
69
70 content::NotificationRegistrar registrar_;
[email protected]d7ea39e2014-05-22 03:59:1871
[email protected]73929422014-05-22 08:19:0572 NetworkStatsUploader network_stats_uploader_;
73
[email protected]4b4892b2014-05-22 15:06:1574 // Saved callback received from CollectFinalMetrics().
75 base::Closure collect_final_metrics_done_callback_;
76
77 // Indicates that collect final metrics step is running.
78 bool waiting_for_collect_final_metrics_step_;
79
80 // Number of async histogram fetch requests in progress.
81 int num_async_histogram_fetches_in_progress_;
82
83 base::WeakPtrFactory<ChromeMetricsServiceClient> weak_ptr_factory_;
84
[email protected]5bdaa2d2014-05-19 14:59:5185 DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceClient);
86};
87
88#endif // CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_CLIENT_H_