| 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/pref_hash_store_impl.h" | 5 #include "chrome/browser/prefs/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/pref_hash_store_transaction.h" | 10 #include "chrome/browser/prefs/pref_hash_store_transaction.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 bool GetSplitMacs(const std::string& path, | 52 bool GetSplitMacs(const std::string& path, |
| 53 std::map<std::string, std::string>* split_macs) const; | 53 std::map<std::string, std::string>* split_macs) const; |
| 54 PrefHashStoreImpl* outer_; | 54 PrefHashStoreImpl* outer_; |
| 55 bool has_changed_; | 55 bool has_changed_; |
| 56 | 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(PrefHashStoreTransactionImpl); | 57 DISALLOW_COPY_AND_ASSIGN(PrefHashStoreTransactionImpl); |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 PrefHashStoreImpl::PrefHashStoreImpl(const std::string& seed, | 60 PrefHashStoreImpl::PrefHashStoreImpl(const std::string& seed, |
| 61 const std::string& device_id, | 61 const std::string& device_id, |
| 62 scoped_ptr<HashStoreContents> contents) | 62 scoped_ptr<HashStoreContents> contents, |
| 63 bool use_super_mac) |
| 63 : pref_hash_calculator_(seed, device_id), | 64 : pref_hash_calculator_(seed, device_id), |
| 64 contents_(contents.Pass()), | 65 contents_(contents.Pass()), |
| 65 initial_hashes_dictionary_trusted_( | 66 initial_hashes_dictionary_trusted_( |
| 66 IsHashDictionaryTrusted(pref_hash_calculator_, *contents_)), | 67 use_super_mac |
| 68 ? IsHashDictionaryTrusted(pref_hash_calculator_, *contents_) |
| 69 : false), |
| 70 use_super_mac_(use_super_mac), |
| 67 has_pending_write_(false) { | 71 has_pending_write_(false) { |
| 68 DCHECK(contents_); | 72 DCHECK(contents_); |
| 69 UMA_HISTOGRAM_BOOLEAN("Settings.HashesDictionaryTrusted", | 73 UMA_HISTOGRAM_BOOLEAN("Settings.HashesDictionaryTrusted", |
| 70 initial_hashes_dictionary_trusted_); | 74 initial_hashes_dictionary_trusted_); |
| 71 } | 75 } |
| 72 | 76 |
| 73 PrefHashStoreImpl::~PrefHashStoreImpl() {} | 77 PrefHashStoreImpl::~PrefHashStoreImpl() {} |
| 74 | 78 |
| 75 void PrefHashStoreImpl::Reset() { | 79 void PrefHashStoreImpl::Reset() { |
| 76 contents_->Reset(); | 80 contents_->Reset(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 90 | 94 |
| 91 PrefHashStoreImpl::PrefHashStoreTransactionImpl::PrefHashStoreTransactionImpl( | 95 PrefHashStoreImpl::PrefHashStoreTransactionImpl::PrefHashStoreTransactionImpl( |
| 92 PrefHashStoreImpl* outer) : outer_(outer), has_changed_(false) { | 96 PrefHashStoreImpl* outer) : outer_(outer), has_changed_(false) { |
| 93 } | 97 } |
| 94 | 98 |
| 95 PrefHashStoreImpl::PrefHashStoreTransactionImpl:: | 99 PrefHashStoreImpl::PrefHashStoreTransactionImpl:: |
| 96 ~PrefHashStoreTransactionImpl() { | 100 ~PrefHashStoreTransactionImpl() { |
| 97 // Update the super MAC if and only if the hashes dictionary has been | 101 // Update the super MAC if and only if the hashes dictionary has been |
| 98 // modified in this transaction. | 102 // modified in this transaction. |
| 99 if (has_changed_) { | 103 if (has_changed_) { |
| 100 // Get the dictionary of hashes (or NULL if it doesn't exist). | 104 if (outer_->use_super_mac_) { |
| 101 const base::DictionaryValue* hashes_dict = outer_->contents_->GetContents(); | 105 // Get the dictionary of hashes (or NULL if it doesn't exist). |
| 102 outer_->contents_->SetSuperMac(outer_->pref_hash_calculator_.Calculate( | 106 const base::DictionaryValue* hashes_dict = |
| 103 outer_->contents_->hash_store_id(), hashes_dict)); | 107 outer_->contents_->GetContents(); |
| 104 | 108 outer_->contents_->SetSuperMac(outer_->pref_hash_calculator_.Calculate( |
| 109 outer_->contents_->hash_store_id(), hashes_dict)); |
| 110 } |
| 105 outer_->has_pending_write_ = true; | 111 outer_->has_pending_write_ = true; |
| 106 } | 112 } |
| 107 | 113 |
| 108 } | 114 } |
| 109 | 115 |
| 110 PrefHashStoreTransaction::ValueState | 116 PrefHashStoreTransaction::ValueState |
| 111 PrefHashStoreImpl::PrefHashStoreTransactionImpl::CheckValue( | 117 PrefHashStoreImpl::PrefHashStoreTransactionImpl::CheckValue( |
| 112 const std::string& path, const base::Value* initial_value) const { | 118 const std::string& path, const base::Value* initial_value) const { |
| 113 const base::DictionaryValue* hashed_prefs = outer_->contents_->GetContents(); | 119 const base::DictionaryValue* hashed_prefs = outer_->contents_->GetContents(); |
| 114 | 120 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 it.Advance()) { | 268 it.Advance()) { |
| 263 std::string mac_string; | 269 std::string mac_string; |
| 264 if (!it.value().GetAsString(&mac_string)) { | 270 if (!it.value().GetAsString(&mac_string)) { |
| 265 NOTREACHED(); | 271 NOTREACHED(); |
| 266 continue; | 272 continue; |
| 267 } | 273 } |
| 268 split_macs->insert(make_pair(it.key(), mac_string)); | 274 split_macs->insert(make_pair(it.key(), mac_string)); |
| 269 } | 275 } |
| 270 return true; | 276 return true; |
| 271 } | 277 } |
| OLD | NEW |