Chromium Code Reviews| Index: webkit/browser/blob/blob_data_handle.cc |
| diff --git a/webkit/browser/blob/blob_data_handle.cc b/webkit/browser/blob/blob_data_handle.cc |
| index fd0ae54db73307d78774a037b4b52a6286a5f5c7..438e4c76142068cf4723be0a1e4a2399e20eec46 100644 |
| --- a/webkit/browser/blob/blob_data_handle.cc |
| +++ b/webkit/browser/blob/blob_data_handle.cc |
| @@ -13,44 +13,58 @@ |
| namespace webkit_blob { |
| -BlobDataHandle::BlobDataHandle(BlobData* blob_data, BlobStorageContext* context, |
| - base::SequencedTaskRunner* task_runner) |
| +BlobDataHandle::BlobDataHandleShared::BlobDataHandleShared( |
| + BlobData* blob_data, |
| + BlobStorageContext* context, |
| + base::SequencedTaskRunner* task_runner) |
| : blob_data_(blob_data), |
| context_(context->AsWeakPtr()), |
| io_task_runner_(task_runner) { |
| - // Ensures the uuid remains registered and the underlying data is not deleted. |
| + DCHECK(io_task_runner_); |
| DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| context_->IncrementBlobRefCount(blob_data->uuid()); |
| - blob_data_->AddRef(); |
| } |
| -BlobDataHandle::~BlobDataHandle() { |
| - if (io_task_runner_->RunsTasksOnCurrentThread()) { |
| - // Note: Do not test context_ or alter the blob_data_ refcount |
| - // on the wrong thread. |
| - if (context_.get()) |
| - context_->DecrementBlobRefCount(blob_data_->uuid()); |
| - blob_data_->Release(); |
| - return; |
| - } |
| +BlobData* BlobDataHandle::BlobDataHandleShared::data() const { |
| + DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| + return blob_data_; |
| +} |
| - io_task_runner_->PostTask( |
| - FROM_HERE, |
| - base::Bind(&DeleteHelper, context_, base::Unretained(blob_data_))); |
| +const std::string& BlobDataHandle::BlobDataHandleShared::uuid() const { |
| + return blob_data_->uuid(); |
| +} |
| + |
| +BlobDataHandle::BlobDataHandleShared::~BlobDataHandleShared() { |
| + if (context_.get()) |
| + context_->DecrementBlobRefCount(blob_data_->uuid()); |
| +} |
| + |
| +BlobDataHandle::BlobDataHandle(BlobData* blob_data, |
| + BlobStorageContext* context, |
| + base::SequencedTaskRunner* task_runner) |
| + : io_task_runner_(task_runner), |
| + shared_(new BlobDataHandleShared(blob_data, context, task_runner)) { |
| + DCHECK(io_task_runner_); |
| +} |
| + |
| +BlobDataHandle::BlobDataHandle(const BlobDataHandle& other) { |
| + io_task_runner_ = other.io_task_runner_; |
| + shared_ = other.shared_; |
| +} |
| + |
| +BlobDataHandle::~BlobDataHandle() { |
| + BlobDataHandleShared* raw = shared_.get(); |
| + raw->AddRef(); |
| + shared_ = 0; |
| + io_task_runner_->ReleaseSoon(FROM_HERE, raw); |
| } |
| BlobData* BlobDataHandle::data() const { |
|
michaeln
2014/04/28 18:25:22
if the DCHECK(io_task_runner_->RunsTasksOnCurrentT
ericu
2014/04/28 18:43:01
Good point; done.
|
| - DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| - return blob_data_; |
| + return shared_->data(); |
| } |
| -// static |
| -void BlobDataHandle::DeleteHelper( |
|
michaeln
2014/04/28 18:25:22
nice that this is no longer needed since the Share
|
| - base::WeakPtr<BlobStorageContext> context, |
| - BlobData* blob_data) { |
| - if (context.get()) |
| - context->DecrementBlobRefCount(blob_data->uuid()); |
| - blob_data->Release(); |
| +std::string BlobDataHandle::uuid() const { |
| + return shared_->uuid(); |
| } |
| } // namespace webkit_blob |