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

Side by Side Diff: storage/browser/blob/blob_reader.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 compile error 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_reader.h" 5 #include "storage/browser/blob/blob_reader.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 21 matching lines...) Expand all
32 namespace { 32 namespace {
33 bool IsFileType(DataElement::Type type) { 33 bool IsFileType(DataElement::Type type) {
34 switch (type) { 34 switch (type) {
35 case DataElement::TYPE_FILE: 35 case DataElement::TYPE_FILE:
36 case DataElement::TYPE_FILE_FILESYSTEM: 36 case DataElement::TYPE_FILE_FILESYSTEM:
37 return true; 37 return true;
38 default: 38 default:
39 return false; 39 return false;
40 } 40 }
41 } 41 }
42
43 int TransformBlobErrorToNetError(IPCBlobCreationCancelCode reason) {
kinuko 2016/04/05 09:42:35 nit: ditto, ConvertBlobError?
dmurph 2016/04/05 18:15:23 Done.
44 switch (reason) {
45 case IPCBlobCreationCancelCode::UNKNOWN:
46 return net::ERR_FAILED;
47 case IPCBlobCreationCancelCode::OUT_OF_MEMORY:
48 return net::ERR_OUT_OF_MEMORY;
49 case IPCBlobCreationCancelCode::FILE_WRITE_FAILED:
50 return net::ERR_FILE_NO_SPACE;
51 case IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT:
52 return net::ERR_UNEXPECTED;
53 case IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING:
54 return net::ERR_UNEXPECTED;
55 case IPCBlobCreationCancelCode::REFERENCED_BLOB_BROKEN:
56 return net::ERR_INVALID_HANDLE;
57 }
58 NOTREACHED();
59 return net::ERR_FAILED;
60 }
42 } // namespace 61 } // namespace
43 62
44 BlobReader::FileStreamReaderProvider::~FileStreamReaderProvider() {} 63 BlobReader::FileStreamReaderProvider::~FileStreamReaderProvider() {}
45 64
46 BlobReader::BlobReader( 65 BlobReader::BlobReader(
47 const BlobDataHandle* blob_handle, 66 const BlobDataHandle* blob_handle,
48 std::unique_ptr<FileStreamReaderProvider> file_stream_provider, 67 std::unique_ptr<FileStreamReaderProvider> file_stream_provider,
49 base::SequencedTaskRunner* file_task_runner) 68 base::SequencedTaskRunner* file_task_runner)
50 : file_stream_provider_(std::move(file_stream_provider)), 69 : file_stream_provider_(std::move(file_stream_provider)),
51 file_task_runner_(file_task_runner), 70 file_task_runner_(file_task_runner),
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 read_buf_ = nullptr; 197 read_buf_ = nullptr;
179 done.Run(net_error); 198 done.Run(net_error);
180 } 199 }
181 200
182 BlobReader::Status BlobReader::ReportError(int net_error) { 201 BlobReader::Status BlobReader::ReportError(int net_error) {
183 net_error_ = net_error; 202 net_error_ = net_error;
184 return Status::NET_ERROR; 203 return Status::NET_ERROR;
185 } 204 }
186 205
187 void BlobReader::AsyncCalculateSize(const net::CompletionCallback& done, 206 void BlobReader::AsyncCalculateSize(const net::CompletionCallback& done,
188 bool async_succeeded) { 207 bool async_succeeded,
208 IPCBlobCreationCancelCode reason) {
189 if (!async_succeeded) { 209 if (!async_succeeded) {
190 InvalidateCallbacksAndDone(net::ERR_FAILED, done); 210 InvalidateCallbacksAndDone(TransformBlobErrorToNetError(reason), done);
191 return; 211 return;
192 } 212 }
193 DCHECK(!blob_handle_->IsBroken()) << "Callback should have returned false."; 213 DCHECK(!blob_handle_->IsBroken()) << "Callback should have returned false.";
194 blob_data_ = blob_handle_->CreateSnapshot(); 214 blob_data_ = blob_handle_->CreateSnapshot();
195 Status size_status = CalculateSizeImpl(done); 215 Status size_status = CalculateSizeImpl(done);
196 switch (size_status) { 216 switch (size_status) {
197 case Status::NET_ERROR: 217 case Status::NET_ERROR:
198 InvalidateCallbacksAndDone(net_error_, done); 218 InvalidateCallbacksAndDone(net_error_, done);
199 return; 219 return;
200 case Status::DONE: 220 case Status::DONE:
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 index_to_reader_.erase(found); 619 index_to_reader_.erase(found);
600 return; 620 return;
601 } 621 }
602 found->second = reader.release(); 622 found->second = reader.release();
603 } else if (reader.get()) { 623 } else if (reader.get()) {
604 index_to_reader_[current_item_index_] = reader.release(); 624 index_to_reader_[current_item_index_] = reader.release();
605 } 625 }
606 } 626 }
607 627
608 } // namespace storage 628 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698