Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: chrome/browser/metrics/metrics_log.cc

Issue 282093012: Remove dependencies of Metrics{Service,Log} on g_browser_process->local_state() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Android compile fix Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/metrics/metrics_log.h ('k') | chrome/browser/metrics/metrics_log_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/metrics/metrics_log.h" 5 #include "chrome/browser/metrics/metrics_log.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 // timestamps. 174 // timestamps.
175 int64 RoundSecondsToHour(int64 time_in_seconds) { 175 int64 RoundSecondsToHour(int64 time_in_seconds) {
176 return 3600 * (time_in_seconds / 3600); 176 return 3600 * (time_in_seconds / 3600);
177 } 177 }
178 178
179 } // namespace 179 } // namespace
180 180
181 MetricsLog::MetricsLog(const std::string& client_id, 181 MetricsLog::MetricsLog(const std::string& client_id,
182 int session_id, 182 int session_id,
183 LogType log_type, 183 LogType log_type,
184 metrics::MetricsServiceClient* client) 184 metrics::MetricsServiceClient* client,
185 PrefService* local_state)
185 : MetricsLogBase(client_id, 186 : MetricsLogBase(client_id,
186 session_id, 187 session_id,
187 log_type, 188 log_type,
188 client->GetVersionString()), 189 client->GetVersionString()),
189 client_(client), 190 client_(client),
190 creation_time_(base::TimeTicks::Now()) { 191 creation_time_(base::TimeTicks::Now()),
192 local_state_(local_state) {
191 uma_proto()->mutable_system_profile()->set_channel(client_->GetChannel()); 193 uma_proto()->mutable_system_profile()->set_channel(client_->GetChannel());
192 } 194 }
193 195
194 MetricsLog::~MetricsLog() {} 196 MetricsLog::~MetricsLog() {}
195 197
196 void MetricsLog::RecordStabilityMetrics( 198 void MetricsLog::RecordStabilityMetrics(
197 const std::vector<metrics::MetricsProvider*>& metrics_providers, 199 const std::vector<metrics::MetricsProvider*>& metrics_providers,
198 base::TimeDelta incremental_uptime, 200 base::TimeDelta incremental_uptime,
199 base::TimeDelta uptime) { 201 base::TimeDelta uptime) {
200 DCHECK(!locked()); 202 DCHECK(!locked());
201 DCHECK(HasEnvironment()); 203 DCHECK(HasEnvironment());
202 DCHECK(!HasStabilityMetrics()); 204 DCHECK(!HasStabilityMetrics());
203 205
204 PrefService* pref = GetPrefService(); 206 PrefService* pref = local_state_;
205 DCHECK(pref); 207 DCHECK(pref);
206 208
207 // Get stability attributes out of Local State, zeroing out stored values. 209 // Get stability attributes out of Local State, zeroing out stored values.
208 // NOTE: This could lead to some data loss if this report isn't successfully 210 // NOTE: This could lead to some data loss if this report isn't successfully
209 // sent, but that's true for all the metrics. 211 // sent, but that's true for all the metrics.
210 212
211 WriteRequiredStabilityAttributes(pref); 213 WriteRequiredStabilityAttributes(pref);
212 214
213 // Record recent delta for critical stability metrics. We can't wait for a 215 // Record recent delta for critical stability metrics. We can't wait for a
214 // restart to gather these, as that delay biases our observation away from 216 // restart to gather these, as that delay biases our observation away from
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 stability->set_debugger_present_count(debugger_present_count); 254 stability->set_debugger_present_count(debugger_present_count);
253 stability->set_debugger_not_present_count(debugger_not_present_count); 255 stability->set_debugger_not_present_count(debugger_not_present_count);
254 } 256 }
255 257
256 void MetricsLog::RecordGeneralMetrics( 258 void MetricsLog::RecordGeneralMetrics(
257 const std::vector<metrics::MetricsProvider*>& metrics_providers) { 259 const std::vector<metrics::MetricsProvider*>& metrics_providers) {
258 for (size_t i = 0; i < metrics_providers.size(); ++i) 260 for (size_t i = 0; i < metrics_providers.size(); ++i)
259 metrics_providers[i]->ProvideGeneralMetrics(uma_proto()); 261 metrics_providers[i]->ProvideGeneralMetrics(uma_proto());
260 } 262 }
261 263
262 PrefService* MetricsLog::GetPrefService() {
263 return g_browser_process->local_state();
264 }
265
266 void MetricsLog::GetFieldTrialIds( 264 void MetricsLog::GetFieldTrialIds(
267 std::vector<ActiveGroupId>* field_trial_ids) const { 265 std::vector<ActiveGroupId>* field_trial_ids) const {
268 variations::GetFieldTrialActiveGroupIds(field_trial_ids); 266 variations::GetFieldTrialActiveGroupIds(field_trial_ids);
269 } 267 }
270 268
271 bool MetricsLog::HasEnvironment() const { 269 bool MetricsLog::HasEnvironment() const {
272 return uma_proto()->system_profile().has_uma_enabled_date(); 270 return uma_proto()->system_profile().has_uma_enabled_date();
273 } 271 }
274 272
275 bool MetricsLog::HasStabilityMetrics() const { 273 bool MetricsLog::HasStabilityMetrics() const {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 const std::vector<variations::ActiveGroupId>& synthetic_trials) { 320 const std::vector<variations::ActiveGroupId>& synthetic_trials) {
323 DCHECK(!HasEnvironment()); 321 DCHECK(!HasEnvironment());
324 322
325 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); 323 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
326 324
327 std::string brand_code; 325 std::string brand_code;
328 if (client_->GetBrand(&brand_code)) 326 if (client_->GetBrand(&brand_code))
329 system_profile->set_brand_code(brand_code); 327 system_profile->set_brand_code(brand_code);
330 328
331 int enabled_date; 329 int enabled_date;
332 bool success = base::StringToInt(GetMetricsEnabledDate(GetPrefService()), 330 bool success =
333 &enabled_date); 331 base::StringToInt(GetMetricsEnabledDate(local_state_), &enabled_date);
334 DCHECK(success); 332 DCHECK(success);
335 333
336 // Reduce granularity of the enabled_date field to nearest hour. 334 // Reduce granularity of the enabled_date field to nearest hour.
337 system_profile->set_uma_enabled_date(RoundSecondsToHour(enabled_date)); 335 system_profile->set_uma_enabled_date(RoundSecondsToHour(enabled_date));
338 336
339 int64 install_date = GetPrefService()->GetInt64(prefs::kInstallDate); 337 int64 install_date = local_state_->GetInt64(prefs::kInstallDate);
340 338
341 // Reduce granularity of the install_date field to nearest hour. 339 // Reduce granularity of the install_date field to nearest hour.
342 system_profile->set_install_date(RoundSecondsToHour(install_date)); 340 system_profile->set_install_date(RoundSecondsToHour(install_date));
343 341
344 system_profile->set_application_locale(client_->GetApplicationLocale()); 342 system_profile->set_application_locale(client_->GetApplicationLocale());
345 343
346 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware(); 344 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
347 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture()); 345 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
348 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB()); 346 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
349 #if defined(OS_WIN) 347 #if defined(OS_WIN)
(...skipping 28 matching lines...) Expand all
378 WriteFieldTrials(field_trial_ids, system_profile); 376 WriteFieldTrials(field_trial_ids, system_profile);
379 WriteFieldTrials(synthetic_trials, system_profile); 377 WriteFieldTrials(synthetic_trials, system_profile);
380 378
381 for (size_t i = 0; i < metrics_providers.size(); ++i) 379 for (size_t i = 0; i < metrics_providers.size(); ++i)
382 metrics_providers[i]->ProvideSystemProfileMetrics(system_profile); 380 metrics_providers[i]->ProvideSystemProfileMetrics(system_profile);
383 381
384 std::string serialied_system_profile; 382 std::string serialied_system_profile;
385 std::string base64_system_profile; 383 std::string base64_system_profile;
386 if (system_profile->SerializeToString(&serialied_system_profile)) { 384 if (system_profile->SerializeToString(&serialied_system_profile)) {
387 base::Base64Encode(serialied_system_profile, &base64_system_profile); 385 base::Base64Encode(serialied_system_profile, &base64_system_profile);
388 PrefService* local_state = GetPrefService(); 386 PrefService* local_state = local_state_;
389 local_state->SetString(prefs::kStabilitySavedSystemProfile, 387 local_state->SetString(prefs::kStabilitySavedSystemProfile,
390 base64_system_profile); 388 base64_system_profile);
391 local_state->SetString(prefs::kStabilitySavedSystemProfileHash, 389 local_state->SetString(prefs::kStabilitySavedSystemProfileHash,
392 ComputeSHA1(serialied_system_profile)); 390 ComputeSHA1(serialied_system_profile));
393 } 391 }
394 } 392 }
395 393
396 bool MetricsLog::LoadSavedEnvironmentFromPrefs() { 394 bool MetricsLog::LoadSavedEnvironmentFromPrefs() {
397 PrefService* local_state = GetPrefService(); 395 PrefService* local_state = local_state_;
398 const std::string base64_system_profile = 396 const std::string base64_system_profile =
399 local_state->GetString(prefs::kStabilitySavedSystemProfile); 397 local_state->GetString(prefs::kStabilitySavedSystemProfile);
400 if (base64_system_profile.empty()) 398 if (base64_system_profile.empty())
401 return false; 399 return false;
402 400
403 const std::string system_profile_hash = 401 const std::string system_profile_hash =
404 local_state->GetString(prefs::kStabilitySavedSystemProfileHash); 402 local_state->GetString(prefs::kStabilitySavedSystemProfileHash);
405 local_state->ClearPref(prefs::kStabilitySavedSystemProfile); 403 local_state->ClearPref(prefs::kStabilitySavedSystemProfile);
406 local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash); 404 local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash);
407 405
(...skipping 21 matching lines...) Expand all
429 profile = uma_proto()->add_profiler_event(); 427 profile = uma_proto()->add_profiler_event();
430 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE); 428 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
431 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME); 429 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
432 } else { 430 } else {
433 // For the remaining calls, re-use the existing field. 431 // For the remaining calls, re-use the existing field.
434 profile = uma_proto()->mutable_profiler_event(0); 432 profile = uma_proto()->mutable_profiler_event(0);
435 } 433 }
436 434
437 WriteProfilerData(process_data, process_type, profile); 435 WriteProfilerData(process_data, process_type, profile);
438 } 436 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_log.h ('k') | chrome/browser/metrics/metrics_log_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698