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

Side by Side Diff: chrome/browser/prefs/tracked/segregated_pref_store.cc

Issue 220203011: Changes requested by gab for previously committed CLs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/segregated_pref_store.h" 5 #include "chrome/browser/prefs/tracked/segregated_pref_store.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 10
(...skipping 17 matching lines...) Expand all
28 void SegregatedPrefStore::AggregatingObserver::OnInitializationCompleted( 28 void SegregatedPrefStore::AggregatingObserver::OnInitializationCompleted(
29 bool succeeded) { 29 bool succeeded) {
30 if (succeeded) 30 if (succeeded)
31 ++successful_sub_initializations_; 31 ++successful_sub_initializations_;
32 else 32 else
33 ++failed_sub_initializations_; 33 ++failed_sub_initializations_;
34 34
35 DCHECK_LE(failed_sub_initializations_ + successful_sub_initializations_, 2); 35 DCHECK_LE(failed_sub_initializations_ + successful_sub_initializations_, 2);
36 36
37 if (failed_sub_initializations_ + successful_sub_initializations_ == 2) { 37 if (failed_sub_initializations_ + successful_sub_initializations_ == 2) {
38
39 if (!outer_->on_initialization_.is_null()) 38 if (!outer_->on_initialization_.is_null())
40 outer_->on_initialization_.Run(); 39 outer_->on_initialization_.Run();
41 40
42 if (successful_sub_initializations_ == 2 && outer_->read_error_delegate_) { 41 if (successful_sub_initializations_ == 2 && outer_->read_error_delegate_) {
43 PersistentPrefStore::PrefReadError read_error = outer_->GetReadError(); 42 PersistentPrefStore::PrefReadError read_error = outer_->GetReadError();
44 if (read_error != PersistentPrefStore::PREF_READ_ERROR_NONE) 43 if (read_error != PersistentPrefStore::PREF_READ_ERROR_NONE)
45 outer_->read_error_delegate_->OnError(read_error); 44 outer_->read_error_delegate_->OnError(read_error);
46 } 45 }
47 46
48 FOR_EACH_OBSERVER( 47 FOR_EACH_OBSERVER(
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 void SegregatedPrefStore::CommitPendingWrite() { 143 void SegregatedPrefStore::CommitPendingWrite() {
145 default_pref_store_->CommitPendingWrite(); 144 default_pref_store_->CommitPendingWrite();
146 selected_pref_store_->CommitPendingWrite(); 145 selected_pref_store_->CommitPendingWrite();
147 } 146 }
148 147
149 SegregatedPrefStore::~SegregatedPrefStore() { 148 SegregatedPrefStore::~SegregatedPrefStore() {
150 default_pref_store_->RemoveObserver(&aggregating_observer_); 149 default_pref_store_->RemoveObserver(&aggregating_observer_);
151 selected_pref_store_->RemoveObserver(&aggregating_observer_); 150 selected_pref_store_->RemoveObserver(&aggregating_observer_);
152 } 151 }
153 152
154 const PersistentPrefStore* 153 const PersistentPrefStore* SegregatedPrefStore::StoreForKey(
155 SegregatedPrefStore::StoreForKey(const std::string& key) const { 154 const std::string& key) const {
156 if (ContainsKey(selected_preference_names_, key) || 155 if (ContainsKey(selected_preference_names_, key) ||
157 selected_pref_store_->GetValue(key, NULL)) { 156 selected_pref_store_->GetValue(key, NULL)) {
158 return selected_pref_store_.get(); 157 return selected_pref_store_.get();
159 } 158 }
160 return default_pref_store_.get(); 159 return default_pref_store_.get();
161 } 160 }
162 161
163 PersistentPrefStore* SegregatedPrefStore::StoreForKey(const std::string& key) { 162 PersistentPrefStore* SegregatedPrefStore::StoreForKey(const std::string& key) {
164 if (ContainsKey(selected_preference_names_, key)) 163 if (ContainsKey(selected_preference_names_, key))
165 return selected_pref_store_.get(); 164 return selected_pref_store_.get();
166 165
167 // Check if this unselected value was previously selected. If so, migrate it 166 // Check if this unselected value was previously selected. If so, migrate it
168 // back to the unselected store. 167 // back to the unselected store.
169 // It's hard to do this in a single pass at startup because PrefStore does not 168 // It's hard to do this in a single pass at startup because PrefStore does not
170 // permit us to enumerate its contents. 169 // permit us to enumerate its contents.
171 const base::Value* value = NULL; 170 const base::Value* value = NULL;
172 if (selected_pref_store_->GetValue(key, &value)) { 171 if (selected_pref_store_->GetValue(key, &value)) {
173 scoped_ptr<base::Value> migrated_value(value->DeepCopy()); 172 default_pref_store_->SetValue(key, value->DeepCopy());
173 default_pref_store_->CommitPendingWrite();
gab 2014/04/02 17:02:15 Add a comment as to why this commit is required, i
erikwright (departed) 2014/04/03 13:25:47 Done.
174
174 value = NULL; 175 value = NULL;
gab 2014/04/02 17:02:15 Why even do this? It doesn't seem to matter that |
erikwright (departed) 2014/04/03 13:25:47 AfterRemoveValue, |value| is invalid. If this 'if
gab 2014/04/03 15:47:13 Oh right, good point.
175 default_pref_store_->SetValue(key, migrated_value.release());
176 default_pref_store_->CommitPendingWrite();
177 selected_pref_store_->RemoveValue(key); 176 selected_pref_store_->RemoveValue(key);
178 selected_pref_store_->CommitPendingWrite();
179 } 177 }
180 178
181 return default_pref_store_.get(); 179 return default_pref_store_.get();
182 } 180 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698