OLD | NEW |
---|---|
(Empty) | |
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 #include "chromecast/metrics/cast_metrics_service_client.h" | |
6 | |
7 #include "base/i18n/rtl.h" | |
8 #include "chromecast/common/chromecast_config.h" | |
9 #include "chromecast/metrics/platform_metrics_providers.h" | |
10 #include "components/metrics/metrics_provider.h" | |
11 #include "components/metrics/metrics_service.h" | |
12 #include "components/metrics/metrics_state_manager.h" | |
13 #include "components/metrics/net/net_metrics_log_uploader.h" | |
14 | |
15 namespace chromecast { | |
16 namespace metrics { | |
17 | |
18 // static | |
19 CastMetricsServiceClient* CastMetricsServiceClient::Create( | |
20 net::URLRequestContextGetter* request_context) { | |
21 return new CastMetricsServiceClient(request_context); | |
22 } | |
23 | |
24 void CastMetricsServiceClient::SetMetricsClientId( | |
25 const std::string& client_id) { | |
26 LOG(INFO) << "Metrics client ID set: " << client_id; | |
27 PlatformSetClientID(client_id); | |
28 } | |
29 | |
30 bool CastMetricsServiceClient::IsOffTheRecordSessionActive() { | |
31 // Chromecast behaves as "off the record" w/r/t recording browsing state, | |
32 // but this value is about not disabling metrics because of it. | |
33 return false; | |
34 } | |
35 | |
36 std::string CastMetricsServiceClient::GetApplicationLocale() { | |
37 return base::i18n::GetConfiguredLocale(); | |
38 } | |
39 | |
40 bool CastMetricsServiceClient::GetBrand(std::string* brand_code) { | |
41 brand_code->clear(); | |
42 return true; | |
Alexei Svitkine (slow)
2014/08/20 21:21:47
Why not just return false, so that a brand isn't s
gunsch
2014/08/22 16:42:20
Done.
| |
43 } | |
44 | |
45 ::metrics::SystemProfileProto::Channel CastMetricsServiceClient::GetChannel() { | |
46 return GetPlatformReleaseChannel(); | |
47 } | |
48 | |
49 std::string CastMetricsServiceClient::GetVersionString() { | |
50 return GetPlatformVersionString(); | |
51 } | |
52 | |
53 void CastMetricsServiceClient::OnLogUploadComplete() { | |
54 PlatformOnLogUploadComplete(); | |
55 } | |
56 | |
57 void CastMetricsServiceClient::StartGatheringMetrics( | |
58 const base::Closure& done_callback) { | |
59 done_callback.Run(); | |
60 } | |
61 | |
62 void CastMetricsServiceClient::CollectFinalMetrics( | |
63 const base::Closure& done_callback) { | |
64 done_callback.Run(); | |
65 } | |
66 | |
67 scoped_ptr< ::metrics::MetricsLogUploader> | |
68 CastMetricsServiceClient::CreateUploader( | |
69 const std::string& server_url, | |
70 const std::string& mime_type, | |
71 const base::Callback<void(int)>& on_upload_complete) { | |
72 return scoped_ptr< ::metrics::MetricsLogUploader>( | |
73 new ::metrics::NetMetricsLogUploader( | |
74 request_context_, | |
75 server_url, | |
76 mime_type, | |
77 on_upload_complete)); | |
78 } | |
79 | |
80 void CastMetricsServiceClient::EnableMetricsService(bool enabled) { | |
81 if (enabled) { | |
82 if (!metrics_service_->recording_active() || | |
83 !metrics_service_->reporting_active()) { | |
Alexei Svitkine (slow)
2014/08/20 21:21:46
Doesn't MetricsService do these checks internally
gunsch
2014/08/22 16:42:20
Done.
| |
84 metrics_service_->Start(); | |
85 } | |
86 } else { | |
87 if (metrics_service_->recording_active() || | |
88 metrics_service_->reporting_active()) { | |
89 metrics_service_->Stop(); | |
90 } | |
91 } | |
92 } | |
93 | |
94 CastMetricsServiceClient::CastMetricsServiceClient( | |
95 net::URLRequestContextGetter* request_context) | |
96 : metrics_state_manager_(::metrics::MetricsStateManager::Create( | |
97 ChromecastConfig::GetInstance()->pref_service(), | |
Alexei Svitkine (slow)
2014/08/20 21:21:46
Nit: I think it would be cleaner to pass this as a
gunsch
2014/08/22 16:42:20
Done.
| |
98 base::Bind(&CastMetricsServiceClient::IsReportingEnabled, | |
99 base::Unretained(this)), | |
100 ::metrics::MetricsStateManager::StoreClientInfoCallback(), | |
101 ::metrics::MetricsStateManager::LoadClientInfoCallback())), | |
102 metrics_service_(new MetricsService( | |
103 metrics_state_manager_.get(), | |
104 this, | |
105 ChromecastConfig::GetInstance()->pref_service())), | |
106 request_context_(request_context) { | |
107 // Always create a client id as it may also be used by crash reporting, | |
108 // (indirectly) included in feedback, and can be queried during setup. | |
109 // For UMA and crash reporting, associated opt-in settings will control | |
110 // sending reports as directed by the user. | |
111 // For Setup (which also communicates the user's opt-in preferences), | |
112 // report the client-id and expect that setup will handle the current opt-in | |
113 // value. | |
114 metrics_state_manager_->ForceClientIdCreation(); | |
115 | |
116 // TODO(gunsch): Add the following: GPUMetricsProvider, | |
117 // NetworkMetricsProvider, ProfilerMetricsProvider. See: crbug/404791 | |
118 RegisterPlatformMetricsProviders(metrics_service_.get()); | |
119 | |
120 metrics_service_->InitializeMetricsRecordingState(); | |
121 | |
122 if (IsReportingEnabled()) { | |
Alexei Svitkine (slow)
2014/08/20 21:21:46
Nit: Chromium style usually prefers no {}'s on sin
gunsch
2014/08/22 16:42:20
Done.
| |
123 metrics_service_->Start(); | |
124 } | |
125 } | |
126 | |
127 CastMetricsServiceClient::~CastMetricsServiceClient() { | |
128 } | |
129 | |
130 bool CastMetricsServiceClient::IsReportingEnabled() { | |
131 return PlatformIsReportingEnabled(); | |
132 } | |
133 | |
134 } // namespace metrics | |
135 } // namespace chromecast | |
OLD | NEW |