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 |
(...skipping 11 matching lines...) Expand all Loading... |
157 using blink::WebIDBKeyTypeNumber; | 172 using blink::WebIDBKeyTypeNumber; |
158 using blink::WebIDBKeyTypeString; | 173 using blink::WebIDBKeyTypeString; |
159 using blink::WebIDBKeyPathType; | 174 using blink::WebIDBKeyPathType; |
160 using blink::WebIDBKeyPathTypeArray; | 175 using blink::WebIDBKeyPathTypeArray; |
161 using blink::WebIDBKeyPathTypeNull; | 176 using blink::WebIDBKeyPathTypeNull; |
162 using blink::WebIDBKeyPathTypeString; | 177 using blink::WebIDBKeyPathTypeString; |
163 | 178 |
164 namespace content { | 179 namespace content { |
165 | 180 |
166 // As most of the IndexedDBKeys and encoded values are short, we | 181 // As most of the IndexedDBKeys and encoded values are short, we |
167 // initialize some Vectors with a default inline buffer size to reduce | 182 // initialize some std::vectors with a default inline buffer size to reduce |
168 // the memory re-allocations when the Vectors are appended. | 183 // the memory re-allocations when the std::vectors are appended. |
169 static const size_t kDefaultInlineBufferSize = 32; | 184 static const size_t kDefaultInlineBufferSize = 32; |
170 | 185 |
171 static const unsigned char kIndexedDBKeyNullTypeByte = 0; | 186 static const unsigned char kIndexedDBKeyNullTypeByte = 0; |
172 static const unsigned char kIndexedDBKeyStringTypeByte = 1; | 187 static const unsigned char kIndexedDBKeyStringTypeByte = 1; |
173 static const unsigned char kIndexedDBKeyDateTypeByte = 2; | 188 static const unsigned char kIndexedDBKeyDateTypeByte = 2; |
174 static const unsigned char kIndexedDBKeyNumberTypeByte = 3; | 189 static const unsigned char kIndexedDBKeyNumberTypeByte = 3; |
175 static const unsigned char kIndexedDBKeyArrayTypeByte = 4; | 190 static const unsigned char kIndexedDBKeyArrayTypeByte = 4; |
176 static const unsigned char kIndexedDBKeyMinKeyTypeByte = 5; | 191 static const unsigned char kIndexedDBKeyMinKeyTypeByte = 5; |
177 static const unsigned char kIndexedDBKeyBinaryTypeByte = 6; | 192 static const unsigned char kIndexedDBKeyBinaryTypeByte = 6; |
178 | 193 |
179 static const unsigned char kIndexedDBKeyPathTypeCodedByte1 = 0; | 194 static const unsigned char kIndexedDBKeyPathTypeCodedByte1 = 0; |
180 static const unsigned char kIndexedDBKeyPathTypeCodedByte2 = 0; | 195 static const unsigned char kIndexedDBKeyPathTypeCodedByte2 = 0; |
181 | 196 |
182 static const unsigned char kObjectStoreDataIndexId = 1; | 197 static const unsigned char kObjectStoreDataIndexId = 1; |
183 static const unsigned char kExistsEntryIndexId = 2; | 198 static const unsigned char kExistsEntryIndexId = 2; |
| 199 static const unsigned char kBlobEntryIndexId = 3; |
184 | 200 |
185 static const unsigned char kSchemaVersionTypeByte = 0; | 201 static const unsigned char kSchemaVersionTypeByte = 0; |
186 static const unsigned char kMaxDatabaseIdTypeByte = 1; | 202 static const unsigned char kMaxDatabaseIdTypeByte = 1; |
187 static const unsigned char kDataVersionTypeByte = 2; | 203 static const unsigned char kDataVersionTypeByte = 2; |
| 204 static const unsigned char kBlobJournalTypeByte = 3; |
| 205 static const unsigned char kLiveBlobJournalTypeByte = 4; |
188 static const unsigned char kMaxSimpleGlobalMetaDataTypeByte = | 206 static const unsigned char kMaxSimpleGlobalMetaDataTypeByte = |
189 3; // Insert before this and increment. | 207 5; // Insert before this and increment. |
190 static const unsigned char kDatabaseFreeListTypeByte = 100; | 208 static const unsigned char kDatabaseFreeListTypeByte = 100; |
191 static const unsigned char kDatabaseNameTypeByte = 201; | 209 static const unsigned char kDatabaseNameTypeByte = 201; |
192 | 210 |
193 static const unsigned char kObjectStoreMetaDataTypeByte = 50; | 211 static const unsigned char kObjectStoreMetaDataTypeByte = 50; |
194 static const unsigned char kIndexMetaDataTypeByte = 100; | 212 static const unsigned char kIndexMetaDataTypeByte = 100; |
195 static const unsigned char kObjectStoreFreeListTypeByte = 150; | 213 static const unsigned char kObjectStoreFreeListTypeByte = 150; |
196 static const unsigned char kIndexFreeListTypeByte = 151; | 214 static const unsigned char kIndexFreeListTypeByte = 151; |
197 static const unsigned char kObjectStoreNamesTypeByte = 200; | 215 static const unsigned char kObjectStoreNamesTypeByte = 200; |
198 static const unsigned char kIndexNamesKeyTypeByte = 201; | 216 static const unsigned char kIndexNamesKeyTypeByte = 201; |
199 | 217 |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 | 900 |
883 template <> | 901 template <> |
884 int CompareSuffix<ObjectStoreDataKey>(StringPiece* slice_a, | 902 int CompareSuffix<ObjectStoreDataKey>(StringPiece* slice_a, |
885 StringPiece* slice_b, | 903 StringPiece* slice_b, |
886 bool only_compare_index_keys, | 904 bool only_compare_index_keys, |
887 bool* ok) { | 905 bool* ok) { |
888 return CompareEncodedIDBKeys(slice_a, slice_b, ok); | 906 return CompareEncodedIDBKeys(slice_a, slice_b, ok); |
889 } | 907 } |
890 | 908 |
891 template <> | 909 template <> |
| 910 int CompareSuffix<BlobEntryKey>(StringPiece* slice_a, |
| 911 StringPiece* slice_b, |
| 912 bool only_compare_index_keys, |
| 913 bool* ok) { |
| 914 return CompareEncodedIDBKeys(slice_a, slice_b, ok); |
| 915 } |
| 916 |
| 917 template <> |
892 int CompareSuffix<IndexDataKey>(StringPiece* slice_a, | 918 int CompareSuffix<IndexDataKey>(StringPiece* slice_a, |
893 StringPiece* slice_b, | 919 StringPiece* slice_b, |
894 bool only_compare_index_keys, | 920 bool only_compare_index_keys, |
895 bool* ok) { | 921 bool* ok) { |
896 // index key | 922 // index key |
897 int result = CompareEncodedIDBKeys(slice_a, slice_b, ok); | 923 int result = CompareEncodedIDBKeys(slice_a, slice_b, ok); |
898 if (!*ok || result) | 924 if (!*ok || result) |
899 return result; | 925 return result; |
900 if (only_compare_index_keys) | 926 if (only_compare_index_keys) |
901 return 0; | 927 return 0; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 | 1058 |
1033 case KeyPrefix::EXISTS_ENTRY: { | 1059 case KeyPrefix::EXISTS_ENTRY: { |
1034 // Provide a stable ordering for invalid data. | 1060 // Provide a stable ordering for invalid data. |
1035 if (slice_a.empty() || slice_b.empty()) | 1061 if (slice_a.empty() || slice_b.empty()) |
1036 return CompareSizes(slice_a.size(), slice_b.size()); | 1062 return CompareSizes(slice_a.size(), slice_b.size()); |
1037 | 1063 |
1038 return CompareSuffix<ExistsEntryKey>( | 1064 return CompareSuffix<ExistsEntryKey>( |
1039 &slice_a, &slice_b, /*only_compare_index_keys*/ false, ok); | 1065 &slice_a, &slice_b, /*only_compare_index_keys*/ false, ok); |
1040 } | 1066 } |
1041 | 1067 |
| 1068 case KeyPrefix::BLOB_ENTRY: { |
| 1069 // Provide a stable ordering for invalid data. |
| 1070 if (slice_a.empty() || slice_b.empty()) |
| 1071 return CompareSizes(slice_a.size(), slice_b.size()); |
| 1072 |
| 1073 return CompareSuffix<BlobEntryKey>( |
| 1074 &slice_a, &slice_b, /*only_compare_index_keys*/ false, ok); |
| 1075 } |
| 1076 |
1042 case KeyPrefix::INDEX_DATA: { | 1077 case KeyPrefix::INDEX_DATA: { |
1043 // Provide a stable ordering for invalid data. | 1078 // Provide a stable ordering for invalid data. |
1044 if (slice_a.empty() || slice_b.empty()) | 1079 if (slice_a.empty() || slice_b.empty()) |
1045 return CompareSizes(slice_a.size(), slice_b.size()); | 1080 return CompareSizes(slice_a.size(), slice_b.size()); |
1046 | 1081 |
1047 return CompareSuffix<IndexDataKey>( | 1082 return CompareSuffix<IndexDataKey>( |
1048 &slice_a, &slice_b, only_compare_index_keys, ok); | 1083 &slice_a, &slice_b, only_compare_index_keys, ok); |
1049 } | 1084 } |
1050 | 1085 |
1051 case KeyPrefix::INVALID_TYPE: | 1086 case KeyPrefix::INVALID_TYPE: |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1233 DCHECK(index_id_ != kInvalidId); | 1268 DCHECK(index_id_ != kInvalidId); |
1234 | 1269 |
1235 if (!database_id_) | 1270 if (!database_id_) |
1236 return GLOBAL_METADATA; | 1271 return GLOBAL_METADATA; |
1237 if (!object_store_id_) | 1272 if (!object_store_id_) |
1238 return DATABASE_METADATA; | 1273 return DATABASE_METADATA; |
1239 if (index_id_ == kObjectStoreDataIndexId) | 1274 if (index_id_ == kObjectStoreDataIndexId) |
1240 return OBJECT_STORE_DATA; | 1275 return OBJECT_STORE_DATA; |
1241 if (index_id_ == kExistsEntryIndexId) | 1276 if (index_id_ == kExistsEntryIndexId) |
1242 return EXISTS_ENTRY; | 1277 return EXISTS_ENTRY; |
| 1278 if (index_id_ == kBlobEntryIndexId) |
| 1279 return BLOB_ENTRY; |
1243 if (index_id_ >= kMinimumIndexId) | 1280 if (index_id_ >= kMinimumIndexId) |
1244 return INDEX_DATA; | 1281 return INDEX_DATA; |
1245 | 1282 |
1246 NOTREACHED(); | 1283 NOTREACHED(); |
1247 return INVALID_TYPE; | 1284 return INVALID_TYPE; |
1248 } | 1285 } |
1249 | 1286 |
1250 std::string SchemaVersionKey::Encode() { | 1287 std::string SchemaVersionKey::Encode() { |
1251 std::string ret = KeyPrefix::EncodeEmpty(); | 1288 std::string ret = KeyPrefix::EncodeEmpty(); |
1252 ret.push_back(kSchemaVersionTypeByte); | 1289 ret.push_back(kSchemaVersionTypeByte); |
1253 return ret; | 1290 return ret; |
1254 } | 1291 } |
1255 | 1292 |
1256 std::string MaxDatabaseIdKey::Encode() { | 1293 std::string MaxDatabaseIdKey::Encode() { |
1257 std::string ret = KeyPrefix::EncodeEmpty(); | 1294 std::string ret = KeyPrefix::EncodeEmpty(); |
1258 ret.push_back(kMaxDatabaseIdTypeByte); | 1295 ret.push_back(kMaxDatabaseIdTypeByte); |
1259 return ret; | 1296 return ret; |
1260 } | 1297 } |
1261 | 1298 |
1262 std::string DataVersionKey::Encode() { | 1299 std::string DataVersionKey::Encode() { |
1263 std::string ret = KeyPrefix::EncodeEmpty(); | 1300 std::string ret = KeyPrefix::EncodeEmpty(); |
1264 ret.push_back(kDataVersionTypeByte); | 1301 ret.push_back(kDataVersionTypeByte); |
1265 return ret; | 1302 return ret; |
1266 } | 1303 } |
1267 | 1304 |
| 1305 std::string BlobJournalKey::Encode() |
| 1306 { |
| 1307 std::string ret = KeyPrefix::EncodeEmpty(); |
| 1308 ret.push_back(kBlobJournalTypeByte); |
| 1309 return ret; |
| 1310 } |
| 1311 |
| 1312 std::string LiveBlobJournalKey::Encode() |
| 1313 { |
| 1314 std::string ret = KeyPrefix::EncodeEmpty(); |
| 1315 ret.push_back(kLiveBlobJournalTypeByte); |
| 1316 return ret; |
| 1317 } |
| 1318 |
1268 DatabaseFreeListKey::DatabaseFreeListKey() : database_id_(-1) {} | 1319 DatabaseFreeListKey::DatabaseFreeListKey() : database_id_(-1) {} |
1269 | 1320 |
1270 bool DatabaseFreeListKey::Decode(StringPiece* slice, | 1321 bool DatabaseFreeListKey::Decode(StringPiece* slice, |
1271 DatabaseFreeListKey* result) { | 1322 DatabaseFreeListKey* result) { |
1272 KeyPrefix prefix; | 1323 KeyPrefix prefix; |
1273 if (!KeyPrefix::Decode(slice, &prefix)) | 1324 if (!KeyPrefix::Decode(slice, &prefix)) |
1274 return false; | 1325 return false; |
1275 DCHECK(!prefix.database_id_); | 1326 DCHECK(!prefix.database_id_); |
1276 DCHECK(!prefix.object_store_id_); | 1327 DCHECK(!prefix.object_store_id_); |
1277 DCHECK(!prefix.index_id_); | 1328 DCHECK(!prefix.index_id_); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1342 // just after origin in collation order | 1393 // just after origin in collation order |
1343 return EncodeMinKeyForOrigin(origin_identifier + '\x01'); | 1394 return EncodeMinKeyForOrigin(origin_identifier + '\x01'); |
1344 } | 1395 } |
1345 | 1396 |
1346 int DatabaseNameKey::Compare(const DatabaseNameKey& other) { | 1397 int DatabaseNameKey::Compare(const DatabaseNameKey& other) { |
1347 if (int x = origin_.compare(other.origin_)) | 1398 if (int x = origin_.compare(other.origin_)) |
1348 return x; | 1399 return x; |
1349 return database_name_.compare(other.database_name_); | 1400 return database_name_.compare(other.database_name_); |
1350 } | 1401 } |
1351 | 1402 |
| 1403 bool DatabaseMetaDataKey::IsValidBlobKey(int64 blob_key) { |
| 1404 return blob_key >= kBlobKeyGeneratorInitialNumber; |
| 1405 } |
| 1406 |
1352 std::string DatabaseMetaDataKey::Encode(int64 database_id, | 1407 std::string DatabaseMetaDataKey::Encode(int64 database_id, |
1353 MetaDataType meta_data_type) { | 1408 MetaDataType meta_data_type) { |
1354 KeyPrefix prefix(database_id); | 1409 KeyPrefix prefix(database_id); |
1355 std::string ret = prefix.Encode(); | 1410 std::string ret = prefix.Encode(); |
1356 ret.push_back(meta_data_type); | 1411 ret.push_back(meta_data_type); |
1357 return ret; | 1412 return ret; |
1358 } | 1413 } |
1359 | 1414 |
1360 ObjectStoreMetaDataKey::ObjectStoreMetaDataKey() | 1415 ObjectStoreMetaDataKey::ObjectStoreMetaDataKey() |
1361 : object_store_id_(-1), meta_data_type_(-1) {} | 1416 : 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; | 1803 scoped_ptr<IndexedDBKey> key; |
1749 StringPiece slice(encoded_user_key_); | 1804 StringPiece slice(encoded_user_key_); |
1750 if (!DecodeIDBKey(&slice, &key)) { | 1805 if (!DecodeIDBKey(&slice, &key)) { |
1751 // TODO(jsbell): Return error. | 1806 // TODO(jsbell): Return error. |
1752 } | 1807 } |
1753 return key.Pass(); | 1808 return key.Pass(); |
1754 } | 1809 } |
1755 | 1810 |
1756 const int64 ExistsEntryKey::kSpecialIndexNumber = kExistsEntryIndexId; | 1811 const int64 ExistsEntryKey::kSpecialIndexNumber = kExistsEntryIndexId; |
1757 | 1812 |
| 1813 bool BlobEntryKey::Decode(StringPiece* slice, BlobEntryKey* result) { |
| 1814 KeyPrefix prefix; |
| 1815 if (!KeyPrefix::Decode(slice, &prefix)) |
| 1816 return false; |
| 1817 DCHECK(prefix.database_id_); |
| 1818 DCHECK(prefix.object_store_id_); |
| 1819 DCHECK_EQ(prefix.index_id_, kSpecialIndexNumber); |
| 1820 |
| 1821 if (!ExtractEncodedIDBKey(slice, &result->encoded_user_key_)) |
| 1822 return false; |
| 1823 result->database_id_ = prefix.database_id_; |
| 1824 result->object_store_id_ = prefix.object_store_id_; |
| 1825 |
| 1826 return true; |
| 1827 } |
| 1828 |
| 1829 bool BlobEntryKey::FromObjectStoreDataKey(StringPiece* slice, |
| 1830 BlobEntryKey* result) { |
| 1831 KeyPrefix prefix; |
| 1832 if (!KeyPrefix::Decode(slice, &prefix)) |
| 1833 return false; |
| 1834 DCHECK(prefix.database_id_); |
| 1835 DCHECK(prefix.object_store_id_); |
| 1836 DCHECK_EQ(prefix.index_id_, ObjectStoreDataKey::kSpecialIndexNumber); |
| 1837 |
| 1838 if (!ExtractEncodedIDBKey(slice, &result->encoded_user_key_)) |
| 1839 return false; |
| 1840 result->database_id_ = prefix.database_id_; |
| 1841 result->object_store_id_ = prefix.object_store_id_; |
| 1842 return true; |
| 1843 } |
| 1844 |
| 1845 std::string BlobEntryKey::ReencodeToObjectStoreDataKey(StringPiece* slice) { |
| 1846 BlobEntryKey key; |
| 1847 if (!Decode(slice, &key)) |
| 1848 return std::string(); |
| 1849 |
| 1850 return ObjectStoreDataKey::Encode( |
| 1851 key.database_id_, key.object_store_id_, key.encoded_user_key_); |
| 1852 } |
| 1853 |
| 1854 std::string BlobEntryKey::EncodeMinForObjectStore(int64 database_id, |
| 1855 int64 object_store_id) { |
| 1856 // Our implied encoded_user_key_ here is empty, the lowest possible key. |
| 1857 return Encode(database_id, object_store_id, std::string()); |
| 1858 } |
| 1859 |
| 1860 // This isn't technically the max for this object store--it's one higher, which |
| 1861 // means that it's the first key /not/ in the range. That's more what we want, |
| 1862 // but doesn't match the terminology elsewhere in this file, which is a bit |
| 1863 // messy. |
| 1864 std::string BlobEntryKey::EncodeMaxForObjectStore(int64 database_id, |
| 1865 int64 object_store_id) |
| 1866 { |
| 1867 DCHECK(KeyPrefix::ValidIds(database_id, object_store_id)); |
| 1868 KeyPrefix prefix( |
| 1869 KeyPrefix::CreateWithSpecialIndex(database_id, object_store_id, |
| 1870 kSpecialIndexNumber + 1)); |
| 1871 return prefix.Encode(); |
| 1872 } |
| 1873 |
| 1874 std::string BlobEntryKey::Encode() const |
| 1875 { |
| 1876 DCHECK_GT(encoded_user_key_.size(), 0UL); |
| 1877 return Encode(database_id_, object_store_id_, encoded_user_key_); |
| 1878 } |
| 1879 |
| 1880 std::string BlobEntryKey::Encode(int64 database_id, |
| 1881 int64 object_store_id, |
| 1882 const IndexedDBKey& user_key) |
| 1883 { |
| 1884 std::string encoded_key; |
| 1885 EncodeIDBKey(user_key, &encoded_key); |
| 1886 return Encode(database_id, object_store_id, encoded_key); |
| 1887 } |
| 1888 |
| 1889 std::string BlobEntryKey::Encode( |
| 1890 int64 database_id, int64 object_store_id, |
| 1891 const std::string& encoded_user_key) { |
| 1892 DCHECK(KeyPrefix::ValidIds(database_id, object_store_id)); |
| 1893 KeyPrefix prefix( |
| 1894 KeyPrefix::CreateWithSpecialIndex(database_id, object_store_id, |
| 1895 kSpecialIndexNumber)); |
| 1896 std::string ret = prefix.Encode(); |
| 1897 ret.insert(ret.end(), encoded_user_key.begin(), encoded_user_key.end()); |
| 1898 return ret; |
| 1899 } |
| 1900 |
| 1901 int BlobEntryKey::Compare(const BlobEntryKey& other, bool* ok) |
| 1902 { |
| 1903 DCHECK_GT(encoded_user_key_.size(), 0UL); |
| 1904 DCHECK_GT(other.encoded_user_key_.size(), 0UL); |
| 1905 return CompareEncodedIDBKeys(encoded_user_key_, other.encoded_user_key_, ok); |
| 1906 } |
| 1907 |
| 1908 const int64 BlobEntryKey::kSpecialIndexNumber = kBlobEntryIndexId; |
| 1909 |
1758 IndexDataKey::IndexDataKey() | 1910 IndexDataKey::IndexDataKey() |
1759 : database_id_(-1), | 1911 : database_id_(-1), |
1760 object_store_id_(-1), | 1912 object_store_id_(-1), |
1761 index_id_(-1), | 1913 index_id_(-1), |
1762 sequence_number_(-1) {} | 1914 sequence_number_(-1) {} |
1763 | 1915 |
1764 IndexDataKey::~IndexDataKey() {} | 1916 IndexDataKey::~IndexDataKey() {} |
1765 | 1917 |
1766 bool IndexDataKey::Decode(StringPiece* slice, IndexDataKey* result) { | 1918 bool IndexDataKey::Decode(StringPiece* slice, IndexDataKey* result) { |
1767 KeyPrefix prefix; | 1919 KeyPrefix prefix; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1898 scoped_ptr<IndexedDBKey> IndexDataKey::primary_key() const { | 2050 scoped_ptr<IndexedDBKey> IndexDataKey::primary_key() const { |
1899 scoped_ptr<IndexedDBKey> key; | 2051 scoped_ptr<IndexedDBKey> key; |
1900 StringPiece slice(encoded_primary_key_); | 2052 StringPiece slice(encoded_primary_key_); |
1901 if (!DecodeIDBKey(&slice, &key)) { | 2053 if (!DecodeIDBKey(&slice, &key)) { |
1902 // TODO(jsbell): Return error. | 2054 // TODO(jsbell): Return error. |
1903 } | 2055 } |
1904 return key.Pass(); | 2056 return key.Pass(); |
1905 } | 2057 } |
1906 | 2058 |
1907 } // namespace content | 2059 } // namespace content |
OLD | NEW |