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