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

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"
vandebo (ex-Chrome) 2011/01/18 21:51:17 This header isn't needed.
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,
26 TYPE_FILE, 27 TYPE_FILE,
27 TYPE_BLOB 28 TYPE_BLOB,
29
30 // A block of bytes to be sent in chunked encoding immediately, without
31 // waiting for rest of the data.
32 TYPE_CHUNK,
33 };
34
35 // Interface implemented by callers who require callbacks when new chunks
36 // of data are received.
wtc 2011/01/20 00:29:47 Nit: received => added Make the same change to up
37 class ChunkCallback {
willchan no longer on Chromium 2011/01/20 08:51:04 I don't understand this. Why don't you just typede
Satish 2011/01/20 18:02:36 I used a callback initially and was suggested an i
vandebo (ex-Chrome) 2011/01/21 18:08:41 Will implied that using Callback0::Type would woul
willchan no longer on Chromium 2011/01/21 18:16:19 Callback0::Type by itself isn't safer. But ScopedC
38 public:
39 // Invoked when a new data chunk was given for a chunked transfer upload.
40 virtual void OnChunkAvailable() = 0;
41
42 protected:
43 virtual ~ChunkCallback() {}
28 }; 44 };
29 45
30 class Element { 46 class Element {
31 public: 47 public:
32 Element(); 48 Element();
33 ~Element(); 49 ~Element();
34 50
35 Type type() const { return type_; } 51 Type type() const { return type_; }
36 const std::vector<char>& bytes() const { return bytes_; } 52 const std::vector<char>& bytes() const { return bytes_; }
37 const FilePath& file_path() const { return file_path_; } 53 const FilePath& file_path() const { return file_path_; }
(...skipping 27 matching lines...) Expand all
65 expected_file_modification_time_ = expected_modification_time; 81 expected_file_modification_time_ = expected_modification_time;
66 } 82 }
67 83
68 // TODO(jianli): UploadData should not contain any blob reference. We need 84 // TODO(jianli): UploadData should not contain any blob reference. We need
69 // to define another structure to represent WebKit::WebHTTPBody. 85 // to define another structure to represent WebKit::WebHTTPBody.
70 void SetToBlobUrl(const GURL& blob_url) { 86 void SetToBlobUrl(const GURL& blob_url) {
71 type_ = TYPE_BLOB; 87 type_ = TYPE_BLOB;
72 blob_url_ = blob_url; 88 blob_url_ = blob_url;
73 } 89 }
74 90
91 // Though similar to bytes, a chunk indicates that the stream is sent via
wtc 2011/01/20 00:29:47 Nit: stream => element
92 // chunked transfer encoding and not buffered until the full upload data
93 // is available.
94 void SetToChunk(const char* bytes, int bytes_len);
95
96 void SetToEndOfChunksMarker();
97
75 // Returns the byte-length of the element. For files that do not exist, 0 98 // Returns the byte-length of the element. For files that do not exist, 0
76 // is returned. This is done for consistency with Mozilla. 99 // is returned. This is done for consistency with Mozilla.
77 // Once called, this function will always return the same value. 100 // Once called, this function will always return the same value.
78 uint64 GetContentLength(); 101 uint64 GetContentLength();
79 102
80 // Returns a FileStream opened for reading for this element, positioned at 103 // Returns a FileStream opened for reading for this element, positioned at
81 // |file_range_offset_|. The caller gets ownership and is responsible 104 // |file_range_offset_|. The caller gets ownership and is responsible
82 // for cleaning up the FileStream. Returns NULL if this element is not of 105 // for cleaning up the FileStream. Returns NULL if this element is not of
83 // type TYPE_FILE or if the file is not openable. 106 // type TYPE_FILE or if the file is not openable.
84 FileStream* NewFileStreamForReading(); 107 FileStream* NewFileStreamForReading();
(...skipping 27 matching lines...) Expand all
112 void AppendBytes(const char* bytes, int bytes_len); 135 void AppendBytes(const char* bytes, int bytes_len);
113 136
114 void AppendFile(const FilePath& file_path); 137 void AppendFile(const FilePath& file_path);
115 138
116 void AppendFileRange(const FilePath& file_path, 139 void AppendFileRange(const FilePath& file_path,
117 uint64 offset, uint64 length, 140 uint64 offset, uint64 length,
118 const base::Time& expected_modification_time); 141 const base::Time& expected_modification_time);
119 142
120 void AppendBlob(const GURL& blob_url); 143 void AppendBlob(const GURL& blob_url);
121 144
145 void AppendChunk(const char* bytes, int bytes_len);
146
147 // Sets the callback to be invoked when a new chunk is available to upload.
148 void set_chunk_callback(ChunkCallback* callback);
149
150 // Iniitalizes the object to receive chunks of upload data over time rather
wtc 2011/01/20 00:29:47 Nit: receive => send ?
151 // than all at once.
152 void set_is_chunked(bool set) { is_chunked_ = set; }
153 bool is_chunked() const { return is_chunked_; }
154
122 // Returns the total size in bytes of the data to upload. 155 // Returns the total size in bytes of the data to upload.
123 uint64 GetContentLength(); 156 uint64 GetContentLength();
124 157
125 std::vector<Element>* elements() { 158 std::vector<Element>* elements() {
126 return &elements_; 159 return &elements_;
127 } 160 }
128 161
129 void SetElements(const std::vector<Element>& elements); 162 void SetElements(const std::vector<Element>& elements);
130 163
131 void swap_elements(std::vector<Element>* elements) { 164 void swap_elements(std::vector<Element>* elements) {
132 elements_.swap(*elements); 165 elements_.swap(*elements);
133 } 166 }
134 167
135 // Identifies a particular upload instance, which is used by the cache to 168 // Identifies a particular upload instance, which is used by the cache to
136 // formulate a cache key. This value should be unique across browser 169 // formulate a cache key. This value should be unique across browser
137 // sessions. A value of 0 is used to indicate an unspecified identifier. 170 // sessions. A value of 0 is used to indicate an unspecified identifier.
138 void set_identifier(int64 id) { identifier_ = id; } 171 void set_identifier(int64 id) { identifier_ = id; }
139 int64 identifier() const { return identifier_; } 172 int64 identifier() const { return identifier_; }
140 173
141 private: 174 private:
142 friend class base::RefCounted<UploadData>; 175 friend class base::RefCounted<UploadData>;
143 176
144 ~UploadData(); 177 ~UploadData();
145 178
146 std::vector<Element> elements_; 179 std::vector<Element> elements_;
147 int64 identifier_; 180 int64 identifier_;
181 ChunkCallback* chunk_callback_;
182 bool is_chunked_;
148 183
149 DISALLOW_COPY_AND_ASSIGN(UploadData); 184 DISALLOW_COPY_AND_ASSIGN(UploadData);
150 }; 185 };
151 186
152 #if defined(UNIT_TEST) 187 #if defined(UNIT_TEST)
153 inline bool operator==(const UploadData::Element& a, 188 inline bool operator==(const UploadData::Element& a,
154 const UploadData::Element& b) { 189 const UploadData::Element& b) {
155 if (a.type() != b.type()) 190 if (a.type() != b.type())
156 return false; 191 return false;
157 if (a.type() == UploadData::TYPE_BYTES) 192 if (a.type() == UploadData::TYPE_BYTES)
(...skipping 12 matching lines...) Expand all
170 205
171 inline bool operator!=(const UploadData::Element& a, 206 inline bool operator!=(const UploadData::Element& a,
172 const UploadData::Element& b) { 207 const UploadData::Element& b) {
173 return !(a == b); 208 return !(a == b);
174 } 209 }
175 #endif // defined(UNIT_TEST) 210 #endif // defined(UNIT_TEST)
176 211
177 } // namespace net 212 } // namespace net
178 213
179 #endif // NET_BASE_UPLOAD_DATA_H_ 214 #endif // NET_BASE_UPLOAD_DATA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698