| 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 "base/command_line.h" |    7 #include "base/command_line.h" | 
|    8 #include "base/guid.h" |    8 #include "base/guid.h" | 
|    9 #include "base/metrics/histogram_macros.h" |    9 #include "base/metrics/histogram_macros.h" | 
|   10 #include "base/metrics/sparse_histogram.h" |   10 #include "base/metrics/sparse_histogram.h" | 
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  241   } |  241   } | 
|  242  |  242  | 
|  243   // The GUID retrieved (and possibly fixed above) should be valid unless |  243   // The GUID retrieved (and possibly fixed above) should be valid unless | 
|  244   // retrieval failed. |  244   // retrieval failed. | 
|  245   DCHECK(!client_info || base::IsValidGUID(client_info->client_id)); |  245   DCHECK(!client_info || base::IsValidGUID(client_info->client_id)); | 
|  246  |  246  | 
|  247   return client_info.Pass(); |  247   return client_info.Pass(); | 
|  248 } |  248 } | 
|  249  |  249  | 
|  250 int MetricsStateManager::GetLowEntropySource() { |  250 int MetricsStateManager::GetLowEntropySource() { | 
 |  251   UpdateLowEntropySource(); | 
 |  252   return low_entropy_source_; | 
 |  253 } | 
 |  254  | 
 |  255 void MetricsStateManager::UpdateLowEntropySource() { | 
|  251   // Note that the default value for the low entropy source and the default pref |  256   // Note that the default value for the low entropy source and the default pref | 
|  252   // value are both kLowEntropySourceNotSet, which is used to identify if the |  257   // value are both kLowEntropySourceNotSet, which is used to identify if the | 
|  253   // value has been set or not. |  258   // value has been set or not. | 
|  254   if (low_entropy_source_ != kLowEntropySourceNotSet) |  259   if (low_entropy_source_ != kLowEntropySourceNotSet) | 
|  255     return low_entropy_source_; |  260     return; | 
|  256  |  261  | 
|  257   const base::CommandLine* command_line(base::CommandLine::ForCurrentProcess()); |  262   const base::CommandLine* command_line(base::CommandLine::ForCurrentProcess()); | 
|  258   // Only try to load the value from prefs if the user did not request a |  263   // Only try to load the value from prefs if the user did not request a | 
|  259   // reset. |  264   // reset. | 
|  260   // Otherwise, skip to generating a new value. |  265   // Otherwise, skip to generating a new value. | 
|  261   if (!command_line->HasSwitch(switches::kResetVariationState)) { |  266   if (!command_line->HasSwitch(switches::kResetVariationState)) { | 
|  262     int value = local_state_->GetInteger(prefs::kMetricsLowEntropySource); |  267     int value = local_state_->GetInteger(prefs::kMetricsLowEntropySource); | 
|  263     // If the value is outside the [0, kMaxLowEntropySize) range, re-generate |  268     // If the value is outside the [0, kMaxLowEntropySize) range, re-generate | 
|  264     // it below. |  269     // it below. | 
|  265     if (value >= 0 && value < kMaxLowEntropySize) { |  270     if (value >= 0 && value < kMaxLowEntropySize) { | 
|  266       low_entropy_source_ = value; |  271       low_entropy_source_ = value; | 
|  267       UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", false); |  272       return; | 
|  268       return low_entropy_source_; |  | 
|  269     } |  273     } | 
|  270   } |  274   } | 
|  271  |  275  | 
|  272   UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", true); |  | 
|  273   low_entropy_source_ = GenerateLowEntropySource(); |  276   low_entropy_source_ = GenerateLowEntropySource(); | 
|  274   local_state_->SetInteger(prefs::kMetricsLowEntropySource, |  277   local_state_->SetInteger(prefs::kMetricsLowEntropySource, | 
|  275                            low_entropy_source_); |  278                            low_entropy_source_); | 
|  276   CachingPermutedEntropyProvider::ClearCache(local_state_); |  279   CachingPermutedEntropyProvider::ClearCache(local_state_); | 
|  277  |  | 
|  278   return low_entropy_source_; |  | 
|  279 } |  280 } | 
|  280  |  281  | 
|  281 void MetricsStateManager::UpdateEntropySourceReturnedValue( |  282 void MetricsStateManager::UpdateEntropySourceReturnedValue( | 
|  282     EntropySourceType type) { |  283     EntropySourceType type) { | 
|  283   if (entropy_source_returned_ != ENTROPY_SOURCE_NONE) |  284   if (entropy_source_returned_ != ENTROPY_SOURCE_NONE) | 
|  284     return; |  285     return; | 
|  285  |  286  | 
|  286   entropy_source_returned_ = type; |  287   entropy_source_returned_ = type; | 
|  287   UMA_HISTOGRAM_ENUMERATION("UMA.EntropySourceType", type, |  288   UMA_HISTOGRAM_ENUMERATION("UMA.EntropySourceType", type, | 
|  288                             ENTROPY_SOURCE_ENUM_SIZE); |  289                             ENTROPY_SOURCE_ENUM_SIZE); | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|  299  |  300  | 
|  300   local_state_->ClearPref(prefs::kMetricsClientID); |  301   local_state_->ClearPref(prefs::kMetricsClientID); | 
|  301   local_state_->ClearPref(prefs::kMetricsLowEntropySource); |  302   local_state_->ClearPref(prefs::kMetricsLowEntropySource); | 
|  302   local_state_->ClearPref(prefs::kMetricsResetIds); |  303   local_state_->ClearPref(prefs::kMetricsResetIds); | 
|  303  |  304  | 
|  304   // Also clear the backed up client info. |  305   // Also clear the backed up client info. | 
|  305   store_client_info_.Run(ClientInfo()); |  306   store_client_info_.Run(ClientInfo()); | 
|  306 } |  307 } | 
|  307  |  308  | 
|  308 }  // namespace metrics |  309 }  // namespace metrics | 
| OLD | NEW |