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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "chrome/browser/extensions/extension_settings_storage.h" | 6 #include "chrome/browser/extensions/extension_settings_storage.h" |
7 | 7 |
8 // Implementation of ExtensionSettingsStorage::Result | 8 // Implementation of ExtensionSettingsStorage::Result |
9 | 9 |
10 ExtensionSettingsStorage::Result::Result( | 10 ExtensionSettingsStorage::Result::Result( |
11 DictionaryValue* settings, std::set<std::string>* changed_keys) | 11 DictionaryValue* settings, |
12 : inner_(new Inner(settings, changed_keys, std::string())) {} | 12 DictionaryValue* old_settings, |
| 13 std::set<std::string>* changed_keys) |
| 14 : inner_(new Inner(settings, old_settings, changed_keys, std::string())) {} |
13 | 15 |
14 ExtensionSettingsStorage::Result::Result(const std::string& error) | 16 ExtensionSettingsStorage::Result::Result(const std::string& error) |
15 : inner_(new Inner(NULL, new std::set<std::string>(), error)) { | 17 : inner_(new Inner(NULL, NULL, new std::set<std::string>(), error)) { |
16 DCHECK(!error.empty()); | 18 DCHECK(!error.empty()); |
17 } | 19 } |
18 | 20 |
19 ExtensionSettingsStorage::Result::~Result() {} | 21 ExtensionSettingsStorage::Result::~Result() {} |
20 | 22 |
21 DictionaryValue* ExtensionSettingsStorage::Result::GetSettings() const { | 23 DictionaryValue* ExtensionSettingsStorage::Result::GetSettings() const { |
22 DCHECK(!HasError()); | 24 DCHECK(!HasError()); |
23 return inner_->settings_.get(); | 25 return inner_->settings_.get(); |
24 } | 26 } |
25 | 27 |
26 std::set<std::string>* | 28 std::set<std::string>* |
27 ExtensionSettingsStorage::Result::GetChangedKeys() const { | 29 ExtensionSettingsStorage::Result::GetChangedKeys() const { |
28 DCHECK(!HasError()); | 30 DCHECK(!HasError()); |
29 return inner_->changed_keys_.get(); | 31 return inner_->changed_keys_.get(); |
30 } | 32 } |
31 | 33 |
| 34 bool ExtensionSettingsStorage::Result::GetOldValue( |
| 35 const std::string& key, Value** old_value) const { |
| 36 DCHECK(!HasError()); |
| 37 DCHECK(old_value); |
| 38 if (!inner_->changed_keys_.get()) { |
| 39 return false; |
| 40 } |
| 41 if (!inner_->changed_keys_->count(key)) { |
| 42 return inner_->settings_->GetWithoutPathExpansion(key, old_value); |
| 43 } |
| 44 *old_value = NULL; |
| 45 inner_->old_settings_->GetWithoutPathExpansion(key, old_value); |
| 46 return true; |
| 47 } |
| 48 |
| 49 bool ExtensionSettingsStorage::Result::GetNewValue( |
| 50 const std::string& key, Value** new_value) const { |
| 51 DCHECK(!HasError()); |
| 52 DCHECK(new_value); |
| 53 if (!inner_->changed_keys_.get()) { |
| 54 return false; |
| 55 } |
| 56 *new_value = NULL; |
| 57 if (!inner_->settings_.get()) { |
| 58 return true; |
| 59 } |
| 60 inner_->settings_->GetWithoutPathExpansion(key, new_value); |
| 61 return true; |
| 62 } |
| 63 |
32 bool ExtensionSettingsStorage::Result::HasError() const { | 64 bool ExtensionSettingsStorage::Result::HasError() const { |
33 return !inner_->error_.empty(); | 65 return !inner_->error_.empty(); |
34 } | 66 } |
35 | 67 |
36 const std::string& ExtensionSettingsStorage::Result::GetError() const { | 68 const std::string& ExtensionSettingsStorage::Result::GetError() const { |
37 DCHECK(HasError()); | 69 DCHECK(HasError()); |
38 return inner_->error_; | 70 return inner_->error_; |
39 } | 71 } |
40 | 72 |
41 ExtensionSettingsStorage::Result::Inner::Inner( | 73 ExtensionSettingsStorage::Result::Inner::Inner( |
42 DictionaryValue* settings, | 74 DictionaryValue* settings, |
| 75 DictionaryValue* old_settings, |
43 std::set<std::string>* changed_keys, | 76 std::set<std::string>* changed_keys, |
44 const std::string& error) | 77 const std::string& error) |
45 : settings_(settings), changed_keys_(changed_keys), error_(error) {} | 78 : settings_(settings), |
| 79 old_settings_(old_settings), |
| 80 changed_keys_(changed_keys), |
| 81 error_(error) {} |
46 | 82 |
47 ExtensionSettingsStorage::Result::Inner::~Inner() {} | 83 ExtensionSettingsStorage::Result::Inner::~Inner() {} |
OLD | NEW |