| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/data_use_tracker.h" | 5 #include "components/metrics/data_use_tracker.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 const base::DictionaryValue* user_pref_dict = | 112 const base::DictionaryValue* user_pref_dict = |
| 113 local_state_->GetDictionary(pref_name); | 113 local_state_->GetDictionary(pref_name); |
| 114 const base::Time current_date = GetCurrentMeasurementDate(); | 114 const base::Time current_date = GetCurrentMeasurementDate(); |
| 115 const base::Time week_ago = current_date - base::TimeDelta::FromDays(7); | 115 const base::Time week_ago = current_date - base::TimeDelta::FromDays(7); |
| 116 | 116 |
| 117 base::DictionaryValue user_pref_new_dict; | 117 base::DictionaryValue user_pref_new_dict; |
| 118 for (base::DictionaryValue::Iterator it(*user_pref_dict); !it.IsAtEnd(); | 118 for (base::DictionaryValue::Iterator it(*user_pref_dict); !it.IsAtEnd(); |
| 119 it.Advance()) { | 119 it.Advance()) { |
| 120 base::Time key_date; | 120 base::Time key_date; |
| 121 base::Time::FromUTCString(it.key().c_str(), &key_date); | 121 if (base::Time::FromUTCString(it.key().c_str(), &key_date) && |
| 122 if (key_date > week_ago) | 122 key_date > week_ago) |
| 123 user_pref_new_dict.Set(it.key(), it.value().CreateDeepCopy()); | 123 user_pref_new_dict.Set(it.key(), it.value().CreateDeepCopy()); |
| 124 } | 124 } |
| 125 local_state_->Set(pref_name, user_pref_new_dict); | 125 local_state_->Set(pref_name, user_pref_new_dict); |
| 126 } | 126 } |
| 127 | 127 |
| 128 // Note: We compute total data use regardless of what is the current date. In | 128 // Note: We compute total data use regardless of what is the current date. In |
| 129 // scenario when user travels back in time zone and current date becomes earlier | 129 // scenario when user travels back in time zone and current date becomes earlier |
| 130 // than latest registered date in perf, we still count that in total use as user | 130 // than latest registered date in perf, we still count that in total use as user |
| 131 // actually used that data. | 131 // actually used that data. |
| 132 int DataUseTracker::ComputeTotalDataUse(const std::string& pref_name) { | 132 int DataUseTracker::ComputeTotalDataUse(const std::string& pref_name) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 std::string DataUseTracker::GetCurrentMeasurementDateAsString() const { | 175 std::string DataUseTracker::GetCurrentMeasurementDateAsString() const { |
| 176 DCHECK(thread_checker_.CalledOnValidThread()); | 176 DCHECK(thread_checker_.CalledOnValidThread()); |
| 177 | 177 |
| 178 base::Time::Exploded today_exploded; | 178 base::Time::Exploded today_exploded; |
| 179 GetCurrentMeasurementDate().LocalExplode(&today_exploded); | 179 GetCurrentMeasurementDate().LocalExplode(&today_exploded); |
| 180 return base::StringPrintf("%04d-%02d-%02d", today_exploded.year, | 180 return base::StringPrintf("%04d-%02d-%02d", today_exploded.year, |
| 181 today_exploded.month, today_exploded.day_of_month); | 181 today_exploded.month, today_exploded.day_of_month); |
| 182 } | 182 } |
| 183 | 183 |
| 184 } // namespace metrics | 184 } // namespace metrics |
| OLD | NEW |