OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_ | 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_ |
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_ | 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_ |
7 | 7 |
8 #include <vector> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
16 #include "content/common/indexed_db/indexed_db_key.h" | 16 #include "content/common/indexed_db/indexed_db_key.h" |
17 #include "content/common/indexed_db/indexed_db_key_path.h" | 17 #include "content/common/indexed_db/indexed_db_key_path.h" |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
21 class LevelDBSlice; | |
22 | |
23 CONTENT_EXPORT extern const unsigned char kMinimumIndexId; | 21 CONTENT_EXPORT extern const unsigned char kMinimumIndexId; |
24 | 22 |
25 CONTENT_EXPORT std::vector<char> MaxIDBKey(); | 23 CONTENT_EXPORT std::string MaxIDBKey(); |
26 CONTENT_EXPORT std::vector<char> MinIDBKey(); | 24 CONTENT_EXPORT std::string MinIDBKey(); |
27 | 25 |
28 CONTENT_EXPORT void EncodeByte(unsigned char value, std::vector<char>* into); | 26 CONTENT_EXPORT void EncodeByte(unsigned char value, std::string* into); |
29 CONTENT_EXPORT void EncodeBool(bool value, std::vector<char>* into); | 27 CONTENT_EXPORT void EncodeBool(bool value, std::string* into); |
30 CONTENT_EXPORT void EncodeInt(int64 value, std::vector<char>* into); | 28 CONTENT_EXPORT void EncodeInt(int64 value, std::string* into); |
31 CONTENT_EXPORT void EncodeVarInt(int64 value, std::vector<char>* into); | 29 CONTENT_EXPORT void EncodeVarInt(int64 value, std::string* into); |
32 CONTENT_EXPORT void EncodeString(const string16& value, | 30 CONTENT_EXPORT void EncodeString(const string16& value, std::string* into); |
33 std::vector<char>* into); | |
34 CONTENT_EXPORT void EncodeStringWithLength(const string16& value, | 31 CONTENT_EXPORT void EncodeStringWithLength(const string16& value, |
35 std::vector<char>* into); | 32 std::string* into); |
36 CONTENT_EXPORT void EncodeDouble(double value, std::vector<char>* into); | 33 CONTENT_EXPORT void EncodeDouble(double value, std::string* into); |
37 CONTENT_EXPORT void EncodeIDBKey(const IndexedDBKey& value, | 34 CONTENT_EXPORT void EncodeIDBKey(const IndexedDBKey& value, std::string* into); |
38 std::vector<char>* into); | |
39 CONTENT_EXPORT void EncodeIDBKeyPath(const IndexedDBKeyPath& value, | 35 CONTENT_EXPORT void EncodeIDBKeyPath(const IndexedDBKeyPath& value, |
40 std::vector<char>* into); | 36 std::string* into); |
41 | 37 |
42 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeByte(base::StringPiece* slice, | 38 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeByte(base::StringPiece* slice, |
43 unsigned char* value); | 39 unsigned char* value); |
44 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeBool(base::StringPiece* slice, | 40 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeBool(base::StringPiece* slice, |
45 bool* value); | 41 bool* value); |
46 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeInt(base::StringPiece* slice, | 42 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeInt(base::StringPiece* slice, |
47 int64* value); | 43 int64* value); |
48 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeVarInt(base::StringPiece* slice, | 44 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeVarInt(base::StringPiece* slice, |
49 int64* value); | 45 int64* value); |
50 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeString(base::StringPiece* slice, | 46 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeString(base::StringPiece* slice, |
51 string16* value); | 47 string16* value); |
52 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeStringWithLength( | 48 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeStringWithLength( |
53 base::StringPiece* slice, | 49 base::StringPiece* slice, |
54 string16* value); | 50 string16* value); |
55 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeDouble(base::StringPiece* slice, | 51 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeDouble(base::StringPiece* slice, |
56 double* value); | 52 double* value); |
57 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeIDBKey( | 53 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeIDBKey( |
58 base::StringPiece* slice, | 54 base::StringPiece* slice, |
59 scoped_ptr<IndexedDBKey>* value); | 55 scoped_ptr<IndexedDBKey>* value); |
60 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeIDBKeyPath( | 56 CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeIDBKeyPath( |
61 base::StringPiece* slice, | 57 base::StringPiece* slice, |
62 IndexedDBKeyPath* value); | 58 IndexedDBKeyPath* value); |
63 | 59 |
64 CONTENT_EXPORT int CompareEncodedStringsWithLength(base::StringPiece* slice1, | 60 CONTENT_EXPORT int CompareEncodedStringsWithLength(base::StringPiece* slice1, |
65 base::StringPiece* slice2, | 61 base::StringPiece* slice2, |
66 bool* ok); | 62 bool* ok); |
67 | 63 |
68 CONTENT_EXPORT WARN_UNUSED_RESULT bool ExtractEncodedIDBKey( | 64 CONTENT_EXPORT WARN_UNUSED_RESULT bool ExtractEncodedIDBKey( |
69 base::StringPiece* slice, | 65 base::StringPiece* slice, |
70 std::vector<char>* result); | 66 std::string* result); |
71 | 67 |
72 CONTENT_EXPORT int CompareEncodedIDBKeys(const std::vector<char>& a, | 68 CONTENT_EXPORT int CompareEncodedIDBKeys(const std::string& a, |
73 const std::vector<char>& b, | 69 const std::string& b, |
74 bool* ok); | 70 bool* ok); |
75 | 71 |
76 CONTENT_EXPORT int Compare(const LevelDBSlice& a, | 72 CONTENT_EXPORT int Compare(const base::StringPiece& a, |
77 const LevelDBSlice& b, | 73 const base::StringPiece& b, |
78 bool index_keys); | 74 bool index_keys); |
79 | 75 |
80 class KeyPrefix { | 76 class KeyPrefix { |
81 public: | 77 public: |
82 KeyPrefix(); | 78 KeyPrefix(); |
83 explicit KeyPrefix(int64 database_id); | 79 explicit KeyPrefix(int64 database_id); |
84 KeyPrefix(int64 database_id, int64 object_store_id); | 80 KeyPrefix(int64 database_id, int64 object_store_id); |
85 KeyPrefix(int64 database_id, int64 object_store_id, int64 index_id); | 81 KeyPrefix(int64 database_id, int64 object_store_id, int64 index_id); |
86 static KeyPrefix CreateWithSpecialIndex(int64 database_id, | 82 static KeyPrefix CreateWithSpecialIndex(int64 database_id, |
87 int64 object_store_id, | 83 int64 object_store_id, |
88 int64 index_id); | 84 int64 index_id); |
89 | 85 |
90 static const char* Decode(const char* start, | 86 static const char* Decode(const char* start, |
91 const char* limit, | 87 const char* limit, |
92 KeyPrefix* result); | 88 KeyPrefix* result); |
93 std::vector<char> Encode() const; | 89 std::string Encode() const; |
94 static std::vector<char> EncodeEmpty(); | 90 static std::string EncodeEmpty(); |
95 int Compare(const KeyPrefix& other) const; | 91 int Compare(const KeyPrefix& other) const; |
96 | 92 |
97 enum Type { | 93 enum Type { |
98 GLOBAL_METADATA, | 94 GLOBAL_METADATA, |
99 DATABASE_METADATA, | 95 DATABASE_METADATA, |
100 OBJECT_STORE_DATA, | 96 OBJECT_STORE_DATA, |
101 EXISTS_ENTRY, | 97 EXISTS_ENTRY, |
102 INDEX_DATA, | 98 INDEX_DATA, |
103 INVALID_TYPE | 99 INVALID_TYPE |
104 }; | 100 }; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 138 |
143 Type type() const; | 139 Type type() const; |
144 | 140 |
145 int64 database_id_; | 141 int64 database_id_; |
146 int64 object_store_id_; | 142 int64 object_store_id_; |
147 int64 index_id_; | 143 int64 index_id_; |
148 | 144 |
149 static const int64 kInvalidId = -1; | 145 static const int64 kInvalidId = -1; |
150 | 146 |
151 private: | 147 private: |
152 static std::vector<char> EncodeInternal(int64 database_id, | 148 static std::string EncodeInternal(int64 database_id, |
153 int64 object_store_id, | 149 int64 object_store_id, |
154 int64 index_id); | 150 int64 index_id); |
155 // Special constructor for CreateWithSpecialIndex() | 151 // Special constructor for CreateWithSpecialIndex() |
156 KeyPrefix(enum Type, | 152 KeyPrefix(enum Type, |
157 int64 database_id, | 153 int64 database_id, |
158 int64 object_store_id, | 154 int64 object_store_id, |
159 int64 index_id); | 155 int64 index_id); |
160 }; | 156 }; |
161 | 157 |
162 class SchemaVersionKey { | 158 class SchemaVersionKey { |
163 public: | 159 public: |
164 CONTENT_EXPORT static std::vector<char> Encode(); | 160 CONTENT_EXPORT static std::string Encode(); |
165 }; | 161 }; |
166 | 162 |
167 class MaxDatabaseIdKey { | 163 class MaxDatabaseIdKey { |
168 public: | 164 public: |
169 CONTENT_EXPORT static std::vector<char> Encode(); | 165 CONTENT_EXPORT static std::string Encode(); |
170 }; | 166 }; |
171 | 167 |
172 class DataVersionKey { | 168 class DataVersionKey { |
173 public: | 169 public: |
174 static std::vector<char> Encode(); | 170 static std::string Encode(); |
175 }; | 171 }; |
176 | 172 |
177 class DatabaseFreeListKey { | 173 class DatabaseFreeListKey { |
178 public: | 174 public: |
179 DatabaseFreeListKey(); | 175 DatabaseFreeListKey(); |
180 static const char* Decode(const char* start, | 176 static const char* Decode(const char* start, |
181 const char* limit, | 177 const char* limit, |
182 DatabaseFreeListKey* result); | 178 DatabaseFreeListKey* result); |
183 CONTENT_EXPORT static std::vector<char> Encode(int64 database_id); | 179 CONTENT_EXPORT static std::string Encode(int64 database_id); |
184 static CONTENT_EXPORT std::vector<char> EncodeMaxKey(); | 180 static CONTENT_EXPORT std::string EncodeMaxKey(); |
185 int64 DatabaseId() const; | 181 int64 DatabaseId() const; |
186 int Compare(const DatabaseFreeListKey& other) const; | 182 int Compare(const DatabaseFreeListKey& other) const; |
187 | 183 |
188 private: | 184 private: |
189 int64 database_id_; | 185 int64 database_id_; |
190 }; | 186 }; |
191 | 187 |
192 class DatabaseNameKey { | 188 class DatabaseNameKey { |
193 public: | 189 public: |
194 static const char* Decode(const char* start, | 190 static const char* Decode(const char* start, |
195 const char* limit, | 191 const char* limit, |
196 DatabaseNameKey* result); | 192 DatabaseNameKey* result); |
197 CONTENT_EXPORT static std::vector<char> Encode( | 193 CONTENT_EXPORT static std::string Encode(const std::string& origin_identifier, |
198 const std::string& origin_identifier, | 194 const string16& database_name); |
199 const string16& database_name); | 195 static std::string EncodeMinKeyForOrigin( |
200 static std::vector<char> EncodeMinKeyForOrigin( | |
201 const std::string& origin_identifier); | 196 const std::string& origin_identifier); |
202 static std::vector<char> EncodeStopKeyForOrigin( | 197 static std::string EncodeStopKeyForOrigin( |
203 const std::string& origin_identifier); | 198 const std::string& origin_identifier); |
204 string16 origin() const { return origin_; } | 199 string16 origin() const { return origin_; } |
205 string16 database_name() const { return database_name_; } | 200 string16 database_name() const { return database_name_; } |
206 int Compare(const DatabaseNameKey& other); | 201 int Compare(const DatabaseNameKey& other); |
207 | 202 |
208 private: | 203 private: |
209 string16 origin_; // TODO(jsbell): Store encoded strings, or just pointers. | 204 string16 origin_; // TODO(jsbell): Store encoded strings, or just pointers. |
210 string16 database_name_; | 205 string16 database_name_; |
211 }; | 206 }; |
212 | 207 |
213 class DatabaseMetaDataKey { | 208 class DatabaseMetaDataKey { |
214 public: | 209 public: |
215 enum MetaDataType { | 210 enum MetaDataType { |
216 ORIGIN_NAME = 0, | 211 ORIGIN_NAME = 0, |
217 DATABASE_NAME = 1, | 212 DATABASE_NAME = 1, |
218 USER_VERSION = 2, | 213 USER_VERSION = 2, |
219 MAX_OBJECT_STORE_ID = 3, | 214 MAX_OBJECT_STORE_ID = 3, |
220 USER_INT_VERSION = 4, | 215 USER_INT_VERSION = 4, |
221 MAX_SIMPLE_METADATA_TYPE = 5 | 216 MAX_SIMPLE_METADATA_TYPE = 5 |
222 }; | 217 }; |
223 | 218 |
224 CONTENT_EXPORT static std::vector<char> Encode(int64 database_id, | 219 CONTENT_EXPORT static std::string Encode(int64 database_id, |
225 MetaDataType type); | 220 MetaDataType type); |
226 }; | 221 }; |
227 | 222 |
228 class ObjectStoreMetaDataKey { | 223 class ObjectStoreMetaDataKey { |
229 public: | 224 public: |
230 enum MetaDataType { | 225 enum MetaDataType { |
231 NAME = 0, | 226 NAME = 0, |
232 KEY_PATH = 1, | 227 KEY_PATH = 1, |
233 AUTO_INCREMENT = 2, | 228 AUTO_INCREMENT = 2, |
234 EVICTABLE = 3, | 229 EVICTABLE = 3, |
235 LAST_VERSION = 4, | 230 LAST_VERSION = 4, |
236 MAX_INDEX_ID = 5, | 231 MAX_INDEX_ID = 5, |
237 HAS_KEY_PATH = 6, | 232 HAS_KEY_PATH = 6, |
238 KEY_GENERATOR_CURRENT_NUMBER = 7 | 233 KEY_GENERATOR_CURRENT_NUMBER = 7 |
239 }; | 234 }; |
240 | 235 |
241 ObjectStoreMetaDataKey(); | 236 ObjectStoreMetaDataKey(); |
242 static const char* Decode(const char* start, | 237 static const char* Decode(const char* start, |
243 const char* limit, | 238 const char* limit, |
244 ObjectStoreMetaDataKey* result); | 239 ObjectStoreMetaDataKey* result); |
245 CONTENT_EXPORT static std::vector<char> Encode(int64 database_id, | 240 CONTENT_EXPORT static std::string Encode(int64 database_id, |
246 int64 object_store_id, | 241 int64 object_store_id, |
247 unsigned char meta_data_type); | 242 unsigned char meta_data_type); |
248 CONTENT_EXPORT static std::vector<char> EncodeMaxKey(int64 database_id); | 243 CONTENT_EXPORT static std::string EncodeMaxKey(int64 database_id); |
249 CONTENT_EXPORT static std::vector<char> EncodeMaxKey(int64 database_id, | 244 CONTENT_EXPORT static std::string EncodeMaxKey(int64 database_id, |
250 int64 object_store_id); | 245 int64 object_store_id); |
251 int64 ObjectStoreId() const; | 246 int64 ObjectStoreId() const; |
252 unsigned char MetaDataType() const; | 247 unsigned char MetaDataType() const; |
253 int Compare(const ObjectStoreMetaDataKey& other); | 248 int Compare(const ObjectStoreMetaDataKey& other); |
254 | 249 |
255 private: | 250 private: |
256 int64 object_store_id_; | 251 int64 object_store_id_; |
257 unsigned char meta_data_type_; | 252 unsigned char meta_data_type_; |
258 }; | 253 }; |
259 | 254 |
260 class IndexMetaDataKey { | 255 class IndexMetaDataKey { |
261 public: | 256 public: |
262 enum MetaDataType { | 257 enum MetaDataType { |
263 NAME = 0, | 258 NAME = 0, |
264 UNIQUE = 1, | 259 UNIQUE = 1, |
265 KEY_PATH = 2, | 260 KEY_PATH = 2, |
266 MULTI_ENTRY = 3 | 261 MULTI_ENTRY = 3 |
267 }; | 262 }; |
268 | 263 |
269 IndexMetaDataKey(); | 264 IndexMetaDataKey(); |
270 static const char* Decode(const char* start, | 265 static const char* Decode(const char* start, |
271 const char* limit, | 266 const char* limit, |
272 IndexMetaDataKey* result); | 267 IndexMetaDataKey* result); |
273 CONTENT_EXPORT static std::vector<char> Encode(int64 database_id, | 268 CONTENT_EXPORT static std::string Encode(int64 database_id, |
| 269 int64 object_store_id, |
| 270 int64 index_id, |
| 271 unsigned char meta_data_type); |
| 272 CONTENT_EXPORT static std::string EncodeMaxKey(int64 database_id, |
| 273 int64 object_store_id); |
| 274 CONTENT_EXPORT static std::string EncodeMaxKey(int64 database_id, |
274 int64 object_store_id, | 275 int64 object_store_id, |
275 int64 index_id, | 276 int64 index_id); |
276 unsigned char meta_data_type); | |
277 CONTENT_EXPORT static std::vector<char> EncodeMaxKey(int64 database_id, | |
278 int64 object_store_id); | |
279 CONTENT_EXPORT static std::vector<char> EncodeMaxKey(int64 database_id, | |
280 int64 object_store_id, | |
281 int64 index_id); | |
282 int Compare(const IndexMetaDataKey& other); | 277 int Compare(const IndexMetaDataKey& other); |
283 int64 IndexId() const; | 278 int64 IndexId() const; |
284 unsigned char meta_data_type() const { return meta_data_type_; } | 279 unsigned char meta_data_type() const { return meta_data_type_; } |
285 | 280 |
286 private: | 281 private: |
287 int64 object_store_id_; | 282 int64 object_store_id_; |
288 int64 index_id_; | 283 int64 index_id_; |
289 unsigned char meta_data_type_; | 284 unsigned char meta_data_type_; |
290 }; | 285 }; |
291 | 286 |
292 class ObjectStoreFreeListKey { | 287 class ObjectStoreFreeListKey { |
293 public: | 288 public: |
294 ObjectStoreFreeListKey(); | 289 ObjectStoreFreeListKey(); |
295 static const char* Decode(const char* start, | 290 static const char* Decode(const char* start, |
296 const char* limit, | 291 const char* limit, |
297 ObjectStoreFreeListKey* result); | 292 ObjectStoreFreeListKey* result); |
298 CONTENT_EXPORT static std::vector<char> Encode(int64 database_id, | 293 CONTENT_EXPORT static std::string Encode(int64 database_id, |
299 int64 object_store_id); | 294 int64 object_store_id); |
300 CONTENT_EXPORT static std::vector<char> EncodeMaxKey(int64 database_id); | 295 CONTENT_EXPORT static std::string EncodeMaxKey(int64 database_id); |
301 int64 ObjectStoreId() const; | 296 int64 ObjectStoreId() const; |
302 int Compare(const ObjectStoreFreeListKey& other); | 297 int Compare(const ObjectStoreFreeListKey& other); |
303 | 298 |
304 private: | 299 private: |
305 int64 object_store_id_; | 300 int64 object_store_id_; |
306 }; | 301 }; |
307 | 302 |
308 class IndexFreeListKey { | 303 class IndexFreeListKey { |
309 public: | 304 public: |
310 IndexFreeListKey(); | 305 IndexFreeListKey(); |
311 static const char* Decode(const char* start, | 306 static const char* Decode(const char* start, |
312 const char* limit, | 307 const char* limit, |
313 IndexFreeListKey* result); | 308 IndexFreeListKey* result); |
314 CONTENT_EXPORT static std::vector<char> Encode(int64 database_id, | 309 CONTENT_EXPORT static std::string Encode(int64 database_id, |
315 int64 object_store_id, | 310 int64 object_store_id, |
316 int64 index_id); | 311 int64 index_id); |
317 CONTENT_EXPORT static std::vector<char> EncodeMaxKey(int64 database_id, | 312 CONTENT_EXPORT static std::string EncodeMaxKey(int64 database_id, |
318 int64 object_store_id); | 313 int64 object_store_id); |
319 int Compare(const IndexFreeListKey& other); | 314 int Compare(const IndexFreeListKey& other); |
320 int64 ObjectStoreId() const; | 315 int64 ObjectStoreId() const; |
321 int64 IndexId() const; | 316 int64 IndexId() const; |
322 | 317 |
323 private: | 318 private: |
324 int64 object_store_id_; | 319 int64 object_store_id_; |
325 int64 index_id_; | 320 int64 index_id_; |
326 }; | 321 }; |
327 | 322 |
328 class ObjectStoreNamesKey { | 323 class ObjectStoreNamesKey { |
329 public: | 324 public: |
330 // TODO(jsbell): We never use this to look up object store ids, | 325 // TODO(jsbell): We never use this to look up object store ids, |
331 // because a mapping is kept in the IndexedDBDatabase. Can the | 326 // because a mapping is kept in the IndexedDBDatabase. Can the |
332 // mapping become unreliable? Can we remove this? | 327 // mapping become unreliable? Can we remove this? |
333 static const char* Decode(const char* start, | 328 static const char* Decode(const char* start, |
334 const char* limit, | 329 const char* limit, |
335 ObjectStoreNamesKey* result); | 330 ObjectStoreNamesKey* result); |
336 CONTENT_EXPORT static std::vector<char> Encode( | 331 CONTENT_EXPORT static std::string Encode(int64 database_id, |
337 int64 database_id, | 332 const string16& object_store_name); |
338 const string16& object_store_name); | |
339 int Compare(const ObjectStoreNamesKey& other); | 333 int Compare(const ObjectStoreNamesKey& other); |
340 string16 object_store_name() const { return object_store_name_; } | 334 string16 object_store_name() const { return object_store_name_; } |
341 | 335 |
342 private: | 336 private: |
343 // TODO(jsbell): Store the encoded string, or just pointers to it. | 337 // TODO(jsbell): Store the encoded string, or just pointers to it. |
344 string16 object_store_name_; | 338 string16 object_store_name_; |
345 }; | 339 }; |
346 | 340 |
347 class IndexNamesKey { | 341 class IndexNamesKey { |
348 public: | 342 public: |
349 IndexNamesKey(); | 343 IndexNamesKey(); |
350 // TODO(jsbell): We never use this to look up index ids, because a mapping | 344 // TODO(jsbell): We never use this to look up index ids, because a mapping |
351 // is kept at a higher level. | 345 // is kept at a higher level. |
352 static const char* Decode(const char* start, | 346 static const char* Decode(const char* start, |
353 const char* limit, | 347 const char* limit, |
354 IndexNamesKey* result); | 348 IndexNamesKey* result); |
355 CONTENT_EXPORT static std::vector<char> Encode(int64 database_id, | 349 CONTENT_EXPORT static std::string Encode(int64 database_id, |
356 int64 object_store_id, | 350 int64 object_store_id, |
357 const string16& index_name); | 351 const string16& index_name); |
358 int Compare(const IndexNamesKey& other); | 352 int Compare(const IndexNamesKey& other); |
359 string16 index_name() const { return index_name_; } | 353 string16 index_name() const { return index_name_; } |
360 | 354 |
361 private: | 355 private: |
362 int64 object_store_id_; | 356 int64 object_store_id_; |
363 string16 index_name_; | 357 string16 index_name_; |
364 }; | 358 }; |
365 | 359 |
366 class ObjectStoreDataKey { | 360 class ObjectStoreDataKey { |
367 public: | 361 public: |
368 static const char* Decode(const char* start, | 362 static const char* Decode(const char* start, |
369 const char* end, | 363 const char* end, |
370 ObjectStoreDataKey* result); | 364 ObjectStoreDataKey* result); |
371 CONTENT_EXPORT static std::vector<char> Encode( | 365 CONTENT_EXPORT static std::string Encode(int64 database_id, |
372 int64 database_id, | 366 int64 object_store_id, |
373 int64 object_store_id, | 367 const std::string encoded_user_key); |
374 const std::vector<char> encoded_user_key); | 368 static std::string Encode(int64 database_id, |
375 static std::vector<char> Encode(int64 database_id, | 369 int64 object_store_id, |
376 int64 object_store_id, | 370 const IndexedDBKey& user_key); |
377 const IndexedDBKey& user_key); | |
378 int Compare(const ObjectStoreDataKey& other, bool* ok); | 371 int Compare(const ObjectStoreDataKey& other, bool* ok); |
379 scoped_ptr<IndexedDBKey> user_key() const; | 372 scoped_ptr<IndexedDBKey> user_key() const; |
380 static const int64 kSpecialIndexNumber; | 373 static const int64 kSpecialIndexNumber; |
381 ObjectStoreDataKey(); | 374 ObjectStoreDataKey(); |
382 ~ObjectStoreDataKey(); | 375 ~ObjectStoreDataKey(); |
383 | 376 |
384 private: | 377 private: |
385 std::vector<char> encoded_user_key_; | 378 std::string encoded_user_key_; |
386 }; | 379 }; |
387 | 380 |
388 class ExistsEntryKey { | 381 class ExistsEntryKey { |
389 public: | 382 public: |
390 ExistsEntryKey(); | 383 ExistsEntryKey(); |
391 ~ExistsEntryKey(); | 384 ~ExistsEntryKey(); |
392 | 385 |
393 static const char* Decode(const char* start, | 386 static const char* Decode(const char* start, |
394 const char* end, | 387 const char* end, |
395 ExistsEntryKey* result); | 388 ExistsEntryKey* result); |
396 CONTENT_EXPORT static std::vector<char> Encode( | 389 CONTENT_EXPORT static std::string Encode(int64 database_id, |
397 int64 database_id, | 390 int64 object_store_id, |
398 int64 object_store_id, | 391 const std::string& encoded_key); |
399 const std::vector<char>& encoded_key); | 392 static std::string Encode(int64 database_id, |
400 static std::vector<char> Encode(int64 database_id, | 393 int64 object_store_id, |
401 int64 object_store_id, | 394 const IndexedDBKey& user_key); |
402 const IndexedDBKey& user_key); | |
403 int Compare(const ExistsEntryKey& other, bool* ok); | 395 int Compare(const ExistsEntryKey& other, bool* ok); |
404 scoped_ptr<IndexedDBKey> user_key() const; | 396 scoped_ptr<IndexedDBKey> user_key() const; |
405 | 397 |
406 static const int64 kSpecialIndexNumber; | 398 static const int64 kSpecialIndexNumber; |
407 | 399 |
408 private: | 400 private: |
409 std::vector<char> encoded_user_key_; | 401 std::string encoded_user_key_; |
410 DISALLOW_COPY_AND_ASSIGN(ExistsEntryKey); | 402 DISALLOW_COPY_AND_ASSIGN(ExistsEntryKey); |
411 }; | 403 }; |
412 | 404 |
413 class IndexDataKey { | 405 class IndexDataKey { |
414 public: | 406 public: |
415 IndexDataKey(); | 407 IndexDataKey(); |
416 ~IndexDataKey(); | 408 ~IndexDataKey(); |
417 static const char* Decode(const char* start, | 409 static const char* Decode(const char* start, |
418 const char* limit, | 410 const char* limit, |
419 IndexDataKey* result); | 411 IndexDataKey* result); |
420 CONTENT_EXPORT static std::vector<char> Encode( | 412 CONTENT_EXPORT static std::string Encode( |
421 int64 database_id, | 413 int64 database_id, |
422 int64 object_store_id, | 414 int64 object_store_id, |
423 int64 index_id, | 415 int64 index_id, |
424 const std::vector<char>& encoded_user_key, | 416 const std::string& encoded_user_key, |
425 const std::vector<char>& encoded_primary_key, | 417 const std::string& encoded_primary_key, |
426 int64 sequence_number); | 418 int64 sequence_number); |
427 static std::vector<char> Encode(int64 database_id, | 419 static std::string Encode(int64 database_id, |
| 420 int64 object_store_id, |
| 421 int64 index_id, |
| 422 const IndexedDBKey& user_key); |
| 423 static std::string EncodeMinKey(int64 database_id, |
428 int64 object_store_id, | 424 int64 object_store_id, |
429 int64 index_id, | 425 int64 index_id); |
430 const IndexedDBKey& user_key); | 426 CONTENT_EXPORT static std::string EncodeMaxKey(int64 database_id, |
431 static std::vector<char> EncodeMinKey(int64 database_id, | 427 int64 object_store_id, |
432 int64 object_store_id, | 428 int64 index_id); |
433 int64 index_id); | |
434 CONTENT_EXPORT static std::vector<char> EncodeMaxKey(int64 database_id, | |
435 int64 object_store_id, | |
436 int64 index_id); | |
437 int Compare(const IndexDataKey& other, bool ignore_duplicates, bool* ok); | 429 int Compare(const IndexDataKey& other, bool ignore_duplicates, bool* ok); |
438 int64 DatabaseId() const; | 430 int64 DatabaseId() const; |
439 int64 ObjectStoreId() const; | 431 int64 ObjectStoreId() const; |
440 int64 IndexId() const; | 432 int64 IndexId() const; |
441 scoped_ptr<IndexedDBKey> user_key() const; | 433 scoped_ptr<IndexedDBKey> user_key() const; |
442 scoped_ptr<IndexedDBKey> primary_key() const; | 434 scoped_ptr<IndexedDBKey> primary_key() const; |
443 | 435 |
444 private: | 436 private: |
445 int64 database_id_; | 437 int64 database_id_; |
446 int64 object_store_id_; | 438 int64 object_store_id_; |
447 int64 index_id_; | 439 int64 index_id_; |
448 std::vector<char> encoded_user_key_; | 440 std::string encoded_user_key_; |
449 std::vector<char> encoded_primary_key_; | 441 std::string encoded_primary_key_; |
450 int64 sequence_number_; | 442 int64 sequence_number_; |
451 | 443 |
452 DISALLOW_COPY_AND_ASSIGN(IndexDataKey); | 444 DISALLOW_COPY_AND_ASSIGN(IndexDataKey); |
453 }; | 445 }; |
454 | 446 |
455 } // namespace content | 447 } // namespace content |
456 | 448 |
457 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_ | 449 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_ |
OLD | NEW |