OLD | NEW |
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 #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/callback_forward.h" | 12 #include "base/callback_forward.h" |
13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/supports_user_data.h" |
16 #include "base/time.h" | 17 #include "base/time.h" |
17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
18 #include "net/base/net_export.h" | 19 #include "net/base/net_export.h" |
19 | 20 |
20 namespace net { | 21 namespace net { |
21 | 22 |
22 class FileStream; | 23 class FileStream; |
23 | 24 |
24 // Interface implemented by callers who require callbacks when new chunks | 25 // Interface implemented by callers who require callbacks when new chunks |
25 // of data are added. | 26 // of data are added. |
26 class NET_EXPORT_PRIVATE ChunkCallback { | 27 class NET_EXPORT_PRIVATE ChunkCallback { |
27 public: | 28 public: |
28 // Invoked when a new data chunk was given for a chunked transfer upload. | 29 // Invoked when a new data chunk was given for a chunked transfer upload. |
29 virtual void OnChunkAvailable() = 0; | 30 virtual void OnChunkAvailable() = 0; |
30 | 31 |
31 protected: | 32 protected: |
32 virtual ~ChunkCallback() {} | 33 virtual ~ChunkCallback() {} |
33 }; | 34 }; |
34 | 35 |
35 class NET_EXPORT UploadData : public base::RefCounted<UploadData> { | 36 //----------------------------------------------------------------------------- |
| 37 // A very concrete class representing the data to be uploaded as part of a |
| 38 // URLRequest. |
| 39 // |
| 40 // Until there is a more abstract class for this, this one derives from |
| 41 // SupportsUserData to allow users to stash random data by |
| 42 // key and ensure it's destruction when UploadData is finally deleted. |
| 43 class NET_EXPORT UploadData |
| 44 : public base::RefCounted<UploadData>, |
| 45 public base::SupportsUserData { |
36 public: | 46 public: |
37 enum Type { | 47 enum Type { |
38 TYPE_BYTES, | 48 TYPE_BYTES, |
39 TYPE_FILE, | 49 TYPE_FILE, |
40 TYPE_BLOB, | 50 TYPE_BLOB, |
41 | 51 |
42 // A block of bytes to be sent in chunked encoding immediately, without | 52 // A block of bytes to be sent in chunked encoding immediately, without |
43 // waiting for rest of the data. | 53 // waiting for rest of the data. |
44 TYPE_CHUNK, | 54 TYPE_CHUNK, |
45 }; | 55 }; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 // sessions. A value of 0 is used to indicate an unspecified identifier. | 234 // sessions. A value of 0 is used to indicate an unspecified identifier. |
225 void set_identifier(int64 id) { identifier_ = id; } | 235 void set_identifier(int64 id) { identifier_ = id; } |
226 int64 identifier() const { return identifier_; } | 236 int64 identifier() const { return identifier_; } |
227 | 237 |
228 private: | 238 private: |
229 // Helper function for GetContentLength(). | 239 // Helper function for GetContentLength(). |
230 void DoGetContentLength(uint64* content_length); | 240 void DoGetContentLength(uint64* content_length); |
231 | 241 |
232 friend class base::RefCounted<UploadData>; | 242 friend class base::RefCounted<UploadData>; |
233 | 243 |
234 ~UploadData(); | 244 virtual ~UploadData(); |
235 | 245 |
236 std::vector<Element> elements_; | 246 std::vector<Element> elements_; |
237 int64 identifier_; | 247 int64 identifier_; |
238 ChunkCallback* chunk_callback_; | 248 ChunkCallback* chunk_callback_; |
239 bool is_chunked_; | 249 bool is_chunked_; |
240 | 250 |
241 DISALLOW_COPY_AND_ASSIGN(UploadData); | 251 DISALLOW_COPY_AND_ASSIGN(UploadData); |
242 }; | 252 }; |
243 | 253 |
244 #if defined(UNIT_TEST) | 254 #if defined(UNIT_TEST) |
(...skipping 17 matching lines...) Expand all Loading... |
262 | 272 |
263 inline bool operator!=(const UploadData::Element& a, | 273 inline bool operator!=(const UploadData::Element& a, |
264 const UploadData::Element& b) { | 274 const UploadData::Element& b) { |
265 return !(a == b); | 275 return !(a == b); |
266 } | 276 } |
267 #endif // defined(UNIT_TEST) | 277 #endif // defined(UNIT_TEST) |
268 | 278 |
269 } // namespace net | 279 } // namespace net |
270 | 280 |
271 #endif // NET_BASE_UPLOAD_DATA_H_ | 281 #endif // NET_BASE_UPLOAD_DATA_H_ |
OLD | NEW |