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

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

Issue 1846363002: [BlobAsync] Adding better error reporting and some new tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed switch statement Created 4 years, 8 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 "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 const std::string& content_type, 65 const std::string& content_type,
66 const std::string& content_disposition, 66 const std::string& content_disposition,
67 BlobStorageContext* context) 67 BlobStorageContext* context)
68 : uuid_(uuid), 68 : uuid_(uuid),
69 content_type_(content_type), 69 content_type_(content_type),
70 content_disposition_(content_disposition), 70 content_disposition_(content_disposition),
71 context_(context->AsWeakPtr()) { 71 context_(context->AsWeakPtr()) {
72 context_->IncrementBlobRefCount(uuid); 72 context_->IncrementBlobRefCount(uuid);
73 } 73 }
74 74
75 void BlobDataHandle::BlobDataHandleShared::RunOnConstructionComplete(
76 const base::Callback<void(bool)>& done) {
77 if (!context_.get()) {
78 done.Run(false);
79 return;
80 }
81 context_->RunOnConstructionComplete(uuid_, done);
82 }
83
84 scoped_ptr<BlobReader> BlobDataHandle::CreateReader( 75 scoped_ptr<BlobReader> BlobDataHandle::CreateReader(
85 FileSystemContext* file_system_context, 76 FileSystemContext* file_system_context,
86 base::SequencedTaskRunner* file_task_runner) const { 77 base::SequencedTaskRunner* file_task_runner) const {
87 return scoped_ptr<BlobReader>(new BlobReader( 78 return scoped_ptr<BlobReader>(new BlobReader(
88 this, scoped_ptr<BlobReader::FileStreamReaderProvider>( 79 this, scoped_ptr<BlobReader::FileStreamReaderProvider>(
89 new FileStreamReaderProviderImpl(file_system_context)), 80 new FileStreamReaderProviderImpl(file_system_context)),
90 file_task_runner)); 81 file_task_runner));
91 } 82 }
92 83
93 scoped_ptr<BlobDataSnapshot>
94 BlobDataHandle::BlobDataHandleShared::CreateSnapshot() const {
95 if (!context_.get())
96 return nullptr;
97 return context_->CreateSnapshot(uuid_);
98 }
99
100 BlobDataHandle::BlobDataHandleShared::~BlobDataHandleShared() { 84 BlobDataHandle::BlobDataHandleShared::~BlobDataHandleShared() {
101 if (context_.get()) 85 if (context_.get())
102 context_->DecrementBlobRefCount(uuid_); 86 context_->DecrementBlobRefCount(uuid_);
103 } 87 }
104 88
105 BlobDataHandle::BlobDataHandle(const std::string& uuid, 89 BlobDataHandle::BlobDataHandle(const std::string& uuid,
106 const std::string& content_type, 90 const std::string& content_type,
107 const std::string& content_disposition, 91 const std::string& content_disposition,
108 BlobStorageContext* context, 92 BlobStorageContext* context,
109 base::SequencedTaskRunner* io_task_runner) 93 base::SequencedTaskRunner* io_task_runner)
(...skipping 28 matching lines...) Expand all
138 } 122 }
139 123
140 bool BlobDataHandle::IsBroken() const { 124 bool BlobDataHandle::IsBroken() const {
141 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 125 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
142 if (!shared_->context_) 126 if (!shared_->context_)
143 return true; 127 return true;
144 return shared_->context_->IsBroken(shared_->uuid_); 128 return shared_->context_->IsBroken(shared_->uuid_);
145 } 129 }
146 130
147 void BlobDataHandle::RunOnConstructionComplete( 131 void BlobDataHandle::RunOnConstructionComplete(
148 const base::Callback<void(bool)>& done) { 132 const BlobConstructedCallback& done) {
149 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 133 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
150 shared_->RunOnConstructionComplete(done); 134 if (!shared_->context_.get()) {
135 done.Run(false, IPCBlobCreationCancelCode::UNKNOWN);
jsbell 2016/04/04 20:41:19 Add a code for this case?
dmurph 2016/04/04 22:17:42 This is a crazy edge case, where the context is ev
136 return;
137 }
138 shared_->context_->RunOnConstructionComplete(shared_->uuid_, done);
151 } 139 }
152 140
153 scoped_ptr<BlobDataSnapshot> BlobDataHandle::CreateSnapshot() const { 141 scoped_ptr<BlobDataSnapshot> BlobDataHandle::CreateSnapshot() const {
154 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 142 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
155 return shared_->CreateSnapshot(); 143 if (!shared_->context_.get())
144 return nullptr;
145 return shared_->context_->CreateSnapshot(shared_->uuid_);
156 } 146 }
157 147
158 const std::string& BlobDataHandle::uuid() const { 148 const std::string& BlobDataHandle::uuid() const {
159 return shared_->uuid_; 149 return shared_->uuid_;
160 } 150 }
161 151
162 const std::string& BlobDataHandle::content_type() const { 152 const std::string& BlobDataHandle::content_type() const {
163 return shared_->content_type_; 153 return shared_->content_type_;
164 } 154 }
165 155
166 const std::string& BlobDataHandle::content_disposition() const { 156 const std::string& BlobDataHandle::content_disposition() const {
167 return shared_->content_disposition_; 157 return shared_->content_disposition_;
168 } 158 }
169 159
170 } // namespace storage 160 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698