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 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 virtual ~ChunkCallback() {} | 33 virtual ~ChunkCallback() {} |
34 }; | 34 }; |
35 | 35 |
36 //----------------------------------------------------------------------------- | 36 //----------------------------------------------------------------------------- |
37 // A very concrete class representing the data to be uploaded as part of a | 37 // A very concrete class representing the data to be uploaded as part of a |
38 // URLRequest. | 38 // URLRequest. |
39 // | 39 // |
40 // Until there is a more abstract class for this, this one derives from | 40 // Until there is a more abstract class for this, this one derives from |
41 // SupportsUserData to allow users to stash random data by | 41 // SupportsUserData to allow users to stash random data by |
42 // key and ensure its destruction when UploadData is finally deleted. | 42 // key and ensure its destruction when UploadData is finally deleted. |
| 43 // |
| 44 // Chunked uploads are handled by repeatedly calling AppendChunk() as data |
| 45 // becomes available. When more data becomes available, the ChunkCallback's |
| 46 // OnChunkAvailable function is called. The UploadData creator is then |
| 47 // responsible for checking if the UploadData stream has more data available, if |
| 48 // necessary. |
43 class NET_EXPORT UploadData | 49 class NET_EXPORT UploadData |
44 : public base::RefCounted<UploadData>, | 50 : public base::RefCounted<UploadData>, |
45 public base::SupportsUserData { | 51 public base::SupportsUserData { |
46 public: | 52 public: |
47 UploadData(); | 53 UploadData(); |
48 | 54 |
49 void AppendBytes(const char* bytes, int bytes_len); | 55 void AppendBytes(const char* bytes, int bytes_len); |
50 | 56 |
51 void AppendFileRange(const FilePath& file_path, | 57 void AppendFileRange(const FilePath& file_path, |
52 uint64 offset, uint64 length, | 58 uint64 offset, uint64 length, |
53 const base::Time& expected_modification_time); | 59 const base::Time& expected_modification_time); |
54 | 60 |
55 // Adds the given chunk of bytes to be sent immediately with chunked transfer | 61 // Adds the given chunk of bytes to be sent immediately with chunked transfer |
56 // encoding. | 62 // encoding. |
57 void AppendChunk(const char* bytes, int bytes_len, bool is_last_chunk); | 63 void AppendChunk(const char* bytes, int bytes_len, bool is_last_chunk); |
58 | 64 |
59 // Sets the callback to be invoked when a new chunk is available to upload. | 65 // Sets the callback to be invoked when a new chunk is available to upload. |
60 void set_chunk_callback(ChunkCallback* callback); | 66 void set_chunk_callback(ChunkCallback* callback); |
61 | 67 |
62 // Initializes the object to send chunks of upload data over time rather | 68 // Initializes the object to send chunks of upload data over time rather |
63 // than all at once. | 69 // than all at once. Chunked data may only contain bytes, not files. |
64 void set_is_chunked(bool set) { is_chunked_ = set; } | 70 void set_is_chunked(bool set) { is_chunked_ = set; } |
65 bool is_chunked() const { return is_chunked_; } | 71 bool is_chunked() const { return is_chunked_; } |
66 | 72 |
| 73 // set_last_chunk_appended() is only used for serialization. |
67 void set_last_chunk_appended(bool set) { last_chunk_appended_ = set; } | 74 void set_last_chunk_appended(bool set) { last_chunk_appended_ = set; } |
68 bool last_chunk_appended() const { return last_chunk_appended_; } | 75 bool last_chunk_appended() const { return last_chunk_appended_; } |
69 | 76 |
70 const std::vector<UploadElement>* elements() const { | 77 const std::vector<UploadElement>* elements() const { |
71 return &elements_; | 78 return &elements_; |
72 } | 79 } |
73 | 80 |
74 std::vector<UploadElement>* elements_mutable() { | 81 std::vector<UploadElement>* elements_mutable() { |
75 return &elements_; | 82 return &elements_; |
76 } | 83 } |
(...skipping 20 matching lines...) Expand all Loading... |
97 ChunkCallback* chunk_callback_; | 104 ChunkCallback* chunk_callback_; |
98 bool is_chunked_; | 105 bool is_chunked_; |
99 bool last_chunk_appended_; | 106 bool last_chunk_appended_; |
100 | 107 |
101 DISALLOW_COPY_AND_ASSIGN(UploadData); | 108 DISALLOW_COPY_AND_ASSIGN(UploadData); |
102 }; | 109 }; |
103 | 110 |
104 } // namespace net | 111 } // namespace net |
105 | 112 |
106 #endif // NET_BASE_UPLOAD_DATA_H_ | 113 #endif // NET_BASE_UPLOAD_DATA_H_ |
OLD | NEW |