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 #include "content/common/indexed_db/indexed_db_key.h" | 5 #include "content/common/indexed_db/indexed_db_key.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include "base/logging.h" | |
9 | 8 |
10 namespace content { | 9 namespace content { |
11 | 10 |
12 using blink::WebIDBKey; | 11 using blink::WebIDBKey; |
13 using blink::WebIDBKeyType; | 12 using blink::WebIDBKeyType; |
14 using blink::WebIDBKeyTypeArray; | 13 using blink::WebIDBKeyTypeArray; |
15 using blink::WebIDBKeyTypeBinary; | 14 using blink::WebIDBKeyTypeBinary; |
16 using blink::WebIDBKeyTypeDate; | 15 using blink::WebIDBKeyTypeDate; |
17 using blink::WebIDBKeyTypeInvalid; | 16 using blink::WebIDBKeyTypeInvalid; |
18 using blink::WebIDBKeyTypeMin; | 17 using blink::WebIDBKeyTypeMin; |
(...skipping 30 matching lines...) Expand all Loading... |
49 for (size_t i = 0; i < array.size(); ++i) { | 48 for (size_t i = 0; i < array.size(); ++i) { |
50 result.push_back(IndexedDBKey(array[i])); | 49 result.push_back(IndexedDBKey(array[i])); |
51 } | 50 } |
52 return result; | 51 return result; |
53 } | 52 } |
54 | 53 |
55 } // namespace | 54 } // namespace |
56 | 55 |
57 IndexedDBKey::IndexedDBKey() | 56 IndexedDBKey::IndexedDBKey() |
58 : type_(WebIDBKeyTypeNull), | 57 : type_(WebIDBKeyTypeNull), |
59 date_(0), | |
60 number_(0), | |
61 size_estimate_(kOverheadSize) {} | 58 size_estimate_(kOverheadSize) {} |
62 | 59 |
63 IndexedDBKey::IndexedDBKey(WebIDBKeyType type) | 60 IndexedDBKey::IndexedDBKey(WebIDBKeyType type) |
64 : type_(type), date_(0), number_(0), size_estimate_(kOverheadSize) { | 61 : type_(type), size_estimate_(kOverheadSize) { |
65 DCHECK(type == WebIDBKeyTypeNull || type == WebIDBKeyTypeInvalid); | 62 DCHECK(type == WebIDBKeyTypeNull || type == WebIDBKeyTypeInvalid); |
66 } | 63 } |
67 | 64 |
68 IndexedDBKey::IndexedDBKey(double number, WebIDBKeyType type) | 65 IndexedDBKey::IndexedDBKey(double number, WebIDBKeyType type) |
69 : type_(type), | 66 : type_(type), |
70 date_(number), | |
71 number_(number), | 67 number_(number), |
72 size_estimate_(kOverheadSize + sizeof(number)) { | 68 size_estimate_(kOverheadSize + sizeof(number)) { |
73 DCHECK(type == WebIDBKeyTypeNumber || type == WebIDBKeyTypeDate); | 69 DCHECK(type == WebIDBKeyTypeNumber || type == WebIDBKeyTypeDate); |
74 } | 70 } |
75 | 71 |
76 IndexedDBKey::IndexedDBKey(const KeyArray& array) | 72 IndexedDBKey::IndexedDBKey(const KeyArray& array) |
77 : type_(WebIDBKeyTypeArray), | 73 : type_(WebIDBKeyTypeArray), |
78 array_(CopyKeyArray(array)), | 74 array_(CopyKeyArray(array)), |
79 date_(0), | |
80 number_(0), | |
81 size_estimate_(kOverheadSize + CalculateArraySize(array)) {} | 75 size_estimate_(kOverheadSize + CalculateArraySize(array)) {} |
82 | 76 |
83 IndexedDBKey::IndexedDBKey(const std::string& binary) | 77 IndexedDBKey::IndexedDBKey(const std::string& binary) |
84 : type_(WebIDBKeyTypeBinary), | 78 : type_(WebIDBKeyTypeBinary), |
85 binary_(binary), | 79 binary_(binary), |
86 size_estimate_(kOverheadSize + | 80 size_estimate_(kOverheadSize + |
87 (binary.length() * sizeof(std::string::value_type))) {} | 81 (binary.length() * sizeof(std::string::value_type))) {} |
88 | 82 |
89 IndexedDBKey::IndexedDBKey(const base::string16& string) | 83 IndexedDBKey::IndexedDBKey(const base::string16& string) |
90 : type_(WebIDBKeyTypeString), | 84 : type_(WebIDBKeyTypeString), |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 int result = array_[i].CompareTo(other.array_[i]); | 124 int result = array_[i].CompareTo(other.array_[i]); |
131 if (result != 0) | 125 if (result != 0) |
132 return result; | 126 return result; |
133 } | 127 } |
134 return Compare(array_.size(), other.array_.size()); | 128 return Compare(array_.size(), other.array_.size()); |
135 case WebIDBKeyTypeBinary: | 129 case WebIDBKeyTypeBinary: |
136 return binary_.compare(other.binary_); | 130 return binary_.compare(other.binary_); |
137 case WebIDBKeyTypeString: | 131 case WebIDBKeyTypeString: |
138 return string_.compare(other.string_); | 132 return string_.compare(other.string_); |
139 case WebIDBKeyTypeDate: | 133 case WebIDBKeyTypeDate: |
140 return Compare(date_, other.date_); | |
141 case WebIDBKeyTypeNumber: | 134 case WebIDBKeyTypeNumber: |
142 return Compare(number_, other.number_); | 135 return Compare(number_, other.number_); |
143 case WebIDBKeyTypeInvalid: | 136 case WebIDBKeyTypeInvalid: |
144 case WebIDBKeyTypeNull: | 137 case WebIDBKeyTypeNull: |
145 case WebIDBKeyTypeMin: | 138 case WebIDBKeyTypeMin: |
146 default: | 139 default: |
147 NOTREACHED(); | 140 NOTREACHED(); |
148 return 0; | 141 return 0; |
149 } | 142 } |
150 } | 143 } |
151 | 144 |
152 } // namespace content | 145 } // namespace content |
OLD | NEW |