| 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 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 active_blob_registry_(this), | 764 active_blob_registry_(this), |
| 765 committing_transaction_count_(0) {} | 765 committing_transaction_count_(0) {} |
| 766 | 766 |
| 767 IndexedDBBackingStore::~IndexedDBBackingStore() { | 767 IndexedDBBackingStore::~IndexedDBBackingStore() { |
| 768 if (!blob_path_.empty() && !child_process_ids_granted_.empty()) { | 768 if (!blob_path_.empty() && !child_process_ids_granted_.empty()) { |
| 769 ChildProcessSecurityPolicyImpl* policy = | 769 ChildProcessSecurityPolicyImpl* policy = |
| 770 ChildProcessSecurityPolicyImpl::GetInstance(); | 770 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 771 for (const auto& pid : child_process_ids_granted_) | 771 for (const auto& pid : child_process_ids_granted_) |
| 772 policy->RevokeAllPermissionsForFile(pid, blob_path_); | 772 policy->RevokeAllPermissionsForFile(pid, blob_path_); |
| 773 } | 773 } |
| 774 base::STLDeleteContainerPairSecondPointers(incognito_blob_map_.begin(), | |
| 775 incognito_blob_map_.end()); | |
| 776 // db_'s destructor uses comparator_. The order of destruction is important. | 774 // db_'s destructor uses comparator_. The order of destruction is important. |
| 777 db_.reset(); | 775 db_.reset(); |
| 778 comparator_.reset(); | 776 comparator_.reset(); |
| 779 } | 777 } |
| 780 | 778 |
| 781 IndexedDBBackingStore::RecordIdentifier::RecordIdentifier( | 779 IndexedDBBackingStore::RecordIdentifier::RecordIdentifier( |
| 782 const std::string& primary_key, | 780 const std::string& primary_key, |
| 783 int64_t version) | 781 int64_t version) |
| 784 : primary_key_(primary_key), version_(version) { | 782 : primary_key_(primary_key), version_(version) { |
| 785 DCHECK(!primary_key.empty()); | 783 DCHECK(!primary_key.empty()); |
| (...skipping 1913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2699 if (!s.ok()) | 2697 if (!s.ok()) |
| 2700 return s; | 2698 return s; |
| 2701 ClearBlobJournal(journal_transaction.get(), level_db_key); | 2699 ClearBlobJournal(journal_transaction.get(), level_db_key); |
| 2702 return journal_transaction->Commit(); | 2700 return journal_transaction->Commit(); |
| 2703 } | 2701 } |
| 2704 | 2702 |
| 2705 leveldb::Status IndexedDBBackingStore::Transaction::GetBlobInfoForRecord( | 2703 leveldb::Status IndexedDBBackingStore::Transaction::GetBlobInfoForRecord( |
| 2706 int64_t database_id, | 2704 int64_t database_id, |
| 2707 const std::string& object_store_data_key, | 2705 const std::string& object_store_data_key, |
| 2708 IndexedDBValue* value) { | 2706 IndexedDBValue* value) { |
| 2709 BlobChangeRecord* change_record = NULL; | 2707 BlobChangeRecord* change_record = nullptr; |
| 2710 auto blob_iter = blob_change_map_.find(object_store_data_key); | 2708 auto blob_iter = blob_change_map_.find(object_store_data_key); |
| 2711 if (blob_iter != blob_change_map_.end()) { | 2709 if (blob_iter != blob_change_map_.end()) { |
| 2712 change_record = blob_iter->second; | 2710 change_record = blob_iter->second.get(); |
| 2713 } else { | 2711 } else { |
| 2714 blob_iter = incognito_blob_map_.find(object_store_data_key); | 2712 blob_iter = incognito_blob_map_.find(object_store_data_key); |
| 2715 if (blob_iter != incognito_blob_map_.end()) | 2713 if (blob_iter != incognito_blob_map_.end()) |
| 2716 change_record = blob_iter->second; | 2714 change_record = blob_iter->second.get(); |
| 2717 } | 2715 } |
| 2718 if (change_record) { | 2716 if (change_record) { |
| 2719 // Either we haven't written the blob to disk yet or we're in incognito | 2717 // Either we haven't written the blob to disk yet or we're in incognito |
| 2720 // mode, so we have to send back the one they sent us. This change record | 2718 // mode, so we have to send back the one they sent us. This change record |
| 2721 // includes the original UUID. | 2719 // includes the original UUID. |
| 2722 value->blob_info = change_record->blob_info(); | 2720 value->blob_info = change_record->blob_info(); |
| 2723 return leveldb::Status::OK(); | 2721 return leveldb::Status::OK(); |
| 2724 } | 2722 } |
| 2725 | 2723 |
| 2726 BlobEntryKey blob_entry_key; | 2724 BlobEntryKey blob_entry_key; |
| (...skipping 1285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4012 | 4010 |
| 4013 return std::move(cursor); | 4011 return std::move(cursor); |
| 4014 } | 4012 } |
| 4015 | 4013 |
| 4016 IndexedDBBackingStore::Transaction::Transaction( | 4014 IndexedDBBackingStore::Transaction::Transaction( |
| 4017 IndexedDBBackingStore* backing_store) | 4015 IndexedDBBackingStore* backing_store) |
| 4018 : backing_store_(backing_store), database_id_(-1), committing_(false) { | 4016 : backing_store_(backing_store), database_id_(-1), committing_(false) { |
| 4019 } | 4017 } |
| 4020 | 4018 |
| 4021 IndexedDBBackingStore::Transaction::~Transaction() { | 4019 IndexedDBBackingStore::Transaction::~Transaction() { |
| 4022 base::STLDeleteContainerPairSecondPointers(blob_change_map_.begin(), | |
| 4023 blob_change_map_.end()); | |
| 4024 base::STLDeleteContainerPairSecondPointers(incognito_blob_map_.begin(), | |
| 4025 incognito_blob_map_.end()); | |
| 4026 DCHECK(!committing_); | 4020 DCHECK(!committing_); |
| 4027 } | 4021 } |
| 4028 | 4022 |
| 4029 void IndexedDBBackingStore::Transaction::Begin() { | 4023 void IndexedDBBackingStore::Transaction::Begin() { |
| 4030 IDB_TRACE("IndexedDBBackingStore::Transaction::Begin"); | 4024 IDB_TRACE("IndexedDBBackingStore::Transaction::Begin"); |
| 4031 DCHECK(!transaction_.get()); | 4025 DCHECK(!transaction_.get()); |
| 4032 transaction_ = IndexedDBClassFactory::Get()->CreateLevelDBTransaction( | 4026 transaction_ = IndexedDBClassFactory::Get()->CreateLevelDBTransaction( |
| 4033 backing_store_->db_.get()); | 4027 backing_store_->db_.get()); |
| 4034 | 4028 |
| 4035 // If incognito, this snapshots blobs just as the above transaction_ | 4029 // If incognito, this snapshots blobs just as the above transaction_ |
| 4036 // constructor snapshots the leveldb. | 4030 // constructor snapshots the leveldb. |
| 4037 for (const auto& iter : backing_store_->incognito_blob_map_) | 4031 for (const auto& iter : backing_store_->incognito_blob_map_) |
| 4038 incognito_blob_map_[iter.first] = iter.second->Clone().release(); | 4032 incognito_blob_map_[iter.first] = iter.second->Clone(); |
| 4039 } | 4033 } |
| 4040 | 4034 |
| 4041 static GURL GetURLFromUUID(const string& uuid) { | 4035 static GURL GetURLFromUUID(const string& uuid) { |
| 4042 return GURL("blob:uuid/" + uuid); | 4036 return GURL("blob:uuid/" + uuid); |
| 4043 } | 4037 } |
| 4044 | 4038 |
| 4045 leveldb::Status IndexedDBBackingStore::Transaction::HandleBlobPreTransaction( | 4039 leveldb::Status IndexedDBBackingStore::Transaction::HandleBlobPreTransaction( |
| 4046 BlobEntryKeyValuePairVec* new_blob_entries, | 4040 BlobEntryKeyValuePairVec* new_blob_entries, |
| 4047 WriteDescriptorVec* new_files_to_write) { | 4041 WriteDescriptorVec* new_files_to_write) { |
| 4048 if (backing_store_->is_incognito()) | 4042 if (backing_store_->is_incognito()) |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4252 if (!s.ok()) { | 4246 if (!s.ok()) { |
| 4253 INTERNAL_WRITE_ERROR(TRANSACTION_COMMIT_METHOD); | 4247 INTERNAL_WRITE_ERROR(TRANSACTION_COMMIT_METHOD); |
| 4254 return s; | 4248 return s; |
| 4255 } | 4249 } |
| 4256 | 4250 |
| 4257 if (backing_store_->is_incognito()) { | 4251 if (backing_store_->is_incognito()) { |
| 4258 if (!blob_change_map_.empty()) { | 4252 if (!blob_change_map_.empty()) { |
| 4259 auto& target_map = backing_store_->incognito_blob_map_; | 4253 auto& target_map = backing_store_->incognito_blob_map_; |
| 4260 for (auto& iter : blob_change_map_) { | 4254 for (auto& iter : blob_change_map_) { |
| 4261 auto target_record = target_map.find(iter.first); | 4255 auto target_record = target_map.find(iter.first); |
| 4262 if (target_record != target_map.end()) { | 4256 if (target_record != target_map.end()) |
| 4263 delete target_record->second; | |
| 4264 target_map.erase(target_record); | 4257 target_map.erase(target_record); |
| 4265 } | 4258 if (iter.second) |
| 4266 if (iter.second) { | 4259 target_map[iter.first] = std::move(iter.second); |
| 4267 target_map[iter.first] = iter.second; | |
| 4268 iter.second = NULL; | |
| 4269 } | |
| 4270 } | 4260 } |
| 4271 } | 4261 } |
| 4272 return leveldb::Status::OK(); | 4262 return leveldb::Status::OK(); |
| 4273 } | 4263 } |
| 4274 | 4264 |
| 4275 // Actually delete dead blob files, then remove those entries | 4265 // Actually delete dead blob files, then remove those entries |
| 4276 // from the persisted primary journal. | 4266 // from the persisted primary journal. |
| 4277 if (dead_blobs.empty()) | 4267 if (dead_blobs.empty()) |
| 4278 return leveldb::Status::OK(); | 4268 return leveldb::Status::OK(); |
| 4279 | 4269 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4437 std::vector<IndexedDBBlobInfo>* blob_info, | 4427 std::vector<IndexedDBBlobInfo>* blob_info, |
| 4438 ScopedVector<storage::BlobDataHandle>* handles) { | 4428 ScopedVector<storage::BlobDataHandle>* handles) { |
| 4439 DCHECK_GT(object_store_data_key.size(), 0UL); | 4429 DCHECK_GT(object_store_data_key.size(), 0UL); |
| 4440 if (database_id_ < 0) | 4430 if (database_id_ < 0) |
| 4441 database_id_ = database_id; | 4431 database_id_ = database_id; |
| 4442 DCHECK_EQ(database_id_, database_id); | 4432 DCHECK_EQ(database_id_, database_id); |
| 4443 | 4433 |
| 4444 const auto& it = blob_change_map_.find(object_store_data_key); | 4434 const auto& it = blob_change_map_.find(object_store_data_key); |
| 4445 BlobChangeRecord* record = NULL; | 4435 BlobChangeRecord* record = NULL; |
| 4446 if (it == blob_change_map_.end()) { | 4436 if (it == blob_change_map_.end()) { |
| 4447 record = new BlobChangeRecord(object_store_data_key, object_store_id); | 4437 std::unique_ptr<BlobChangeRecord> new_record = |
| 4448 blob_change_map_[object_store_data_key] = record; | 4438 base::MakeUnique<BlobChangeRecord>(object_store_data_key, |
| 4439 object_store_id); |
| 4440 record = new_record.get(); |
| 4441 blob_change_map_[object_store_data_key] = std::move(new_record); |
| 4449 } else { | 4442 } else { |
| 4450 record = it->second; | 4443 record = it->second.get(); |
| 4451 } | 4444 } |
| 4452 DCHECK_EQ(record->object_store_id(), object_store_id); | 4445 DCHECK_EQ(record->object_store_id(), object_store_id); |
| 4453 record->SetBlobInfo(blob_info); | 4446 record->SetBlobInfo(blob_info); |
| 4454 record->SetHandles(handles); | 4447 record->SetHandles(handles); |
| 4455 DCHECK(!handles || handles->empty()); | 4448 DCHECK(!handles || handles->empty()); |
| 4456 } | 4449 } |
| 4457 | 4450 |
| 4458 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( | 4451 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( |
| 4459 const GURL& url, | 4452 const GURL& url, |
| 4460 int64_t key, | 4453 int64_t key, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 4481 | 4474 |
| 4482 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( | 4475 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( |
| 4483 const WriteDescriptor& other) = default; | 4476 const WriteDescriptor& other) = default; |
| 4484 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = | 4477 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = |
| 4485 default; | 4478 default; |
| 4486 IndexedDBBackingStore::Transaction::WriteDescriptor& | 4479 IndexedDBBackingStore::Transaction::WriteDescriptor& |
| 4487 IndexedDBBackingStore::Transaction::WriteDescriptor:: | 4480 IndexedDBBackingStore::Transaction::WriteDescriptor:: |
| 4488 operator=(const WriteDescriptor& other) = default; | 4481 operator=(const WriteDescriptor& other) = default; |
| 4489 | 4482 |
| 4490 } // namespace content | 4483 } // namespace content |
| OLD | NEW |