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