Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: storage/browser/blob/blob_data_handle.cc

Issue 2055053003: [BlobAsync] Disk support for blob storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/sequenced_task_runner.h" 17 #include "base/sequenced_task_runner.h"
18 #include "base/task_runner.h" 18 #include "base/task_runner.h"
19 #include "base/time/time.h" 19 #include "base/time/time.h"
20 #include "storage/browser/blob/blob_data_snapshot.h" 20 #include "storage/browser/blob/blob_data_snapshot.h"
21 #include "storage/browser/blob/blob_reader.h" 21 #include "storage/browser/blob/blob_reader.h"
22 #include "storage/browser/blob/blob_storage_context.h" 22 #include "storage/browser/blob/blob_storage_context.h"
23 #include "storage/browser/fileapi/file_stream_reader.h" 23 #include "storage/browser/fileapi/file_stream_reader.h"
24 #include "storage/browser/fileapi/file_system_context.h" 24 #include "storage/browser/fileapi/file_system_context.h"
25 #include "storage/browser/fileapi/file_system_url.h" 25 #include "storage/browser/fileapi/file_system_url.h"
26 #include "url/gurl.h" 26 #include "url/gurl.h"
27 27
28 namespace storage { 28 namespace storage {
29 using BlobState = BlobStorageRegistry::BlobState;
30
31 namespace { 29 namespace {
32 30
33 class FileStreamReaderProviderImpl 31 class FileStreamReaderProviderImpl
34 : public BlobReader::FileStreamReaderProvider { 32 : public BlobReader::FileStreamReaderProvider {
35 public: 33 public:
36 explicit FileStreamReaderProviderImpl(FileSystemContext* file_system_context) 34 explicit FileStreamReaderProviderImpl(FileSystemContext* file_system_context)
37 : file_system_context_(file_system_context) {} 35 : file_system_context_(file_system_context) {}
38 ~FileStreamReaderProviderImpl() override {} 36 ~FileStreamReaderProviderImpl() override {}
39 37
40 std::unique_ptr<FileStreamReader> CreateForLocalFile( 38 std::unique_ptr<FileStreamReader> CreateForLocalFile(
(...skipping 19 matching lines...) Expand all
60 scoped_refptr<FileSystemContext> file_system_context_; 58 scoped_refptr<FileSystemContext> file_system_context_;
61 DISALLOW_COPY_AND_ASSIGN(FileStreamReaderProviderImpl); 59 DISALLOW_COPY_AND_ASSIGN(FileStreamReaderProviderImpl);
62 }; 60 };
63 61
64 } // namespace 62 } // namespace
65 63
66 BlobDataHandle::BlobDataHandleShared::BlobDataHandleShared( 64 BlobDataHandle::BlobDataHandleShared::BlobDataHandleShared(
67 const std::string& uuid, 65 const std::string& uuid,
68 const std::string& content_type, 66 const std::string& content_type,
69 const std::string& content_disposition, 67 const std::string& content_disposition,
68 uint64_t size,
70 BlobStorageContext* context) 69 BlobStorageContext* context)
71 : uuid_(uuid), 70 : uuid_(uuid),
72 content_type_(content_type), 71 content_type_(content_type),
73 content_disposition_(content_disposition), 72 content_disposition_(content_disposition),
73 size_(size),
74 context_(context->AsWeakPtr()) { 74 context_(context->AsWeakPtr()) {
75 context_->IncrementBlobRefCount(uuid); 75 context_->IncrementBlobRefCount(uuid);
76 } 76 }
77 77
78 std::unique_ptr<BlobReader> BlobDataHandle::CreateReader( 78 std::unique_ptr<BlobReader> BlobDataHandle::CreateReader(
79 FileSystemContext* file_system_context, 79 FileSystemContext* file_system_context,
80 base::SequencedTaskRunner* file_task_runner) const { 80 base::SequencedTaskRunner* file_task_runner) const {
81 return std::unique_ptr<BlobReader>(new BlobReader( 81 return std::unique_ptr<BlobReader>(new BlobReader(
82 this, std::unique_ptr<BlobReader::FileStreamReaderProvider>( 82 this, std::unique_ptr<BlobReader::FileStreamReaderProvider>(
83 new FileStreamReaderProviderImpl(file_system_context)), 83 new FileStreamReaderProviderImpl(file_system_context)),
84 file_task_runner)); 84 file_task_runner));
85 } 85 }
86 86
87 BlobDataHandle::BlobDataHandleShared::~BlobDataHandleShared() { 87 BlobDataHandle::BlobDataHandleShared::~BlobDataHandleShared() {
88 if (context_.get()) 88 if (context_.get())
89 context_->DecrementBlobRefCount(uuid_); 89 context_->DecrementBlobRefCount(uuid_);
90 } 90 }
91 91
92 BlobDataHandle::BlobDataHandle(const std::string& uuid, 92 BlobDataHandle::BlobDataHandle(const std::string& uuid,
93 const std::string& content_type, 93 const std::string& content_type,
94 const std::string& content_disposition, 94 const std::string& content_disposition,
95 uint64_t size,
95 BlobStorageContext* context, 96 BlobStorageContext* context,
96 base::SequencedTaskRunner* io_task_runner) 97 base::SequencedTaskRunner* io_task_runner)
97 : io_task_runner_(io_task_runner), 98 : io_task_runner_(io_task_runner),
98 shared_(new BlobDataHandleShared(uuid, 99 shared_(new BlobDataHandleShared(uuid,
99 content_type, 100 content_type,
100 content_disposition, 101 content_disposition,
102 size,
101 context)) { 103 context)) {
102 DCHECK(io_task_runner_.get()); 104 DCHECK(io_task_runner_.get());
103 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 105 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
104 } 106 }
105 107
106 BlobDataHandle::BlobDataHandle(const BlobDataHandle& other) { 108 BlobDataHandle::BlobDataHandle(const BlobDataHandle& other) {
107 io_task_runner_ = other.io_task_runner_; 109 io_task_runner_ = other.io_task_runner_;
108 shared_ = other.shared_; 110 shared_ = other.shared_;
109 } 111 }
110 112
111 BlobDataHandle::~BlobDataHandle() { 113 BlobDataHandle::~BlobDataHandle() {
112 if (!io_task_runner_->RunsTasksOnCurrentThread()) { 114 if (!io_task_runner_->RunsTasksOnCurrentThread()) {
113 BlobDataHandleShared* raw = shared_.get(); 115 BlobDataHandleShared* raw = shared_.get();
114 raw->AddRef(); 116 raw->AddRef();
115 shared_ = nullptr; 117 shared_ = nullptr;
116 io_task_runner_->ReleaseSoon(FROM_HERE, raw); 118 io_task_runner_->ReleaseSoon(FROM_HERE, raw);
117 } 119 }
118 } 120 }
119 121
120 bool BlobDataHandle::IsBeingBuilt() const { 122 bool BlobDataHandle::IsBeingBuilt() const {
121 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 123 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
122 if (!shared_->context_) 124 if (!shared_->context_)
123 return false; 125 return false;
124 return shared_->context_->IsBeingBuilt(shared_->uuid_); 126 return shared_->context_->GetBlobStatus(shared_->uuid_) ==
Marijn Kruisselbrink 2016/07/12 21:33:06 nit: could just write this as GetBlobStatus() == B
dmurph 2016/07/14 01:04:31 Done.
127 BlobStatus::PENDING;
125 } 128 }
126 129
127 bool BlobDataHandle::IsBroken() const { 130 bool BlobDataHandle::IsBroken() const {
128 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 131 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
129 if (!shared_->context_) 132 if (!shared_->context_)
130 return true; 133 return true;
131 return shared_->context_->IsBroken(shared_->uuid_); 134 return BlobStatusIsError(shared_->context_->GetBlobStatus(shared_->uuid_));
Marijn Kruisselbrink 2016/07/12 21:33:06 nit: here too, could just use BlobDataHandle::GetB
dmurph 2016/07/14 01:04:31 Done.
132 } 135 }
133 136
134 void BlobDataHandle::RunOnConstructionComplete( 137 BlobStatus BlobDataHandle::GetBlobStatus() const {
135 const BlobConstructedCallback& done) { 138 return shared_->context_->GetBlobStatus(shared_->uuid_);
139 }
140
141 void BlobDataHandle::RunOnConstructionComplete(const BlobStatusCallback& done) {
136 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 142 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
137 if (!shared_->context_.get()) { 143 if (!shared_->context_.get()) {
138 done.Run(false, IPCBlobCreationCancelCode::UNKNOWN); 144 done.Run(BlobStatus::INVALID_CONSTRUCTION_ARGUMENTS);
139 return; 145 return;
140 } 146 }
141 shared_->context_->RunOnConstructionComplete(shared_->uuid_, done); 147 shared_->context_->RunOnConstructionComplete(shared_->uuid_, done);
142 } 148 }
143 149
144 std::unique_ptr<BlobDataSnapshot> BlobDataHandle::CreateSnapshot() const { 150 std::unique_ptr<BlobDataSnapshot> BlobDataHandle::CreateSnapshot() const {
145 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 151 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
146 if (!shared_->context_.get()) 152 if (!shared_->context_.get())
147 return nullptr; 153 return nullptr;
148 return shared_->context_->CreateSnapshot(shared_->uuid_); 154 return shared_->context_->CreateSnapshot(shared_->uuid_);
149 } 155 }
150 156
151 const std::string& BlobDataHandle::uuid() const { 157 const std::string& BlobDataHandle::uuid() const {
152 return shared_->uuid_; 158 return shared_->uuid_;
153 } 159 }
154 160
155 const std::string& BlobDataHandle::content_type() const { 161 const std::string& BlobDataHandle::content_type() const {
156 return shared_->content_type_; 162 return shared_->content_type_;
157 } 163 }
158 164
159 const std::string& BlobDataHandle::content_disposition() const { 165 const std::string& BlobDataHandle::content_disposition() const {
160 return shared_->content_disposition_; 166 return shared_->content_disposition_;
161 } 167 }
162 168
169 uint64_t BlobDataHandle::size() const {
170 return shared_->size_;
171 }
172
163 } // namespace storage 173 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698