| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" |
| 8 #include "base/location.h" | 9 #include "base/location.h" |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
| 11 #include "base/task_runner.h" | 12 #include "base/task_runner.h" |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 13 #include "storage/browser/blob/blob_data_snapshot.h" | 14 #include "storage/browser/blob/blob_data_snapshot.h" |
| 14 #include "storage/browser/blob/blob_reader.h" | 15 #include "storage/browser/blob/blob_reader.h" |
| 15 #include "storage/browser/blob/blob_storage_context.h" | 16 #include "storage/browser/blob/blob_storage_context.h" |
| 16 #include "storage/browser/fileapi/file_stream_reader.h" | 17 #include "storage/browser/fileapi/file_stream_reader.h" |
| 17 #include "storage/browser/fileapi/file_system_context.h" | 18 #include "storage/browser/fileapi/file_system_context.h" |
| 18 #include "storage/browser/fileapi/file_system_url.h" | 19 #include "storage/browser/fileapi/file_system_url.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 20 | 21 |
| 21 namespace storage { | 22 namespace storage { |
| 23 using BlobState = BlobStorageRegistry::BlobState; |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 | 26 |
| 25 class FileStreamReaderProviderImpl | 27 class FileStreamReaderProviderImpl |
| 26 : public BlobReader::FileStreamReaderProvider { | 28 : public BlobReader::FileStreamReaderProvider { |
| 27 public: | 29 public: |
| 28 FileStreamReaderProviderImpl(FileSystemContext* file_system_context) | 30 explicit FileStreamReaderProviderImpl(FileSystemContext* file_system_context) |
| 29 : file_system_context_(file_system_context) {} | 31 : file_system_context_(file_system_context) {} |
| 30 ~FileStreamReaderProviderImpl() override {} | 32 ~FileStreamReaderProviderImpl() override {} |
| 31 | 33 |
| 32 scoped_ptr<FileStreamReader> CreateForLocalFile( | 34 scoped_ptr<FileStreamReader> CreateForLocalFile( |
| 33 base::TaskRunner* task_runner, | 35 base::TaskRunner* task_runner, |
| 34 const base::FilePath& file_path, | 36 const base::FilePath& file_path, |
| 35 int64_t initial_offset, | 37 int64_t initial_offset, |
| 36 const base::Time& expected_modification_time) override { | 38 const base::Time& expected_modification_time) override { |
| 37 return make_scoped_ptr(FileStreamReader::CreateForLocalFile( | 39 return make_scoped_ptr(FileStreamReader::CreateForLocalFile( |
| 38 task_runner, file_path, initial_offset, expected_modification_time)); | 40 task_runner, file_path, initial_offset, expected_modification_time)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 64 const std::string& content_type, | 66 const std::string& content_type, |
| 65 const std::string& content_disposition, | 67 const std::string& content_disposition, |
| 66 BlobStorageContext* context) | 68 BlobStorageContext* context) |
| 67 : uuid_(uuid), | 69 : uuid_(uuid), |
| 68 content_type_(content_type), | 70 content_type_(content_type), |
| 69 content_disposition_(content_disposition), | 71 content_disposition_(content_disposition), |
| 70 context_(context->AsWeakPtr()) { | 72 context_(context->AsWeakPtr()) { |
| 71 context_->IncrementBlobRefCount(uuid); | 73 context_->IncrementBlobRefCount(uuid); |
| 72 } | 74 } |
| 73 | 75 |
| 76 bool BlobDataHandle::BlobDataHandleShared::IsAsyncConstructing() const { |
| 77 if (!context_.get()) |
| 78 return false; |
| 79 return context_->IsBeingBuilt(uuid_); |
| 80 } |
| 81 |
| 82 void BlobDataHandle::BlobDataHandleShared::RunOnConstructionComplete( |
| 83 const base::Callback<void(bool)>& done) { |
| 84 if (!context_.get()) { |
| 85 done.Run(false); |
| 86 return; |
| 87 } |
| 88 context_->RunOnConstructionComplete(uuid_, done); |
| 89 } |
| 90 |
| 74 scoped_ptr<BlobReader> BlobDataHandle::CreateReader( | 91 scoped_ptr<BlobReader> BlobDataHandle::CreateReader( |
| 75 FileSystemContext* file_system_context, | 92 FileSystemContext* file_system_context, |
| 76 base::SequencedTaskRunner* file_task_runner) const { | 93 base::SequencedTaskRunner* file_task_runner) const { |
| 77 return scoped_ptr<BlobReader>(new BlobReader( | 94 return scoped_ptr<BlobReader>(new BlobReader( |
| 78 this, scoped_ptr<BlobReader::FileStreamReaderProvider>( | 95 this, scoped_ptr<BlobReader::FileStreamReaderProvider>( |
| 79 new FileStreamReaderProviderImpl(file_system_context)), | 96 new FileStreamReaderProviderImpl(file_system_context)), |
| 80 file_task_runner)); | 97 file_task_runner)); |
| 81 } | 98 } |
| 82 | 99 |
| 83 scoped_ptr<BlobDataSnapshot> | 100 scoped_ptr<BlobDataSnapshot> |
| 84 BlobDataHandle::BlobDataHandleShared::CreateSnapshot() const { | 101 BlobDataHandle::BlobDataHandleShared::CreateSnapshot() const { |
| 102 if (!context_.get()) |
| 103 return nullptr; |
| 85 return context_->CreateSnapshot(uuid_).Pass(); | 104 return context_->CreateSnapshot(uuid_).Pass(); |
| 86 } | 105 } |
| 87 | 106 |
| 88 BlobDataHandle::BlobDataHandleShared::~BlobDataHandleShared() { | 107 BlobDataHandle::BlobDataHandleShared::~BlobDataHandleShared() { |
| 89 if (context_.get()) | 108 if (context_.get()) |
| 90 context_->DecrementBlobRefCount(uuid_); | 109 context_->DecrementBlobRefCount(uuid_); |
| 91 } | 110 } |
| 92 | 111 |
| 93 BlobDataHandle::BlobDataHandle(const std::string& uuid, | 112 BlobDataHandle::BlobDataHandle(const std::string& uuid, |
| 94 const std::string& content_type, | 113 const std::string& content_type, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 109 shared_ = other.shared_; | 128 shared_ = other.shared_; |
| 110 } | 129 } |
| 111 | 130 |
| 112 BlobDataHandle::~BlobDataHandle() { | 131 BlobDataHandle::~BlobDataHandle() { |
| 113 BlobDataHandleShared* raw = shared_.get(); | 132 BlobDataHandleShared* raw = shared_.get(); |
| 114 raw->AddRef(); | 133 raw->AddRef(); |
| 115 shared_ = nullptr; | 134 shared_ = nullptr; |
| 116 io_task_runner_->ReleaseSoon(FROM_HERE, raw); | 135 io_task_runner_->ReleaseSoon(FROM_HERE, raw); |
| 117 } | 136 } |
| 118 | 137 |
| 138 bool BlobDataHandle::IsAsyncConstructing() const { |
| 139 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 140 return shared_->IsAsyncConstructing(); |
| 141 } |
| 142 |
| 143 void BlobDataHandle::RunOnConstructionComplete( |
| 144 const base::Callback<void(bool)>& done) { |
| 145 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 146 shared_->RunOnConstructionComplete(done); |
| 147 } |
| 148 |
| 119 scoped_ptr<BlobDataSnapshot> BlobDataHandle::CreateSnapshot() const { | 149 scoped_ptr<BlobDataSnapshot> BlobDataHandle::CreateSnapshot() const { |
| 120 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 150 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 121 return shared_->CreateSnapshot().Pass(); | 151 return shared_->CreateSnapshot().Pass(); |
| 122 } | 152 } |
| 123 | 153 |
| 124 const std::string& BlobDataHandle::uuid() const { | 154 const std::string& BlobDataHandle::uuid() const { |
| 125 return shared_->uuid_; | 155 return shared_->uuid_; |
| 126 } | 156 } |
| 127 | 157 |
| 128 const std::string& BlobDataHandle::content_type() const { | 158 const std::string& BlobDataHandle::content_type() const { |
| 129 return shared_->content_type_; | 159 return shared_->content_type_; |
| 130 } | 160 } |
| 131 | 161 |
| 132 const std::string& BlobDataHandle::content_disposition() const { | 162 const std::string& BlobDataHandle::content_disposition() const { |
| 133 return shared_->content_disposition_; | 163 return shared_->content_disposition_; |
| 134 } | 164 } |
| 135 | 165 |
| 136 } // namespace storage | 166 } // namespace storage |
| OLD | NEW |