OLD | NEW |
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 22 matching lines...) Expand all Loading... |
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 | 42 |
43 int ConvertBlobErrorToNetError(IPCBlobCreationCancelCode reason) { | 43 int ConvertBlobErrorToNetError(BlobStatus reason) { |
44 switch (reason) { | 44 switch (reason) { |
45 case IPCBlobCreationCancelCode::UNKNOWN: | 45 case BlobStatus::INVALID_CONSTRUCTION_ARGUMENTS: |
46 return net::ERR_FAILED; | 46 return net::ERR_FAILED; |
47 case IPCBlobCreationCancelCode::OUT_OF_MEMORY: | 47 case BlobStatus::OUT_OF_MEMORY: |
48 return net::ERR_OUT_OF_MEMORY; | 48 return net::ERR_OUT_OF_MEMORY; |
49 case IPCBlobCreationCancelCode::FILE_WRITE_FAILED: | 49 case BlobStatus::FILE_WRITE_FAILED: |
50 return net::ERR_FILE_NO_SPACE; | 50 return net::ERR_FILE_NO_SPACE; |
51 case IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT: | 51 case BlobStatus::SOURCE_DIED_IN_TRANSIT: |
52 return net::ERR_UNEXPECTED; | 52 return net::ERR_UNEXPECTED; |
53 case IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING: | 53 case BlobStatus::BLOB_DEREFERENCED_WHILE_BUILDING: |
54 return net::ERR_UNEXPECTED; | 54 return net::ERR_UNEXPECTED; |
55 case IPCBlobCreationCancelCode::REFERENCED_BLOB_BROKEN: | 55 case BlobStatus::REFERENCED_BLOB_BROKEN: |
56 return net::ERR_INVALID_HANDLE; | 56 return net::ERR_INVALID_HANDLE; |
| 57 case BlobStatus::DONE: |
| 58 case BlobStatus::PENDING: |
| 59 NOTREACHED(); |
57 } | 60 } |
58 NOTREACHED(); | 61 NOTREACHED(); |
59 return net::ERR_FAILED; | 62 return net::ERR_FAILED; |
60 } | 63 } |
61 } // namespace | 64 } // namespace |
62 | 65 |
63 BlobReader::FileStreamReaderProvider::~FileStreamReaderProvider() {} | 66 BlobReader::FileStreamReaderProvider::~FileStreamReaderProvider() {} |
64 | 67 |
65 BlobReader::BlobReader( | 68 BlobReader::BlobReader( |
66 const BlobDataHandle* blob_handle, | 69 const BlobDataHandle* blob_handle, |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 read_buf_ = nullptr; | 252 read_buf_ = nullptr; |
250 done.Run(net_error); | 253 done.Run(net_error); |
251 } | 254 } |
252 | 255 |
253 BlobReader::Status BlobReader::ReportError(int net_error) { | 256 BlobReader::Status BlobReader::ReportError(int net_error) { |
254 net_error_ = net_error; | 257 net_error_ = net_error; |
255 return Status::NET_ERROR; | 258 return Status::NET_ERROR; |
256 } | 259 } |
257 | 260 |
258 void BlobReader::AsyncCalculateSize(const net::CompletionCallback& done, | 261 void BlobReader::AsyncCalculateSize(const net::CompletionCallback& done, |
259 bool async_succeeded, | 262 BlobStatus status) { |
260 IPCBlobCreationCancelCode reason) { | 263 if (BlobStatusIsError(status)) { |
261 if (!async_succeeded) { | 264 InvalidateCallbacksAndDone(ConvertBlobErrorToNetError(status), done); |
262 InvalidateCallbacksAndDone(ConvertBlobErrorToNetError(reason), done); | |
263 return; | 265 return; |
264 } | 266 } |
265 DCHECK(!blob_handle_->IsBroken()) << "Callback should have returned false."; | 267 DCHECK(!blob_handle_->IsBroken()) << "Callback should have returned false."; |
266 blob_data_ = blob_handle_->CreateSnapshot(); | 268 blob_data_ = blob_handle_->CreateSnapshot(); |
267 Status size_status = CalculateSizeImpl(done); | 269 Status size_status = CalculateSizeImpl(done); |
268 switch (size_status) { | 270 switch (size_status) { |
269 case Status::NET_ERROR: | 271 case Status::NET_ERROR: |
270 InvalidateCallbacksAndDone(net_error_, done); | 272 InvalidateCallbacksAndDone(net_error_, done); |
271 return; | 273 return; |
272 case Status::DONE: | 274 case Status::DONE: |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 index_to_reader_.erase(found); | 673 index_to_reader_.erase(found); |
672 return; | 674 return; |
673 } | 675 } |
674 found->second = reader.release(); | 676 found->second = reader.release(); |
675 } else if (reader.get()) { | 677 } else if (reader.get()) { |
676 index_to_reader_[current_item_index_] = reader.release(); | 678 index_to_reader_[current_item_index_] = reader.release(); |
677 } | 679 } |
678 } | 680 } |
679 | 681 |
680 } // namespace storage | 682 } // namespace storage |
OLD | NEW |