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

Unified Diff: net/base/upload_bytes_element_reader.cc

Issue 10868064: net: Move data reading functionalities from UploadElement to UploadElementReader (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/upload_bytes_element_reader.cc
diff --git a/net/base/upload_bytes_element_reader.cc b/net/base/upload_bytes_element_reader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c99ce74eaceaea39460bcc4424e25ca9c7fb24e6
--- /dev/null
+++ b/net/base/upload_bytes_element_reader.cc
@@ -0,0 +1,54 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/base/upload_bytes_element_reader.h"
+
+#include "base/logging.h"
+#include "net/base/net_errors.h"
+
+namespace net {
+
+UploadBytesElementReader::UploadBytesElementReader(const char* bytes,
+ int bytes_length)
+ : bytes_(bytes),
+ bytes_length_(bytes_length),
+ offset_(0) {
+}
+
+UploadBytesElementReader::~UploadBytesElementReader() {
+}
+
+int UploadBytesElementReader::InitSync() {
+ return OK;
+}
+
+uint64 UploadBytesElementReader::GetContentLength() const {
+ return bytes_length_;
+}
+
+uint64 UploadBytesElementReader::BytesRemaining() const {
+ return bytes_length_ - offset_;
+}
+
+int UploadBytesElementReader::ReadSync(char* buf, int buf_length) {
+ DCHECK_LT(0, buf_length);
+
+ const size_t num_bytes_to_read =
+ std::min(BytesRemaining(), static_cast<uint64>(buf_length));
+
+ // Check if we have anything to copy first, because we are getting
+ // the address of an element in |bytes_| and that will throw an
+ // exception if |bytes_| is an empty vector.
+ if (num_bytes_to_read > 0)
+ memcpy(buf, bytes_ + offset_, num_bytes_to_read);
+
+ offset_ += num_bytes_to_read;
+ return num_bytes_to_read;
+}
+
+bool UploadBytesElementReader::IsInMemory() const {
+ return true;
+}
+
+} // namespace net
« 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