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 // Use |client_id| when starting MetricsService instead of generating a new
52 // client ID. If used, SetForceClientId must be called before Initialize.
53 void SetForceClientId(const std::string
& client_id
);
54 void OnApplicationNotIdle();
56 void Initialize(CastService
* cast_service
);
59 // metrics::MetricsServiceClient implementation:
60 void SetMetricsClientId(const std::string
& client_id
) override
;
61 void OnRecordingDisabled() override
;
62 bool IsOffTheRecordSessionActive() override
;
63 int32_t GetProduct() override
;
64 std::string
GetApplicationLocale() override
;
65 bool GetBrand(std::string
* brand_code
) override
;
66 ::metrics::SystemProfileProto::Channel
GetChannel() override
;
67 std::string
GetVersionString() override
;
68 void OnLogUploadComplete() override
;
69 void InitializeSystemProfileMetrics(
70 const base::Closure
& done_callback
) override
;
71 void CollectFinalMetricsForLog(const base::Closure
& done_callback
) override
;
72 scoped_ptr
< ::metrics::MetricsLogUploader
> CreateUploader(
73 const base::Callback
<void(int)>& on_upload_complete
) override
;
74 base::TimeDelta
GetStandardUploadInterval() override
;
76 // Starts/stops the metrics service.
77 void EnableMetricsService(bool enabled
);
79 std::string
client_id() const { return client_id_
; }
82 CastMetricsServiceClient(base::TaskRunner
* io_task_runner
,
83 PrefService
* pref_service
,
84 net::URLRequestContextGetter
* request_context
);
86 // Returns whether or not metrics reporting is enabled.
87 bool IsReportingEnabled();
89 scoped_ptr
< ::metrics::ClientInfo
> LoadClientInfo();
90 void StoreClientInfo(const ::metrics::ClientInfo
& client_info
);
92 base::TaskRunner
* const io_task_runner_
;
93 PrefService
* const pref_service_
;
94 CastService
* cast_service_
;
95 std::string client_id_
;
96 std::string force_client_id_
;
97 bool client_info_loaded_
;
100 ExternalMetrics
* external_metrics_
;
101 ExternalMetrics
* platform_metrics_
;
102 #endif // defined(OS_LINUX)
103 const scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
104 scoped_ptr
< ::metrics::MetricsStateManager
> metrics_state_manager_
;
105 scoped_ptr
< ::metrics::MetricsService
> metrics_service_
;
106 net::URLRequestContextGetter
* const request_context_
;
108 DISALLOW_COPY_AND_ASSIGN(CastMetricsServiceClient
);
111 } // namespace metrics
112 } // namespace chromecast
114 #endif // CHROMECAST_BROWSER_METRICS_CAST_METRICS_SERVICE_CLIENT_H_