| OLD | NEW |
| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 | 9 |
| 10 namespace login { | 10 namespace login { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 } | 140 } |
| 141 | 141 |
| 142 void ScreenContext::ApplyChanges(const base::DictionaryValue& diff, | 142 void ScreenContext::ApplyChanges(const base::DictionaryValue& diff, |
| 143 std::vector<std::string>* keys) { | 143 std::vector<std::string>* keys) { |
| 144 DCHECK(CalledOnValidThread()); | 144 DCHECK(CalledOnValidThread()); |
| 145 DCHECK(!HasChanges()); | 145 DCHECK(!HasChanges()); |
| 146 if (keys) { | 146 if (keys) { |
| 147 keys->clear(); | 147 keys->clear(); |
| 148 keys->reserve(diff.size()); | 148 keys->reserve(diff.size()); |
| 149 } | 149 } |
| 150 base::DictionaryValue::Iterator it(diff); | 150 |
| 151 while (!it.IsAtEnd()) { | 151 for (base::DictionaryValue::Iterator it(diff); !it.IsAtEnd(); it.Advance()) { |
| 152 Set(it.key(), it.value().DeepCopy()); | 152 Set(it.key(), it.value().DeepCopy()); |
| 153 if (keys) | 153 if (keys) |
| 154 keys->push_back(it.key()); | 154 keys->push_back(it.key()); |
| 155 it.Advance(); | |
| 156 } | 155 } |
| 157 changes_.Clear(); | 156 changes_.Clear(); |
| 158 } | 157 } |
| 159 | 158 |
| 160 bool ScreenContext::Set(const KeyType& key, base::Value* value) { | 159 bool ScreenContext::Set(const KeyType& key, base::Value* value) { |
| 161 DCHECK(CalledOnValidThread()); | 160 DCHECK(CalledOnValidThread()); |
| 162 DCHECK(value); | 161 DCHECK(value); |
| 163 scoped_ptr<base::Value> new_value(value); | 162 scoped_ptr<base::Value> new_value(value); |
| 164 | 163 |
| 165 base::Value* current_value; | 164 base::Value* current_value; |
| 166 bool in_storage = storage_.Get(key, ¤t_value); | 165 bool in_storage = storage_.Get(key, ¤t_value); |
| 167 | 166 |
| 168 // Don't do anything if |storage_| already contains <|key|, |new_value|> pair. | 167 // Don't do anything if |storage_| already contains <|key|, |new_value|> pair. |
| 169 if (in_storage && new_value->Equals(current_value)) | 168 if (in_storage && new_value->Equals(current_value)) |
| 170 return false; | 169 return false; |
| 171 | 170 |
| 172 changes_.Set(key, new_value->DeepCopy()); | 171 changes_.Set(key, new_value->DeepCopy()); |
| 173 storage_.Set(key, new_value.release()); | 172 storage_.Set(key, new_value.release()); |
| 174 return true; | 173 return true; |
| 175 } | 174 } |
| 176 | 175 |
| 177 } // namespace login | 176 } // namespace login |
| OLD | NEW |