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 CHROMECAST_BROWSER_METRICS_CAST_METRICS_SERVICE_CLIENT_H_
6 #define CHROMECAST_BROWSER_METRICS_CAST_METRICS_SERVICE_CLIENT_H_
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "components/metrics/metrics_service_client.h"
15 class PrefRegistrySimple
;
19 class SingleThreadTaskRunner
;
26 class MetricsStateManager
;
27 } // namespace metrics
30 class URLRequestContextGetter
;
33 namespace chromecast
{
39 class ExternalMetrics
;
41 class CastMetricsServiceClient
: public ::metrics::MetricsServiceClient
{
43 ~CastMetricsServiceClient() override
;
45 static scoped_ptr
<CastMetricsServiceClient
> Create(
46 base::TaskRunner
* io_task_runner
,
47 PrefService
* pref_service
,
48 net::URLRequestContextGetter
* request_context
);
49 static void RegisterPrefs(PrefRegistrySimple
* registry
);
51 void Initialize(CastService
* cast_service
);
54 // metrics::MetricsServiceClient implementation:
55 void SetMetricsClientId(const std::string
& client_id
) override
;
56 void OnRecordingDisabled() override
;
57 bool IsOffTheRecordSessionActive() override
;
58 int32_t GetProduct() override
;
59 std::string
GetApplicationLocale() override
;
60 bool GetBrand(std::string
* brand_code
) override
;
61 ::metrics::SystemProfileProto::Channel
GetChannel() override
;
62 std::string
GetVersionString() override
;
63 void OnLogUploadComplete() override
;
64 void StartGatheringMetrics(const base::Closure
& done_callback
) override
;
65 void CollectFinalMetrics(const base::Closure
& done_callback
) override
;
66 scoped_ptr
< ::metrics::MetricsLogUploader
> CreateUploader(
67 const base::Callback
<void(int)>& on_upload_complete
) override
;
68 base::TimeDelta
GetStandardUploadInterval() override
;
70 // Starts/stops the metrics service.
71 void EnableMetricsService(bool enabled
);
73 std::string
client_id() const {
78 CastMetricsServiceClient(
79 base::TaskRunner
* io_task_runner
,
80 PrefService
* pref_service
,
81 net::URLRequestContextGetter
* request_context
);
83 // Returns whether or not metrics reporting is enabled.
84 bool IsReportingEnabled();
86 scoped_ptr
< ::metrics::ClientInfo
> LoadClientInfo();
87 void StoreClientInfo(const ::metrics::ClientInfo
& client_info
);
89 base::TaskRunner
* const io_task_runner_
;
90 PrefService
* const pref_service_
;
91 CastService
* cast_service_
;
92 std::string client_id_
;
95 ExternalMetrics
* external_metrics_
;
96 #endif // defined(OS_LINUX)
97 const scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
98 scoped_ptr
< ::metrics::MetricsStateManager
> metrics_state_manager_
;
99 scoped_ptr
< ::metrics::MetricsService
> metrics_service_
;
100 net::URLRequestContextGetter
* const request_context_
;
102 DISALLOW_COPY_AND_ASSIGN(CastMetricsServiceClient
);
105 } // namespace metrics
106 } // namespace chromecast
108 #endif // CHROMECAST_BROWSER_METRICS_CAST_METRICS_SERVICE_CLIENT_H_