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

Side by Side Diff: net/base/upload_bytes_element_reader.cc

Issue 10910268: net: Make UploadDataStream::Read() asynchronous (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/base/upload_bytes_element_reader.h" 5 #include "net/base/upload_bytes_element_reader.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "net/base/io_buffer.h"
8 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
9 10
10 namespace net { 11 namespace net {
11 12
12 UploadBytesElementReader::UploadBytesElementReader(const char* bytes, 13 UploadBytesElementReader::UploadBytesElementReader(const char* bytes,
13 int bytes_length) 14 int bytes_length)
14 : bytes_(bytes), 15 : bytes_(bytes),
15 bytes_length_(bytes_length), 16 bytes_length_(bytes_length),
16 offset_(0) { 17 offset_(0) {
17 } 18 }
(...skipping 10 matching lines...) Expand all
28 } 29 }
29 30
30 uint64 UploadBytesElementReader::GetContentLength() const { 31 uint64 UploadBytesElementReader::GetContentLength() const {
31 return bytes_length_; 32 return bytes_length_;
32 } 33 }
33 34
34 uint64 UploadBytesElementReader::BytesRemaining() const { 35 uint64 UploadBytesElementReader::BytesRemaining() const {
35 return bytes_length_ - offset_; 36 return bytes_length_ - offset_;
36 } 37 }
37 38
38 int UploadBytesElementReader::ReadSync(char* buf, int buf_length) { 39 bool UploadBytesElementReader::IsInMemory() const {
40 return true;
41 }
42
43 int UploadBytesElementReader::Read(IOBuffer* buf,
44 int buf_length,
45 const CompletionCallback& callback) {
46 DCHECK(!callback.is_null());
47 return ReadSync(buf, buf_length);
48 }
49
50 int UploadBytesElementReader::ReadSync(IOBuffer* buf, int buf_length) {
39 DCHECK_LT(0, buf_length); 51 DCHECK_LT(0, buf_length);
40 52
41 const size_t num_bytes_to_read = 53 const size_t num_bytes_to_read =
42 std::min(BytesRemaining(), static_cast<uint64>(buf_length)); 54 std::min(BytesRemaining(), static_cast<uint64>(buf_length));
43 55
44 // Check if we have anything to copy first, because we are getting 56 // Check if we have anything to copy first, because we are getting
45 // the address of an element in |bytes_| and that will throw an 57 // the address of an element in |bytes_| and that will throw an
46 // exception if |bytes_| is an empty vector. 58 // exception if |bytes_| is an empty vector.
47 if (num_bytes_to_read > 0) 59 if (num_bytes_to_read > 0)
48 memcpy(buf, bytes_ + offset_, num_bytes_to_read); 60 memcpy(buf->data(), bytes_ + offset_, num_bytes_to_read);
49 61
50 offset_ += num_bytes_to_read; 62 offset_ += num_bytes_to_read;
51 return num_bytes_to_read; 63 return num_bytes_to_read;
52 } 64 }
53 65
54 bool UploadBytesElementReader::IsInMemory() const {
55 return true;
56 }
57
58 } // namespace net 66 } // namespace net
OLDNEW
« no previous file with comments | « net/base/upload_bytes_element_reader.h ('k') | net/base/upload_bytes_element_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698