| 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 <memory> | 10 #include <memory> |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 } | 457 } |
| 458 | 458 |
| 459 size_t IndexedDBDatabase::GetMaxMessageSizeInBytes() const { | 459 size_t IndexedDBDatabase::GetMaxMessageSizeInBytes() const { |
| 460 return kMaxIDBMessageSizeInBytes; | 460 return kMaxIDBMessageSizeInBytes; |
| 461 } | 461 } |
| 462 | 462 |
| 463 std::unique_ptr<IndexedDBConnection> IndexedDBDatabase::CreateConnection( | 463 std::unique_ptr<IndexedDBConnection> IndexedDBDatabase::CreateConnection( |
| 464 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, | 464 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, |
| 465 int child_process_id) { | 465 int child_process_id) { |
| 466 std::unique_ptr<IndexedDBConnection> connection( | 466 std::unique_ptr<IndexedDBConnection> connection( |
| 467 new IndexedDBConnection(this, database_callbacks)); | 467 base::MakeUnique<IndexedDBConnection>(this, database_callbacks)); |
| 468 connections_.insert(connection.get()); | 468 connections_.insert(connection.get()); |
| 469 backing_store_->GrantChildProcessPermissions(child_process_id); | 469 backing_store_->GrantChildProcessPermissions(child_process_id); |
| 470 return connection; | 470 return connection; |
| 471 } | 471 } |
| 472 | 472 |
| 473 IndexedDBTransaction* IndexedDBDatabase::GetTransaction( | 473 IndexedDBTransaction* IndexedDBDatabase::GetTransaction( |
| 474 int64_t transaction_id) const { | 474 int64_t transaction_id) const { |
| 475 const auto& trans_iterator = transactions_.find(transaction_id); | 475 const auto& trans_iterator = transactions_.find(transaction_id); |
| 476 if (trans_iterator == transactions_.end()) | 476 if (trans_iterator == transactions_.end()) |
| 477 return NULL; | 477 return NULL; |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 blink::WebIDBOperationType type, | 789 blink::WebIDBOperationType type, |
| 790 const IndexedDBKeyRange& key_range) { | 790 const IndexedDBKeyRange& key_range) { |
| 791 for (auto* connection : connections_) { | 791 for (auto* connection : connections_) { |
| 792 bool recorded = false; | 792 bool recorded = false; |
| 793 for (const auto& observer : connection->active_observers()) { | 793 for (const auto& observer : connection->active_observers()) { |
| 794 if (!observer->IsRecordingType(type) || | 794 if (!observer->IsRecordingType(type) || |
| 795 !observer->IsRecordingObjectStore(object_store_id)) | 795 !observer->IsRecordingObjectStore(object_store_id)) |
| 796 continue; | 796 continue; |
| 797 if (!recorded) { | 797 if (!recorded) { |
| 798 if (type == blink::WebIDBClear) { | 798 if (type == blink::WebIDBClear) { |
| 799 transaction->AddObservation(connection->id(), | 799 transaction->AddObservation( |
| 800 base::WrapUnique(new IndexedDBObservation( | 800 connection->id(), |
| 801 object_store_id, type))); | 801 base::MakeUnique<IndexedDBObservation>(object_store_id, type)); |
| 802 } else { | 802 } else { |
| 803 transaction->AddObservation(connection->id(), | 803 transaction->AddObservation(connection->id(), |
| 804 base::WrapUnique(new IndexedDBObservation( | 804 base::MakeUnique<IndexedDBObservation>( |
| 805 object_store_id, type, key_range))); | 805 object_store_id, type, key_range)); |
| 806 } | 806 } |
| 807 recorded = true; | 807 recorded = true; |
| 808 } | 808 } |
| 809 transaction->RecordObserverForLastObservation(connection->id(), | 809 transaction->RecordObserverForLastObservation(connection->id(), |
| 810 observer->id()); | 810 observer->id()); |
| 811 } | 811 } |
| 812 } | 812 } |
| 813 } | 813 } |
| 814 | 814 |
| 815 void IndexedDBDatabase::SendObservations( | 815 void IndexedDBDatabase::SendObservations( |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 const int64_t max_generator_value = | 1165 const int64_t max_generator_value = |
| 1166 9007199254740992LL; // Maximum integer storable as ECMAScript number. | 1166 9007199254740992LL; // Maximum integer storable as ECMAScript number. |
| 1167 int64_t current_number; | 1167 int64_t current_number; |
| 1168 leveldb::Status s = backing_store->GetKeyGeneratorCurrentNumber( | 1168 leveldb::Status s = backing_store->GetKeyGeneratorCurrentNumber( |
| 1169 transaction->BackingStoreTransaction(), | 1169 transaction->BackingStoreTransaction(), |
| 1170 database_id, | 1170 database_id, |
| 1171 object_store_id, | 1171 object_store_id, |
| 1172 ¤t_number); | 1172 ¤t_number); |
| 1173 if (!s.ok()) { | 1173 if (!s.ok()) { |
| 1174 LOG(ERROR) << "Failed to GetKeyGeneratorCurrentNumber"; | 1174 LOG(ERROR) << "Failed to GetKeyGeneratorCurrentNumber"; |
| 1175 return base::WrapUnique(new IndexedDBKey()); | 1175 return base::MakeUnique<IndexedDBKey>(); |
| 1176 } | 1176 } |
| 1177 if (current_number < 0 || current_number > max_generator_value) | 1177 if (current_number < 0 || current_number > max_generator_value) |
| 1178 return base::WrapUnique(new IndexedDBKey()); | 1178 return base::MakeUnique<IndexedDBKey>(); |
| 1179 | 1179 |
| 1180 return base::WrapUnique( | 1180 return base::MakeUnique<IndexedDBKey>(current_number, WebIDBKeyTypeNumber); |
| 1181 new IndexedDBKey(current_number, WebIDBKeyTypeNumber)); | |
| 1182 } | 1181 } |
| 1183 | 1182 |
| 1184 static leveldb::Status UpdateKeyGenerator(IndexedDBBackingStore* backing_store, | 1183 static leveldb::Status UpdateKeyGenerator(IndexedDBBackingStore* backing_store, |
| 1185 IndexedDBTransaction* transaction, | 1184 IndexedDBTransaction* transaction, |
| 1186 int64_t database_id, | 1185 int64_t database_id, |
| 1187 int64_t object_store_id, | 1186 int64_t object_store_id, |
| 1188 const IndexedDBKey& key, | 1187 const IndexedDBKey& key, |
| 1189 bool check_current) { | 1188 bool check_current) { |
| 1190 DCHECK_EQ(WebIDBKeyTypeNumber, key.type()); | 1189 DCHECK_EQ(WebIDBKeyTypeNumber, key.type()); |
| 1191 return backing_store->MaybeUpdateKeyGeneratorCurrentNumber( | 1190 return backing_store->MaybeUpdateKeyGeneratorCurrentNumber( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1219 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 1218 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
| 1220 if (!transaction) | 1219 if (!transaction) |
| 1221 return; | 1220 return; |
| 1222 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); | 1221 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); |
| 1223 | 1222 |
| 1224 if (!ValidateObjectStoreId(object_store_id)) | 1223 if (!ValidateObjectStoreId(object_store_id)) |
| 1225 return; | 1224 return; |
| 1226 | 1225 |
| 1227 DCHECK(key); | 1226 DCHECK(key); |
| 1228 DCHECK(value); | 1227 DCHECK(value); |
| 1229 std::unique_ptr<PutOperationParams> params(new PutOperationParams()); | 1228 std::unique_ptr<PutOperationParams> params( |
| 1229 base::MakeUnique<PutOperationParams>()); |
| 1230 params->object_store_id = object_store_id; | 1230 params->object_store_id = object_store_id; |
| 1231 params->value.swap(*value); | 1231 params->value.swap(*value); |
| 1232 params->handles.swap(*handles); | 1232 params->handles.swap(*handles); |
| 1233 params->key = std::move(key); | 1233 params->key = std::move(key); |
| 1234 params->put_mode = put_mode; | 1234 params->put_mode = put_mode; |
| 1235 params->callbacks = callbacks; | 1235 params->callbacks = callbacks; |
| 1236 params->index_keys = index_keys; | 1236 params->index_keys = index_keys; |
| 1237 transaction->ScheduleTask(base::Bind( | 1237 transaction->ScheduleTask(base::Bind( |
| 1238 &IndexedDBDatabase::PutOperation, this, base::Passed(¶ms))); | 1238 &IndexedDBDatabase::PutOperation, this, base::Passed(¶ms))); |
| 1239 } | 1239 } |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1504 scoped_refptr<IndexedDBCallbacks> callbacks) { | 1504 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 1505 IDB_TRACE1("IndexedDBDatabase::OpenCursor", "txn.id", transaction_id); | 1505 IDB_TRACE1("IndexedDBDatabase::OpenCursor", "txn.id", transaction_id); |
| 1506 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 1506 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
| 1507 if (!transaction) | 1507 if (!transaction) |
| 1508 return; | 1508 return; |
| 1509 | 1509 |
| 1510 if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id)) | 1510 if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id)) |
| 1511 return; | 1511 return; |
| 1512 | 1512 |
| 1513 std::unique_ptr<OpenCursorOperationParams> params( | 1513 std::unique_ptr<OpenCursorOperationParams> params( |
| 1514 new OpenCursorOperationParams()); | 1514 base::MakeUnique<OpenCursorOperationParams>()); |
| 1515 params->object_store_id = object_store_id; | 1515 params->object_store_id = object_store_id; |
| 1516 params->index_id = index_id; | 1516 params->index_id = index_id; |
| 1517 params->key_range = std::move(key_range); | 1517 params->key_range = std::move(key_range); |
| 1518 params->direction = direction; | 1518 params->direction = direction; |
| 1519 params->cursor_type = | 1519 params->cursor_type = |
| 1520 key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE; | 1520 key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE; |
| 1521 params->task_type = task_type; | 1521 params->task_type = task_type; |
| 1522 params->callbacks = callbacks; | 1522 params->callbacks = callbacks; |
| 1523 transaction->ScheduleTask(base::Bind( | 1523 transaction->ScheduleTask(base::Bind( |
| 1524 &IndexedDBDatabase::OpenCursorOperation, this, base::Passed(¶ms))); | 1524 &IndexedDBDatabase::OpenCursorOperation, this, base::Passed(¶ms))); |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2004 | 2004 |
| 2005 void IndexedDBDatabase::VersionChangeAbortOperation( | 2005 void IndexedDBDatabase::VersionChangeAbortOperation( |
| 2006 int64_t previous_version, | 2006 int64_t previous_version, |
| 2007 IndexedDBTransaction* transaction) { | 2007 IndexedDBTransaction* transaction) { |
| 2008 DCHECK(!transaction); | 2008 DCHECK(!transaction); |
| 2009 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); | 2009 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); |
| 2010 metadata_.version = previous_version; | 2010 metadata_.version = previous_version; |
| 2011 } | 2011 } |
| 2012 | 2012 |
| 2013 } // namespace content | 2013 } // namespace content |
| OLD | NEW |