| 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 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 } | 742 } |
| 743 output->swap(ret); | 743 output->swap(ret); |
| 744 | 744 |
| 745 return true; | 745 return true; |
| 746 } | 746 } |
| 747 | 747 |
| 748 IndexedDBBackingStore::IndexedDBBackingStore( | 748 IndexedDBBackingStore::IndexedDBBackingStore( |
| 749 IndexedDBFactory* indexed_db_factory, | 749 IndexedDBFactory* indexed_db_factory, |
| 750 const Origin& origin, | 750 const Origin& origin, |
| 751 const base::FilePath& blob_path, | 751 const base::FilePath& blob_path, |
| 752 net::URLRequestContext* request_context, | 752 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 753 std::unique_ptr<LevelDBDatabase> db, | 753 std::unique_ptr<LevelDBDatabase> db, |
| 754 std::unique_ptr<LevelDBComparator> comparator, | 754 std::unique_ptr<LevelDBComparator> comparator, |
| 755 base::SequencedTaskRunner* task_runner) | 755 base::SequencedTaskRunner* task_runner) |
| 756 : indexed_db_factory_(indexed_db_factory), | 756 : indexed_db_factory_(indexed_db_factory), |
| 757 origin_(origin), | 757 origin_(origin), |
| 758 blob_path_(blob_path), | 758 blob_path_(blob_path), |
| 759 origin_identifier_(ComputeOriginIdentifier(origin)), | 759 origin_identifier_(ComputeOriginIdentifier(origin)), |
| 760 request_context_(request_context), | 760 request_context_getter_(request_context_getter), |
| 761 task_runner_(task_runner), | 761 task_runner_(task_runner), |
| 762 db_(std::move(db)), | 762 db_(std::move(db)), |
| 763 comparator_(std::move(comparator)), | 763 comparator_(std::move(comparator)), |
| 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(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 INDEXED_DB_BACKING_STORE_OPEN_FAILED_PRIOR_CORRUPTION, | 810 INDEXED_DB_BACKING_STORE_OPEN_FAILED_PRIOR_CORRUPTION, |
| 811 INDEXED_DB_BACKING_STORE_OPEN_FAILED_CLEANUP_JOURNAL_ERROR, | 811 INDEXED_DB_BACKING_STORE_OPEN_FAILED_CLEANUP_JOURNAL_ERROR, |
| 812 INDEXED_DB_BACKING_STORE_OPEN_MAX, | 812 INDEXED_DB_BACKING_STORE_OPEN_MAX, |
| 813 }; | 813 }; |
| 814 | 814 |
| 815 // static | 815 // static |
| 816 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open( | 816 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open( |
| 817 IndexedDBFactory* indexed_db_factory, | 817 IndexedDBFactory* indexed_db_factory, |
| 818 const Origin& origin, | 818 const Origin& origin, |
| 819 const base::FilePath& path_base, | 819 const base::FilePath& path_base, |
| 820 net::URLRequestContext* request_context, | 820 scoped_refptr<net::URLRequestContextGetter> request_context, |
| 821 IndexedDBDataLossInfo* data_loss_info, | 821 IndexedDBDataLossInfo* data_loss_info, |
| 822 bool* disk_full, | 822 bool* disk_full, |
| 823 base::SequencedTaskRunner* task_runner, | 823 base::SequencedTaskRunner* task_runner, |
| 824 bool clean_journal, | 824 bool clean_journal, |
| 825 leveldb::Status* status) { | 825 leveldb::Status* status) { |
| 826 DefaultLevelDBFactory leveldb_factory; | 826 DefaultLevelDBFactory leveldb_factory; |
| 827 return IndexedDBBackingStore::Open( | 827 return IndexedDBBackingStore::Open( |
| 828 indexed_db_factory, origin, path_base, request_context, data_loss_info, | 828 indexed_db_factory, origin, path_base, request_context, data_loss_info, |
| 829 disk_full, &leveldb_factory, task_runner, clean_journal, status); | 829 disk_full, &leveldb_factory, task_runner, clean_journal, status); |
| 830 } | 830 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 return false; | 951 return false; |
| 952 int written = file.Write(0, output_js.c_str(), output_js.length()); | 952 int written = file.Write(0, output_js.c_str(), output_js.length()); |
| 953 return size_t(written) == output_js.length(); | 953 return size_t(written) == output_js.length(); |
| 954 } | 954 } |
| 955 | 955 |
| 956 // static | 956 // static |
| 957 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open( | 957 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open( |
| 958 IndexedDBFactory* indexed_db_factory, | 958 IndexedDBFactory* indexed_db_factory, |
| 959 const Origin& origin, | 959 const Origin& origin, |
| 960 const base::FilePath& path_base, | 960 const base::FilePath& path_base, |
| 961 net::URLRequestContext* request_context, | 961 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 962 IndexedDBDataLossInfo* data_loss_info, | 962 IndexedDBDataLossInfo* data_loss_info, |
| 963 bool* is_disk_full, | 963 bool* is_disk_full, |
| 964 LevelDBFactory* leveldb_factory, | 964 LevelDBFactory* leveldb_factory, |
| 965 base::SequencedTaskRunner* task_runner, | 965 base::SequencedTaskRunner* task_runner, |
| 966 bool clean_journal, | 966 bool clean_journal, |
| 967 leveldb::Status* status) { | 967 leveldb::Status* status) { |
| 968 IDB_TRACE("IndexedDBBackingStore::Open"); | 968 IDB_TRACE("IndexedDBBackingStore::Open"); |
| 969 DCHECK(!path_base.empty()); | 969 DCHECK(!path_base.empty()); |
| 970 *is_disk_full = false; | 970 *is_disk_full = false; |
| 971 | 971 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1078 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_CLEANUP_REOPEN_SUCCESS, | 1078 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_CLEANUP_REOPEN_SUCCESS, |
| 1079 origin); | 1079 origin); |
| 1080 } | 1080 } |
| 1081 | 1081 |
| 1082 base::trace_event::MemoryDumpManager::GetInstance() | 1082 base::trace_event::MemoryDumpManager::GetInstance() |
| 1083 ->RegisterDumpProviderWithSequencedTaskRunner( | 1083 ->RegisterDumpProviderWithSequencedTaskRunner( |
| 1084 db.get(), "IndexedDBBackingStore", task_runner, | 1084 db.get(), "IndexedDBBackingStore", task_runner, |
| 1085 base::trace_event::MemoryDumpProvider::Options()); | 1085 base::trace_event::MemoryDumpProvider::Options()); |
| 1086 | 1086 |
| 1087 scoped_refptr<IndexedDBBackingStore> backing_store = | 1087 scoped_refptr<IndexedDBBackingStore> backing_store = |
| 1088 Create(indexed_db_factory, origin, blob_path, request_context, | 1088 Create(indexed_db_factory, origin, blob_path, request_context_getter, |
| 1089 std::move(db), std::move(comparator), task_runner, status); | 1089 std::move(db), std::move(comparator), task_runner, status); |
| 1090 | 1090 |
| 1091 if (clean_journal && backing_store.get()) { | 1091 if (clean_journal && backing_store.get()) { |
| 1092 *status = backing_store->CleanUpBlobJournal(LiveBlobJournalKey::Encode()); | 1092 *status = backing_store->CleanUpBlobJournal(LiveBlobJournalKey::Encode()); |
| 1093 if (!status->ok()) { | 1093 if (!status->ok()) { |
| 1094 HistogramOpenStatus( | 1094 HistogramOpenStatus( |
| 1095 INDEXED_DB_BACKING_STORE_OPEN_FAILED_CLEANUP_JOURNAL_ERROR, origin); | 1095 INDEXED_DB_BACKING_STORE_OPEN_FAILED_CLEANUP_JOURNAL_ERROR, origin); |
| 1096 return scoped_refptr<IndexedDBBackingStore>(); | 1096 return scoped_refptr<IndexedDBBackingStore>(); |
| 1097 } | 1097 } |
| 1098 } | 1098 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 return Create(NULL /* indexed_db_factory */, origin, base::FilePath(), | 1134 return Create(NULL /* indexed_db_factory */, origin, base::FilePath(), |
| 1135 NULL /* request_context */, std::move(db), | 1135 NULL /* request_context */, std::move(db), |
| 1136 std::move(comparator), task_runner, status); | 1136 std::move(comparator), task_runner, status); |
| 1137 } | 1137 } |
| 1138 | 1138 |
| 1139 // static | 1139 // static |
| 1140 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Create( | 1140 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Create( |
| 1141 IndexedDBFactory* indexed_db_factory, | 1141 IndexedDBFactory* indexed_db_factory, |
| 1142 const Origin& origin, | 1142 const Origin& origin, |
| 1143 const base::FilePath& blob_path, | 1143 const base::FilePath& blob_path, |
| 1144 net::URLRequestContext* request_context, | 1144 scoped_refptr<net::URLRequestContextGetter> request_context, |
| 1145 std::unique_ptr<LevelDBDatabase> db, | 1145 std::unique_ptr<LevelDBDatabase> db, |
| 1146 std::unique_ptr<LevelDBComparator> comparator, | 1146 std::unique_ptr<LevelDBComparator> comparator, |
| 1147 base::SequencedTaskRunner* task_runner, | 1147 base::SequencedTaskRunner* task_runner, |
| 1148 leveldb::Status* status) { | 1148 leveldb::Status* status) { |
| 1149 // TODO(jsbell): Handle comparator name changes. | 1149 // TODO(jsbell): Handle comparator name changes. |
| 1150 scoped_refptr<IndexedDBBackingStore> backing_store(new IndexedDBBackingStore( | 1150 scoped_refptr<IndexedDBBackingStore> backing_store(new IndexedDBBackingStore( |
| 1151 indexed_db_factory, origin, blob_path, request_context, std::move(db), | 1151 indexed_db_factory, origin, blob_path, request_context, std::move(db), |
| 1152 std::move(comparator), task_runner)); | 1152 std::move(comparator), task_runner)); |
| 1153 *status = backing_store->SetUpMetadata(); | 1153 *status = backing_store->SetUpMetadata(); |
| 1154 if (!status->ok()) | 1154 if (!status->ok()) |
| (...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2316 task_runner_->PostTask( | 2316 task_runner_->PostTask( |
| 2317 FROM_HERE, | 2317 FROM_HERE, |
| 2318 base::Bind(&IndexedDBBackingStore::Transaction::ChainedBlobWriter:: | 2318 base::Bind(&IndexedDBBackingStore::Transaction::ChainedBlobWriter:: |
| 2319 ReportWriteCompletion, | 2319 ReportWriteCompletion, |
| 2320 chained_blob_writer_, | 2320 chained_blob_writer_, |
| 2321 success, | 2321 success, |
| 2322 bytes_written_)); | 2322 bytes_written_)); |
| 2323 } | 2323 } |
| 2324 } | 2324 } |
| 2325 | 2325 |
| 2326 void WriteBlobToFileOnIOThread(const FilePath& file_path, | 2326 void WriteBlobToFileOnIOThread( |
| 2327 const GURL& blob_url, | 2327 const FilePath& file_path, |
| 2328 const base::Time& last_modified, | 2328 const GURL& blob_url, |
| 2329 net::URLRequestContext* request_context) { | 2329 const base::Time& last_modified, |
| 2330 scoped_refptr<net::URLRequestContextGetter> request_context_getter) { |
| 2330 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 2331 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 2331 std::unique_ptr<storage::FileStreamWriter> writer( | 2332 std::unique_ptr<storage::FileStreamWriter> writer( |
| 2332 storage::FileStreamWriter::CreateForLocalFile( | 2333 storage::FileStreamWriter::CreateForLocalFile( |
| 2333 task_runner_.get(), file_path, 0, | 2334 task_runner_.get(), file_path, 0, |
| 2334 storage::FileStreamWriter::CREATE_NEW_FILE)); | 2335 storage::FileStreamWriter::CREATE_NEW_FILE)); |
| 2335 std::unique_ptr<FileWriterDelegate> delegate( | 2336 std::unique_ptr<FileWriterDelegate> delegate( |
| 2336 base::MakeUnique<FileWriterDelegate>( | 2337 base::MakeUnique<FileWriterDelegate>( |
| 2337 std::move(writer), storage::FlushPolicy::FLUSH_ON_COMPLETION)); | 2338 std::move(writer), storage::FlushPolicy::FLUSH_ON_COMPLETION)); |
| 2338 | 2339 |
| 2339 DCHECK(blob_url.is_valid()); | 2340 DCHECK(blob_url.is_valid()); |
| 2341 net::URLRequestContext* request_context = |
| 2342 request_context_getter->GetURLRequestContext(); |
| 2340 std::unique_ptr<net::URLRequest> blob_request( | 2343 std::unique_ptr<net::URLRequest> blob_request( |
| 2341 request_context->CreateRequest(blob_url, net::DEFAULT_PRIORITY, | 2344 request_context->CreateRequest(blob_url, net::DEFAULT_PRIORITY, |
| 2342 delegate.get())); | 2345 delegate.get())); |
| 2343 | 2346 |
| 2344 this->file_path_ = file_path; | 2347 this->file_path_ = file_path; |
| 2345 this->last_modified_ = last_modified; | 2348 this->last_modified_ = last_modified; |
| 2346 | 2349 |
| 2347 delegate->Start(std::move(blob_request), | 2350 delegate->Start(std::move(blob_request), |
| 2348 base::Bind(&LocalWriteClosure::Run, this)); | 2351 base::Bind(&LocalWriteClosure::Run, this)); |
| 2349 chained_blob_writer_->set_delegate(std::move(delegate)); | 2352 chained_blob_writer_->set_delegate(std::move(delegate)); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2432 FROM_HERE, | 2435 FROM_HERE, |
| 2433 base::Bind(&Transaction::ChainedBlobWriter::ReportWriteCompletion, | 2436 base::Bind(&Transaction::ChainedBlobWriter::ReportWriteCompletion, |
| 2434 chained_blob_writer, | 2437 chained_blob_writer, |
| 2435 true, | 2438 true, |
| 2436 info.size)); | 2439 info.size)); |
| 2437 } else { | 2440 } else { |
| 2438 DCHECK(descriptor.url().is_valid()); | 2441 DCHECK(descriptor.url().is_valid()); |
| 2439 scoped_refptr<LocalWriteClosure> write_closure( | 2442 scoped_refptr<LocalWriteClosure> write_closure( |
| 2440 new LocalWriteClosure(chained_blob_writer, task_runner_.get())); | 2443 new LocalWriteClosure(chained_blob_writer, task_runner_.get())); |
| 2441 content::BrowserThread::PostTask( | 2444 content::BrowserThread::PostTask( |
| 2442 content::BrowserThread::IO, | 2445 content::BrowserThread::IO, FROM_HERE, |
| 2443 FROM_HERE, | |
| 2444 base::Bind(&LocalWriteClosure::WriteBlobToFileOnIOThread, | 2446 base::Bind(&LocalWriteClosure::WriteBlobToFileOnIOThread, |
| 2445 write_closure.get(), | 2447 write_closure.get(), path, descriptor.url(), |
| 2446 path, | 2448 descriptor.last_modified(), request_context_getter_)); |
| 2447 descriptor.url(), | |
| 2448 descriptor.last_modified(), | |
| 2449 request_context_)); | |
| 2450 } | 2449 } |
| 2451 return true; | 2450 return true; |
| 2452 } | 2451 } |
| 2453 | 2452 |
| 2454 void IndexedDBBackingStore::ReportBlobUnused(int64_t database_id, | 2453 void IndexedDBBackingStore::ReportBlobUnused(int64_t database_id, |
| 2455 int64_t blob_key) { | 2454 int64_t blob_key) { |
| 2456 DCHECK(KeyPrefix::IsValidDatabaseId(database_id)); | 2455 DCHECK(KeyPrefix::IsValidDatabaseId(database_id)); |
| 2457 bool all_blobs = blob_key == DatabaseMetaDataKey::kAllBlobsKey; | 2456 bool all_blobs = blob_key == DatabaseMetaDataKey::kAllBlobsKey; |
| 2458 DCHECK(all_blobs || DatabaseMetaDataKey::IsValidBlobKey(blob_key)); | 2457 DCHECK(all_blobs || DatabaseMetaDataKey::IsValidBlobKey(blob_key)); |
| 2459 scoped_refptr<LevelDBTransaction> transaction = | 2458 scoped_refptr<LevelDBTransaction> transaction = |
| (...skipping 2014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4474 | 4473 |
| 4475 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( | 4474 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( |
| 4476 const WriteDescriptor& other) = default; | 4475 const WriteDescriptor& other) = default; |
| 4477 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = | 4476 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = |
| 4478 default; | 4477 default; |
| 4479 IndexedDBBackingStore::Transaction::WriteDescriptor& | 4478 IndexedDBBackingStore::Transaction::WriteDescriptor& |
| 4480 IndexedDBBackingStore::Transaction::WriteDescriptor:: | 4479 IndexedDBBackingStore::Transaction::WriteDescriptor:: |
| 4481 operator=(const WriteDescriptor& other) = default; | 4480 operator=(const WriteDescriptor& other) = default; |
| 4482 | 4481 |
| 4483 } // namespace content | 4482 } // namespace content |
| OLD | NEW |