| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_MAP_H_ | 5 #ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_MAP_H_ |
| 6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_MAP_H_ | 6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_MAP_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/nullable_string16.h" | 12 #include "base/nullable_string16.h" |
| 13 #include "base/string16.h" | 13 #include "base/string16.h" |
| 14 #include "webkit/dom_storage/dom_storage_types.h" | 14 #include "webkit/dom_storage/dom_storage_types.h" |
| 15 | 15 |
| 16 namespace dom_storage { | 16 namespace dom_storage { |
| 17 | 17 |
| 18 // A wrapper around a std::map that adds refcounting and | 18 // A wrapper around a std::map that adds refcounting and |
| 19 // tracks the size in bytes of the keys/values, enforcing a quota. | 19 // tracks the size in bytes of the keys/values, enforcing a quota. |
| 20 // See class comments for DomStorageContext for a larger overview. | 20 // See class comments for DomStorageContext for a larger overview. |
| 21 class DomStorageMap | 21 class DomStorageMap |
| 22 : public base::RefCountedThreadSafe<DomStorageMap> { | 22 : public base::RefCountedThreadSafe<DomStorageMap> { |
| 23 public: | 23 public: |
| 24 DomStorageMap(size_t quota); | 24 explicit DomStorageMap(size_t quota); |
| 25 | 25 |
| 26 unsigned Length() const; | 26 unsigned Length() const; |
| 27 NullableString16 Key(unsigned index); | 27 NullableString16 Key(unsigned index); |
| 28 NullableString16 GetItem(const string16& key) const; | 28 NullableString16 GetItem(const string16& key) const; |
| 29 bool SetItem(const string16& key, const string16& value, | 29 bool SetItem(const string16& key, const string16& value, |
| 30 NullableString16* old_value); | 30 NullableString16* old_value); |
| 31 bool RemoveItem(const string16& key, string16* old_value); | 31 bool RemoveItem(const string16& key, string16* old_value); |
| 32 | 32 |
| 33 // Swaps this instances values_ with |map|. | 33 // Swaps this instances values_ with |map|. |
| 34 // Note: to grandfather in pre-existing files that are overbudget, | 34 // Note: to grandfather in pre-existing files that are overbudget, |
| 35 // this method does not do quota checking. | 35 // this method does not do quota checking. |
| 36 void SwapValues(ValuesMap* map); | 36 void SwapValues(ValuesMap* map); |
| 37 | 37 |
| 38 // Writes a copy of the current set of values_ to the |map|. | 38 // Writes a copy of the current set of values_ to the |map|. |
| 39 void ExtractValues(ValuesMap* map) const { *map = values_; } | 39 void ExtractValues(ValuesMap* map) const { *map = values_; } |
| 40 | 40 |
| 41 // Creates a new instance of DomStorageMap containing | 41 // Creates a new instance of DomStorageMap containing |
| 42 // a deep copy of values_. | 42 // a deep copy of values_. |
| 43 DomStorageMap* DeepCopy() const; | 43 DomStorageMap* DeepCopy() const; |
| 44 | 44 |
| 45 size_t bytes_used() const { return bytes_used_; } | 45 size_t bytes_used() const { return bytes_used_; } |
| 46 size_t quota() { return quota_; } |
| 47 void set_quota(size_t quota) { quota_ = quota; } |
| 46 | 48 |
| 47 private: | 49 private: |
| 48 friend class base::RefCountedThreadSafe<DomStorageMap>; | 50 friend class base::RefCountedThreadSafe<DomStorageMap>; |
| 49 ~DomStorageMap(); | 51 ~DomStorageMap(); |
| 50 | 52 |
| 51 void ResetKeyIterator(); | 53 void ResetKeyIterator(); |
| 52 | 54 |
| 53 ValuesMap values_; | 55 ValuesMap values_; |
| 54 ValuesMap::const_iterator key_iterator_; | 56 ValuesMap::const_iterator key_iterator_; |
| 55 unsigned last_key_index_; | 57 unsigned last_key_index_; |
| 56 size_t bytes_used_; | 58 size_t bytes_used_; |
| 57 size_t quota_; | 59 size_t quota_; |
| 58 }; | 60 }; |
| 59 | 61 |
| 60 } // namespace dom_storage | 62 } // namespace dom_storage |
| 61 | 63 |
| 62 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_MAP_H_ | 64 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_MAP_H_ |
| OLD | NEW |