| 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 2444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4360 } | 4360 } |
| 4361 | 4361 |
| 4362 void IndexedDBBackingStore::BlobChangeRecord::SetBlobInfo( | 4362 void IndexedDBBackingStore::BlobChangeRecord::SetBlobInfo( |
| 4363 std::vector<IndexedDBBlobInfo>* blob_info) { | 4363 std::vector<IndexedDBBlobInfo>* blob_info) { |
| 4364 blob_info_.clear(); | 4364 blob_info_.clear(); |
| 4365 if (blob_info) | 4365 if (blob_info) |
| 4366 blob_info_.swap(*blob_info); | 4366 blob_info_.swap(*blob_info); |
| 4367 } | 4367 } |
| 4368 | 4368 |
| 4369 void IndexedDBBackingStore::BlobChangeRecord::SetHandles( | 4369 void IndexedDBBackingStore::BlobChangeRecord::SetHandles( |
| 4370 ScopedVector<storage::BlobDataHandle>* handles) { | 4370 std::vector<std::unique_ptr<storage::BlobDataHandle>>* handles) { |
| 4371 handles_.clear(); | 4371 handles_.clear(); |
| 4372 if (handles) | 4372 if (handles) |
| 4373 handles_.swap(*handles); | 4373 handles_.swap(*handles); |
| 4374 } | 4374 } |
| 4375 | 4375 |
| 4376 std::unique_ptr<IndexedDBBackingStore::BlobChangeRecord> | 4376 std::unique_ptr<IndexedDBBackingStore::BlobChangeRecord> |
| 4377 IndexedDBBackingStore::BlobChangeRecord::Clone() const { | 4377 IndexedDBBackingStore::BlobChangeRecord::Clone() const { |
| 4378 std::unique_ptr<IndexedDBBackingStore::BlobChangeRecord> record( | 4378 std::unique_ptr<IndexedDBBackingStore::BlobChangeRecord> record( |
| 4379 new BlobChangeRecord(key_, object_store_id_)); | 4379 new BlobChangeRecord(key_, object_store_id_)); |
| 4380 record->blob_info_ = blob_info_; | 4380 record->blob_info_ = blob_info_; |
| 4381 | 4381 |
| 4382 for (const auto* handle : handles_) | 4382 for (const auto& handle : handles_) { |
| 4383 record->handles_.push_back(new storage::BlobDataHandle(*handle)); | 4383 record->handles_.push_back( |
| 4384 base::MakeUnique<storage::BlobDataHandle>(*handle)); |
| 4385 } |
| 4384 return record; | 4386 return record; |
| 4385 } | 4387 } |
| 4386 | 4388 |
| 4387 leveldb::Status IndexedDBBackingStore::Transaction::PutBlobInfoIfNeeded( | 4389 leveldb::Status IndexedDBBackingStore::Transaction::PutBlobInfoIfNeeded( |
| 4388 int64_t database_id, | 4390 int64_t database_id, |
| 4389 int64_t object_store_id, | 4391 int64_t object_store_id, |
| 4390 const std::string& object_store_data_key, | 4392 const std::string& object_store_data_key, |
| 4391 std::vector<IndexedDBBlobInfo>* blob_info, | 4393 std::vector<IndexedDBBlobInfo>* blob_info, |
| 4392 ScopedVector<storage::BlobDataHandle>* handles) { | 4394 std::vector<std::unique_ptr<storage::BlobDataHandle>>* handles) { |
| 4393 if (!blob_info || blob_info->empty()) { | 4395 if (!blob_info || blob_info->empty()) { |
| 4394 blob_change_map_.erase(object_store_data_key); | 4396 blob_change_map_.erase(object_store_data_key); |
| 4395 incognito_blob_map_.erase(object_store_data_key); | 4397 incognito_blob_map_.erase(object_store_data_key); |
| 4396 | 4398 |
| 4397 BlobEntryKey blob_entry_key; | 4399 BlobEntryKey blob_entry_key; |
| 4398 StringPiece leveldb_key_piece(object_store_data_key); | 4400 StringPiece leveldb_key_piece(object_store_data_key); |
| 4399 if (!BlobEntryKey::FromObjectStoreDataKey(&leveldb_key_piece, | 4401 if (!BlobEntryKey::FromObjectStoreDataKey(&leveldb_key_piece, |
| 4400 &blob_entry_key)) { | 4402 &blob_entry_key)) { |
| 4401 NOTREACHED(); | 4403 NOTREACHED(); |
| 4402 return InternalInconsistencyStatus(); | 4404 return InternalInconsistencyStatus(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4417 | 4419 |
| 4418 // This is storing an info, even if empty, even if the previous key had no blob | 4420 // This is storing an info, even if empty, even if the previous key had no blob |
| 4419 // info that we know of. It duplicates a bunch of information stored in the | 4421 // info that we know of. It duplicates a bunch of information stored in the |
| 4420 // leveldb transaction, but only w.r.t. the user keys altered--we don't keep the | 4422 // leveldb transaction, but only w.r.t. the user keys altered--we don't keep the |
| 4421 // changes to exists or index keys here. | 4423 // changes to exists or index keys here. |
| 4422 void IndexedDBBackingStore::Transaction::PutBlobInfo( | 4424 void IndexedDBBackingStore::Transaction::PutBlobInfo( |
| 4423 int64_t database_id, | 4425 int64_t database_id, |
| 4424 int64_t object_store_id, | 4426 int64_t object_store_id, |
| 4425 const std::string& object_store_data_key, | 4427 const std::string& object_store_data_key, |
| 4426 std::vector<IndexedDBBlobInfo>* blob_info, | 4428 std::vector<IndexedDBBlobInfo>* blob_info, |
| 4427 ScopedVector<storage::BlobDataHandle>* handles) { | 4429 std::vector<std::unique_ptr<storage::BlobDataHandle>>* handles) { |
| 4428 DCHECK_GT(object_store_data_key.size(), 0UL); | 4430 DCHECK_GT(object_store_data_key.size(), 0UL); |
| 4429 if (database_id_ < 0) | 4431 if (database_id_ < 0) |
| 4430 database_id_ = database_id; | 4432 database_id_ = database_id; |
| 4431 DCHECK_EQ(database_id_, database_id); | 4433 DCHECK_EQ(database_id_, database_id); |
| 4432 | 4434 |
| 4433 const auto& it = blob_change_map_.find(object_store_data_key); | 4435 const auto& it = blob_change_map_.find(object_store_data_key); |
| 4434 BlobChangeRecord* record = NULL; | 4436 BlobChangeRecord* record = NULL; |
| 4435 if (it == blob_change_map_.end()) { | 4437 if (it == blob_change_map_.end()) { |
| 4436 std::unique_ptr<BlobChangeRecord> new_record = | 4438 std::unique_ptr<BlobChangeRecord> new_record = |
| 4437 base::MakeUnique<BlobChangeRecord>(object_store_data_key, | 4439 base::MakeUnique<BlobChangeRecord>(object_store_data_key, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4473 | 4475 |
| 4474 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( | 4476 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( |
| 4475 const WriteDescriptor& other) = default; | 4477 const WriteDescriptor& other) = default; |
| 4476 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = | 4478 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = |
| 4477 default; | 4479 default; |
| 4478 IndexedDBBackingStore::Transaction::WriteDescriptor& | 4480 IndexedDBBackingStore::Transaction::WriteDescriptor& |
| 4479 IndexedDBBackingStore::Transaction::WriteDescriptor:: | 4481 IndexedDBBackingStore::Transaction::WriteDescriptor:: |
| 4480 operator=(const WriteDescriptor& other) = default; | 4482 operator=(const WriteDescriptor& other) = default; |
| 4481 | 4483 |
| 4482 } // namespace content | 4484 } // namespace content |
| OLD | NEW |