OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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. |
| 4 |
| 5 #include "webkit/dom_storage/dom_storage_map.h" |
| 6 |
| 7 namespace dom_storage { |
| 8 |
| 9 unsigned DomStorageMap::Length() { |
| 10 return values_.size(); |
| 11 } |
| 12 |
| 13 NullableString16 DomStorageMap::Key(unsigned index) { |
| 14 if (index > values_.size()) |
| 15 return NullableString16(true); |
| 16 ValuesMap::const_iterator it = values_.begin(); |
| 17 for (unsigned i = 0; i < index; ++i, ++it) { |
| 18 // TODO(michaeln): Fix this so we don't have to walk |
| 19 // up to the key from the beginning on each call. |
| 20 } |
| 21 return NullableString16(it->first, false); |
| 22 } |
| 23 |
| 24 NullableString16 DomStorageMap::GetItem(const string16& key) { |
| 25 ValuesMap::const_iterator found = values_.find(key); |
| 26 if (found == values_.end()) |
| 27 return NullableString16(true); |
| 28 return found->second; |
| 29 } |
| 30 |
| 31 bool DomStorageMap::SetItem( |
| 32 const string16& key, const string16& value, |
| 33 NullableString16* old_value) { |
| 34 // TODO(michaeln): check quota and return false if exceeded |
| 35 ValuesMap::const_iterator found = values_.find(key); |
| 36 if (found == values_.end()) { |
| 37 *old_value = NullableString16(true); |
| 38 return true; |
| 39 } |
| 40 values_[key] = NullableString16(value, false); |
| 41 return true; |
| 42 } |
| 43 |
| 44 bool DomStorageMap::RemoveItem( |
| 45 const string16& key, |
| 46 string16* old_value) { |
| 47 ValuesMap::const_iterator found = values_.find(key); |
| 48 if (found == values_.end()) |
| 49 return false; |
| 50 *old_value = found->second.string(); |
| 51 values_.erase(found); |
| 52 return true; |
| 53 } |
| 54 |
| 55 DomStorageMap* DomStorageMap::DeepCopy() { |
| 56 DomStorageMap* copy = new DomStorageMap; |
| 57 copy->values_ = values_; |
| 58 return copy; |
| 59 } |
| 60 |
| 61 } // namespace dom_storage |
OLD | NEW |