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

Unified Diff: net/base/upload_data.h

Issue 9452040: net: Move the logic reading upload elements to UploadData::Element. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move resetoffset to init Created 8 years, 10 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 | « no previous file | net/base/upload_data.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/upload_data.h
diff --git a/net/base/upload_data.h b/net/base/upload_data.h
index d42ffad16352f8e7be97fc08f0b8f8440af87d44..a7f3d34da61e2d17bd3ce8a8928a15ef44171dc9 100644
--- a/net/base/upload_data.h
+++ b/net/base/upload_data.h
@@ -110,13 +110,31 @@ class NET_EXPORT UploadData : public base::RefCounted<UploadData> {
// is returned. This is done for consistency with Mozilla.
uint64 GetContentLength();
- // Returns a FileStream opened for reading for this element, positioned at
- // |file_range_offset_|. The caller gets ownership and is responsible
- // for cleaning up the FileStream. Returns NULL if this element is not of
- // type TYPE_FILE or if the file is not openable.
- FileStream* NewFileStreamForReading();
+ // Reads up to |buf_len| bytes synchronously. Returns the number of bytes
+ // read. This function never fails. If there's less data to read than we
+ // initially observed, then pad with zero (this can happen with files).
+ // |buf_len| must be greater than 0.
+ int ReadSync(char* buf, int buf_len);
+
+ // Returns the number of bytes remaining to read.
+ uint64 BytesRemaining();
+
+ // Resets the offset to zero, so that the element can be reread.
+ void ResetOffset() { offset_ = 0; }
private:
+ // Returns a FileStream opened for reading for this element, positioned
+ // at |file_range_offset_|. Returns NULL if the file is not openable.
+ FileStream* OpenFileStream();
+
+ // Reads up to |buf_len| bytes synchronously from memory (i.e. type_ is
+ // TYPE_BYTES or TYPE_CHUNK).
+ int ReadFromMemorySync(char* buf, int buf_len);
+
+ // Reads up to |buf_len| bytes synchronously from a file (i.e. type_ is
+ // TYPE_FILE).
+ int ReadFromFileSync(char* buf, int buf_len);
+
// Allows tests to override the result of GetContentLength.
void SetContentLength(uint64 content_length) {
override_content_length_ = true;
@@ -134,6 +152,12 @@ class NET_EXPORT UploadData : public base::RefCounted<UploadData> {
bool override_content_length_;
bool content_length_computed_;
uint64 content_length_;
+
+ // The byte offset from the beginning of the element data. Used to track
+ // the current position when reading data.
+ size_t offset_;
+
+ // The stream of the element data, if this element is of TYPE_FILE.
FileStream* file_stream_;
FRIEND_TEST_ALL_PREFIXES(UploadDataStreamTest, FileSmallerThanLength);
@@ -180,6 +204,11 @@ class NET_EXPORT UploadData : public base::RefCounted<UploadData> {
// upload data is not chunked, and all elemnts are of TYPE_BYTES).
bool IsInMemory() const;
+ // Resets the offset of each upload data element to zero, so that the
+ // upload data can be reread. This can happen if the same upload data is
+ // reused for a new UploadDataStream.
+ void ResetOffset();
+
std::vector<Element>* elements() {
return &elements_;
}
« no previous file with comments | « no previous file | net/base/upload_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698