| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/prefs/tracked/pref_hash_store_impl.h" | 5 #include "chrome/browser/prefs/tracked/pref_hash_store_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/prefs/tracked/hash_store_contents.h" | 10 #include "chrome/browser/prefs/tracked/hash_store_contents.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 const base::Value* initial_value) const { | 126 const base::Value* initial_value) const { |
| 127 const base::DictionaryValue* hashes_dict = contents()->GetContents(); | 127 const base::DictionaryValue* hashes_dict = contents()->GetContents(); |
| 128 | 128 |
| 129 std::string last_hash; | 129 std::string last_hash; |
| 130 if (hashes_dict) | 130 if (hashes_dict) |
| 131 hashes_dict->GetString(path, &last_hash); | 131 hashes_dict->GetString(path, &last_hash); |
| 132 | 132 |
| 133 if (last_hash.empty()) { | 133 if (last_hash.empty()) { |
| 134 // In the absence of a hash for this pref, always trust a NULL value, but | 134 // In the absence of a hash for this pref, always trust a NULL value, but |
| 135 // only trust an existing value if the initial hashes dictionary is trusted. | 135 // only trust an existing value if the initial hashes dictionary is trusted. |
| 136 return (!initial_value || super_mac_valid_) ? TRUSTED_UNKNOWN_VALUE | 136 if (!initial_value) |
| 137 : UNTRUSTED_UNKNOWN_VALUE; | 137 return TRUSTED_NULL_VALUE; |
| 138 else if (super_mac_valid_) |
| 139 return TRUSTED_UNKNOWN_VALUE; |
| 140 else |
| 141 return UNTRUSTED_UNKNOWN_VALUE; |
| 138 } | 142 } |
| 139 | 143 |
| 140 PrefHashCalculator::ValidationResult validation_result = | 144 PrefHashCalculator::ValidationResult validation_result = |
| 141 outer_->pref_hash_calculator_.Validate(path, initial_value, last_hash); | 145 outer_->pref_hash_calculator_.Validate(path, initial_value, last_hash); |
| 142 switch (validation_result) { | 146 switch (validation_result) { |
| 143 case PrefHashCalculator::VALID: | 147 case PrefHashCalculator::VALID: |
| 144 return UNCHANGED; | 148 return UNCHANGED; |
| 145 case PrefHashCalculator::VALID_SECURE_LEGACY: | 149 case PrefHashCalculator::VALID_SECURE_LEGACY: |
| 146 return SECURE_LEGACY; | 150 return SECURE_LEGACY; |
| 147 case PrefHashCalculator::INVALID: | 151 case PrefHashCalculator::INVALID: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 164 PrefHashStoreTransaction::ValueState | 168 PrefHashStoreTransaction::ValueState |
| 165 PrefHashStoreImpl::PrefHashStoreTransactionImpl::CheckSplitValue( | 169 PrefHashStoreImpl::PrefHashStoreTransactionImpl::CheckSplitValue( |
| 166 const std::string& path, | 170 const std::string& path, |
| 167 const base::DictionaryValue* initial_split_value, | 171 const base::DictionaryValue* initial_split_value, |
| 168 std::vector<std::string>* invalid_keys) const { | 172 std::vector<std::string>* invalid_keys) const { |
| 169 DCHECK(invalid_keys && invalid_keys->empty()); | 173 DCHECK(invalid_keys && invalid_keys->empty()); |
| 170 | 174 |
| 171 std::map<std::string, std::string> split_macs; | 175 std::map<std::string, std::string> split_macs; |
| 172 const bool has_hashes = GetSplitMacs(path, &split_macs); | 176 const bool has_hashes = GetSplitMacs(path, &split_macs); |
| 173 | 177 |
| 174 // Treat NULL and empty the same; otherwise we would need to store a hash | 178 // Treat NULL and empty the same; otherwise we would need to store a hash for |
| 175 // for the entire dictionary (or some other special beacon) to | 179 // the entire dictionary (or some other special beacon) to differentiate these |
| 176 // differentiate these two cases which are really the same for | 180 // two cases which are really the same for dictionaries. |
| 177 // dictionaries. | |
| 178 if (!initial_split_value || initial_split_value->empty()) | 181 if (!initial_split_value || initial_split_value->empty()) |
| 179 return has_hashes ? CLEARED : UNCHANGED; | 182 return has_hashes ? CLEARED : UNCHANGED; |
| 180 | 183 |
| 181 if (!has_hashes) | 184 if (!has_hashes) |
| 182 return super_mac_valid_ ? TRUSTED_UNKNOWN_VALUE : UNTRUSTED_UNKNOWN_VALUE; | 185 return super_mac_valid_ ? TRUSTED_UNKNOWN_VALUE : UNTRUSTED_UNKNOWN_VALUE; |
| 183 | 186 |
| 184 bool has_secure_legacy_id_hashes = false; | 187 bool has_secure_legacy_id_hashes = false; |
| 185 std::string keyed_path(path); | 188 std::string keyed_path(path); |
| 186 keyed_path.push_back('.'); | 189 keyed_path.push_back('.'); |
| 187 const size_t common_part_length = keyed_path.length(); | 190 const size_t common_part_length = keyed_path.length(); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::IsSuperMACValid() const { | 305 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::IsSuperMACValid() const { |
| 303 return super_mac_valid_; | 306 return super_mac_valid_; |
| 304 } | 307 } |
| 305 | 308 |
| 306 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::StampSuperMac() { | 309 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::StampSuperMac() { |
| 307 if (!outer_->use_super_mac_ || super_mac_valid_) | 310 if (!outer_->use_super_mac_ || super_mac_valid_) |
| 308 return false; | 311 return false; |
| 309 super_mac_dirty_ = true; | 312 super_mac_dirty_ = true; |
| 310 return true; | 313 return true; |
| 311 } | 314 } |
| OLD | NEW |