Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: chrome/browser/prefs/pref_hash_store_impl.cc

Issue 332473002: Make super MAC optional. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 bool GetSplitMacs(const std::string& path, 53 bool GetSplitMacs(const std::string& path,
54 std::map<std::string, std::string>* split_macs) const; 54 std::map<std::string, std::string>* split_macs) const;
55 PrefHashStoreImpl* outer_; 55 PrefHashStoreImpl* outer_;
56 bool has_changed_; 56 bool has_changed_;
57 57
58 DISALLOW_COPY_AND_ASSIGN(PrefHashStoreTransactionImpl); 58 DISALLOW_COPY_AND_ASSIGN(PrefHashStoreTransactionImpl);
59 }; 59 };
60 60
61 PrefHashStoreImpl::PrefHashStoreImpl(const std::string& seed, 61 PrefHashStoreImpl::PrefHashStoreImpl(const std::string& seed,
62 const std::string& device_id, 62 const std::string& device_id,
63 scoped_ptr<HashStoreContents> contents) 63 scoped_ptr<HashStoreContents> contents,
64 bool use_super_mac)
64 : pref_hash_calculator_(seed, device_id), 65 : pref_hash_calculator_(seed, device_id),
65 contents_(contents.Pass()), 66 contents_(contents.Pass()),
66 initial_hashes_dictionary_trusted_( 67 initial_hashes_dictionary_trusted_(
67 IsHashDictionaryTrusted(pref_hash_calculator_, *contents_)), 68 use_super_mac
69 ? IsHashDictionaryTrusted(pref_hash_calculator_, *contents_)
70 : false),
gab 2014/06/11 18:57:54 What do you think of making the default "true" her
gab 2014/06/11 21:54:32 Actually, never mind. Setting this to false will
71 use_super_mac_(use_super_mac),
68 has_pending_write_(false) { 72 has_pending_write_(false) {
69 DCHECK(contents_); 73 DCHECK(contents_);
70 UMA_HISTOGRAM_BOOLEAN("Settings.HashesDictionaryTrusted", 74 UMA_HISTOGRAM_BOOLEAN("Settings.HashesDictionaryTrusted",
71 initial_hashes_dictionary_trusted_); 75 initial_hashes_dictionary_trusted_);
72 } 76 }
73 77
74 PrefHashStoreImpl::~PrefHashStoreImpl() {} 78 PrefHashStoreImpl::~PrefHashStoreImpl() {}
75 79
76 void PrefHashStoreImpl::Reset() { 80 void PrefHashStoreImpl::Reset() {
77 contents_->Reset(); 81 contents_->Reset();
(...skipping 13 matching lines...) Expand all
91 95
92 PrefHashStoreImpl::PrefHashStoreTransactionImpl::PrefHashStoreTransactionImpl( 96 PrefHashStoreImpl::PrefHashStoreTransactionImpl::PrefHashStoreTransactionImpl(
93 PrefHashStoreImpl* outer) : outer_(outer), has_changed_(false) { 97 PrefHashStoreImpl* outer) : outer_(outer), has_changed_(false) {
94 } 98 }
95 99
96 PrefHashStoreImpl::PrefHashStoreTransactionImpl:: 100 PrefHashStoreImpl::PrefHashStoreTransactionImpl::
97 ~PrefHashStoreTransactionImpl() { 101 ~PrefHashStoreTransactionImpl() {
98 // Update the super MAC if and only if the hashes dictionary has been 102 // Update the super MAC if and only if the hashes dictionary has been
99 // modified in this transaction. 103 // modified in this transaction.
100 if (has_changed_) { 104 if (has_changed_) {
101 // Get the dictionary of hashes (or NULL if it doesn't exist). 105 if (outer_->use_super_mac_) {
102 const base::DictionaryValue* hashes_dict = outer_->contents_->GetContents(); 106 // Get the dictionary of hashes (or NULL if it doesn't exist).
103 outer_->contents_->SetSuperMac(outer_->pref_hash_calculator_.Calculate( 107 const base::DictionaryValue* hashes_dict =
104 outer_->contents_->hash_store_id(), hashes_dict)); 108 outer_->contents_->GetContents();
105 109 outer_->contents_->SetSuperMac(outer_->pref_hash_calculator_.Calculate(
110 outer_->contents_->hash_store_id(), hashes_dict));
111 }
106 outer_->has_pending_write_ = true; 112 outer_->has_pending_write_ = true;
107 } 113 }
108 114
109 } 115 }
110 116
111 PrefHashStoreTransaction::ValueState 117 PrefHashStoreTransaction::ValueState
112 PrefHashStoreImpl::PrefHashStoreTransactionImpl::CheckValue( 118 PrefHashStoreImpl::PrefHashStoreTransactionImpl::CheckValue(
113 const std::string& path, const base::Value* initial_value) const { 119 const std::string& path, const base::Value* initial_value) const {
114 const base::DictionaryValue* hashed_prefs = outer_->contents_->GetContents(); 120 const base::DictionaryValue* hashed_prefs = outer_->contents_->GetContents();
115 121
(...skipping 27 matching lines...) Expand all
143 149
144 void PrefHashStoreImpl::PrefHashStoreTransactionImpl::StoreHash( 150 void PrefHashStoreImpl::PrefHashStoreTransactionImpl::StoreHash(
145 const std::string& path, const base::Value* new_value) { 151 const std::string& path, const base::Value* new_value) {
146 const std::string mac = 152 const std::string mac =
147 outer_->pref_hash_calculator_.Calculate(path, new_value); 153 outer_->pref_hash_calculator_.Calculate(path, new_value);
148 (*outer_->contents_->GetMutableContents())->SetString(path, mac); 154 (*outer_->contents_->GetMutableContents())->SetString(path, mac);
149 has_changed_ = true; 155 has_changed_ = true;
150 } 156 }
151 157
152 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::StampSuperMac() { 158 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::StampSuperMac() {
153 if (outer_->initial_hashes_dictionary_trusted_) 159 if (!outer_->use_super_mac_ || outer_->initial_hashes_dictionary_trusted_)
gab 2014/06/11 21:54:32 I don't think this is even required since line 104
erikwright (departed) 2014/06/13 13:25:24 This saves us thinking that we have altered the st
gab 2014/06/13 14:48:57 I see, good point :-)!
154 return false; 160 return false;
155 has_changed_ = true; 161 has_changed_ = true;
156 return true; 162 return true;
157 } 163 }
158 164
159 PrefHashStoreTransaction::ValueState 165 PrefHashStoreTransaction::ValueState
160 PrefHashStoreImpl::PrefHashStoreTransactionImpl::CheckSplitValue( 166 PrefHashStoreImpl::PrefHashStoreTransactionImpl::CheckSplitValue(
161 const std::string& path, 167 const std::string& path,
162 const base::DictionaryValue* initial_split_value, 168 const base::DictionaryValue* initial_split_value,
163 std::vector<std::string>* invalid_keys) const { 169 std::vector<std::string>* invalid_keys) const {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 it.Advance()) { 276 it.Advance()) {
271 std::string mac_string; 277 std::string mac_string;
272 if (!it.value().GetAsString(&mac_string)) { 278 if (!it.value().GetAsString(&mac_string)) {
273 NOTREACHED(); 279 NOTREACHED();
274 continue; 280 continue;
275 } 281 }
276 split_macs->insert(make_pair(it.key(), mac_string)); 282 split_macs->insert(make_pair(it.key(), mac_string));
277 } 283 }
278 return true; 284 return true;
279 } 285 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/pref_hash_store_impl.h ('k') | chrome/browser/prefs/pref_hash_store_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698