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_database.h" | 5 #include "content/browser/indexed_db/indexed_db_database.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <set> | 10 #include <set> |
(...skipping 1188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); | 1199 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
1200 } | 1200 } |
1201 return; | 1201 return; |
1202 } | 1202 } |
1203 | 1203 |
1204 std::vector<IndexedDBKey> found_keys; | 1204 std::vector<IndexedDBKey> found_keys; |
1205 std::vector<IndexedDBReturnValue> found_values; | 1205 std::vector<IndexedDBReturnValue> found_values; |
1206 if (!cursor) { | 1206 if (!cursor) { |
1207 // Doesn't matter if key or value array here - will be empty array when it | 1207 // Doesn't matter if key or value array here - will be empty array when it |
1208 // hits JavaScript. | 1208 // hits JavaScript. |
1209 callbacks->OnSuccessArray(&found_values, object_store_metadata.key_path); | 1209 callbacks->OnSuccessArray(&found_values); |
1210 return; | 1210 return; |
1211 } | 1211 } |
1212 | 1212 |
1213 bool did_first_seek = false; | 1213 bool did_first_seek = false; |
1214 bool generated_key = object_store_metadata.auto_increment && | 1214 bool generated_key = object_store_metadata.auto_increment && |
1215 !object_store_metadata.key_path.IsNull(); | 1215 !object_store_metadata.key_path.IsNull(); |
1216 | 1216 |
1217 size_t response_size = kMaxIDBMessageOverhead; | 1217 size_t response_size = kMaxIDBMessageOverhead; |
1218 int64_t num_found_items = 0; | 1218 int64_t num_found_items = 0; |
1219 while (num_found_items++ < max_count) { | 1219 while (num_found_items++ < max_count) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1265 found_keys.push_back(return_key); | 1265 found_keys.push_back(return_key); |
1266 else | 1266 else |
1267 found_values.push_back(return_value); | 1267 found_values.push_back(return_value); |
1268 } | 1268 } |
1269 | 1269 |
1270 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) { | 1270 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) { |
1271 // IndexedDBKey already supports an array of values so we can leverage this | 1271 // IndexedDBKey already supports an array of values so we can leverage this |
1272 // to return an array of keys - no need to create our own array of keys. | 1272 // to return an array of keys - no need to create our own array of keys. |
1273 callbacks->OnSuccess(IndexedDBKey(found_keys)); | 1273 callbacks->OnSuccess(IndexedDBKey(found_keys)); |
1274 } else { | 1274 } else { |
1275 callbacks->OnSuccessArray(&found_values, object_store_metadata.key_path); | 1275 callbacks->OnSuccessArray(&found_values); |
1276 } | 1276 } |
1277 } | 1277 } |
1278 | 1278 |
1279 static std::unique_ptr<IndexedDBKey> GenerateKey( | 1279 static std::unique_ptr<IndexedDBKey> GenerateKey( |
1280 IndexedDBBackingStore* backing_store, | 1280 IndexedDBBackingStore* backing_store, |
1281 IndexedDBTransaction* transaction, | 1281 IndexedDBTransaction* transaction, |
1282 int64_t database_id, | 1282 int64_t database_id, |
1283 int64_t object_store_id) { | 1283 int64_t object_store_id) { |
1284 const int64_t max_generator_value = | 1284 const int64_t max_generator_value = |
1285 9007199254740992LL; // Maximum integer storable as ECMAScript number. | 1285 9007199254740992LL; // Maximum integer storable as ECMAScript number. |
(...skipping 26 matching lines...) Expand all Loading... |
1312 } | 1312 } |
1313 | 1313 |
1314 struct IndexedDBDatabase::PutOperationParams { | 1314 struct IndexedDBDatabase::PutOperationParams { |
1315 PutOperationParams() {} | 1315 PutOperationParams() {} |
1316 int64_t object_store_id; | 1316 int64_t object_store_id; |
1317 IndexedDBValue value; | 1317 IndexedDBValue value; |
1318 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; | 1318 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; |
1319 std::unique_ptr<IndexedDBKey> key; | 1319 std::unique_ptr<IndexedDBKey> key; |
1320 blink::WebIDBPutMode put_mode; | 1320 blink::WebIDBPutMode put_mode; |
1321 scoped_refptr<IndexedDBCallbacks> callbacks; | 1321 scoped_refptr<IndexedDBCallbacks> callbacks; |
1322 std::vector<IndexKeys> index_keys; | 1322 std::vector<IndexedDBIndexKeys> index_keys; |
1323 | 1323 |
1324 private: | 1324 private: |
1325 DISALLOW_COPY_AND_ASSIGN(PutOperationParams); | 1325 DISALLOW_COPY_AND_ASSIGN(PutOperationParams); |
1326 }; | 1326 }; |
1327 | 1327 |
1328 void IndexedDBDatabase::Put( | 1328 void IndexedDBDatabase::Put( |
1329 int64_t transaction_id, | 1329 int64_t transaction_id, |
1330 int64_t object_store_id, | 1330 int64_t object_store_id, |
1331 IndexedDBValue* value, | 1331 IndexedDBValue* value, |
1332 std::vector<std::unique_ptr<storage::BlobDataHandle>>* handles, | 1332 std::vector<std::unique_ptr<storage::BlobDataHandle>>* handles, |
1333 std::unique_ptr<IndexedDBKey> key, | 1333 std::unique_ptr<IndexedDBKey> key, |
1334 blink::WebIDBPutMode put_mode, | 1334 blink::WebIDBPutMode put_mode, |
1335 scoped_refptr<IndexedDBCallbacks> callbacks, | 1335 scoped_refptr<IndexedDBCallbacks> callbacks, |
1336 const std::vector<IndexKeys>& index_keys) { | 1336 const std::vector<IndexedDBIndexKeys>& index_keys) { |
1337 IDB_TRACE1("IndexedDBDatabase::Put", "txn.id", transaction_id); | 1337 IDB_TRACE1("IndexedDBDatabase::Put", "txn.id", transaction_id); |
1338 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 1338 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
1339 if (!transaction) | 1339 if (!transaction) |
1340 return; | 1340 return; |
1341 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); | 1341 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); |
1342 | 1342 |
1343 if (!ValidateObjectStoreId(object_store_id)) | 1343 if (!ValidateObjectStoreId(object_store_id)) |
1344 return; | 1344 return; |
1345 | 1345 |
1346 DCHECK(key); | 1346 DCHECK(key); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1494 transaction->id()); | 1494 transaction->id()); |
1495 params->callbacks->OnSuccess(*key); | 1495 params->callbacks->OnSuccess(*key); |
1496 } | 1496 } |
1497 FilterObservation(transaction, params->object_store_id, | 1497 FilterObservation(transaction, params->object_store_id, |
1498 params->put_mode == blink::WebIDBPutModeAddOnly | 1498 params->put_mode == blink::WebIDBPutModeAddOnly |
1499 ? blink::WebIDBAdd | 1499 ? blink::WebIDBAdd |
1500 : blink::WebIDBPut, | 1500 : blink::WebIDBPut, |
1501 IndexedDBKeyRange(*key)); | 1501 IndexedDBKeyRange(*key)); |
1502 } | 1502 } |
1503 | 1503 |
1504 void IndexedDBDatabase::SetIndexKeys(int64_t transaction_id, | 1504 void IndexedDBDatabase::SetIndexKeys( |
1505 int64_t object_store_id, | 1505 int64_t transaction_id, |
1506 std::unique_ptr<IndexedDBKey> primary_key, | 1506 int64_t object_store_id, |
1507 const std::vector<IndexKeys>& index_keys) { | 1507 std::unique_ptr<IndexedDBKey> primary_key, |
| 1508 const std::vector<IndexedDBIndexKeys>& index_keys) { |
1508 IDB_TRACE1("IndexedDBDatabase::SetIndexKeys", "txn.id", transaction_id); | 1509 IDB_TRACE1("IndexedDBDatabase::SetIndexKeys", "txn.id", transaction_id); |
1509 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 1510 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
1510 if (!transaction) | 1511 if (!transaction) |
1511 return; | 1512 return; |
1512 DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 1513 DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); |
1513 | 1514 |
1514 // TODO(alecflett): This method could be asynchronous, but we need to | 1515 // TODO(alecflett): This method could be asynchronous, but we need to |
1515 // evaluate if it's worth the extra complexity. | 1516 // evaluate if it's worth the extra complexity. |
1516 IndexedDBBackingStore::RecordIdentifier record_identifier; | 1517 IndexedDBBackingStore::RecordIdentifier record_identifier; |
1517 bool found = false; | 1518 bool found = false; |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2125 | 2126 |
2126 void IndexedDBDatabase::VersionChangeAbortOperation( | 2127 void IndexedDBDatabase::VersionChangeAbortOperation( |
2127 int64_t previous_version, | 2128 int64_t previous_version, |
2128 IndexedDBTransaction* transaction) { | 2129 IndexedDBTransaction* transaction) { |
2129 DCHECK(!transaction); | 2130 DCHECK(!transaction); |
2130 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); | 2131 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); |
2131 metadata_.version = previous_version; | 2132 metadata_.version = previous_version; |
2132 } | 2133 } |
2133 | 2134 |
2134 } // namespace content | 2135 } // namespace content |
OLD | NEW |