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

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

Issue 2448353002: [BlobAsync] Moving async handling into BlobStorageContext & quota out. (Closed)
Patch Set: comments from Marijn Created 4 years, 1 month 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) = default; 108 BlobDataHandle::BlobDataHandle(const BlobDataHandle& other) = default;
107 109
108 BlobDataHandle::~BlobDataHandle() { 110 BlobDataHandle::~BlobDataHandle() {
109 if (!io_task_runner_->RunsTasksOnCurrentThread()) { 111 if (!io_task_runner_->RunsTasksOnCurrentThread()) {
110 BlobDataHandleShared* raw = shared_.get(); 112 BlobDataHandleShared* raw = shared_.get();
111 raw->AddRef(); 113 raw->AddRef();
112 shared_ = nullptr; 114 shared_ = nullptr;
113 io_task_runner_->ReleaseSoon(FROM_HERE, raw); 115 io_task_runner_->ReleaseSoon(FROM_HERE, raw);
114 } 116 }
115 } 117 }
116 118
117 BlobDataHandle& BlobDataHandle::operator=( 119 BlobDataHandle& BlobDataHandle::operator=(
118 const BlobDataHandle& other) = default; 120 const BlobDataHandle& other) = default;
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 BlobStatusIsPending(GetBlobStatus());
125 } 127 }
126 128
127 bool BlobDataHandle::IsBroken() const { 129 bool BlobDataHandle::IsBroken() const {
128 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 130 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
129 if (!shared_->context_) 131 if (!shared_->context_)
130 return true; 132 return true;
131 return shared_->context_->IsBroken(shared_->uuid_); 133 return BlobStatusIsError(GetBlobStatus());
132 } 134 }
133 135
134 void BlobDataHandle::RunOnConstructionComplete( 136 BlobStatus BlobDataHandle::GetBlobStatus() const {
135 const BlobConstructedCallback& done) { 137 return shared_->context_->GetBlobStatus(shared_->uuid_);
138 }
139
140 void BlobDataHandle::RunOnConstructionComplete(const BlobStatusCallback& done) {
136 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 141 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
137 if (!shared_->context_.get()) { 142 if (!shared_->context_.get()) {
138 done.Run(false, IPCBlobCreationCancelCode::UNKNOWN); 143 done.Run(BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS);
139 return; 144 return;
140 } 145 }
141 shared_->context_->RunOnConstructionComplete(shared_->uuid_, done); 146 shared_->context_->RunOnConstructionComplete(shared_->uuid_, done);
142 } 147 }
143 148
144 std::unique_ptr<BlobDataSnapshot> BlobDataHandle::CreateSnapshot() const { 149 std::unique_ptr<BlobDataSnapshot> BlobDataHandle::CreateSnapshot() const {
145 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 150 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
146 if (!shared_->context_.get()) 151 if (!shared_->context_.get())
147 return nullptr; 152 return nullptr;
148 return shared_->context_->CreateSnapshot(shared_->uuid_); 153 return shared_->context_->CreateSnapshot(shared_->uuid_);
149 } 154 }
150 155
151 const std::string& BlobDataHandle::uuid() const { 156 const std::string& BlobDataHandle::uuid() const {
152 return shared_->uuid_; 157 return shared_->uuid_;
153 } 158 }
154 159
155 const std::string& BlobDataHandle::content_type() const { 160 const std::string& BlobDataHandle::content_type() const {
156 return shared_->content_type_; 161 return shared_->content_type_;
157 } 162 }
158 163
159 const std::string& BlobDataHandle::content_disposition() const { 164 const std::string& BlobDataHandle::content_disposition() const {
160 return shared_->content_disposition_; 165 return shared_->content_disposition_;
161 } 166 }
162 167
168 uint64_t BlobDataHandle::size() const {
169 return shared_->size_;
170 }
171
163 } // namespace storage 172 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698