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 kAllBlobsKey, 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 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
871 | 888 |
872 template <> | 889 template <> |
873 int CompareSuffix<ObjectStoreDataKey>(StringPiece* slice_a, | 890 int CompareSuffix<ObjectStoreDataKey>(StringPiece* slice_a, |
874 StringPiece* slice_b, | 891 StringPiece* slice_b, |
875 bool only_compare_index_keys, | 892 bool only_compare_index_keys, |
876 bool* ok) { | 893 bool* ok) { |
877 return CompareEncodedIDBKeys(slice_a, slice_b, ok); | 894 return CompareEncodedIDBKeys(slice_a, slice_b, ok); |
878 } | 895 } |
879 | 896 |
880 template <> | 897 template <> |
898 int CompareSuffix<BlobEntryKey>(StringPiece* slice_a, | |
899 StringPiece* slice_b, | |
900 bool only_compare_index_keys, | |
901 bool* ok) { | |
902 return CompareEncodedIDBKeys(slice_a, slice_b, ok); | |
903 } | |
904 | |
905 template <> | |
881 int CompareSuffix<IndexDataKey>(StringPiece* slice_a, | 906 int CompareSuffix<IndexDataKey>(StringPiece* slice_a, |
882 StringPiece* slice_b, | 907 StringPiece* slice_b, |
883 bool only_compare_index_keys, | 908 bool only_compare_index_keys, |
884 bool* ok) { | 909 bool* ok) { |
885 // index key | 910 // index key |
886 int result = CompareEncodedIDBKeys(slice_a, slice_b, ok); | 911 int result = CompareEncodedIDBKeys(slice_a, slice_b, ok); |
887 if (!*ok || result) | 912 if (!*ok || result) |
888 return result; | 913 return result; |
889 if (only_compare_index_keys) | 914 if (only_compare_index_keys) |
890 return 0; | 915 return 0; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1031 | 1056 |
1032 case KeyPrefix::EXISTS_ENTRY: { | 1057 case KeyPrefix::EXISTS_ENTRY: { |
1033 // Provide a stable ordering for invalid data. | 1058 // Provide a stable ordering for invalid data. |
1034 if (slice_a.empty() || slice_b.empty()) | 1059 if (slice_a.empty() || slice_b.empty()) |
1035 return CompareSizes(slice_a.size(), slice_b.size()); | 1060 return CompareSizes(slice_a.size(), slice_b.size()); |
1036 | 1061 |
1037 return CompareSuffix<ExistsEntryKey>( | 1062 return CompareSuffix<ExistsEntryKey>( |
1038 &slice_a, &slice_b, /*only_compare_index_keys*/ false, ok); | 1063 &slice_a, &slice_b, /*only_compare_index_keys*/ false, ok); |
1039 } | 1064 } |
1040 | 1065 |
1066 case KeyPrefix::BLOB_ENTRY: { | |
1067 // Provide a stable ordering for invalid data. | |
1068 if (slice_a.empty() || slice_b.empty()) | |
1069 return CompareSizes(slice_a.size(), slice_b.size()); | |
1070 | |
1071 return CompareSuffix<BlobEntryKey>( | |
1072 &slice_a, &slice_b, /*only_compare_index_keys*/ false, ok); | |
1073 } | |
1074 | |
1041 case KeyPrefix::INDEX_DATA: { | 1075 case KeyPrefix::INDEX_DATA: { |
1042 // Provide a stable ordering for invalid data. | 1076 // Provide a stable ordering for invalid data. |
1043 if (slice_a.empty() || slice_b.empty()) | 1077 if (slice_a.empty() || slice_b.empty()) |
1044 return CompareSizes(slice_a.size(), slice_b.size()); | 1078 return CompareSizes(slice_a.size(), slice_b.size()); |
1045 | 1079 |
1046 return CompareSuffix<IndexDataKey>( | 1080 return CompareSuffix<IndexDataKey>( |
1047 &slice_a, &slice_b, only_compare_index_keys, ok); | 1081 &slice_a, &slice_b, only_compare_index_keys, ok); |
1048 } | 1082 } |
1049 | 1083 |
1050 case KeyPrefix::INVALID_TYPE: | 1084 case KeyPrefix::INVALID_TYPE: |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1232 DCHECK(index_id_ != kInvalidId); | 1266 DCHECK(index_id_ != kInvalidId); |
1233 | 1267 |
1234 if (!database_id_) | 1268 if (!database_id_) |
1235 return GLOBAL_METADATA; | 1269 return GLOBAL_METADATA; |
1236 if (!object_store_id_) | 1270 if (!object_store_id_) |
1237 return DATABASE_METADATA; | 1271 return DATABASE_METADATA; |
1238 if (index_id_ == kObjectStoreDataIndexId) | 1272 if (index_id_ == kObjectStoreDataIndexId) |
1239 return OBJECT_STORE_DATA; | 1273 return OBJECT_STORE_DATA; |
1240 if (index_id_ == kExistsEntryIndexId) | 1274 if (index_id_ == kExistsEntryIndexId) |
1241 return EXISTS_ENTRY; | 1275 return EXISTS_ENTRY; |
1276 if (index_id_ == kBlobEntryIndexId) | |
1277 return BLOB_ENTRY; | |
1242 if (index_id_ >= kMinimumIndexId) | 1278 if (index_id_ >= kMinimumIndexId) |
1243 return INDEX_DATA; | 1279 return INDEX_DATA; |
1244 | 1280 |
1245 NOTREACHED(); | 1281 NOTREACHED(); |
1246 return INVALID_TYPE; | 1282 return INVALID_TYPE; |
1247 } | 1283 } |
1248 | 1284 |
1249 std::string SchemaVersionKey::Encode() { | 1285 std::string SchemaVersionKey::Encode() { |
1250 std::string ret = KeyPrefix::EncodeEmpty(); | 1286 std::string ret = KeyPrefix::EncodeEmpty(); |
1251 ret.push_back(kSchemaVersionTypeByte); | 1287 ret.push_back(kSchemaVersionTypeByte); |
1252 return ret; | 1288 return ret; |
1253 } | 1289 } |
1254 | 1290 |
1255 std::string MaxDatabaseIdKey::Encode() { | 1291 std::string MaxDatabaseIdKey::Encode() { |
1256 std::string ret = KeyPrefix::EncodeEmpty(); | 1292 std::string ret = KeyPrefix::EncodeEmpty(); |
1257 ret.push_back(kMaxDatabaseIdTypeByte); | 1293 ret.push_back(kMaxDatabaseIdTypeByte); |
1258 return ret; | 1294 return ret; |
1259 } | 1295 } |
1260 | 1296 |
1261 std::string DataVersionKey::Encode() { | 1297 std::string DataVersionKey::Encode() { |
1262 std::string ret = KeyPrefix::EncodeEmpty(); | 1298 std::string ret = KeyPrefix::EncodeEmpty(); |
1263 ret.push_back(kDataVersionTypeByte); | 1299 ret.push_back(kDataVersionTypeByte); |
1264 return ret; | 1300 return ret; |
1265 } | 1301 } |
1266 | 1302 |
1303 std::string BlobJournalKey::Encode() { | |
1304 std::string ret = KeyPrefix::EncodeEmpty(); | |
1305 ret.push_back(kBlobJournalTypeByte); | |
1306 return ret; | |
1307 } | |
1308 | |
1309 std::string LiveBlobJournalKey::Encode() { | |
1310 std::string ret = KeyPrefix::EncodeEmpty(); | |
1311 ret.push_back(kLiveBlobJournalTypeByte); | |
1312 return ret; | |
1313 } | |
1314 | |
1267 DatabaseFreeListKey::DatabaseFreeListKey() : database_id_(-1) {} | 1315 DatabaseFreeListKey::DatabaseFreeListKey() : database_id_(-1) {} |
1268 | 1316 |
1269 bool DatabaseFreeListKey::Decode(StringPiece* slice, | 1317 bool DatabaseFreeListKey::Decode(StringPiece* slice, |
1270 DatabaseFreeListKey* result) { | 1318 DatabaseFreeListKey* result) { |
1271 KeyPrefix prefix; | 1319 KeyPrefix prefix; |
1272 if (!KeyPrefix::Decode(slice, &prefix)) | 1320 if (!KeyPrefix::Decode(slice, &prefix)) |
1273 return false; | 1321 return false; |
1274 DCHECK(!prefix.database_id_); | 1322 DCHECK(!prefix.database_id_); |
1275 DCHECK(!prefix.object_store_id_); | 1323 DCHECK(!prefix.object_store_id_); |
1276 DCHECK(!prefix.index_id_); | 1324 DCHECK(!prefix.index_id_); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1341 // just after origin in collation order | 1389 // just after origin in collation order |
1342 return EncodeMinKeyForOrigin(origin_identifier + '\x01'); | 1390 return EncodeMinKeyForOrigin(origin_identifier + '\x01'); |
1343 } | 1391 } |
1344 | 1392 |
1345 int DatabaseNameKey::Compare(const DatabaseNameKey& other) { | 1393 int DatabaseNameKey::Compare(const DatabaseNameKey& other) { |
1346 if (int x = origin_.compare(other.origin_)) | 1394 if (int x = origin_.compare(other.origin_)) |
1347 return x; | 1395 return x; |
1348 return database_name_.compare(other.database_name_); | 1396 return database_name_.compare(other.database_name_); |
1349 } | 1397 } |
1350 | 1398 |
1399 bool DatabaseMetaDataKey::IsValidBlobKey(int64 blob_key) { | |
1400 return blob_key >= kBlobKeyGeneratorInitialNumber; | |
1401 } | |
1402 | |
1351 std::string DatabaseMetaDataKey::Encode(int64 database_id, | 1403 std::string DatabaseMetaDataKey::Encode(int64 database_id, |
1352 MetaDataType meta_data_type) { | 1404 MetaDataType meta_data_type) { |
1353 KeyPrefix prefix(database_id); | 1405 KeyPrefix prefix(database_id); |
1354 std::string ret = prefix.Encode(); | 1406 std::string ret = prefix.Encode(); |
1355 ret.push_back(meta_data_type); | 1407 ret.push_back(meta_data_type); |
1356 return ret; | 1408 return ret; |
1357 } | 1409 } |
1358 | 1410 |
1359 ObjectStoreMetaDataKey::ObjectStoreMetaDataKey() | 1411 ObjectStoreMetaDataKey::ObjectStoreMetaDataKey() |
1360 : object_store_id_(-1), meta_data_type_(-1) {} | 1412 : object_store_id_(-1), meta_data_type_(-1) {} |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1740 scoped_ptr<IndexedDBKey> key; | 1792 scoped_ptr<IndexedDBKey> key; |
1741 StringPiece slice(encoded_user_key_); | 1793 StringPiece slice(encoded_user_key_); |
1742 if (!DecodeIDBKey(&slice, &key)) { | 1794 if (!DecodeIDBKey(&slice, &key)) { |
1743 // TODO(jsbell): Return error. | 1795 // TODO(jsbell): Return error. |
1744 } | 1796 } |
1745 return key.Pass(); | 1797 return key.Pass(); |
1746 } | 1798 } |
1747 | 1799 |
1748 const int64 ExistsEntryKey::kSpecialIndexNumber = kExistsEntryIndexId; | 1800 const int64 ExistsEntryKey::kSpecialIndexNumber = kExistsEntryIndexId; |
1749 | 1801 |
1802 bool BlobEntryKey::Decode(StringPiece* slice, BlobEntryKey* result) { | |
1803 KeyPrefix prefix; | |
1804 if (!KeyPrefix::Decode(slice, &prefix)) | |
1805 return false; | |
1806 DCHECK(prefix.database_id_); | |
1807 DCHECK(prefix.object_store_id_); | |
1808 DCHECK_EQ(prefix.index_id_, kSpecialIndexNumber); | |
1809 | |
1810 if (!ExtractEncodedIDBKey(slice, &result->encoded_user_key_)) | |
1811 return false; | |
1812 result->database_id_ = prefix.database_id_; | |
1813 result->object_store_id_ = prefix.object_store_id_; | |
1814 | |
1815 return true; | |
1816 } | |
1817 | |
1818 bool BlobEntryKey::FromObjectStoreDataKey(StringPiece* slice, | |
1819 BlobEntryKey* result) { | |
1820 KeyPrefix prefix; | |
1821 if (!KeyPrefix::Decode(slice, &prefix)) | |
1822 return false; | |
1823 DCHECK(prefix.database_id_); | |
1824 DCHECK(prefix.object_store_id_); | |
1825 DCHECK_EQ(prefix.index_id_, ObjectStoreDataKey::kSpecialIndexNumber); | |
1826 | |
1827 if (!ExtractEncodedIDBKey(slice, &result->encoded_user_key_)) | |
1828 return false; | |
1829 result->database_id_ = prefix.database_id_; | |
1830 result->object_store_id_ = prefix.object_store_id_; | |
1831 return true; | |
1832 } | |
1833 | |
1834 std::string BlobEntryKey::ReencodeToObjectStoreDataKey(StringPiece* slice) { | |
1835 BlobEntryKey key; | |
1836 if (!Decode(slice, &key)) | |
jsbell
2014/03/13 20:58:48
Maybe stick in a TODO that we could be smarter and
ericu
2014/03/13 21:05:53
Done.
| |
1837 return std::string(); | |
1838 | |
1839 return ObjectStoreDataKey::Encode( | |
1840 key.database_id_, key.object_store_id_, key.encoded_user_key_); | |
1841 } | |
1842 | |
1843 std::string BlobEntryKey::EncodeMinKeyForObjectStore(int64 database_id, | |
1844 int64 object_store_id) { | |
1845 // Our implied encoded_user_key_ here is empty, the lowest possible key. | |
1846 return Encode(database_id, object_store_id, std::string()); | |
1847 } | |
1848 | |
1849 std::string BlobEntryKey::EncodeStopKeyForObjectStore(int64 database_id, | |
1850 int64 object_store_id) { | |
1851 DCHECK(KeyPrefix::ValidIds(database_id, object_store_id)); | |
1852 KeyPrefix prefix(KeyPrefix::CreateWithSpecialIndex( | |
1853 database_id, object_store_id, kSpecialIndexNumber + 1)); | |
1854 return prefix.Encode(); | |
1855 } | |
1856 | |
1857 std::string BlobEntryKey::Encode() const { | |
1858 DCHECK(!encoded_user_key_.empty()); | |
1859 return Encode(database_id_, object_store_id_, encoded_user_key_); | |
1860 } | |
1861 | |
1862 std::string BlobEntryKey::Encode(int64 database_id, | |
1863 int64 object_store_id, | |
1864 const IndexedDBKey& user_key) { | |
1865 std::string encoded_key; | |
1866 EncodeIDBKey(user_key, &encoded_key); | |
1867 return Encode(database_id, object_store_id, encoded_key); | |
1868 } | |
1869 | |
1870 std::string BlobEntryKey::Encode(int64 database_id, | |
1871 int64 object_store_id, | |
1872 const std::string& encoded_user_key) { | |
1873 DCHECK(KeyPrefix::ValidIds(database_id, object_store_id)); | |
1874 KeyPrefix prefix(KeyPrefix::CreateWithSpecialIndex( | |
1875 database_id, object_store_id, kSpecialIndexNumber)); | |
1876 return prefix.Encode() + encoded_user_key; | |
1877 } | |
1878 | |
1879 const int64 BlobEntryKey::kSpecialIndexNumber = kBlobEntryIndexId; | |
1880 | |
1750 IndexDataKey::IndexDataKey() | 1881 IndexDataKey::IndexDataKey() |
1751 : database_id_(-1), | 1882 : database_id_(-1), |
1752 object_store_id_(-1), | 1883 object_store_id_(-1), |
1753 index_id_(-1), | 1884 index_id_(-1), |
1754 sequence_number_(-1) {} | 1885 sequence_number_(-1) {} |
1755 | 1886 |
1756 IndexDataKey::~IndexDataKey() {} | 1887 IndexDataKey::~IndexDataKey() {} |
1757 | 1888 |
1758 bool IndexDataKey::Decode(StringPiece* slice, IndexDataKey* result) { | 1889 bool IndexDataKey::Decode(StringPiece* slice, IndexDataKey* result) { |
1759 KeyPrefix prefix; | 1890 KeyPrefix prefix; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1871 scoped_ptr<IndexedDBKey> IndexDataKey::primary_key() const { | 2002 scoped_ptr<IndexedDBKey> IndexDataKey::primary_key() const { |
1872 scoped_ptr<IndexedDBKey> key; | 2003 scoped_ptr<IndexedDBKey> key; |
1873 StringPiece slice(encoded_primary_key_); | 2004 StringPiece slice(encoded_primary_key_); |
1874 if (!DecodeIDBKey(&slice, &key)) { | 2005 if (!DecodeIDBKey(&slice, &key)) { |
1875 // TODO(jsbell): Return error. | 2006 // TODO(jsbell): Return error. |
1876 } | 2007 } |
1877 return key.Pass(); | 2008 return key.Pass(); |
1878 } | 2009 } |
1879 | 2010 |
1880 } // namespace content | 2011 } // namespace content |
OLD | NEW |