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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 bool ScreenContext::HasKey(const KeyType& key) const { | 80 bool ScreenContext::HasKey(const KeyType& key) const { |
81 DCHECK(CalledOnValidThread()); | 81 DCHECK(CalledOnValidThread()); |
82 return storage_.HasKey(key); | 82 return storage_.HasKey(key); |
83 } | 83 } |
84 | 84 |
85 bool ScreenContext::HasChanges() const { | 85 bool ScreenContext::HasChanges() const { |
86 DCHECK(CalledOnValidThread()); | 86 DCHECK(CalledOnValidThread()); |
87 return !changes_.empty(); | 87 return !changes_.empty(); |
88 } | 88 } |
89 | 89 |
90 void ScreenContext::GetChangesAndReset(DictionaryValue* diff) { | 90 void ScreenContext::GetChangesAndReset(base::DictionaryValue* diff) { |
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 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 DCHECK(keys); |
102 keys->clear(); | 102 keys->clear(); |
103 keys->reserve(diff.size()); | 103 keys->reserve(diff.size()); |
104 base::DictionaryValue::Iterator it(diff); | 104 base::DictionaryValue::Iterator it(diff); |
105 while (!it.IsAtEnd()) { | 105 while (!it.IsAtEnd()) { |
106 Set(it.key(), it.value().DeepCopy()); | 106 Set(it.key(), it.value().DeepCopy()); |
107 keys->push_back(it.key()); | 107 keys->push_back(it.key()); |
108 it.Advance(); | 108 it.Advance(); |
109 } | 109 } |
110 changes_.Clear(); | 110 changes_.Clear(); |
111 } | 111 } |
112 | 112 |
113 bool ScreenContext::Set(const KeyType& key, Value* value) { | 113 bool ScreenContext::Set(const KeyType& key, base::Value* value) { |
114 DCHECK(CalledOnValidThread()); | 114 DCHECK(CalledOnValidThread()); |
115 DCHECK(value); | 115 DCHECK(value); |
116 scoped_ptr<Value> new_value(value); | 116 scoped_ptr<base::Value> new_value(value); |
117 | 117 |
118 Value* current_value; | 118 base::Value* current_value; |
119 bool in_storage = storage_.Get(key, ¤t_value); | 119 bool in_storage = storage_.Get(key, ¤t_value); |
120 | 120 |
121 // Don't do anything if |storage_| already contains <|key|, |new_value|> pair. | 121 // Don't do anything if |storage_| already contains <|key|, |new_value|> pair. |
122 if (in_storage && new_value->Equals(current_value)) | 122 if (in_storage && new_value->Equals(current_value)) |
123 return false; | 123 return false; |
124 | 124 |
125 changes_.Set(key, new_value->DeepCopy()); | 125 changes_.Set(key, new_value->DeepCopy()); |
126 storage_.Set(key, new_value.release()); | 126 storage_.Set(key, new_value.release()); |
127 return true; | 127 return true; |
128 } | 128 } |
129 | 129 |
130 } // namespace chromeos | 130 } // namespace chromeos |
OLD | NEW |