Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / screens / screen_context.cc
blob658bd53675b877ce7638fa78a7bad7ec303b772d
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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/login/screens/screen_context.h"
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
10 namespace chromeos {
12 ScreenContext::ScreenContext() {
15 ScreenContext::~ScreenContext() {
18 bool ScreenContext::SetBoolean(const KeyType& key, bool value) {
19 return Set(key, new base::FundamentalValue(value));
22 bool ScreenContext::SetInteger(const KeyType& key, int value) {
23 return Set(key, new base::FundamentalValue(value));
26 bool ScreenContext::SetDouble(const KeyType& key, double value) {
27 return Set(key, new base::FundamentalValue(value));
30 bool ScreenContext::SetString(const KeyType& key, const std::string& value) {
31 return Set(key, new base::StringValue(value));
34 bool ScreenContext::SetString(const KeyType& key, const base::string16& value) {
35 return Set(key, new base::StringValue(value));
38 bool ScreenContext::GetBoolean(const KeyType& key) {
39 return Get<bool>(key);
42 bool ScreenContext::GetBoolean(const KeyType& key, bool default_value) {
43 return Get(key, default_value);
46 int ScreenContext::GetInteger(const KeyType& key) {
47 return Get<int>(key);
50 int ScreenContext::GetInteger(const KeyType& key, int default_value) {
51 return Get(key, default_value);
54 double ScreenContext::GetDouble(const KeyType& key) {
55 return Get<double>(key);
58 double ScreenContext::GetDouble(const KeyType& key, double default_value) {
59 return Get(key, default_value);
62 std::string ScreenContext::GetString(const KeyType& key) {
63 return Get<std::string>(key);
66 std::string ScreenContext::GetString(const KeyType& key,
67 const std::string& default_value) {
68 return Get(key, default_value);
71 base::string16 ScreenContext::GetString16(const KeyType& key) {
72 return Get<base::string16>(key);
75 base::string16 ScreenContext::GetString16(const KeyType& key,
76 const base::string16& default_value) {
77 return Get(key, default_value);
80 bool ScreenContext::HasKey(const KeyType& key) const {
81 DCHECK(CalledOnValidThread());
82 return storage_.HasKey(key);
85 bool ScreenContext::HasChanges() const {
86 DCHECK(CalledOnValidThread());
87 return !changes_.empty();
90 void ScreenContext::GetChangesAndReset(base::DictionaryValue* diff) {
91 DCHECK(CalledOnValidThread());
92 DCHECK(diff);
93 changes_.Swap(diff);
94 changes_.Clear();
97 void ScreenContext::ApplyChanges(const base::DictionaryValue& diff,
98 std::vector<std::string>* keys) {
99 DCHECK(CalledOnValidThread());
100 DCHECK(!HasChanges());
101 DCHECK(keys);
102 keys->clear();
103 keys->reserve(diff.size());
104 base::DictionaryValue::Iterator it(diff);
105 while (!it.IsAtEnd()) {
106 Set(it.key(), it.value().DeepCopy());
107 keys->push_back(it.key());
108 it.Advance();
110 changes_.Clear();
113 bool ScreenContext::Set(const KeyType& key, base::Value* value) {
114 DCHECK(CalledOnValidThread());
115 DCHECK(value);
116 scoped_ptr<base::Value> new_value(value);
118 base::Value* current_value;
119 bool in_storage = storage_.Get(key, &current_value);
121 // Don't do anything if |storage_| already contains <|key|, |new_value|> pair.
122 if (in_storage && new_value->Equals(current_value))
123 return false;
125 changes_.Set(key, new_value->DeepCopy());
126 storage_.Set(key, new_value.release());
127 return true;
130 } // namespace chromeos