| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 77 |
| 78 BlobReader::~BlobReader() { | 78 BlobReader::~BlobReader() { |
| 79 STLDeleteValues(&index_to_reader_); | 79 STLDeleteValues(&index_to_reader_); |
| 80 } | 80 } |
| 81 | 81 |
| 82 BlobReader::Status BlobReader::CalculateSize( | 82 BlobReader::Status BlobReader::CalculateSize( |
| 83 const net::CompletionCallback& done) { | 83 const net::CompletionCallback& done) { |
| 84 DCHECK(!total_size_calculated_); | 84 DCHECK(!total_size_calculated_); |
| 85 DCHECK(size_callback_.is_null()); | 85 DCHECK(size_callback_.is_null()); |
| 86 if (!blob_handle_.get() || blob_handle_->IsBroken()) { | 86 if (!blob_handle_.get() || blob_handle_->IsBroken()) { |
| 87 LOG(ERROR) << "Broken blob, or non existant"; |
| 87 return ReportError(net::ERR_FILE_NOT_FOUND); | 88 return ReportError(net::ERR_FILE_NOT_FOUND); |
| 88 } | 89 } |
| 89 if (blob_handle_->IsBeingBuilt()) { | 90 if (blob_handle_->IsBeingBuilt()) { |
| 91 LOG(ERROR) << blob_handle_->uuid() << " blob still being built"; |
| 90 blob_handle_->RunOnConstructionComplete(base::Bind( | 92 blob_handle_->RunOnConstructionComplete(base::Bind( |
| 91 &BlobReader::AsyncCalculateSize, weak_factory_.GetWeakPtr(), done)); | 93 &BlobReader::AsyncCalculateSize, weak_factory_.GetWeakPtr(), done)); |
| 92 return Status::IO_PENDING; | 94 return Status::IO_PENDING; |
| 93 } | 95 } |
| 94 blob_data_ = blob_handle_->CreateSnapshot(); | 96 blob_data_ = blob_handle_->CreateSnapshot(); |
| 95 return CalculateSizeImpl(done); | 97 return CalculateSizeImpl(done); |
| 96 } | 98 } |
| 97 | 99 |
| 98 bool BlobReader::has_side_data() const { | 100 bool BlobReader::has_side_data() const { |
| 99 if (!blob_data_.get()) | 101 if (!blob_data_.get()) |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 net::CompletionCallback done) { | 243 net::CompletionCallback done) { |
| 242 net_error_ = net_error; | 244 net_error_ = net_error; |
| 243 weak_factory_.InvalidateWeakPtrs(); | 245 weak_factory_.InvalidateWeakPtrs(); |
| 244 size_callback_.Reset(); | 246 size_callback_.Reset(); |
| 245 read_callback_.Reset(); | 247 read_callback_.Reset(); |
| 246 read_buf_ = nullptr; | 248 read_buf_ = nullptr; |
| 247 done.Run(net_error); | 249 done.Run(net_error); |
| 248 } | 250 } |
| 249 | 251 |
| 250 BlobReader::Status BlobReader::ReportError(int net_error) { | 252 BlobReader::Status BlobReader::ReportError(int net_error) { |
| 253 LOG(ERROR) << "Reporting error << " << net_error; |
| 251 net_error_ = net_error; | 254 net_error_ = net_error; |
| 252 return Status::NET_ERROR; | 255 return Status::NET_ERROR; |
| 253 } | 256 } |
| 254 | 257 |
| 255 void BlobReader::AsyncCalculateSize(const net::CompletionCallback& done, | 258 void BlobReader::AsyncCalculateSize(const net::CompletionCallback& done, |
| 256 bool async_succeeded, | 259 bool async_succeeded, |
| 257 IPCBlobCreationCancelCode reason) { | 260 IPCBlobCreationCancelCode reason) { |
| 258 if (!async_succeeded) { | 261 if (!async_succeeded) { |
| 262 LOG(ERROR) << "Blob construction failed"; |
| 259 InvalidateCallbacksAndDone(ConvertBlobErrorToNetError(reason), done); | 263 InvalidateCallbacksAndDone(ConvertBlobErrorToNetError(reason), done); |
| 260 return; | 264 return; |
| 261 } | 265 } |
| 266 LOG(ERROR) << blob_handle_->uuid() << " consruction done"; |
| 262 DCHECK(!blob_handle_->IsBroken()) << "Callback should have returned false."; | 267 DCHECK(!blob_handle_->IsBroken()) << "Callback should have returned false."; |
| 263 blob_data_ = blob_handle_->CreateSnapshot(); | 268 blob_data_ = blob_handle_->CreateSnapshot(); |
| 264 Status size_status = CalculateSizeImpl(done); | 269 Status size_status = CalculateSizeImpl(done); |
| 265 switch (size_status) { | 270 switch (size_status) { |
| 266 case Status::NET_ERROR: | 271 case Status::NET_ERROR: |
| 267 InvalidateCallbacksAndDone(net_error_, done); | 272 InvalidateCallbacksAndDone(net_error_, done); |
| 268 return; | 273 return; |
| 269 case Status::DONE: | 274 case Status::DONE: |
| 270 done.Run(net::OK); | 275 done.Run(net::OK); |
| 271 return; | 276 return; |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 index_to_reader_.erase(found); | 673 index_to_reader_.erase(found); |
| 669 return; | 674 return; |
| 670 } | 675 } |
| 671 found->second = reader.release(); | 676 found->second = reader.release(); |
| 672 } else if (reader.get()) { | 677 } else if (reader.get()) { |
| 673 index_to_reader_[current_item_index_] = reader.release(); | 678 index_to_reader_[current_item_index_] = reader.release(); |
| 674 } | 679 } |
| 675 } | 680 } |
| 676 | 681 |
| 677 } // namespace storage | 682 } // namespace storage |
| OLD | NEW |