| 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 2406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2417 WriteDescriptorVec* blobs, | 2417 WriteDescriptorVec* blobs, |
| 2418 scoped_refptr<IndexedDBBackingStore::BlobWriteCallback> callback) | 2418 scoped_refptr<IndexedDBBackingStore::BlobWriteCallback> callback) |
| 2419 : waiting_for_callback_(false), | 2419 : waiting_for_callback_(false), |
| 2420 database_id_(database_id), | 2420 database_id_(database_id), |
| 2421 backing_store_(backing_store), | 2421 backing_store_(backing_store), |
| 2422 callback_(callback), | 2422 callback_(callback), |
| 2423 aborted_(false) { | 2423 aborted_(false) { |
| 2424 blobs_.swap(*blobs); | 2424 blobs_.swap(*blobs); |
| 2425 iter_ = blobs_.begin(); | 2425 iter_ = blobs_.begin(); |
| 2426 backing_store->task_runner()->PostTask( | 2426 backing_store->task_runner()->PostTask( |
| 2427 FROM_HERE, base::Bind(&ChainedBlobWriterImpl::WriteNextFile, this)); | 2427 FROM_HERE, base::BindOnce(&ChainedBlobWriterImpl::WriteNextFile, this)); |
| 2428 } | 2428 } |
| 2429 | 2429 |
| 2430 void set_delegate(std::unique_ptr<FileWriterDelegate> delegate) override { | 2430 void set_delegate(std::unique_ptr<FileWriterDelegate> delegate) override { |
| 2431 delegate_.reset(delegate.release()); | 2431 delegate_.reset(delegate.release()); |
| 2432 } | 2432 } |
| 2433 | 2433 |
| 2434 void ReportWriteCompletion(bool succeeded, int64_t bytes_written) override { | 2434 void ReportWriteCompletion(bool succeeded, int64_t bytes_written) override { |
| 2435 DCHECK(waiting_for_callback_); | 2435 DCHECK(waiting_for_callback_); |
| 2436 DCHECK(!succeeded || bytes_written >= 0); | 2436 DCHECK(!succeeded || bytes_written >= 0); |
| 2437 waiting_for_callback_ = false; | 2437 waiting_for_callback_ = false; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2519 } else { | 2519 } else { |
| 2520 DCHECK(write_status == FileWriterDelegate::ERROR_WRITE_STARTED || | 2520 DCHECK(write_status == FileWriterDelegate::ERROR_WRITE_STARTED || |
| 2521 write_status == FileWriterDelegate::ERROR_WRITE_NOT_STARTED); | 2521 write_status == FileWriterDelegate::ERROR_WRITE_NOT_STARTED); |
| 2522 } | 2522 } |
| 2523 | 2523 |
| 2524 bool success = write_status == FileWriterDelegate::SUCCESS_COMPLETED; | 2524 bool success = write_status == FileWriterDelegate::SUCCESS_COMPLETED; |
| 2525 if (success && !bytes_written_) { | 2525 if (success && !bytes_written_) { |
| 2526 // LocalFileStreamWriter only creates a file if data is actually written. | 2526 // LocalFileStreamWriter only creates a file if data is actually written. |
| 2527 // If none was then create one now. | 2527 // If none was then create one now. |
| 2528 task_runner_->PostTask( | 2528 task_runner_->PostTask( |
| 2529 FROM_HERE, base::Bind(&LocalWriteClosure::CreateEmptyFile, this)); | 2529 FROM_HERE, base::BindOnce(&LocalWriteClosure::CreateEmptyFile, this)); |
| 2530 } else if (success && !last_modified_.is_null()) { | 2530 } else if (success && !last_modified_.is_null()) { |
| 2531 task_runner_->PostTask( | 2531 task_runner_->PostTask( |
| 2532 FROM_HERE, base::Bind(&LocalWriteClosure::UpdateTimeStamp, this)); | 2532 FROM_HERE, base::BindOnce(&LocalWriteClosure::UpdateTimeStamp, this)); |
| 2533 } else { | 2533 } else { |
| 2534 task_runner_->PostTask( | 2534 task_runner_->PostTask( |
| 2535 FROM_HERE, | 2535 FROM_HERE, |
| 2536 base::Bind(&IndexedDBBackingStore::Transaction::ChainedBlobWriter:: | 2536 base::BindOnce(&IndexedDBBackingStore::Transaction:: |
| 2537 ReportWriteCompletion, | 2537 ChainedBlobWriter::ReportWriteCompletion, |
| 2538 chained_blob_writer_, | 2538 chained_blob_writer_, success, bytes_written_)); |
| 2539 success, | |
| 2540 bytes_written_)); | |
| 2541 } | 2539 } |
| 2542 } | 2540 } |
| 2543 | 2541 |
| 2544 void WriteBlobToFileOnIOThread( | 2542 void WriteBlobToFileOnIOThread( |
| 2545 const FilePath& file_path, | 2543 const FilePath& file_path, |
| 2546 const GURL& blob_url, | 2544 const GURL& blob_url, |
| 2547 const base::Time& last_modified, | 2545 const base::Time& last_modified, |
| 2548 scoped_refptr<net::URLRequestContextGetter> request_context_getter) { | 2546 scoped_refptr<net::URLRequestContextGetter> request_context_getter) { |
| 2549 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 2547 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 2550 std::unique_ptr<storage::FileStreamWriter> writer( | 2548 std::unique_ptr<storage::FileStreamWriter> writer( |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2670 } | 2668 } |
| 2671 if (!base::TouchFile(path, info.last_accessed, info.last_modified)) { | 2669 if (!base::TouchFile(path, info.last_accessed, info.last_modified)) { |
| 2672 // TODO(ericu): Complain quietly; timestamp's probably not vital. | 2670 // TODO(ericu): Complain quietly; timestamp's probably not vital. |
| 2673 } | 2671 } |
| 2674 } else { | 2672 } else { |
| 2675 // TODO(ericu): Complain quietly; timestamp's probably not vital. | 2673 // TODO(ericu): Complain quietly; timestamp's probably not vital. |
| 2676 } | 2674 } |
| 2677 | 2675 |
| 2678 task_runner_->PostTask( | 2676 task_runner_->PostTask( |
| 2679 FROM_HERE, | 2677 FROM_HERE, |
| 2680 base::Bind(&Transaction::ChainedBlobWriter::ReportWriteCompletion, | 2678 base::BindOnce(&Transaction::ChainedBlobWriter::ReportWriteCompletion, |
| 2681 chained_blob_writer, | 2679 chained_blob_writer, true, info.size)); |
| 2682 true, | |
| 2683 info.size)); | |
| 2684 } else { | 2680 } else { |
| 2685 DCHECK(descriptor.url().is_valid()); | 2681 DCHECK(descriptor.url().is_valid()); |
| 2686 scoped_refptr<LocalWriteClosure> write_closure( | 2682 scoped_refptr<LocalWriteClosure> write_closure( |
| 2687 new LocalWriteClosure(chained_blob_writer, task_runner_.get())); | 2683 new LocalWriteClosure(chained_blob_writer, task_runner_.get())); |
| 2688 content::BrowserThread::PostTask( | 2684 content::BrowserThread::PostTask( |
| 2689 content::BrowserThread::IO, FROM_HERE, | 2685 content::BrowserThread::IO, FROM_HERE, |
| 2690 base::Bind(&LocalWriteClosure::WriteBlobToFileOnIOThread, | 2686 base::BindOnce(&LocalWriteClosure::WriteBlobToFileOnIOThread, |
| 2691 write_closure, path, descriptor.url(), | 2687 write_closure, path, descriptor.url(), |
| 2692 descriptor.last_modified(), request_context_getter_)); | 2688 descriptor.last_modified(), request_context_getter_)); |
| 2693 } | 2689 } |
| 2694 return true; | 2690 return true; |
| 2695 } | 2691 } |
| 2696 | 2692 |
| 2697 void IndexedDBBackingStore::ReportBlobUnused(int64_t database_id, | 2693 void IndexedDBBackingStore::ReportBlobUnused(int64_t database_id, |
| 2698 int64_t blob_key) { | 2694 int64_t blob_key) { |
| 2699 DCHECK(KeyPrefix::IsValidDatabaseId(database_id)); | 2695 DCHECK(KeyPrefix::IsValidDatabaseId(database_id)); |
| 2700 bool all_blobs = blob_key == DatabaseMetaDataKey::kAllBlobsKey; | 2696 bool all_blobs = blob_key == DatabaseMetaDataKey::kAllBlobsKey; |
| 2701 DCHECK(all_blobs || DatabaseMetaDataKey::IsValidBlobKey(blob_key)); | 2697 DCHECK(all_blobs || DatabaseMetaDataKey::IsValidBlobKey(blob_key)); |
| 2702 scoped_refptr<LevelDBTransaction> transaction = | 2698 scoped_refptr<LevelDBTransaction> transaction = |
| (...skipping 1789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4492 | 4488 |
| 4493 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( | 4489 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( |
| 4494 const WriteDescriptor& other) = default; | 4490 const WriteDescriptor& other) = default; |
| 4495 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = | 4491 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = |
| 4496 default; | 4492 default; |
| 4497 IndexedDBBackingStore::Transaction::WriteDescriptor& | 4493 IndexedDBBackingStore::Transaction::WriteDescriptor& |
| 4498 IndexedDBBackingStore::Transaction::WriteDescriptor:: | 4494 IndexedDBBackingStore::Transaction::WriteDescriptor:: |
| 4499 operator=(const WriteDescriptor& other) = default; | 4495 operator=(const WriteDescriptor& other) = default; |
| 4500 | 4496 |
| 4501 } // namespace content | 4497 } // namespace content |
| OLD | NEW |