| 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/in_memory_extension_settings_storage.h" | 5 #include "chrome/browser/extensions/in_memory_extension_settings_storage.h" |
| 6 | 6 |
| 7 namespace { | 7 namespace { |
| 8 | 8 |
| 9 std::vector<std::string> CreateVector(const std::string& string) { | 9 std::vector<std::string> CreateVector(const std::string& string) { |
| 10 std::vector<std::string> strings; | 10 std::vector<std::string> strings; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 ExtensionSettingsStorage::Result InMemoryExtensionSettingsStorage::Get( | 22 ExtensionSettingsStorage::Result InMemoryExtensionSettingsStorage::Get( |
| 23 const std::vector<std::string>& keys) { | 23 const std::vector<std::string>& keys) { |
| 24 DictionaryValue* settings = new DictionaryValue(); | 24 DictionaryValue* settings = new DictionaryValue(); |
| 25 for (std::vector<std::string>::const_iterator it = keys.begin(); | 25 for (std::vector<std::string>::const_iterator it = keys.begin(); |
| 26 it != keys.end(); ++it) { | 26 it != keys.end(); ++it) { |
| 27 Value* value = NULL; | 27 Value* value = NULL; |
| 28 if (storage_.GetWithoutPathExpansion(*it, &value)) { | 28 if (storage_.GetWithoutPathExpansion(*it, &value)) { |
| 29 settings->SetWithoutPathExpansion(*it, value->DeepCopy()); | 29 settings->SetWithoutPathExpansion(*it, value->DeepCopy()); |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 return Result(settings, NULL); | 32 return Result(settings, NULL, NULL); |
| 33 } | 33 } |
| 34 | 34 |
| 35 ExtensionSettingsStorage::Result InMemoryExtensionSettingsStorage::Get() { | 35 ExtensionSettingsStorage::Result InMemoryExtensionSettingsStorage::Get() { |
| 36 return Result(storage_.DeepCopy(), NULL); | 36 return Result(storage_.DeepCopy(), NULL, NULL); |
| 37 } | 37 } |
| 38 | 38 |
| 39 ExtensionSettingsStorage::Result InMemoryExtensionSettingsStorage::Set( | 39 ExtensionSettingsStorage::Result InMemoryExtensionSettingsStorage::Set( |
| 40 const std::string& key, const Value& value) { | 40 const std::string& key, const Value& value) { |
| 41 DictionaryValue settings; | 41 DictionaryValue settings; |
| 42 settings.SetWithoutPathExpansion(key, value.DeepCopy()); | 42 settings.SetWithoutPathExpansion(key, value.DeepCopy()); |
| 43 return Set(settings); | 43 return Set(settings); |
| 44 } | 44 } |
| 45 | 45 |
| 46 ExtensionSettingsStorage::Result InMemoryExtensionSettingsStorage::Set( | 46 ExtensionSettingsStorage::Result InMemoryExtensionSettingsStorage::Set( |
| 47 const DictionaryValue& settings) { | 47 const DictionaryValue& settings) { |
| 48 DictionaryValue* old_settings = new DictionaryValue(); |
| 48 std::set<std::string>* changed_keys = new std::set<std::string>(); | 49 std::set<std::string>* changed_keys = new std::set<std::string>(); |
| 49 for (DictionaryValue::key_iterator it = settings.begin_keys(); | 50 for (DictionaryValue::key_iterator it = settings.begin_keys(); |
| 50 it != settings.end_keys(); ++it) { | 51 it != settings.end_keys(); ++it) { |
| 51 Value* old_value = NULL; | 52 Value* old_value = NULL; |
| 52 storage_.GetWithoutPathExpansion(*it, &old_value); | 53 if (storage_.GetWithoutPathExpansion(*it, &old_value)) { |
| 54 old_settings->SetWithoutPathExpansion(*it, old_value->DeepCopy()); |
| 55 } |
| 53 Value* new_value = NULL; | 56 Value* new_value = NULL; |
| 54 settings.GetWithoutPathExpansion(*it, &new_value); | 57 settings.GetWithoutPathExpansion(*it, &new_value); |
| 55 if (old_value == NULL || !old_value->Equals(new_value)) { | 58 if (old_value == NULL || !old_value->Equals(new_value)) { |
| 56 changed_keys->insert(*it); | 59 changed_keys->insert(*it); |
| 57 storage_.SetWithoutPathExpansion(*it, new_value->DeepCopy()); | 60 storage_.SetWithoutPathExpansion(*it, new_value->DeepCopy()); |
| 58 } | 61 } |
| 59 } | 62 } |
| 60 return Result(settings.DeepCopy(), changed_keys); | 63 return Result(settings.DeepCopy(), old_settings, changed_keys); |
| 61 } | 64 } |
| 62 | 65 |
| 63 ExtensionSettingsStorage::Result InMemoryExtensionSettingsStorage::Remove( | 66 ExtensionSettingsStorage::Result InMemoryExtensionSettingsStorage::Remove( |
| 64 const std::string& key) { | 67 const std::string& key) { |
| 65 return Remove(CreateVector(key)); | 68 return Remove(CreateVector(key)); |
| 66 } | 69 } |
| 67 | 70 |
| 68 ExtensionSettingsStorage::Result InMemoryExtensionSettingsStorage::Remove( | 71 ExtensionSettingsStorage::Result InMemoryExtensionSettingsStorage::Remove( |
| 69 const std::vector<std::string>& keys) { | 72 const std::vector<std::string>& keys) { |
| 73 DictionaryValue* old_settings = new DictionaryValue(); |
| 70 std::set<std::string>* changed_keys = new std::set<std::string>(); | 74 std::set<std::string>* changed_keys = new std::set<std::string>(); |
| 71 for (std::vector<std::string>::const_iterator it = keys.begin(); | 75 for (std::vector<std::string>::const_iterator it = keys.begin(); |
| 72 it != keys.end(); ++it) { | 76 it != keys.end(); ++it) { |
| 73 if (storage_.RemoveWithoutPathExpansion(*it, NULL)) { | 77 Value* old_value = NULL; |
| 78 if (storage_.RemoveWithoutPathExpansion(*it, &old_value)) { |
| 79 old_settings->SetWithoutPathExpansion(*it, old_value); |
| 74 changed_keys->insert(*it); | 80 changed_keys->insert(*it); |
| 75 } | 81 } |
| 76 } | 82 } |
| 77 return Result(NULL, changed_keys); | 83 return Result(NULL, old_settings, changed_keys); |
| 78 } | 84 } |
| 79 | 85 |
| 80 ExtensionSettingsStorage::Result InMemoryExtensionSettingsStorage::Clear() { | 86 ExtensionSettingsStorage::Result InMemoryExtensionSettingsStorage::Clear() { |
| 81 std::set<std::string>* changed_keys = new std::set<std::string>(); | 87 std::set<std::string>* changed_keys = new std::set<std::string>(); |
| 82 for (DictionaryValue::key_iterator it = storage_.begin_keys(); | 88 for (DictionaryValue::key_iterator it = storage_.begin_keys(); |
| 83 it != storage_.end_keys(); ++it) { | 89 it != storage_.end_keys(); ++it) { |
| 84 changed_keys->insert(*it); | 90 changed_keys->insert(*it); |
| 85 } | 91 } |
| 86 storage_.Clear(); | 92 DictionaryValue* old_settings = new DictionaryValue(); |
| 87 return Result(NULL, changed_keys); | 93 storage_.Swap(old_settings); |
| 94 return Result(NULL, old_settings, changed_keys); |
| 88 } | 95 } |
| OLD | NEW |