| 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 "chrome/browser/chromeos/login/screens/screen_context.h" | 5 #include "chrome/browser/chromeos/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 chromeos { | 10 namespace chromeos { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 DCHECK(CalledOnValidThread()); | 91 DCHECK(CalledOnValidThread()); |
| 92 DCHECK(diff); | 92 DCHECK(diff); |
| 93 changes_.Swap(diff); | 93 changes_.Swap(diff); |
| 94 changes_.Clear(); | 94 changes_.Clear(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void ScreenContext::ApplyChanges(const base::DictionaryValue& diff, | 97 void ScreenContext::ApplyChanges(const base::DictionaryValue& diff, |
| 98 std::vector<std::string>* keys) { | 98 std::vector<std::string>* keys) { |
| 99 DCHECK(CalledOnValidThread()); | 99 DCHECK(CalledOnValidThread()); |
| 100 DCHECK(!HasChanges()); | 100 DCHECK(!HasChanges()); |
| 101 DCHECK(keys); | 101 if (keys) { |
| 102 keys->clear(); | 102 keys->clear(); |
| 103 keys->reserve(diff.size()); | 103 keys->reserve(diff.size()); |
| 104 } |
| 104 base::DictionaryValue::Iterator it(diff); | 105 base::DictionaryValue::Iterator it(diff); |
| 105 while (!it.IsAtEnd()) { | 106 while (!it.IsAtEnd()) { |
| 106 Set(it.key(), it.value().DeepCopy()); | 107 Set(it.key(), it.value().DeepCopy()); |
| 107 keys->push_back(it.key()); | 108 if (keys) |
| 109 keys->push_back(it.key()); |
| 108 it.Advance(); | 110 it.Advance(); |
| 109 } | 111 } |
| 110 changes_.Clear(); | 112 changes_.Clear(); |
| 111 } | 113 } |
| 112 | 114 |
| 113 bool ScreenContext::Set(const KeyType& key, base::Value* value) { | 115 bool ScreenContext::Set(const KeyType& key, base::Value* value) { |
| 114 DCHECK(CalledOnValidThread()); | 116 DCHECK(CalledOnValidThread()); |
| 115 DCHECK(value); | 117 DCHECK(value); |
| 116 scoped_ptr<base::Value> new_value(value); | 118 scoped_ptr<base::Value> new_value(value); |
| 117 | 119 |
| 118 base::Value* current_value; | 120 base::Value* current_value; |
| 119 bool in_storage = storage_.Get(key, ¤t_value); | 121 bool in_storage = storage_.Get(key, ¤t_value); |
| 120 | 122 |
| 121 // Don't do anything if |storage_| already contains <|key|, |new_value|> pair. | 123 // Don't do anything if |storage_| already contains <|key|, |new_value|> pair. |
| 122 if (in_storage && new_value->Equals(current_value)) | 124 if (in_storage && new_value->Equals(current_value)) |
| 123 return false; | 125 return false; |
| 124 | 126 |
| 125 changes_.Set(key, new_value->DeepCopy()); | 127 changes_.Set(key, new_value->DeepCopy()); |
| 126 storage_.Set(key, new_value.release()); | 128 storage_.Set(key, new_value.release()); |
| 127 return true; | 129 return true; |
| 128 } | 130 } |
| 129 | 131 |
| 130 } // namespace chromeos | 132 } // namespace chromeos |
| OLD | NEW |