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

Side by Side Diff: components/metrics/metrics_log.cc

Issue 2428413005: Revise system profile prefs clearing (Closed)
Patch Set: Update LoadSavedEnvironmentFromPrefs's comment Created 4 years, 2 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
« no previous file with comments | « components/metrics/metrics_log.h ('k') | components/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 2014 The Chromium Authors. All rights reserved. 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 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 "components/metrics/metrics_log.h" 5 #include "components/metrics/metrics_log.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 GetFieldTrialIds(&field_trial_ids); 413 GetFieldTrialIds(&field_trial_ids);
414 WriteFieldTrials(field_trial_ids, system_profile); 414 WriteFieldTrials(field_trial_ids, system_profile);
415 WriteFieldTrials(synthetic_trials, system_profile); 415 WriteFieldTrials(synthetic_trials, system_profile);
416 416
417 for (size_t i = 0; i < metrics_providers.size(); ++i) 417 for (size_t i = 0; i < metrics_providers.size(); ++i)
418 metrics_providers[i]->ProvideSystemProfileMetrics(system_profile); 418 metrics_providers[i]->ProvideSystemProfileMetrics(system_profile);
419 419
420 std::string serialized_system_profile; 420 std::string serialized_system_profile;
421 std::string base64_system_profile; 421 std::string base64_system_profile;
422 if (system_profile->SerializeToString(&serialized_system_profile)) { 422 if (system_profile->SerializeToString(&serialized_system_profile)) {
423 // Persist the system profile to disk. In the event of an unclean shutdown,
424 // it will be used as part of the initial stability report.
423 base::Base64Encode(serialized_system_profile, &base64_system_profile); 425 base::Base64Encode(serialized_system_profile, &base64_system_profile);
424 PrefService* local_state = local_state_; 426 PrefService* local_state = local_state_;
425 local_state->SetString(prefs::kStabilitySavedSystemProfile, 427 local_state->SetString(prefs::kStabilitySavedSystemProfile,
426 base64_system_profile); 428 base64_system_profile);
427 local_state->SetString(prefs::kStabilitySavedSystemProfileHash, 429 local_state->SetString(prefs::kStabilitySavedSystemProfileHash,
428 ComputeSHA1(serialized_system_profile)); 430 ComputeSHA1(serialized_system_profile));
429 } 431 }
430 } 432 }
431 433
432 bool MetricsLog::LoadSavedEnvironmentFromPrefs(std::string* app_version) { 434 bool MetricsLog::LoadSavedEnvironmentFromPrefs(std::string* app_version) {
433 DCHECK(app_version); 435 DCHECK(app_version);
434 app_version->clear(); 436 app_version->clear();
435 437
436 PrefService* local_state = local_state_; 438 PrefService* local_state = local_state_;
437 const std::string base64_system_profile = 439 const std::string base64_system_profile =
438 local_state->GetString(prefs::kStabilitySavedSystemProfile); 440 local_state->GetString(prefs::kStabilitySavedSystemProfile);
439 if (base64_system_profile.empty()) 441 if (base64_system_profile.empty())
440 return false; 442 return false;
441
442 const std::string system_profile_hash = 443 const std::string system_profile_hash =
443 local_state->GetString(prefs::kStabilitySavedSystemProfileHash); 444 local_state->GetString(prefs::kStabilitySavedSystemProfileHash);
444 local_state->ClearPref(prefs::kStabilitySavedSystemProfile);
445 local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash);
446 445
447 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); 446 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
448 std::string serialized_system_profile; 447 std::string serialized_system_profile;
449 448
450 bool success = 449 bool success =
451 base::Base64Decode(base64_system_profile, &serialized_system_profile) && 450 base::Base64Decode(base64_system_profile, &serialized_system_profile) &&
452 ComputeSHA1(serialized_system_profile) == system_profile_hash && 451 ComputeSHA1(serialized_system_profile) == system_profile_hash &&
453 system_profile->ParseFromString(serialized_system_profile); 452 system_profile->ParseFromString(serialized_system_profile);
454 if (success) 453 if (success)
455 *app_version = system_profile->app_version(); 454 *app_version = system_profile->app_version();
456 return success; 455 return success;
457 } 456 }
458 457
459 void MetricsLog::CloseLog() { 458 void MetricsLog::CloseLog() {
460 DCHECK(!closed_); 459 DCHECK(!closed_);
461 closed_ = true; 460 closed_ = true;
462 } 461 }
463 462
464 void MetricsLog::GetEncodedLog(std::string* encoded_log) { 463 void MetricsLog::GetEncodedLog(std::string* encoded_log) {
465 DCHECK(closed_); 464 DCHECK(closed_);
466 uma_proto_.SerializeToString(encoded_log); 465 uma_proto_.SerializeToString(encoded_log);
467 } 466 }
468 467
469 } // namespace metrics 468 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/metrics_log.h ('k') | components/metrics/metrics_log_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698