| OLD | NEW |
| 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_state_manager.h" | 5 #include "components/metrics/metrics_state_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/guid.h" | 10 #include "base/guid.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 MetricsStateManager::~MetricsStateManager() { | 76 MetricsStateManager::~MetricsStateManager() { |
| 77 DCHECK(instance_exists_); | 77 DCHECK(instance_exists_); |
| 78 instance_exists_ = false; | 78 instance_exists_ = false; |
| 79 } | 79 } |
| 80 | 80 |
| 81 bool MetricsStateManager::IsMetricsReportingEnabled() { | 81 bool MetricsStateManager::IsMetricsReportingEnabled() { |
| 82 return enabled_state_provider_->IsReportingEnabled(); | 82 return enabled_state_provider_->IsReportingEnabled(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void MetricsStateManager::ForceClientIdCreation() { | 85 void MetricsStateManager::ForceClientIdCreation() { |
| 86 if (!client_id_.empty()) | 86 { |
| 87 return; | 87 std::string client_id_from_prefs = |
| 88 local_state_->GetString(prefs::kMetricsClientID); |
| 89 // If client id in prefs matches the cached copy, return early. |
| 90 if (!client_id_from_prefs.empty() && client_id_from_prefs == client_id_) |
| 91 return; |
| 92 client_id_.swap(client_id_from_prefs); |
| 93 } |
| 88 | 94 |
| 89 client_id_ = local_state_->GetString(prefs::kMetricsClientID); | |
| 90 if (!client_id_.empty()) { | 95 if (!client_id_.empty()) { |
| 91 // It is technically sufficient to only save a backup of the client id when | 96 // It is technically sufficient to only save a backup of the client id when |
| 92 // it is initially generated below, but since the backup was only introduced | 97 // it is initially generated below, but since the backup was only introduced |
| 93 // in M38, seed it explicitly from here for some time. | 98 // in M38, seed it explicitly from here for some time. |
| 94 BackUpCurrentClientInfo(); | 99 BackUpCurrentClientInfo(); |
| 95 return; | 100 return; |
| 96 } | 101 } |
| 97 | 102 |
| 98 const std::unique_ptr<ClientInfo> client_info_backup = | 103 const std::unique_ptr<ClientInfo> client_info_backup = |
| 99 LoadClientInfoAndMaybeMigrate(); | 104 LoadClientInfoAndMaybeMigrate(); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 326 |
| 322 local_state_->ClearPref(prefs::kMetricsClientID); | 327 local_state_->ClearPref(prefs::kMetricsClientID); |
| 323 local_state_->ClearPref(prefs::kMetricsLowEntropySource); | 328 local_state_->ClearPref(prefs::kMetricsLowEntropySource); |
| 324 local_state_->ClearPref(prefs::kMetricsResetIds); | 329 local_state_->ClearPref(prefs::kMetricsResetIds); |
| 325 | 330 |
| 326 // Also clear the backed up client info. | 331 // Also clear the backed up client info. |
| 327 store_client_info_.Run(ClientInfo()); | 332 store_client_info_.Run(ClientInfo()); |
| 328 } | 333 } |
| 329 | 334 |
| 330 } // namespace metrics | 335 } // namespace metrics |
| OLD | NEW |