Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: content/browser/indexed_db/indexed_db_leveldb_coding.cc

Issue 18023022: Blob support for IDB [Chromium] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge fixes [builds, untested] Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 10 matching lines...) Expand all
156 using WebKit::WebIDBKeyTypeNumber; 171 using WebKit::WebIDBKeyTypeNumber;
157 using WebKit::WebIDBKeyTypeString; 172 using WebKit::WebIDBKeyTypeString;
158 using WebKit::WebIDBKeyPathType; 173 using WebKit::WebIDBKeyPathType;
159 using WebKit::WebIDBKeyPathTypeArray; 174 using WebKit::WebIDBKeyPathTypeArray;
160 using WebKit::WebIDBKeyPathTypeNull; 175 using WebKit::WebIDBKeyPathTypeNull;
161 using WebKit::WebIDBKeyPathTypeString; 176 using WebKit::WebIDBKeyPathTypeString;
162 177
163 namespace content { 178 namespace content {
164 179
165 // As most of the IndexedDBKeys and encoded values are short, we 180 // As most of the IndexedDBKeys and encoded values are short, we
166 // initialize some Vectors with a default inline buffer size to reduce 181 // initialize some std::vectors with a default inline buffer size to reduce
167 // the memory re-allocations when the Vectors are appended. 182 // the memory re-allocations when the std::vectors are appended.
168 static const size_t kDefaultInlineBufferSize = 32; 183 static const size_t kDefaultInlineBufferSize = 32;
169 184
170 static const unsigned char kIndexedDBKeyNullTypeByte = 0; 185 static const unsigned char kIndexedDBKeyNullTypeByte = 0;
171 static const unsigned char kIndexedDBKeyStringTypeByte = 1; 186 static const unsigned char kIndexedDBKeyStringTypeByte = 1;
172 static const unsigned char kIndexedDBKeyDateTypeByte = 2; 187 static const unsigned char kIndexedDBKeyDateTypeByte = 2;
173 static const unsigned char kIndexedDBKeyNumberTypeByte = 3; 188 static const unsigned char kIndexedDBKeyNumberTypeByte = 3;
174 static const unsigned char kIndexedDBKeyArrayTypeByte = 4; 189 static const unsigned char kIndexedDBKeyArrayTypeByte = 4;
175 static const unsigned char kIndexedDBKeyMinKeyTypeByte = 5; 190 static const unsigned char kIndexedDBKeyMinKeyTypeByte = 5;
176 191
177 static const unsigned char kIndexedDBKeyPathTypeCodedByte1 = 0; 192 static const unsigned char kIndexedDBKeyPathTypeCodedByte1 = 0;
178 static const unsigned char kIndexedDBKeyPathTypeCodedByte2 = 0; 193 static const unsigned char kIndexedDBKeyPathTypeCodedByte2 = 0;
179 194
180 static const unsigned char kObjectStoreDataIndexId = 1; 195 static const unsigned char kObjectStoreDataIndexId = 1;
181 static const unsigned char kExistsEntryIndexId = 2; 196 static const unsigned char kExistsEntryIndexId = 2;
197 static const unsigned char kBlobEntryIndexId = 3;
182 198
183 static const unsigned char kSchemaVersionTypeByte = 0; 199 static const unsigned char kSchemaVersionTypeByte = 0;
184 static const unsigned char kMaxDatabaseIdTypeByte = 1; 200 static const unsigned char kMaxDatabaseIdTypeByte = 1;
185 static const unsigned char kDataVersionTypeByte = 2; 201 static const unsigned char kDataVersionTypeByte = 2;
202 static const unsigned char kBlobJournalTypeByte = 3;
203 static const unsigned char kLiveBlobJournalTypeByte = 4;
186 static const unsigned char kMaxSimpleGlobalMetaDataTypeByte = 204 static const unsigned char kMaxSimpleGlobalMetaDataTypeByte =
187 3; // Insert before this and increment. 205 5; // Insert before this and increment.
188 static const unsigned char kDatabaseFreeListTypeByte = 100; 206 static const unsigned char kDatabaseFreeListTypeByte = 100;
189 static const unsigned char kDatabaseNameTypeByte = 201; 207 static const unsigned char kDatabaseNameTypeByte = 201;
190 208
191 static const unsigned char kObjectStoreMetaDataTypeByte = 50; 209 static const unsigned char kObjectStoreMetaDataTypeByte = 50;
192 static const unsigned char kIndexMetaDataTypeByte = 100; 210 static const unsigned char kIndexMetaDataTypeByte = 100;
193 static const unsigned char kObjectStoreFreeListTypeByte = 150; 211 static const unsigned char kObjectStoreFreeListTypeByte = 150;
194 static const unsigned char kIndexFreeListTypeByte = 151; 212 static const unsigned char kIndexFreeListTypeByte = 151;
195 static const unsigned char kObjectStoreNamesTypeByte = 200; 213 static const unsigned char kObjectStoreNamesTypeByte = 200;
196 static const unsigned char kIndexNamesKeyTypeByte = 201; 214 static const unsigned char kIndexNamesKeyTypeByte = 201;
197 215
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 DCHECK(!slice_a.empty()); 869 DCHECK(!slice_a.empty());
852 DCHECK(!slice_b.empty()); 870 DCHECK(!slice_b.empty());
853 // Prefixes are not compared - it is assumed this was already done. 871 // Prefixes are not compared - it is assumed this was already done.
854 DCHECK(!prefix_a.Compare(prefix_b)); 872 DCHECK(!prefix_a.Compare(prefix_b));
855 873
856 return CompareSuffix<ObjectStoreDataKey>( 874 return CompareSuffix<ObjectStoreDataKey>(
857 &slice_a, &slice_b, only_compare_index_keys, ok); 875 &slice_a, &slice_b, only_compare_index_keys, ok);
858 } 876 }
859 877
860 template <> 878 template <>
879 int Compare<BlobEntryKey>(const StringPiece& a,
880 const StringPiece& b,
881 bool,
882 bool* ok) {
883 KeyPrefix prefix_a;
884 KeyPrefix prefix_b;
885 StringPiece slice_a(a);
886 StringPiece slice_b(b);
887 bool ok_a = KeyPrefix::Decode(&slice_a, &prefix_a);
888 bool ok_b = KeyPrefix::Decode(&slice_b, &prefix_b);
889 DCHECK(ok_a);
890 DCHECK(ok_b);
891 DCHECK(prefix_a.database_id_);
892 DCHECK(prefix_a.object_store_id_);
893 DCHECK_EQ(prefix_a.index_id_, BlobEntryKey::kSpecialIndexNumber);
894 DCHECK(prefix_b.database_id_);
895 DCHECK(prefix_b.object_store_id_);
896 DCHECK_EQ(prefix_b.index_id_, BlobEntryKey::kSpecialIndexNumber);
897 DCHECK(!slice_a.empty());
898 DCHECK(!slice_b.empty());
899 // Prefixes are not compared - it is assumed this was already done.
900 DCHECK(!prefix_a.Compare(prefix_b));
901
902 return CompareSuffix<ObjectStoreDataKey>(
903 &slice_a, &slice_b, false, ok);
904 }
905
906 template <>
861 int CompareSuffix<IndexDataKey>(StringPiece* slice_a, 907 int CompareSuffix<IndexDataKey>(StringPiece* slice_a,
862 StringPiece* slice_b, 908 StringPiece* slice_b,
863 bool only_compare_index_keys, 909 bool only_compare_index_keys,
864 bool* ok) { 910 bool* ok) {
865 // index key 911 // index key
866 int result = CompareEncodedIDBKeys(slice_a, slice_b, ok); 912 int result = CompareEncodedIDBKeys(slice_a, slice_b, ok);
867 if (!*ok || result) 913 if (!*ok || result)
868 return result; 914 return result;
869 if (only_compare_index_keys) 915 if (only_compare_index_keys)
870 return 0; 916 return 0;
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 1075
1030 case KeyPrefix::EXISTS_ENTRY: { 1076 case KeyPrefix::EXISTS_ENTRY: {
1031 // Provide a stable ordering for invalid data. 1077 // Provide a stable ordering for invalid data.
1032 if (slice_a.empty() || slice_b.empty()) 1078 if (slice_a.empty() || slice_b.empty())
1033 return CompareSizes(slice_a.size(), slice_b.size()); 1079 return CompareSizes(slice_a.size(), slice_b.size());
1034 1080
1035 return CompareSuffix<ExistsEntryKey>( 1081 return CompareSuffix<ExistsEntryKey>(
1036 &slice_a, &slice_b, /*only_compare_index_keys*/ false, ok); 1082 &slice_a, &slice_b, /*only_compare_index_keys*/ false, ok);
1037 } 1083 }
1038 1084
1085 case KeyPrefix::BLOB_ENTRY: {
1086 // Provide a stable ordering for invalid data.
1087 if (slice_a.empty() || slice_b.empty())
1088 return CompareSizes(slice_a.size(), slice_b.size());
1089
1090 return CompareSuffix<BlobEntryKey>(
1091 &slice_a, &slice_b, /*only_compare_index_keys*/ false, ok);
1092 }
1093
1039 case KeyPrefix::INDEX_DATA: { 1094 case KeyPrefix::INDEX_DATA: {
1040 // Provide a stable ordering for invalid data. 1095 // Provide a stable ordering for invalid data.
1041 if (slice_a.empty() || slice_b.empty()) 1096 if (slice_a.empty() || slice_b.empty())
1042 return CompareSizes(slice_a.size(), slice_b.size()); 1097 return CompareSizes(slice_a.size(), slice_b.size());
1043 1098
1044 return CompareSuffix<IndexDataKey>( 1099 return CompareSuffix<IndexDataKey>(
1045 &slice_a, &slice_b, only_compare_index_keys, ok); 1100 &slice_a, &slice_b, only_compare_index_keys, ok);
1046 } 1101 }
1047 1102
1048 case KeyPrefix::INVALID_TYPE: 1103 case KeyPrefix::INVALID_TYPE:
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 DCHECK(index_id_ != kInvalidId); 1285 DCHECK(index_id_ != kInvalidId);
1231 1286
1232 if (!database_id_) 1287 if (!database_id_)
1233 return GLOBAL_METADATA; 1288 return GLOBAL_METADATA;
1234 if (!object_store_id_) 1289 if (!object_store_id_)
1235 return DATABASE_METADATA; 1290 return DATABASE_METADATA;
1236 if (index_id_ == kObjectStoreDataIndexId) 1291 if (index_id_ == kObjectStoreDataIndexId)
1237 return OBJECT_STORE_DATA; 1292 return OBJECT_STORE_DATA;
1238 if (index_id_ == kExistsEntryIndexId) 1293 if (index_id_ == kExistsEntryIndexId)
1239 return EXISTS_ENTRY; 1294 return EXISTS_ENTRY;
1295 if (index_id_ == kBlobEntryIndexId)
1296 return BLOB_ENTRY;
1240 if (index_id_ >= kMinimumIndexId) 1297 if (index_id_ >= kMinimumIndexId)
1241 return INDEX_DATA; 1298 return INDEX_DATA;
1242 1299
1243 NOTREACHED(); 1300 NOTREACHED();
1244 return INVALID_TYPE; 1301 return INVALID_TYPE;
1245 } 1302 }
1246 1303
1247 std::string SchemaVersionKey::Encode() { 1304 std::string SchemaVersionKey::Encode() {
1248 std::string ret = KeyPrefix::EncodeEmpty(); 1305 std::string ret = KeyPrefix::EncodeEmpty();
1249 ret.push_back(kSchemaVersionTypeByte); 1306 ret.push_back(kSchemaVersionTypeByte);
1250 return ret; 1307 return ret;
1251 } 1308 }
1252 1309
1253 std::string MaxDatabaseIdKey::Encode() { 1310 std::string MaxDatabaseIdKey::Encode() {
1254 std::string ret = KeyPrefix::EncodeEmpty(); 1311 std::string ret = KeyPrefix::EncodeEmpty();
1255 ret.push_back(kMaxDatabaseIdTypeByte); 1312 ret.push_back(kMaxDatabaseIdTypeByte);
1256 return ret; 1313 return ret;
1257 } 1314 }
1258 1315
1259 std::string DataVersionKey::Encode() { 1316 std::string DataVersionKey::Encode() {
1260 std::string ret = KeyPrefix::EncodeEmpty(); 1317 std::string ret = KeyPrefix::EncodeEmpty();
1261 ret.push_back(kDataVersionTypeByte); 1318 ret.push_back(kDataVersionTypeByte);
1262 return ret; 1319 return ret;
1263 } 1320 }
1264 1321
1322 std::string BlobJournalKey::Encode()
1323 {
1324 std::string ret = KeyPrefix::EncodeEmpty();
1325 ret.push_back(kBlobJournalTypeByte);
1326 return ret;
1327 }
1328
1329 std::string LiveBlobJournalKey::Encode()
1330 {
1331 std::string ret = KeyPrefix::EncodeEmpty();
1332 ret.push_back(kLiveBlobJournalTypeByte);
1333 return ret;
1334 }
1335
1265 DatabaseFreeListKey::DatabaseFreeListKey() : database_id_(-1) {} 1336 DatabaseFreeListKey::DatabaseFreeListKey() : database_id_(-1) {}
1266 1337
1267 bool DatabaseFreeListKey::Decode(StringPiece* slice, 1338 bool DatabaseFreeListKey::Decode(StringPiece* slice,
1268 DatabaseFreeListKey* result) { 1339 DatabaseFreeListKey* result) {
1269 KeyPrefix prefix; 1340 KeyPrefix prefix;
1270 if (!KeyPrefix::Decode(slice, &prefix)) 1341 if (!KeyPrefix::Decode(slice, &prefix))
1271 return false; 1342 return false;
1272 DCHECK(!prefix.database_id_); 1343 DCHECK(!prefix.database_id_);
1273 DCHECK(!prefix.object_store_id_); 1344 DCHECK(!prefix.object_store_id_);
1274 DCHECK(!prefix.index_id_); 1345 DCHECK(!prefix.index_id_);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 // just after origin in collation order 1410 // just after origin in collation order
1340 return EncodeMinKeyForOrigin(origin_identifier + '\x01'); 1411 return EncodeMinKeyForOrigin(origin_identifier + '\x01');
1341 } 1412 }
1342 1413
1343 int DatabaseNameKey::Compare(const DatabaseNameKey& other) { 1414 int DatabaseNameKey::Compare(const DatabaseNameKey& other) {
1344 if (int x = origin_.compare(other.origin_)) 1415 if (int x = origin_.compare(other.origin_))
1345 return x; 1416 return x;
1346 return database_name_.compare(other.database_name_); 1417 return database_name_.compare(other.database_name_);
1347 } 1418 }
1348 1419
1420 bool DatabaseMetaDataKey::IsValidBlobKey(int64 blob_key) {
1421 return blob_key >= kBlobKeyGeneratorInitialNumber;
1422 }
1423
1349 std::string DatabaseMetaDataKey::Encode(int64 database_id, 1424 std::string DatabaseMetaDataKey::Encode(int64 database_id,
1350 MetaDataType meta_data_type) { 1425 MetaDataType meta_data_type) {
1351 KeyPrefix prefix(database_id); 1426 KeyPrefix prefix(database_id);
1352 std::string ret = prefix.Encode(); 1427 std::string ret = prefix.Encode();
1353 ret.push_back(meta_data_type); 1428 ret.push_back(meta_data_type);
1354 return ret; 1429 return ret;
1355 } 1430 }
1356 1431
1357 ObjectStoreMetaDataKey::ObjectStoreMetaDataKey() 1432 ObjectStoreMetaDataKey::ObjectStoreMetaDataKey()
1358 : object_store_id_(-1), meta_data_type_(-1) {} 1433 : object_store_id_(-1), meta_data_type_(-1) {}
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 scoped_ptr<IndexedDBKey> key; 1820 scoped_ptr<IndexedDBKey> key;
1746 StringPiece slice(encoded_user_key_); 1821 StringPiece slice(encoded_user_key_);
1747 if (!DecodeIDBKey(&slice, &key)) { 1822 if (!DecodeIDBKey(&slice, &key)) {
1748 // TODO(jsbell): Return error. 1823 // TODO(jsbell): Return error.
1749 } 1824 }
1750 return key.Pass(); 1825 return key.Pass();
1751 } 1826 }
1752 1827
1753 const int64 ExistsEntryKey::kSpecialIndexNumber = kExistsEntryIndexId; 1828 const int64 ExistsEntryKey::kSpecialIndexNumber = kExistsEntryIndexId;
1754 1829
1830 bool BlobEntryKey::Decode(StringPiece* slice, 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_, 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
1843 return true;
1844 }
1845
1846 bool BlobEntryKey::FromObjectStoreDataKey(StringPiece* slice,
1847 BlobEntryKey* result) {
1848 KeyPrefix prefix;
1849 if (!KeyPrefix::Decode(slice, &prefix))
1850 return false;
1851 DCHECK(prefix.database_id_);
1852 DCHECK(prefix.object_store_id_);
1853 DCHECK_EQ(prefix.index_id_, ObjectStoreDataKey::kSpecialIndexNumber);
1854
1855 if (!ExtractEncodedIDBKey(slice, &result->encoded_user_key_))
1856 return false;
1857 result->database_id_ = prefix.database_id_;
1858 result->object_store_id_ = prefix.object_store_id_;
1859 return true;
1860 }
1861
1862 std::string BlobEntryKey::EncodeToObjectStoreDataKey(StringPiece* slice) {
jsbell 2013/09/13 00:12:21 What this method did wasn't obvious to me at the c
ericu 2013/11/20 23:05:39 Done.
1863 BlobEntryKey key;
1864 if (!Decode(slice, &key))
1865 return std::string();
1866
1867 return ObjectStoreDataKey::Encode(
1868 key.database_id_, key.object_store_id_, key.encoded_user_key_);
1869 }
1870
1871 std::string BlobEntryKey::EncodeMinForObjectStore(int64 database_id,
1872 int64 object_store_id) {
1873 // Our implied encoded_user_key_ here is empty, the lowest possible key.
1874 return Encode(database_id, object_store_id, std::string());
1875 }
1876
1877 // This isn't technically the max for this object store--it's one higher, which
1878 // means that it's the first key /not/ in the range. That's more what we want,
1879 // but doesn't match the terminology elsewhere in this file, which is a bit
1880 // messy.
1881 std::string BlobEntryKey::EncodeMaxForObjectStore(int64 database_id,
1882 int64 object_store_id)
1883 {
1884 DCHECK(KeyPrefix::ValidIds(database_id, object_store_id));
1885 KeyPrefix prefix(
1886 KeyPrefix::CreateWithSpecialIndex(database_id, object_store_id,
1887 kSpecialIndexNumber + 1));
jsbell 2013/09/13 00:12:21 Can you introduce another const, rather than kSpec
ericu 2013/11/20 23:05:39 I think that might be confusing. The point is not
jsbell 2013/11/21 22:54:32 Got it, I wasn't paying attention to the usage (i.
1888 return prefix.Encode();
1889 }
1890
1891 std::string BlobEntryKey::Encode() const
1892 {
1893 DCHECK_GT(encoded_user_key_.size(), 0UL);
1894 return Encode(database_id_, object_store_id_, encoded_user_key_);
1895 }
1896
1897 std::string BlobEntryKey::Encode(int64 database_id,
1898 int64 object_store_id,
1899 const IndexedDBKey& user_key)
1900 {
1901 std::string encoded_key;
1902 EncodeIDBKey(user_key, &encoded_key);
1903 return Encode(database_id, object_store_id, encoded_key);
1904 }
1905
1906 std::string BlobEntryKey::Encode(
1907 int64 database_id, int64 object_store_id,
1908 const std::string& encoded_user_key) {
1909 DCHECK(KeyPrefix::ValidIds(database_id, object_store_id));
1910 KeyPrefix prefix(
1911 KeyPrefix::CreateWithSpecialIndex(database_id, object_store_id,
1912 kSpecialIndexNumber));
1913 std::string ret = prefix.Encode();
1914 ret.insert(ret.end(), encoded_user_key.begin(), encoded_user_key.end());
1915 return ret;
1916 }
1917
1918 int BlobEntryKey::Compare(const BlobEntryKey& other, bool* ok)
1919 {
1920 DCHECK_GT(encoded_user_key_.size(), 0UL);
1921 DCHECK_GT(other.encoded_user_key_.size(), 0UL);
1922 return CompareEncodedIDBKeys(encoded_user_key_, other.encoded_user_key_, ok);
1923 }
1924
1925 const int64 BlobEntryKey::kSpecialIndexNumber = kBlobEntryIndexId;
1926
1755 IndexDataKey::IndexDataKey() 1927 IndexDataKey::IndexDataKey()
1756 : database_id_(-1), 1928 : database_id_(-1),
1757 object_store_id_(-1), 1929 object_store_id_(-1),
1758 index_id_(-1), 1930 index_id_(-1),
1759 sequence_number_(-1) {} 1931 sequence_number_(-1) {}
1760 1932
1761 IndexDataKey::~IndexDataKey() {} 1933 IndexDataKey::~IndexDataKey() {}
1762 1934
1763 bool IndexDataKey::Decode(StringPiece* slice, IndexDataKey* result) { 1935 bool IndexDataKey::Decode(StringPiece* slice, IndexDataKey* result) {
1764 KeyPrefix prefix; 1936 KeyPrefix prefix;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1878 scoped_ptr<IndexedDBKey> IndexDataKey::primary_key() const { 2050 scoped_ptr<IndexedDBKey> IndexDataKey::primary_key() const {
1879 scoped_ptr<IndexedDBKey> key; 2051 scoped_ptr<IndexedDBKey> key;
1880 StringPiece slice(encoded_primary_key_); 2052 StringPiece slice(encoded_primary_key_);
1881 if (!DecodeIDBKey(&slice, &key)) { 2053 if (!DecodeIDBKey(&slice, &key)) {
1882 // TODO(jsbell): Return error. 2054 // TODO(jsbell): Return error.
1883 } 2055 }
1884 return key.Pass(); 2056 return key.Pass();
1885 } 2057 }
1886 2058
1887 } // namespace content 2059 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698