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

Side by Side Diff: storage/browser/blob/upload_blob_element_reader.cc

Issue 1337153002: [Blob] BlobReader class & tests, and removal of all redundant reading. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Trybot fixes Created 5 years, 3 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "storage/browser/blob/upload_blob_element_reader.h"
6
7 #include "net/base/net_errors.h"
8 #include "storage/browser/blob/blob_data_handle.h"
9 #include "storage/browser/blob/blob_reader.h"
10
11 namespace storage {
12
13 UploadBlobElementReader::UploadBlobElementReader(
14 scoped_ptr<storage::BlobReader> reader,
15 scoped_ptr<BlobDataHandle> handle)
16 : reader_(reader.Pass()), handle_(handle.Pass()) {}
17
18 UploadBlobElementReader::~UploadBlobElementReader() {}
19
20 const UploadBlobElementReader*
21 UploadBlobElementReader::AsUploadBlobElementReaderForTests() const {
22 return this;
23 }
24
25 int UploadBlobElementReader::Init(const net::CompletionCallback& callback) {
26 BlobReader::Status status = reader_->CalculateSize(callback);
27 switch (status) {
28 case BlobReader::Status::NET_ERROR:
29 return reader_->net_error();
30 case BlobReader::Status::PENDING_IO:
31 return net::ERR_IO_PENDING;
32 case BlobReader::Status::DONE:
33 return net::OK;
34 }
35 NOTREACHED();
36 return net::ERR_FAILED;
37 }
38
39 uint64_t UploadBlobElementReader::GetContentLength() const {
40 return reader_->total_size();
41 }
42
43 uint64_t UploadBlobElementReader::BytesRemaining() const {
44 return reader_->remaining_bytes();
45 }
46
47 bool UploadBlobElementReader::IsInMemory() const {
48 return reader_->IsInMemory();
49 }
50
51 int UploadBlobElementReader::Read(net::IOBuffer* buf,
52 int buf_length,
53 const net::CompletionCallback& callback) {
54 int length = 0;
55 BlobReader::Status status = reader_->Read(buf, buf_length, &length, callback);
56 switch (status) {
57 case BlobReader::Status::NET_ERROR:
58 return reader_->net_error();
59 case BlobReader::Status::PENDING_IO:
60 return net::ERR_IO_PENDING;
61 case BlobReader::Status::DONE:
62 return length;
63 }
64 NOTREACHED();
65 return net::ERR_FAILED;
66 }
67
68 const std::string& UploadBlobElementReader::uuid() const {
69 return handle_->uuid();
70 }
71
72 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698