Chromium Code Reviews| 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 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" | 5 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 // Strings (origins, names, etc) are encoded as UTF-16BE. | 37 // Strings (origins, names, etc) are encoded as UTF-16BE. |
| 38 // | 38 // |
| 39 // | 39 // |
| 40 // Global metadata | 40 // Global metadata |
| 41 // --------------- | 41 // --------------- |
| 42 // The prefix is <0, 0, 0>, followed by a metadata type byte: | 42 // The prefix is <0, 0, 0>, followed by a metadata type byte: |
| 43 // | 43 // |
| 44 // <0, 0, 0, 0> => backing store schema version [SchemaVersionKey] | 44 // <0, 0, 0, 0> => backing store schema version [SchemaVersionKey] |
| 45 // <0, 0, 0, 1> => maximum allocated database [MaxDatabaseIdKey] | 45 // <0, 0, 0, 1> => maximum allocated database [MaxDatabaseIdKey] |
| 46 // <0, 0, 0, 2> => SerializedScriptValue version [DataVersionKey] | 46 // <0, 0, 0, 2> => SerializedScriptValue version [DataVersionKey] |
| 47 // <0, 0, 0, 3> | |
| 48 // => Blob journal | |
| 49 // The format of the journal is: {database_id, blobKey}*. | |
| 50 // If the blobKey is AllBlobsKey, the whole database should be deleted. | |
| 51 // [BlobJournalKey] | |
| 52 // <0, 0, 0, 4> => Live blob journal; same format. [LiveBlobJournalKey] | |
| 47 // <0, 0, 0, 100, database id> | 53 // <0, 0, 0, 100, database id> |
| 48 // => Existence implies the database id is in the free list | 54 // => Existence implies the database id is in the free list |
| 49 // [DatabaseFreeListKey] | 55 // [DatabaseFreeListKey] |
| 50 // <0, 0, 0, 201, origin, database name> => Database id [DatabaseNameKey] | 56 // <0, 0, 0, 201, origin, database name> => Database id [DatabaseNameKey] |
| 51 // | 57 // |
| 52 // | 58 // |
| 53 // Database metadata: [DatabaseMetaDataKey] | 59 // Database metadata: [DatabaseMetaDataKey] |
| 54 // ---------------------------------------- | 60 // ---------------------------------------- |
| 55 // The prefix is <database id, 0, 0> followed by a metadata type byte: | 61 // The prefix is <database id, 0, 0> followed by a metadata type byte: |
| 56 // | 62 // |
| 57 // <database id, 0, 0, 0> => origin name | 63 // <database id, 0, 0, 0> => origin name |
| 58 // <database id, 0, 0, 1> => database name | 64 // <database id, 0, 0, 1> => database name |
| 59 // <database id, 0, 0, 2> => IDB string version data (obsolete) | 65 // <database id, 0, 0, 2> => IDB string version data (obsolete) |
| 60 // <database id, 0, 0, 3> => maximum allocated object store id | 66 // <database id, 0, 0, 3> => maximum allocated object store id |
| 61 // <database id, 0, 0, 4> => IDB integer version (var int) | 67 // <database id, 0, 0, 4> => IDB integer version (var int) |
| 68 // <database id, 0, 0, 5> => blob key generator current number | |
| 62 // | 69 // |
| 63 // | 70 // |
| 64 // Object store metadata: [ObjectStoreMetaDataKey] | 71 // Object store metadata: [ObjectStoreMetaDataKey] |
| 65 // ----------------------------------------------- | 72 // ----------------------------------------------- |
| 66 // The prefix is <database id, 0, 0>, followed by a type byte (50), then the | 73 // The prefix is <database id, 0, 0>, followed by a type byte (50), then the |
| 67 // object store id (var int), then a metadata type byte. | 74 // object store id (var int), then a metadata type byte. |
| 68 // | 75 // |
| 69 // <database id, 0, 0, 50, object store id, 0> => object store name | 76 // <database id, 0, 0, 50, object store id, 0> => object store name |
| 70 // <database id, 0, 0, 50, object store id, 1> => key path | 77 // <database id, 0, 0, 50, object store id, 1> => key path |
| 71 // <database id, 0, 0, 50, object store id, 2> => auto increment flag | 78 // <database id, 0, 0, 50, object store id, 2> => auto increment flag |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 // => "version", serialized script value | 133 // => "version", serialized script value |
| 127 // | 134 // |
| 128 // | 135 // |
| 129 // "Exists" entry: [ExistsEntryKey] | 136 // "Exists" entry: [ExistsEntryKey] |
| 130 // -------------------------------- | 137 // -------------------------------- |
| 131 // The prefix is followed by a type byte and the encoded IDB primary key. | 138 // The prefix is followed by a type byte and the encoded IDB primary key. |
| 132 // | 139 // |
| 133 // <database id, object store id, 2, user key> => "version" | 140 // <database id, object store id, 2, user key> => "version" |
| 134 // | 141 // |
| 135 // | 142 // |
| 143 // Blob entry table: [BlobEntryKey] | |
| 144 // -------------------------------- | |
| 145 // | |
| 146 // The prefix is followed by a type byte and the encoded IDB primary key. | |
| 147 // | |
| 148 // <database id, object store id, 3, user key> => array of IndexedDBBlobInfo | |
| 149 // | |
| 150 // | |
| 136 // Index data | 151 // Index data |
| 137 // ---------- | 152 // ---------- |
| 138 // The prefix is followed by a type byte, the encoded IDB index key, a | 153 // The prefix is followed by a type byte, the encoded IDB index key, a |
| 139 // "sequence" number (obsolete; var int), and the encoded IDB primary key. | 154 // "sequence" number (obsolete; var int), and the encoded IDB primary key. |
| 140 // | 155 // |
| 141 // <database id, object store id, index id, index key, sequence number, | 156 // <database id, object store id, index id, index key, sequence number, |
| 142 // primary key> => "version", primary key [IndexDataKey] | 157 // primary key> => "version", primary key [IndexDataKey] |
| 143 // | 158 // |
| 144 // The sequence number is obsolete; it was used to allow two entries with the | 159 // The sequence number is obsolete; it was used to allow two entries with the |
| 145 // same user (index) key in non-unique indexes prior to the inclusion of the | 160 // same user (index) key in non-unique indexes prior to the inclusion of the |
| 146 // primary key in the data. | 161 // primary key in the data. |
| 147 | 162 |
| 148 | |
| 149 using base::StringPiece; | 163 using base::StringPiece; |
| 150 using blink::WebIDBKeyType; | 164 using blink::WebIDBKeyType; |
| 151 using blink::WebIDBKeyTypeArray; | 165 using blink::WebIDBKeyTypeArray; |
| 152 using blink::WebIDBKeyTypeBinary; | 166 using blink::WebIDBKeyTypeBinary; |
| 153 using blink::WebIDBKeyTypeDate; | 167 using blink::WebIDBKeyTypeDate; |
| 154 using blink::WebIDBKeyTypeInvalid; | 168 using blink::WebIDBKeyTypeInvalid; |
| 155 using blink::WebIDBKeyTypeMin; | 169 using blink::WebIDBKeyTypeMin; |
| 156 using blink::WebIDBKeyTypeNull; | 170 using blink::WebIDBKeyTypeNull; |
| 157 using blink::WebIDBKeyTypeNumber; | 171 using blink::WebIDBKeyTypeNumber; |
| 158 using blink::WebIDBKeyTypeString; | 172 using blink::WebIDBKeyTypeString; |
| 159 using blink::WebIDBKeyPathType; | 173 using blink::WebIDBKeyPathType; |
| 160 using blink::WebIDBKeyPathTypeArray; | 174 using blink::WebIDBKeyPathTypeArray; |
| 161 using blink::WebIDBKeyPathTypeNull; | 175 using blink::WebIDBKeyPathTypeNull; |
| 162 using blink::WebIDBKeyPathTypeString; | 176 using blink::WebIDBKeyPathTypeString; |
| 163 | 177 |
| 164 namespace content { | 178 namespace content { |
| 165 | 179 |
| 166 // As most of the IndexedDBKeys and encoded values are short, we | 180 // As most of the IndexedDBKeys and encoded values are short, we |
| 167 // initialize some Vectors with a default inline buffer size to reduce | 181 // initialize some std::vectors with a default inline buffer size to reduce |
| 168 // the memory re-allocations when the Vectors are appended. | 182 // the memory re-allocations when the std::vectors are appended. |
| 169 static const size_t kDefaultInlineBufferSize = 32; | 183 static const size_t kDefaultInlineBufferSize = 32; |
| 170 | 184 |
| 171 static const unsigned char kIndexedDBKeyNullTypeByte = 0; | 185 static const unsigned char kIndexedDBKeyNullTypeByte = 0; |
| 172 static const unsigned char kIndexedDBKeyStringTypeByte = 1; | 186 static const unsigned char kIndexedDBKeyStringTypeByte = 1; |
| 173 static const unsigned char kIndexedDBKeyDateTypeByte = 2; | 187 static const unsigned char kIndexedDBKeyDateTypeByte = 2; |
| 174 static const unsigned char kIndexedDBKeyNumberTypeByte = 3; | 188 static const unsigned char kIndexedDBKeyNumberTypeByte = 3; |
| 175 static const unsigned char kIndexedDBKeyArrayTypeByte = 4; | 189 static const unsigned char kIndexedDBKeyArrayTypeByte = 4; |
| 176 static const unsigned char kIndexedDBKeyMinKeyTypeByte = 5; | 190 static const unsigned char kIndexedDBKeyMinKeyTypeByte = 5; |
| 177 static const unsigned char kIndexedDBKeyBinaryTypeByte = 6; | 191 static const unsigned char kIndexedDBKeyBinaryTypeByte = 6; |
| 178 | 192 |
| 179 static const unsigned char kIndexedDBKeyPathTypeCodedByte1 = 0; | 193 static const unsigned char kIndexedDBKeyPathTypeCodedByte1 = 0; |
| 180 static const unsigned char kIndexedDBKeyPathTypeCodedByte2 = 0; | 194 static const unsigned char kIndexedDBKeyPathTypeCodedByte2 = 0; |
| 181 | 195 |
| 182 static const unsigned char kObjectStoreDataIndexId = 1; | 196 static const unsigned char kObjectStoreDataIndexId = 1; |
| 183 static const unsigned char kExistsEntryIndexId = 2; | 197 static const unsigned char kExistsEntryIndexId = 2; |
| 198 static const unsigned char kBlobEntryIndexId = 3; | |
| 184 | 199 |
| 185 static const unsigned char kSchemaVersionTypeByte = 0; | 200 static const unsigned char kSchemaVersionTypeByte = 0; |
| 186 static const unsigned char kMaxDatabaseIdTypeByte = 1; | 201 static const unsigned char kMaxDatabaseIdTypeByte = 1; |
| 187 static const unsigned char kDataVersionTypeByte = 2; | 202 static const unsigned char kDataVersionTypeByte = 2; |
| 203 static const unsigned char kBlobJournalTypeByte = 3; | |
| 204 static const unsigned char kLiveBlobJournalTypeByte = 4; | |
| 188 static const unsigned char kMaxSimpleGlobalMetaDataTypeByte = | 205 static const unsigned char kMaxSimpleGlobalMetaDataTypeByte = |
| 189 3; // Insert before this and increment. | 206 5; // Insert before this and increment. |
| 190 static const unsigned char kDatabaseFreeListTypeByte = 100; | 207 static const unsigned char kDatabaseFreeListTypeByte = 100; |
| 191 static const unsigned char kDatabaseNameTypeByte = 201; | 208 static const unsigned char kDatabaseNameTypeByte = 201; |
| 192 | 209 |
| 193 static const unsigned char kObjectStoreMetaDataTypeByte = 50; | 210 static const unsigned char kObjectStoreMetaDataTypeByte = 50; |
| 194 static const unsigned char kIndexMetaDataTypeByte = 100; | 211 static const unsigned char kIndexMetaDataTypeByte = 100; |
| 195 static const unsigned char kObjectStoreFreeListTypeByte = 150; | 212 static const unsigned char kObjectStoreFreeListTypeByte = 150; |
| 196 static const unsigned char kIndexFreeListTypeByte = 151; | 213 static const unsigned char kIndexFreeListTypeByte = 151; |
| 197 static const unsigned char kObjectStoreNamesTypeByte = 200; | 214 static const unsigned char kObjectStoreNamesTypeByte = 200; |
| 198 static const unsigned char kIndexNamesKeyTypeByte = 201; | 215 static const unsigned char kIndexNamesKeyTypeByte = 201; |
| 199 | 216 |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 882 | 899 |
| 883 template <> | 900 template <> |
| 884 int CompareSuffix<ObjectStoreDataKey>(StringPiece* slice_a, | 901 int CompareSuffix<ObjectStoreDataKey>(StringPiece* slice_a, |
| 885 StringPiece* slice_b, | 902 StringPiece* slice_b, |
| 886 bool only_compare_index_keys, | 903 bool only_compare_index_keys, |
| 887 bool* ok) { | 904 bool* ok) { |
| 888 return CompareEncodedIDBKeys(slice_a, slice_b, ok); | 905 return CompareEncodedIDBKeys(slice_a, slice_b, ok); |
| 889 } | 906 } |
| 890 | 907 |
| 891 template <> | 908 template <> |
| 909 int CompareSuffix<BlobEntryKey>(StringPiece* slice_a, | |
| 910 StringPiece* slice_b, | |
| 911 bool only_compare_index_keys, | |
| 912 bool* ok) { | |
| 913 return CompareEncodedIDBKeys(slice_a, slice_b, ok); | |
| 914 } | |
| 915 | |
| 916 template <> | |
| 892 int CompareSuffix<IndexDataKey>(StringPiece* slice_a, | 917 int CompareSuffix<IndexDataKey>(StringPiece* slice_a, |
| 893 StringPiece* slice_b, | 918 StringPiece* slice_b, |
| 894 bool only_compare_index_keys, | 919 bool only_compare_index_keys, |
| 895 bool* ok) { | 920 bool* ok) { |
| 896 // index key | 921 // index key |
| 897 int result = CompareEncodedIDBKeys(slice_a, slice_b, ok); | 922 int result = CompareEncodedIDBKeys(slice_a, slice_b, ok); |
| 898 if (!*ok || result) | 923 if (!*ok || result) |
| 899 return result; | 924 return result; |
| 900 if (only_compare_index_keys) | 925 if (only_compare_index_keys) |
| 901 return 0; | 926 return 0; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1032 | 1057 |
| 1033 case KeyPrefix::EXISTS_ENTRY: { | 1058 case KeyPrefix::EXISTS_ENTRY: { |
| 1034 // Provide a stable ordering for invalid data. | 1059 // Provide a stable ordering for invalid data. |
| 1035 if (slice_a.empty() || slice_b.empty()) | 1060 if (slice_a.empty() || slice_b.empty()) |
| 1036 return CompareSizes(slice_a.size(), slice_b.size()); | 1061 return CompareSizes(slice_a.size(), slice_b.size()); |
| 1037 | 1062 |
| 1038 return CompareSuffix<ExistsEntryKey>( | 1063 return CompareSuffix<ExistsEntryKey>( |
| 1039 &slice_a, &slice_b, /*only_compare_index_keys*/ false, ok); | 1064 &slice_a, &slice_b, /*only_compare_index_keys*/ false, ok); |
| 1040 } | 1065 } |
| 1041 | 1066 |
| 1067 case KeyPrefix::BLOB_ENTRY: { | |
| 1068 // Provide a stable ordering for invalid data. | |
| 1069 if (slice_a.empty() || slice_b.empty()) | |
| 1070 return CompareSizes(slice_a.size(), slice_b.size()); | |
| 1071 | |
| 1072 return CompareSuffix<BlobEntryKey>( | |
| 1073 &slice_a, &slice_b, /*only_compare_index_keys*/ false, ok); | |
| 1074 } | |
| 1075 | |
| 1042 case KeyPrefix::INDEX_DATA: { | 1076 case KeyPrefix::INDEX_DATA: { |
| 1043 // Provide a stable ordering for invalid data. | 1077 // Provide a stable ordering for invalid data. |
| 1044 if (slice_a.empty() || slice_b.empty()) | 1078 if (slice_a.empty() || slice_b.empty()) |
| 1045 return CompareSizes(slice_a.size(), slice_b.size()); | 1079 return CompareSizes(slice_a.size(), slice_b.size()); |
| 1046 | 1080 |
| 1047 return CompareSuffix<IndexDataKey>( | 1081 return CompareSuffix<IndexDataKey>( |
| 1048 &slice_a, &slice_b, only_compare_index_keys, ok); | 1082 &slice_a, &slice_b, only_compare_index_keys, ok); |
| 1049 } | 1083 } |
| 1050 | 1084 |
| 1051 case KeyPrefix::INVALID_TYPE: | 1085 case KeyPrefix::INVALID_TYPE: |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1233 DCHECK(index_id_ != kInvalidId); | 1267 DCHECK(index_id_ != kInvalidId); |
| 1234 | 1268 |
| 1235 if (!database_id_) | 1269 if (!database_id_) |
| 1236 return GLOBAL_METADATA; | 1270 return GLOBAL_METADATA; |
| 1237 if (!object_store_id_) | 1271 if (!object_store_id_) |
| 1238 return DATABASE_METADATA; | 1272 return DATABASE_METADATA; |
| 1239 if (index_id_ == kObjectStoreDataIndexId) | 1273 if (index_id_ == kObjectStoreDataIndexId) |
| 1240 return OBJECT_STORE_DATA; | 1274 return OBJECT_STORE_DATA; |
| 1241 if (index_id_ == kExistsEntryIndexId) | 1275 if (index_id_ == kExistsEntryIndexId) |
| 1242 return EXISTS_ENTRY; | 1276 return EXISTS_ENTRY; |
| 1277 if (index_id_ == kBlobEntryIndexId) | |
| 1278 return BLOB_ENTRY; | |
| 1243 if (index_id_ >= kMinimumIndexId) | 1279 if (index_id_ >= kMinimumIndexId) |
| 1244 return INDEX_DATA; | 1280 return INDEX_DATA; |
| 1245 | 1281 |
| 1246 NOTREACHED(); | 1282 NOTREACHED(); |
| 1247 return INVALID_TYPE; | 1283 return INVALID_TYPE; |
| 1248 } | 1284 } |
| 1249 | 1285 |
| 1250 std::string SchemaVersionKey::Encode() { | 1286 std::string SchemaVersionKey::Encode() { |
| 1251 std::string ret = KeyPrefix::EncodeEmpty(); | 1287 std::string ret = KeyPrefix::EncodeEmpty(); |
| 1252 ret.push_back(kSchemaVersionTypeByte); | 1288 ret.push_back(kSchemaVersionTypeByte); |
| 1253 return ret; | 1289 return ret; |
| 1254 } | 1290 } |
| 1255 | 1291 |
| 1256 std::string MaxDatabaseIdKey::Encode() { | 1292 std::string MaxDatabaseIdKey::Encode() { |
| 1257 std::string ret = KeyPrefix::EncodeEmpty(); | 1293 std::string ret = KeyPrefix::EncodeEmpty(); |
| 1258 ret.push_back(kMaxDatabaseIdTypeByte); | 1294 ret.push_back(kMaxDatabaseIdTypeByte); |
| 1259 return ret; | 1295 return ret; |
| 1260 } | 1296 } |
| 1261 | 1297 |
| 1262 std::string DataVersionKey::Encode() { | 1298 std::string DataVersionKey::Encode() { |
| 1263 std::string ret = KeyPrefix::EncodeEmpty(); | 1299 std::string ret = KeyPrefix::EncodeEmpty(); |
| 1264 ret.push_back(kDataVersionTypeByte); | 1300 ret.push_back(kDataVersionTypeByte); |
| 1265 return ret; | 1301 return ret; |
| 1266 } | 1302 } |
| 1267 | 1303 |
| 1304 std::string BlobJournalKey::Encode() { | |
| 1305 std::string ret = KeyPrefix::EncodeEmpty(); | |
| 1306 ret.push_back(kBlobJournalTypeByte); | |
| 1307 return ret; | |
| 1308 } | |
| 1309 | |
| 1310 std::string LiveBlobJournalKey::Encode() { | |
| 1311 std::string ret = KeyPrefix::EncodeEmpty(); | |
| 1312 ret.push_back(kLiveBlobJournalTypeByte); | |
| 1313 return ret; | |
| 1314 } | |
| 1315 | |
| 1268 DatabaseFreeListKey::DatabaseFreeListKey() : database_id_(-1) {} | 1316 DatabaseFreeListKey::DatabaseFreeListKey() : database_id_(-1) {} |
| 1269 | 1317 |
| 1270 bool DatabaseFreeListKey::Decode(StringPiece* slice, | 1318 bool DatabaseFreeListKey::Decode(StringPiece* slice, |
| 1271 DatabaseFreeListKey* result) { | 1319 DatabaseFreeListKey* result) { |
| 1272 KeyPrefix prefix; | 1320 KeyPrefix prefix; |
| 1273 if (!KeyPrefix::Decode(slice, &prefix)) | 1321 if (!KeyPrefix::Decode(slice, &prefix)) |
| 1274 return false; | 1322 return false; |
| 1275 DCHECK(!prefix.database_id_); | 1323 DCHECK(!prefix.database_id_); |
| 1276 DCHECK(!prefix.object_store_id_); | 1324 DCHECK(!prefix.object_store_id_); |
| 1277 DCHECK(!prefix.index_id_); | 1325 DCHECK(!prefix.index_id_); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1342 // just after origin in collation order | 1390 // just after origin in collation order |
| 1343 return EncodeMinKeyForOrigin(origin_identifier + '\x01'); | 1391 return EncodeMinKeyForOrigin(origin_identifier + '\x01'); |
| 1344 } | 1392 } |
| 1345 | 1393 |
| 1346 int DatabaseNameKey::Compare(const DatabaseNameKey& other) { | 1394 int DatabaseNameKey::Compare(const DatabaseNameKey& other) { |
| 1347 if (int x = origin_.compare(other.origin_)) | 1395 if (int x = origin_.compare(other.origin_)) |
| 1348 return x; | 1396 return x; |
| 1349 return database_name_.compare(other.database_name_); | 1397 return database_name_.compare(other.database_name_); |
| 1350 } | 1398 } |
| 1351 | 1399 |
| 1400 bool DatabaseMetaDataKey::IsValidBlobKey(int64 blob_key) { | |
| 1401 return blob_key >= kBlobKeyGeneratorInitialNumber; | |
| 1402 } | |
| 1403 | |
| 1352 std::string DatabaseMetaDataKey::Encode(int64 database_id, | 1404 std::string DatabaseMetaDataKey::Encode(int64 database_id, |
| 1353 MetaDataType meta_data_type) { | 1405 MetaDataType meta_data_type) { |
| 1354 KeyPrefix prefix(database_id); | 1406 KeyPrefix prefix(database_id); |
| 1355 std::string ret = prefix.Encode(); | 1407 std::string ret = prefix.Encode(); |
| 1356 ret.push_back(meta_data_type); | 1408 ret.push_back(meta_data_type); |
| 1357 return ret; | 1409 return ret; |
| 1358 } | 1410 } |
| 1359 | 1411 |
| 1360 ObjectStoreMetaDataKey::ObjectStoreMetaDataKey() | 1412 ObjectStoreMetaDataKey::ObjectStoreMetaDataKey() |
| 1361 : object_store_id_(-1), meta_data_type_(-1) {} | 1413 : object_store_id_(-1), meta_data_type_(-1) {} |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1748 scoped_ptr<IndexedDBKey> key; | 1800 scoped_ptr<IndexedDBKey> key; |
| 1749 StringPiece slice(encoded_user_key_); | 1801 StringPiece slice(encoded_user_key_); |
| 1750 if (!DecodeIDBKey(&slice, &key)) { | 1802 if (!DecodeIDBKey(&slice, &key)) { |
| 1751 // TODO(jsbell): Return error. | 1803 // TODO(jsbell): Return error. |
| 1752 } | 1804 } |
| 1753 return key.Pass(); | 1805 return key.Pass(); |
| 1754 } | 1806 } |
| 1755 | 1807 |
| 1756 const int64 ExistsEntryKey::kSpecialIndexNumber = kExistsEntryIndexId; | 1808 const int64 ExistsEntryKey::kSpecialIndexNumber = kExistsEntryIndexId; |
| 1757 | 1809 |
| 1810 bool BlobEntryKey::Decode(StringPiece* slice, BlobEntryKey* result) { | |
| 1811 KeyPrefix prefix; | |
| 1812 if (!KeyPrefix::Decode(slice, &prefix)) | |
| 1813 return false; | |
| 1814 DCHECK(prefix.database_id_); | |
| 1815 DCHECK(prefix.object_store_id_); | |
| 1816 DCHECK_EQ(prefix.index_id_, kSpecialIndexNumber); | |
| 1817 | |
| 1818 if (!ExtractEncodedIDBKey(slice, &result->encoded_user_key_)) | |
| 1819 return false; | |
| 1820 result->database_id_ = prefix.database_id_; | |
| 1821 result->object_store_id_ = prefix.object_store_id_; | |
| 1822 | |
| 1823 return true; | |
| 1824 } | |
| 1825 | |
| 1826 bool BlobEntryKey::FromObjectStoreDataKey(StringPiece* slice, | |
| 1827 BlobEntryKey* result) { | |
| 1828 KeyPrefix prefix; | |
| 1829 if (!KeyPrefix::Decode(slice, &prefix)) | |
| 1830 return false; | |
| 1831 DCHECK(prefix.database_id_); | |
| 1832 DCHECK(prefix.object_store_id_); | |
| 1833 DCHECK_EQ(prefix.index_id_, ObjectStoreDataKey::kSpecialIndexNumber); | |
| 1834 | |
| 1835 if (!ExtractEncodedIDBKey(slice, &result->encoded_user_key_)) | |
| 1836 return false; | |
| 1837 result->database_id_ = prefix.database_id_; | |
| 1838 result->object_store_id_ = prefix.object_store_id_; | |
| 1839 return true; | |
| 1840 } | |
| 1841 | |
| 1842 std::string BlobEntryKey::ReencodeToObjectStoreDataKey(StringPiece* slice) { | |
| 1843 BlobEntryKey key; | |
| 1844 if (!Decode(slice, &key)) | |
| 1845 return std::string(); | |
| 1846 | |
| 1847 return ObjectStoreDataKey::Encode( | |
| 1848 key.database_id_, key.object_store_id_, key.encoded_user_key_); | |
| 1849 } | |
| 1850 | |
| 1851 std::string BlobEntryKey::EncodeMinForObjectStore(int64 database_id, | |
| 1852 int64 object_store_id) { | |
| 1853 // Our implied encoded_user_key_ here is empty, the lowest possible key. | |
| 1854 return Encode(database_id, object_store_id, std::string()); | |
| 1855 } | |
| 1856 | |
| 1857 // This isn't technically the max for this object store--it's one higher, which | |
|
jsbell
2013/12/20 00:44:20
I think there are a few other cases like this (whe
ericu
2014/02/20 00:50:29
I see it's called the "stop key" elsewhere, so I'v
| |
| 1858 // means that it's the first key /not/ in the range. That's more what we want, | |
| 1859 // but doesn't match the terminology elsewhere in this file, which is a bit | |
| 1860 // messy. | |
| 1861 std::string BlobEntryKey::EncodeMaxForObjectStore(int64 database_id, | |
| 1862 int64 object_store_id) { | |
| 1863 DCHECK(KeyPrefix::ValidIds(database_id, object_store_id)); | |
| 1864 KeyPrefix prefix(KeyPrefix::CreateWithSpecialIndex( | |
| 1865 database_id, object_store_id, kSpecialIndexNumber + 1)); | |
| 1866 return prefix.Encode(); | |
| 1867 } | |
| 1868 | |
| 1869 std::string BlobEntryKey::Encode() const { | |
| 1870 DCHECK_GT(encoded_user_key_.size(), 0UL); | |
| 1871 return Encode(database_id_, object_store_id_, encoded_user_key_); | |
| 1872 } | |
| 1873 | |
| 1874 std::string BlobEntryKey::Encode(int64 database_id, | |
| 1875 int64 object_store_id, | |
| 1876 const IndexedDBKey& user_key) { | |
| 1877 std::string encoded_key; | |
| 1878 EncodeIDBKey(user_key, &encoded_key); | |
| 1879 return Encode(database_id, object_store_id, encoded_key); | |
| 1880 } | |
| 1881 | |
| 1882 std::string BlobEntryKey::Encode(int64 database_id, | |
| 1883 int64 object_store_id, | |
| 1884 const std::string& encoded_user_key) { | |
| 1885 DCHECK(KeyPrefix::ValidIds(database_id, object_store_id)); | |
| 1886 KeyPrefix prefix(KeyPrefix::CreateWithSpecialIndex( | |
| 1887 database_id, object_store_id, kSpecialIndexNumber)); | |
| 1888 std::string ret = prefix.Encode(); | |
| 1889 ret.insert(ret.end(), encoded_user_key.begin(), encoded_user_key.end()); | |
| 1890 return ret; | |
| 1891 } | |
| 1892 | |
| 1893 int BlobEntryKey::Compare(const BlobEntryKey& other, bool* ok) { | |
|
jsbell
2013/12/20 00:44:20
This is probably unused (outside of tests?) I thin
ericu
2014/02/20 00:50:29
Done.
| |
| 1894 DCHECK_GT(encoded_user_key_.size(), 0UL); | |
| 1895 DCHECK_GT(other.encoded_user_key_.size(), 0UL); | |
| 1896 return CompareEncodedIDBKeys(encoded_user_key_, other.encoded_user_key_, ok); | |
| 1897 } | |
| 1898 | |
| 1899 const int64 BlobEntryKey::kSpecialIndexNumber = kBlobEntryIndexId; | |
| 1900 | |
| 1758 IndexDataKey::IndexDataKey() | 1901 IndexDataKey::IndexDataKey() |
| 1759 : database_id_(-1), | 1902 : database_id_(-1), |
| 1760 object_store_id_(-1), | 1903 object_store_id_(-1), |
| 1761 index_id_(-1), | 1904 index_id_(-1), |
| 1762 sequence_number_(-1) {} | 1905 sequence_number_(-1) {} |
| 1763 | 1906 |
| 1764 IndexDataKey::~IndexDataKey() {} | 1907 IndexDataKey::~IndexDataKey() {} |
| 1765 | 1908 |
| 1766 bool IndexDataKey::Decode(StringPiece* slice, IndexDataKey* result) { | 1909 bool IndexDataKey::Decode(StringPiece* slice, IndexDataKey* result) { |
| 1767 KeyPrefix prefix; | 1910 KeyPrefix prefix; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1898 scoped_ptr<IndexedDBKey> IndexDataKey::primary_key() const { | 2041 scoped_ptr<IndexedDBKey> IndexDataKey::primary_key() const { |
| 1899 scoped_ptr<IndexedDBKey> key; | 2042 scoped_ptr<IndexedDBKey> key; |
| 1900 StringPiece slice(encoded_primary_key_); | 2043 StringPiece slice(encoded_primary_key_); |
| 1901 if (!DecodeIDBKey(&slice, &key)) { | 2044 if (!DecodeIDBKey(&slice, &key)) { |
| 1902 // TODO(jsbell): Return error. | 2045 // TODO(jsbell): Return error. |
| 1903 } | 2046 } |
| 1904 return key.Pass(); | 2047 return key.Pass(); |
| 1905 } | 2048 } |
| 1906 | 2049 |
| 1907 } // namespace content | 2050 } // namespace content |
| OLD | NEW |