| 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 "storage/browser/blob/blob_data_handle.h" | 5 #include "storage/browser/blob/blob_data_handle.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 const std::string& content_type, | 68 const std::string& content_type, |
| 69 const std::string& content_disposition, | 69 const std::string& content_disposition, |
| 70 BlobStorageContext* context) | 70 BlobStorageContext* context) |
| 71 : uuid_(uuid), | 71 : uuid_(uuid), |
| 72 content_type_(content_type), | 72 content_type_(content_type), |
| 73 content_disposition_(content_disposition), | 73 content_disposition_(content_disposition), |
| 74 context_(context->AsWeakPtr()) { | 74 context_(context->AsWeakPtr()) { |
| 75 context_->IncrementBlobRefCount(uuid); | 75 context_->IncrementBlobRefCount(uuid); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void BlobDataHandle::BlobDataHandleShared::RunOnConstructionComplete( | |
| 79 const base::Callback<void(bool)>& done) { | |
| 80 if (!context_.get()) { | |
| 81 done.Run(false); | |
| 82 return; | |
| 83 } | |
| 84 context_->RunOnConstructionComplete(uuid_, done); | |
| 85 } | |
| 86 | |
| 87 std::unique_ptr<BlobReader> BlobDataHandle::CreateReader( | 78 std::unique_ptr<BlobReader> BlobDataHandle::CreateReader( |
| 88 FileSystemContext* file_system_context, | 79 FileSystemContext* file_system_context, |
| 89 base::SequencedTaskRunner* file_task_runner) const { | 80 base::SequencedTaskRunner* file_task_runner) const { |
| 90 return std::unique_ptr<BlobReader>(new BlobReader( | 81 return std::unique_ptr<BlobReader>(new BlobReader( |
| 91 this, std::unique_ptr<BlobReader::FileStreamReaderProvider>( | 82 this, std::unique_ptr<BlobReader::FileStreamReaderProvider>( |
| 92 new FileStreamReaderProviderImpl(file_system_context)), | 83 new FileStreamReaderProviderImpl(file_system_context)), |
| 93 file_task_runner)); | 84 file_task_runner)); |
| 94 } | 85 } |
| 95 | 86 |
| 96 std::unique_ptr<BlobDataSnapshot> | |
| 97 BlobDataHandle::BlobDataHandleShared::CreateSnapshot() const { | |
| 98 if (!context_.get()) | |
| 99 return nullptr; | |
| 100 return context_->CreateSnapshot(uuid_); | |
| 101 } | |
| 102 | |
| 103 BlobDataHandle::BlobDataHandleShared::~BlobDataHandleShared() { | 87 BlobDataHandle::BlobDataHandleShared::~BlobDataHandleShared() { |
| 104 if (context_.get()) | 88 if (context_.get()) |
| 105 context_->DecrementBlobRefCount(uuid_); | 89 context_->DecrementBlobRefCount(uuid_); |
| 106 } | 90 } |
| 107 | 91 |
| 108 BlobDataHandle::BlobDataHandle(const std::string& uuid, | 92 BlobDataHandle::BlobDataHandle(const std::string& uuid, |
| 109 const std::string& content_type, | 93 const std::string& content_type, |
| 110 const std::string& content_disposition, | 94 const std::string& content_disposition, |
| 111 BlobStorageContext* context, | 95 BlobStorageContext* context, |
| 112 base::SequencedTaskRunner* io_task_runner) | 96 base::SequencedTaskRunner* io_task_runner) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 141 } | 125 } |
| 142 | 126 |
| 143 bool BlobDataHandle::IsBroken() const { | 127 bool BlobDataHandle::IsBroken() const { |
| 144 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 128 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 145 if (!shared_->context_) | 129 if (!shared_->context_) |
| 146 return true; | 130 return true; |
| 147 return shared_->context_->IsBroken(shared_->uuid_); | 131 return shared_->context_->IsBroken(shared_->uuid_); |
| 148 } | 132 } |
| 149 | 133 |
| 150 void BlobDataHandle::RunOnConstructionComplete( | 134 void BlobDataHandle::RunOnConstructionComplete( |
| 151 const base::Callback<void(bool)>& done) { | 135 const BlobConstructedCallback& done) { |
| 152 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 136 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 153 shared_->RunOnConstructionComplete(done); | 137 if (!shared_->context_.get()) { |
| 138 done.Run(false, IPCBlobCreationCancelCode::UNKNOWN); |
| 139 return; |
| 140 } |
| 141 shared_->context_->RunOnConstructionComplete(shared_->uuid_, done); |
| 154 } | 142 } |
| 155 | 143 |
| 156 std::unique_ptr<BlobDataSnapshot> BlobDataHandle::CreateSnapshot() const { | 144 std::unique_ptr<BlobDataSnapshot> BlobDataHandle::CreateSnapshot() const { |
| 157 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 145 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 158 return shared_->CreateSnapshot(); | 146 if (!shared_->context_.get()) |
| 147 return nullptr; |
| 148 return shared_->context_->CreateSnapshot(shared_->uuid_); |
| 159 } | 149 } |
| 160 | 150 |
| 161 const std::string& BlobDataHandle::uuid() const { | 151 const std::string& BlobDataHandle::uuid() const { |
| 162 return shared_->uuid_; | 152 return shared_->uuid_; |
| 163 } | 153 } |
| 164 | 154 |
| 165 const std::string& BlobDataHandle::content_type() const { | 155 const std::string& BlobDataHandle::content_type() const { |
| 166 return shared_->content_type_; | 156 return shared_->content_type_; |
| 167 } | 157 } |
| 168 | 158 |
| 169 const std::string& BlobDataHandle::content_disposition() const { | 159 const std::string& BlobDataHandle::content_disposition() const { |
| 170 return shared_->content_disposition_; | 160 return shared_->content_disposition_; |
| 171 } | 161 } |
| 172 | 162 |
| 173 } // namespace storage | 163 } // namespace storage |
| OLD | NEW |