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

Side by Side Diff: net/base/upload_data.h

Issue 6134003: Prototype of chunked transfer encoded POST. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #ifndef NET_BASE_UPLOAD_DATA_H_ 5 #ifndef NET_BASE_UPLOAD_DATA_H_
6 #define NET_BASE_UPLOAD_DATA_H_ 6 #define NET_BASE_UPLOAD_DATA_H_
7 #pragma once 7 #pragma once
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/ref_counted.h" 14 #include "base/ref_counted.h"
15 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 #include "net/base/completion_callback.h"
16 #include "base/time.h" 17 #include "base/time.h"
17 18
18 namespace net { 19 namespace net {
19 20
20 class FileStream; 21 class FileStream;
21 22
22 class UploadData : public base::RefCounted<UploadData> { 23 class UploadData : public base::RefCounted<UploadData> {
23 public: 24 public:
24 enum Type { 25 enum Type {
25 TYPE_BYTES, 26 TYPE_BYTES,
27 TYPE_CHUNK, // Indicates that more data is to come.
wtc 2011/01/12 02:39:02 The more important info is "send the data immediat
Satish 2011/01/13 17:43:27 Done.
26 TYPE_FILE, 28 TYPE_FILE,
27 TYPE_BLOB 29 TYPE_BLOB
28 }; 30 };
29 31
30 class Element { 32 class Element {
31 public: 33 public:
32 Element(); 34 Element();
33 ~Element(); 35 ~Element();
34 36
35 Type type() const { return type_; } 37 Type type() const { return type_; }
(...skipping 29 matching lines...) Expand all
65 expected_file_modification_time_ = expected_modification_time; 67 expected_file_modification_time_ = expected_modification_time;
66 } 68 }
67 69
68 // TODO(jianli): UploadData should not contain any blob reference. We need 70 // TODO(jianli): UploadData should not contain any blob reference. We need
69 // to define another structure to represent WebKit::WebHTTPBody. 71 // to define another structure to represent WebKit::WebHTTPBody.
70 void SetToBlobUrl(const GURL& blob_url) { 72 void SetToBlobUrl(const GURL& blob_url) {
71 type_ = TYPE_BLOB; 73 type_ = TYPE_BLOB;
72 blob_url_ = blob_url; 74 blob_url_ = blob_url;
73 } 75 }
74 76
77 void SetToChunk(const char* bytes, int bytes_len);
78
75 // Returns the byte-length of the element. For files that do not exist, 0 79 // Returns the byte-length of the element. For files that do not exist, 0
76 // is returned. This is done for consistency with Mozilla. 80 // is returned. This is done for consistency with Mozilla.
77 // Once called, this function will always return the same value. 81 // Once called, this function will always return the same value.
78 uint64 GetContentLength(); 82 uint64 GetContentLength();
79 83
80 // Returns a FileStream opened for reading for this element, positioned at 84 // Returns a FileStream opened for reading for this element, positioned at
81 // |file_range_offset_|. The caller gets ownership and is responsible 85 // |file_range_offset_|. The caller gets ownership and is responsible
82 // for cleaning up the FileStream. Returns NULL if this element is not of 86 // for cleaning up the FileStream. Returns NULL if this element is not of
83 // type TYPE_FILE or if the file is not openable. 87 // type TYPE_FILE or if the file is not openable.
84 FileStream* NewFileStreamForReading(); 88 FileStream* NewFileStreamForReading();
(...skipping 27 matching lines...) Expand all
112 void AppendBytes(const char* bytes, int bytes_len); 116 void AppendBytes(const char* bytes, int bytes_len);
113 117
114 void AppendFile(const FilePath& file_path); 118 void AppendFile(const FilePath& file_path);
115 119
116 void AppendFileRange(const FilePath& file_path, 120 void AppendFileRange(const FilePath& file_path,
117 uint64 offset, uint64 length, 121 uint64 offset, uint64 length,
118 const base::Time& expected_modification_time); 122 const base::Time& expected_modification_time);
119 123
120 void AppendBlob(const GURL& blob_url); 124 void AppendBlob(const GURL& blob_url);
121 125
126 void AppendChunk(const char* bytes, int bytes_len);
127
128 // Sets the callback to be invoked when new data is available to upload.
129 void set_data_callback(CompletionCallback* callback);
wtc 2011/01/12 02:39:02 Rename this method set_chunk_callback and the memb
Satish 2011/01/13 17:43:27 Done.
130
131 // Iniitalizes the object to receive chunks of upload data over time rather
132 // than all at once at connection time.
wtc 2011/01/12 02:39:02 The UploadData class doesn't know about the connec
Satish 2011/01/13 17:43:27 Done.
133 void set_is_chunked(bool set) { is_chunked_ = set; }
134 bool is_chunked() { return is_chunked_; }
135
122 // Returns the total size in bytes of the data to upload. 136 // Returns the total size in bytes of the data to upload.
123 uint64 GetContentLength(); 137 uint64 GetContentLength();
124 138
125 std::vector<Element>* elements() { 139 std::vector<Element>* elements() {
126 return &elements_; 140 return &elements_;
127 } 141 }
128 142
129 void SetElements(const std::vector<Element>& elements); 143 void SetElements(const std::vector<Element>& elements);
130 144
131 void swap_elements(std::vector<Element>* elements) { 145 void swap_elements(std::vector<Element>* elements) {
132 elements_.swap(*elements); 146 elements_.swap(*elements);
133 } 147 }
134 148
135 // Identifies a particular upload instance, which is used by the cache to 149 // Identifies a particular upload instance, which is used by the cache to
136 // formulate a cache key. This value should be unique across browser 150 // formulate a cache key. This value should be unique across browser
137 // sessions. A value of 0 is used to indicate an unspecified identifier. 151 // sessions. A value of 0 is used to indicate an unspecified identifier.
138 void set_identifier(int64 id) { identifier_ = id; } 152 void set_identifier(int64 id) { identifier_ = id; }
139 int64 identifier() const { return identifier_; } 153 int64 identifier() const { return identifier_; }
140 154
141 private: 155 private:
142 friend class base::RefCounted<UploadData>; 156 friend class base::RefCounted<UploadData>;
143 157
144 ~UploadData(); 158 ~UploadData();
145 159
146 std::vector<Element> elements_; 160 std::vector<Element> elements_;
147 int64 identifier_; 161 int64 identifier_;
162 CompletionCallback* data_callback_;
163 bool is_chunked_;
148 164
149 DISALLOW_COPY_AND_ASSIGN(UploadData); 165 DISALLOW_COPY_AND_ASSIGN(UploadData);
150 }; 166 };
151 167
152 #if defined(UNIT_TEST) 168 #if defined(UNIT_TEST)
153 inline bool operator==(const UploadData::Element& a, 169 inline bool operator==(const UploadData::Element& a,
154 const UploadData::Element& b) { 170 const UploadData::Element& b) {
155 if (a.type() != b.type()) 171 if (a.type() != b.type())
156 return false; 172 return false;
157 if (a.type() == UploadData::TYPE_BYTES) 173 if (a.type() == UploadData::TYPE_BYTES)
(...skipping 12 matching lines...) Expand all
170 186
171 inline bool operator!=(const UploadData::Element& a, 187 inline bool operator!=(const UploadData::Element& a,
172 const UploadData::Element& b) { 188 const UploadData::Element& b) {
173 return !(a == b); 189 return !(a == b);
174 } 190 }
175 #endif // defined(UNIT_TEST) 191 #endif // defined(UNIT_TEST)
176 192
177 } // namespace net 193 } // namespace net
178 194
179 #endif // NET_BASE_UPLOAD_DATA_H_ 195 #endif // NET_BASE_UPLOAD_DATA_H_
OLDNEW
« no previous file with comments | « net/base/load_flags_list.h ('k') | net/base/upload_data.cc » ('j') | net/base/upload_data.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698