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

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

Issue 329093003: Remove unloaded profile hash store initialization, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review comments. 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 void PrefHashStoreImpl::Reset() { 75 void PrefHashStoreImpl::Reset() {
76 contents_->Reset(); 76 contents_->Reset();
77 } 77 }
78 78
79 scoped_ptr<PrefHashStoreTransaction> PrefHashStoreImpl::BeginTransaction() { 79 scoped_ptr<PrefHashStoreTransaction> PrefHashStoreImpl::BeginTransaction() {
80 return scoped_ptr<PrefHashStoreTransaction>( 80 return scoped_ptr<PrefHashStoreTransaction>(
81 new PrefHashStoreTransactionImpl(this)); 81 new PrefHashStoreTransactionImpl(this));
82 } 82 }
83 83
84 PrefHashStoreImpl::StoreVersion PrefHashStoreImpl::GetCurrentVersion() const {
85 if (!contents_->IsInitialized())
86 return VERSION_UNINITIALIZED;
87
88 int current_version;
89 if (!contents_->GetVersion(&current_version)) {
90 return VERSION_PRE_MIGRATION;
91 }
92
93 DCHECK_GT(current_version, VERSION_PRE_MIGRATION);
94 return static_cast<StoreVersion>(current_version);
95 }
96
97 void PrefHashStoreImpl::CommitPendingWrite() { 84 void PrefHashStoreImpl::CommitPendingWrite() {
98 if (has_pending_write_) { 85 if (has_pending_write_) {
99 contents_->CommitPendingWrite(); 86 contents_->CommitPendingWrite();
100 has_pending_write_ = false; 87 has_pending_write_ = false;
101 } 88 }
102 } 89 }
103 90
104 PrefHashStoreImpl::PrefHashStoreTransactionImpl::PrefHashStoreTransactionImpl( 91 PrefHashStoreImpl::PrefHashStoreTransactionImpl::PrefHashStoreTransactionImpl(
105 PrefHashStoreImpl* outer) : outer_(outer), has_changed_(false) { 92 PrefHashStoreImpl* outer) : outer_(outer), has_changed_(false) {
106 } 93 }
107 94
108 PrefHashStoreImpl::PrefHashStoreTransactionImpl:: 95 PrefHashStoreImpl::PrefHashStoreTransactionImpl::
109 ~PrefHashStoreTransactionImpl() { 96 ~PrefHashStoreTransactionImpl() {
110 // Update the super MAC if and only if the hashes dictionary has been 97 // Update the super MAC if and only if the hashes dictionary has been
111 // modified in this transaction. 98 // modified in this transaction.
112 if (has_changed_) { 99 if (has_changed_) {
113 // Get the dictionary of hashes (or NULL if it doesn't exist). 100 // Get the dictionary of hashes (or NULL if it doesn't exist).
114 const base::DictionaryValue* hashes_dict = outer_->contents_->GetContents(); 101 const base::DictionaryValue* hashes_dict = outer_->contents_->GetContents();
115 outer_->contents_->SetSuperMac(outer_->pref_hash_calculator_.Calculate( 102 outer_->contents_->SetSuperMac(outer_->pref_hash_calculator_.Calculate(
116 outer_->contents_->hash_store_id(), hashes_dict)); 103 outer_->contents_->hash_store_id(), hashes_dict));
117 104
118 outer_->has_pending_write_ = true; 105 outer_->has_pending_write_ = true;
119 } 106 }
120 107
121 // Mark this hash store has having been updated to the latest version (in
122 // practice only initialization transactions will actually do this, but
123 // since they always occur before minor update transaction it's okay
124 // to unconditionally do this here). Only do this if this store's version
125 // isn't already at VERSION_LATEST (to avoid scheduling a write when
126 // unecessary). Note, this is outside of |if (has_changed)| to also seed
127 // version number of otherwise unchanged profiles.
128 int current_version;
129 if (!outer_->contents_->GetVersion(&current_version) ||
130 current_version != VERSION_LATEST) {
131 outer_->contents_->SetVersion(VERSION_LATEST);
132 outer_->has_pending_write_ = true;
133 }
134 } 108 }
135 109
136 PrefHashStoreTransaction::ValueState 110 PrefHashStoreTransaction::ValueState
137 PrefHashStoreImpl::PrefHashStoreTransactionImpl::CheckValue( 111 PrefHashStoreImpl::PrefHashStoreTransactionImpl::CheckValue(
138 const std::string& path, const base::Value* initial_value) const { 112 const std::string& path, const base::Value* initial_value) const {
139 const base::DictionaryValue* hashed_prefs = outer_->contents_->GetContents(); 113 const base::DictionaryValue* hashed_prefs = outer_->contents_->GetContents();
140 114
141 std::string last_hash; 115 std::string last_hash;
142 if (hashed_prefs) 116 if (hashed_prefs)
143 hashed_prefs->GetString(path, &last_hash); 117 hashed_prefs->GetString(path, &last_hash);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 it.Advance()) { 262 it.Advance()) {
289 std::string mac_string; 263 std::string mac_string;
290 if (!it.value().GetAsString(&mac_string)) { 264 if (!it.value().GetAsString(&mac_string)) {
291 NOTREACHED(); 265 NOTREACHED();
292 continue; 266 continue;
293 } 267 }
294 split_macs->insert(make_pair(it.key(), mac_string)); 268 split_macs->insert(make_pair(it.key(), mac_string));
295 } 269 }
296 return true; 270 return true;
297 } 271 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698