OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/common/dom_storage/dom_storage_map.h" | 5 #include "content/common/dom_storage/dom_storage_map.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace content { | 9 namespace content { |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 size_t size_of_item(const base::string16& key, const base::string16& value) { | 13 size_t size_of_item(const base::string16& key, const base::string16& value) { |
14 return (key.length() + value.length()) * sizeof(base::char16); | 14 return (key.length() + value.length()) * sizeof(base::char16); |
15 } | 15 } |
16 | 16 |
17 size_t CountBytes(const DOMStorageValuesMap& values) { | |
18 if (values.size() == 0) | |
19 return 0; | |
20 | |
21 size_t count = 0; | |
22 DOMStorageValuesMap::const_iterator it = values.begin(); | |
23 for (; it != values.end(); ++it) | |
24 count += size_of_item(it->first, it->second.string()); | |
25 return count; | |
26 } | |
27 | |
28 } // namespace | 17 } // namespace |
29 | 18 |
30 DOMStorageMap::DOMStorageMap(size_t quota) | 19 DOMStorageMap::DOMStorageMap(size_t quota) |
31 : bytes_used_(0), | 20 : bytes_used_(0), |
32 quota_(quota) { | 21 quota_(quota) { |
33 ResetKeyIterator(); | 22 ResetKeyIterator(); |
34 } | 23 } |
35 | 24 |
36 DOMStorageMap::~DOMStorageMap() {} | 25 DOMStorageMap::~DOMStorageMap() {} |
37 | 26 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 copy->bytes_used_ = bytes_used_; | 101 copy->bytes_used_ = bytes_used_; |
113 copy->ResetKeyIterator(); | 102 copy->ResetKeyIterator(); |
114 return copy; | 103 return copy; |
115 } | 104 } |
116 | 105 |
117 void DOMStorageMap::ResetKeyIterator() { | 106 void DOMStorageMap::ResetKeyIterator() { |
118 key_iterator_ = values_.begin(); | 107 key_iterator_ = values_.begin(); |
119 last_key_index_ = 0; | 108 last_key_index_ = 0; |
120 } | 109 } |
121 | 110 |
| 111 size_t DOMStorageMap::CountBytes(const DOMStorageValuesMap& values) { |
| 112 if (values.empty()) |
| 113 return 0; |
| 114 |
| 115 size_t count = 0; |
| 116 for (const auto& pair : values) |
| 117 count += size_of_item(pair.first, pair.second.string()); |
| 118 return count; |
| 119 } |
| 120 |
122 } // namespace content | 121 } // namespace content |
OLD | NEW |