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

Side by Side Diff: components/login/screens/screen_context.cc

Issue 2910073003: Replace deprecated base::NonThreadSafe in components/login in favor of SequenceChecker. (Closed)
Patch Set: Created 3 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
« no previous file with comments | « components/login/screens/screen_context.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "components/login/screens/screen_context.h" 5 #include "components/login/screens/screen_context.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
(...skipping 11 matching lines...) Expand all
22 } 22 }
23 return result; 23 return result;
24 } 24 }
25 25
26 } // namespace 26 } // namespace
27 27
28 ScreenContext::ScreenContext() { 28 ScreenContext::ScreenContext() {
29 } 29 }
30 30
31 ScreenContext::~ScreenContext() { 31 ScreenContext::~ScreenContext() {
32 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
32 } 33 }
33 34
34 bool ScreenContext::SetBoolean(const KeyType& key, bool value) { 35 bool ScreenContext::SetBoolean(const KeyType& key, bool value) {
35 return Set(key, new base::Value(value)); 36 return Set(key, new base::Value(value));
36 } 37 }
37 38
38 bool ScreenContext::SetInteger(const KeyType& key, int value) { 39 bool ScreenContext::SetInteger(const KeyType& key, int value) {
39 return Set(key, new base::Value(value)); 40 return Set(key, new base::Value(value));
40 } 41 }
41 42
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 125 }
125 126
126 void ScreenContext::CopyFrom(ScreenContext& context) { 127 void ScreenContext::CopyFrom(ScreenContext& context) {
127 std::unique_ptr<base::DictionaryValue> storage(context.storage_.DeepCopy()); 128 std::unique_ptr<base::DictionaryValue> storage(context.storage_.DeepCopy());
128 std::unique_ptr<base::DictionaryValue> changes(context.changes_.DeepCopy()); 129 std::unique_ptr<base::DictionaryValue> changes(context.changes_.DeepCopy());
129 storage_.Swap(storage.get()); 130 storage_.Swap(storage.get());
130 changes_.Swap(changes.get()); 131 changes_.Swap(changes.get());
131 } 132 }
132 133
133 bool ScreenContext::HasKey(const KeyType& key) const { 134 bool ScreenContext::HasKey(const KeyType& key) const {
134 DCHECK(CalledOnValidThread()); 135 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
135 return storage_.HasKey(key); 136 return storage_.HasKey(key);
136 } 137 }
137 138
138 bool ScreenContext::HasChanges() const { 139 bool ScreenContext::HasChanges() const {
139 DCHECK(CalledOnValidThread()); 140 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
140 return !changes_.empty(); 141 return !changes_.empty();
141 } 142 }
142 143
143 void ScreenContext::GetChangesAndReset(base::DictionaryValue* diff) { 144 void ScreenContext::GetChangesAndReset(base::DictionaryValue* diff) {
144 DCHECK(CalledOnValidThread()); 145 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
145 DCHECK(diff); 146 DCHECK(diff);
146 changes_.Swap(diff); 147 changes_.Swap(diff);
147 changes_.Clear(); 148 changes_.Clear();
148 } 149 }
149 150
150 void ScreenContext::ApplyChanges(const base::DictionaryValue& diff, 151 void ScreenContext::ApplyChanges(const base::DictionaryValue& diff,
151 std::vector<std::string>* keys) { 152 std::vector<std::string>* keys) {
152 DCHECK(CalledOnValidThread()); 153 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
153 DCHECK(!HasChanges()); 154 DCHECK(!HasChanges());
154 if (keys) { 155 if (keys) {
155 keys->clear(); 156 keys->clear();
156 keys->reserve(diff.size()); 157 keys->reserve(diff.size());
157 } 158 }
158 159
159 for (base::DictionaryValue::Iterator it(diff); !it.IsAtEnd(); it.Advance()) { 160 for (base::DictionaryValue::Iterator it(diff); !it.IsAtEnd(); it.Advance()) {
160 Set(it.key(), it.value().DeepCopy()); 161 Set(it.key(), it.value().DeepCopy());
161 if (keys) 162 if (keys)
162 keys->push_back(it.key()); 163 keys->push_back(it.key());
163 } 164 }
164 changes_.Clear(); 165 changes_.Clear();
165 } 166 }
166 167
167 bool ScreenContext::Set(const KeyType& key, base::Value* value) { 168 bool ScreenContext::Set(const KeyType& key, base::Value* value) {
168 DCHECK(CalledOnValidThread()); 169 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
169 DCHECK(value); 170 DCHECK(value);
170 std::unique_ptr<base::Value> new_value(value); 171 std::unique_ptr<base::Value> new_value(value);
171 172
172 base::Value* current_value; 173 base::Value* current_value;
173 bool in_storage = storage_.Get(key, &current_value); 174 bool in_storage = storage_.Get(key, &current_value);
174 175
175 // Don't do anything if |storage_| already contains <|key|, |new_value|> pair. 176 // Don't do anything if |storage_| already contains <|key|, |new_value|> pair.
176 if (in_storage && new_value->Equals(current_value)) 177 if (in_storage && new_value->Equals(current_value))
177 return false; 178 return false;
178 179
179 changes_.Set(key, new_value->DeepCopy()); 180 changes_.Set(key, new_value->DeepCopy());
180 storage_.Set(key, new_value.release()); 181 storage_.Set(key, new_value.release());
181 return true; 182 return true;
182 } 183 }
183 184
184 } // namespace login 185 } // namespace login
OLDNEW
« no previous file with comments | « components/login/screens/screen_context.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698