| 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_backing_store.h" | 5 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 1884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1895 *new_version_number = version; | 1895 *new_version_number = version; |
| 1896 return s; | 1896 return s; |
| 1897 } | 1897 } |
| 1898 | 1898 |
| 1899 leveldb::Status IndexedDBBackingStore::PutRecord( | 1899 leveldb::Status IndexedDBBackingStore::PutRecord( |
| 1900 IndexedDBBackingStore::Transaction* transaction, | 1900 IndexedDBBackingStore::Transaction* transaction, |
| 1901 int64_t database_id, | 1901 int64_t database_id, |
| 1902 int64_t object_store_id, | 1902 int64_t object_store_id, |
| 1903 const IndexedDBKey& key, | 1903 const IndexedDBKey& key, |
| 1904 IndexedDBValue* value, | 1904 IndexedDBValue* value, |
| 1905 ScopedVector<storage::BlobDataHandle>* handles, | 1905 std::vector<std::unique_ptr<storage::BlobDataHandle>>* handles, |
| 1906 RecordIdentifier* record_identifier) { | 1906 RecordIdentifier* record_identifier) { |
| 1907 IDB_TRACE("IndexedDBBackingStore::PutRecord"); | 1907 IDB_TRACE("IndexedDBBackingStore::PutRecord"); |
| 1908 if (!KeyPrefix::ValidIds(database_id, object_store_id)) | 1908 if (!KeyPrefix::ValidIds(database_id, object_store_id)) |
| 1909 return InvalidDBKeyStatus(); | 1909 return InvalidDBKeyStatus(); |
| 1910 DCHECK(key.IsValid()); | 1910 DCHECK(key.IsValid()); |
| 1911 | 1911 |
| 1912 LevelDBTransaction* leveldb_transaction = transaction->transaction(); | 1912 LevelDBTransaction* leveldb_transaction = transaction->transaction(); |
| 1913 int64_t version = -1; | 1913 int64_t version = -1; |
| 1914 leveldb::Status s = GetNewVersionNumber( | 1914 leveldb::Status s = GetNewVersionNumber( |
| 1915 leveldb_transaction, database_id, object_store_id, &version); | 1915 leveldb_transaction, database_id, object_store_id, &version); |
| (...skipping 2445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4361 } | 4361 } |
| 4362 | 4362 |
| 4363 void IndexedDBBackingStore::BlobChangeRecord::SetBlobInfo( | 4363 void IndexedDBBackingStore::BlobChangeRecord::SetBlobInfo( |
| 4364 std::vector<IndexedDBBlobInfo>* blob_info) { | 4364 std::vector<IndexedDBBlobInfo>* blob_info) { |
| 4365 blob_info_.clear(); | 4365 blob_info_.clear(); |
| 4366 if (blob_info) | 4366 if (blob_info) |
| 4367 blob_info_.swap(*blob_info); | 4367 blob_info_.swap(*blob_info); |
| 4368 } | 4368 } |
| 4369 | 4369 |
| 4370 void IndexedDBBackingStore::BlobChangeRecord::SetHandles( | 4370 void IndexedDBBackingStore::BlobChangeRecord::SetHandles( |
| 4371 ScopedVector<storage::BlobDataHandle>* handles) { | 4371 std::vector<std::unique_ptr<storage::BlobDataHandle>>* handles) { |
| 4372 handles_.clear(); | 4372 handles_.clear(); |
| 4373 if (handles) | 4373 if (handles) |
| 4374 handles_.swap(*handles); | 4374 handles_.swap(*handles); |
| 4375 } | 4375 } |
| 4376 | 4376 |
| 4377 std::unique_ptr<IndexedDBBackingStore::BlobChangeRecord> | 4377 std::unique_ptr<IndexedDBBackingStore::BlobChangeRecord> |
| 4378 IndexedDBBackingStore::BlobChangeRecord::Clone() const { | 4378 IndexedDBBackingStore::BlobChangeRecord::Clone() const { |
| 4379 std::unique_ptr<IndexedDBBackingStore::BlobChangeRecord> record( | 4379 std::unique_ptr<IndexedDBBackingStore::BlobChangeRecord> record( |
| 4380 new BlobChangeRecord(key_, object_store_id_)); | 4380 new BlobChangeRecord(key_, object_store_id_)); |
| 4381 record->blob_info_ = blob_info_; | 4381 record->blob_info_ = blob_info_; |
| 4382 | 4382 |
| 4383 for (const auto* handle : handles_) | 4383 for (const auto& handle : handles_) { |
| 4384 record->handles_.push_back(new storage::BlobDataHandle(*handle)); | 4384 record->handles_.push_back( |
| 4385 base::MakeUnique<storage::BlobDataHandle>(*handle)); |
| 4386 } |
| 4385 return record; | 4387 return record; |
| 4386 } | 4388 } |
| 4387 | 4389 |
| 4388 leveldb::Status IndexedDBBackingStore::Transaction::PutBlobInfoIfNeeded( | 4390 leveldb::Status IndexedDBBackingStore::Transaction::PutBlobInfoIfNeeded( |
| 4389 int64_t database_id, | 4391 int64_t database_id, |
| 4390 int64_t object_store_id, | 4392 int64_t object_store_id, |
| 4391 const std::string& object_store_data_key, | 4393 const std::string& object_store_data_key, |
| 4392 std::vector<IndexedDBBlobInfo>* blob_info, | 4394 std::vector<IndexedDBBlobInfo>* blob_info, |
| 4393 ScopedVector<storage::BlobDataHandle>* handles) { | 4395 std::vector<std::unique_ptr<storage::BlobDataHandle>>* handles) { |
| 4394 if (!blob_info || blob_info->empty()) { | 4396 if (!blob_info || blob_info->empty()) { |
| 4395 blob_change_map_.erase(object_store_data_key); | 4397 blob_change_map_.erase(object_store_data_key); |
| 4396 incognito_blob_map_.erase(object_store_data_key); | 4398 incognito_blob_map_.erase(object_store_data_key); |
| 4397 | 4399 |
| 4398 BlobEntryKey blob_entry_key; | 4400 BlobEntryKey blob_entry_key; |
| 4399 StringPiece leveldb_key_piece(object_store_data_key); | 4401 StringPiece leveldb_key_piece(object_store_data_key); |
| 4400 if (!BlobEntryKey::FromObjectStoreDataKey(&leveldb_key_piece, | 4402 if (!BlobEntryKey::FromObjectStoreDataKey(&leveldb_key_piece, |
| 4401 &blob_entry_key)) { | 4403 &blob_entry_key)) { |
| 4402 NOTREACHED(); | 4404 NOTREACHED(); |
| 4403 return InternalInconsistencyStatus(); | 4405 return InternalInconsistencyStatus(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4418 | 4420 |
| 4419 // This is storing an info, even if empty, even if the previous key had no blob | 4421 // This is storing an info, even if empty, even if the previous key had no blob |
| 4420 // info that we know of. It duplicates a bunch of information stored in the | 4422 // info that we know of. It duplicates a bunch of information stored in the |
| 4421 // leveldb transaction, but only w.r.t. the user keys altered--we don't keep the | 4423 // leveldb transaction, but only w.r.t. the user keys altered--we don't keep the |
| 4422 // changes to exists or index keys here. | 4424 // changes to exists or index keys here. |
| 4423 void IndexedDBBackingStore::Transaction::PutBlobInfo( | 4425 void IndexedDBBackingStore::Transaction::PutBlobInfo( |
| 4424 int64_t database_id, | 4426 int64_t database_id, |
| 4425 int64_t object_store_id, | 4427 int64_t object_store_id, |
| 4426 const std::string& object_store_data_key, | 4428 const std::string& object_store_data_key, |
| 4427 std::vector<IndexedDBBlobInfo>* blob_info, | 4429 std::vector<IndexedDBBlobInfo>* blob_info, |
| 4428 ScopedVector<storage::BlobDataHandle>* handles) { | 4430 std::vector<std::unique_ptr<storage::BlobDataHandle>>* handles) { |
| 4429 DCHECK_GT(object_store_data_key.size(), 0UL); | 4431 DCHECK_GT(object_store_data_key.size(), 0UL); |
| 4430 if (database_id_ < 0) | 4432 if (database_id_ < 0) |
| 4431 database_id_ = database_id; | 4433 database_id_ = database_id; |
| 4432 DCHECK_EQ(database_id_, database_id); | 4434 DCHECK_EQ(database_id_, database_id); |
| 4433 | 4435 |
| 4434 const auto& it = blob_change_map_.find(object_store_data_key); | 4436 const auto& it = blob_change_map_.find(object_store_data_key); |
| 4435 BlobChangeRecord* record = NULL; | 4437 BlobChangeRecord* record = NULL; |
| 4436 if (it == blob_change_map_.end()) { | 4438 if (it == blob_change_map_.end()) { |
| 4437 std::unique_ptr<BlobChangeRecord> new_record = | 4439 std::unique_ptr<BlobChangeRecord> new_record = |
| 4438 base::MakeUnique<BlobChangeRecord>(object_store_data_key, | 4440 base::MakeUnique<BlobChangeRecord>(object_store_data_key, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4474 | 4476 |
| 4475 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( | 4477 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( |
| 4476 const WriteDescriptor& other) = default; | 4478 const WriteDescriptor& other) = default; |
| 4477 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = | 4479 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = |
| 4478 default; | 4480 default; |
| 4479 IndexedDBBackingStore::Transaction::WriteDescriptor& | 4481 IndexedDBBackingStore::Transaction::WriteDescriptor& |
| 4480 IndexedDBBackingStore::Transaction::WriteDescriptor:: | 4482 IndexedDBBackingStore::Transaction::WriteDescriptor:: |
| 4481 operator=(const WriteDescriptor& other) = default; | 4483 operator=(const WriteDescriptor& other) = default; |
| 4482 | 4484 |
| 4483 } // namespace content | 4485 } // namespace content |
| OLD | NEW |