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