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

Side by Side Diff: storage/browser/blob/blob_reader.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 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 bool IsFileType(DataElement::Type type) { 32 bool IsFileType(DataElement::Type type) {
33 switch (type) { 33 switch (type) {
34 case DataElement::TYPE_FILE: 34 case DataElement::TYPE_FILE:
35 case DataElement::TYPE_FILE_FILESYSTEM: 35 case DataElement::TYPE_FILE_FILESYSTEM:
36 return true; 36 return true;
37 default: 37 default:
38 return false; 38 return false;
39 } 39 }
40 } 40 }
41 41
42 int ConvertBlobErrorToNetError(IPCBlobCreationCancelCode reason) { 42 int ConvertBlobErrorToNetError(BlobStatus reason) {
43 switch (reason) { 43 switch (reason) {
44 case IPCBlobCreationCancelCode::UNKNOWN: 44 case BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS:
45 return net::ERR_FAILED; 45 return net::ERR_FAILED;
46 case IPCBlobCreationCancelCode::OUT_OF_MEMORY: 46 case BlobStatus::ERR_OUT_OF_MEMORY:
47 return net::ERR_OUT_OF_MEMORY; 47 return net::ERR_OUT_OF_MEMORY;
48 case IPCBlobCreationCancelCode::FILE_WRITE_FAILED: 48 case BlobStatus::ERR_FILE_WRITE_FAILED:
49 return net::ERR_FILE_NO_SPACE; 49 return net::ERR_FILE_NO_SPACE;
50 case IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT: 50 case BlobStatus::ERR_SOURCE_DIED_IN_TRANSIT:
51 return net::ERR_UNEXPECTED; 51 return net::ERR_UNEXPECTED;
52 case IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING: 52 case BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING:
53 return net::ERR_UNEXPECTED; 53 return net::ERR_UNEXPECTED;
54 case IPCBlobCreationCancelCode::REFERENCED_BLOB_BROKEN: 54 case BlobStatus::ERR_REFERENCED_BLOB_BROKEN:
55 return net::ERR_INVALID_HANDLE; 55 return net::ERR_INVALID_HANDLE;
56 case BlobStatus::DONE:
57 case BlobStatus::PENDING_QUOTA:
58 case BlobStatus::PENDING_TRANSPORT:
59 case BlobStatus::PENDING_INTERNALS:
60 NOTREACHED();
56 } 61 }
57 NOTREACHED(); 62 NOTREACHED();
58 return net::ERR_FAILED; 63 return net::ERR_FAILED;
59 } 64 }
60 } // namespace 65 } // namespace
61 66
62 BlobReader::FileStreamReaderProvider::~FileStreamReaderProvider() {} 67 BlobReader::FileStreamReaderProvider::~FileStreamReaderProvider() {}
63 68
64 BlobReader::BlobReader( 69 BlobReader::BlobReader(
65 const BlobDataHandle* blob_handle, 70 const BlobDataHandle* blob_handle,
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 read_buf_ = nullptr; 252 read_buf_ = nullptr;
248 done.Run(net_error); 253 done.Run(net_error);
249 } 254 }
250 255
251 BlobReader::Status BlobReader::ReportError(int net_error) { 256 BlobReader::Status BlobReader::ReportError(int net_error) {
252 net_error_ = net_error; 257 net_error_ = net_error;
253 return Status::NET_ERROR; 258 return Status::NET_ERROR;
254 } 259 }
255 260
256 void BlobReader::AsyncCalculateSize(const net::CompletionCallback& done, 261 void BlobReader::AsyncCalculateSize(const net::CompletionCallback& done,
257 bool async_succeeded, 262 BlobStatus status) {
258 IPCBlobCreationCancelCode reason) { 263 if (BlobStatusIsError(status)) {
259 if (!async_succeeded) { 264 InvalidateCallbacksAndDone(ConvertBlobErrorToNetError(status), done);
260 InvalidateCallbacksAndDone(ConvertBlobErrorToNetError(reason), done);
261 return; 265 return;
262 } 266 }
263 DCHECK(!blob_handle_->IsBroken()) << "Callback should have returned false."; 267 DCHECK(!blob_handle_->IsBroken()) << "Callback should have returned false.";
264 blob_data_ = blob_handle_->CreateSnapshot(); 268 blob_data_ = blob_handle_->CreateSnapshot();
265 Status size_status = CalculateSizeImpl(done); 269 Status size_status = CalculateSizeImpl(done);
266 switch (size_status) { 270 switch (size_status) {
267 case Status::NET_ERROR: 271 case Status::NET_ERROR:
268 InvalidateCallbacksAndDone(net_error_, done); 272 InvalidateCallbacksAndDone(net_error_, done);
269 return; 273 return;
270 case Status::DONE: 274 case Status::DONE:
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 void BlobReader::SetFileReaderAtIndex( 664 void BlobReader::SetFileReaderAtIndex(
661 size_t index, 665 size_t index,
662 std::unique_ptr<FileStreamReader> reader) { 666 std::unique_ptr<FileStreamReader> reader) {
663 if (reader) 667 if (reader)
664 index_to_reader_[index] = std::move(reader); 668 index_to_reader_[index] = std::move(reader);
665 else 669 else
666 index_to_reader_.erase(index); 670 index_to_reader_.erase(index);
667 } 671 }
668 672
669 } // namespace storage 673 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698