OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/settings/setting_change.h" | 5 #include "chrome/browser/extensions/settings/setting_change.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 | 10 |
11 namespace extensions { | 11 namespace extensions { |
12 | 12 |
13 /* static */ | 13 /* static */ |
14 std::string SettingChange::GetEventJson(const SettingChangeList& changes) { | 14 std::string SettingChange::GetEventJson(const SettingChangeList& changes) { |
15 DictionaryValue changes_value; | 15 DictionaryValue changes_value; |
16 for (SettingChangeList::const_iterator it = changes.begin(); | 16 for (SettingChangeList::const_iterator it = changes.begin(); |
17 it != changes.end(); ++it) { | 17 it != changes.end(); ++it) { |
18 DictionaryValue* change_value = new DictionaryValue(); | 18 DictionaryValue* change_value = new DictionaryValue(); |
19 if (it->old_value()) { | 19 if (it->old_value()) { |
20 change_value->Set("oldValue", it->old_value()->DeepCopy()); | 20 change_value->Set("oldValue", it->old_value()->DeepCopy()); |
21 } | 21 } |
22 if (it->new_value()) { | 22 if (it->new_value()) { |
23 change_value->Set("newValue", it->new_value()->DeepCopy()); | 23 change_value->Set("newValue", it->new_value()->DeepCopy()); |
24 } | 24 } |
25 changes_value.Set(it->key(), change_value); | 25 changes_value.Set(it->key(), change_value); |
26 } | 26 } |
27 std::string json; | 27 std::string json; |
28 base::JSONWriter::Write(&changes_value, false, &json); | 28 base::JSONWriter::Write(&changes_value, &json); |
29 return json; | 29 return json; |
30 } | 30 } |
31 | 31 |
32 SettingChange::SettingChange( | 32 SettingChange::SettingChange( |
33 const std::string& key, Value* old_value, Value* new_value) | 33 const std::string& key, Value* old_value, Value* new_value) |
34 : inner_(new Inner(key, old_value, new_value)) {} | 34 : inner_(new Inner(key, old_value, new_value)) {} |
35 | 35 |
36 SettingChange::~SettingChange() {} | 36 SettingChange::~SettingChange() {} |
37 | 37 |
38 const std::string& SettingChange::key() const { | 38 const std::string& SettingChange::key() const { |
(...skipping 11 matching lines...) Expand all Loading... |
50 return inner_->new_value_.get(); | 50 return inner_->new_value_.get(); |
51 } | 51 } |
52 | 52 |
53 SettingChange::Inner::Inner( | 53 SettingChange::Inner::Inner( |
54 const std::string& key, base::Value* old_value, base::Value* new_value) | 54 const std::string& key, base::Value* old_value, base::Value* new_value) |
55 : key_(key), old_value_(old_value), new_value_(new_value) {} | 55 : key_(key), old_value_(old_value), new_value_(new_value) {} |
56 | 56 |
57 SettingChange::Inner::~Inner() {} | 57 SettingChange::Inner::~Inner() {} |
58 | 58 |
59 } // namespace extensions | 59 } // namespace extensions |
OLD | NEW |