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_STREAM_H_ | 5 #ifndef NET_BASE_UPLOAD_DATA_STREAM_H_ |
6 #define NET_BASE_UPLOAD_DATA_STREAM_H_ | 6 #define NET_BASE_UPLOAD_DATA_STREAM_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "net/base/net_export.h" | 10 #include "net/base/net_export.h" |
11 #include "net/base/upload_data.h" | 11 #include "net/base/upload_data.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 class FileStream; | 15 class FileStream; |
16 class IOBuffer; | 16 class IOBuffer; |
17 class SpdyHttpStreamSpdy2Test; | |
18 class SpdyHttpStreamSpdy3Test; | |
19 class SpdyNetworkTransactionSpdy2Test; | |
20 class SpdyNetworkTransactionSpdy3Test; | |
17 | 21 |
18 class NET_EXPORT UploadDataStream { | 22 class NET_EXPORT UploadDataStream { |
19 public: | 23 public: |
20 explicit UploadDataStream(UploadData* upload_data); | 24 explicit UploadDataStream(UploadData* upload_data); |
21 ~UploadDataStream(); | 25 ~UploadDataStream(); |
22 | 26 |
23 // Initializes the stream. This function must be called exactly once, | 27 // Initializes the stream. This function must be called exactly once, |
24 // before calling any other method. It is not valid to call any method | 28 // before calling any other method. It is not valid to call any method |
25 // (other than the destructor) if Init() returns a failure. | 29 // (other than the destructor) if Init() returns a failure. |
26 // | 30 // |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 | 62 |
59 bool is_chunked() const { return upload_data_->is_chunked(); } | 63 bool is_chunked() const { return upload_data_->is_chunked(); } |
60 | 64 |
61 // Returns true if all data has been consumed from this upload data | 65 // Returns true if all data has been consumed from this upload data |
62 // stream. | 66 // stream. |
63 bool IsEOF() const; | 67 bool IsEOF() const; |
64 | 68 |
65 // Returns true if the upload data in the stream is entirely in memory. | 69 // Returns true if the upload data in the stream is entirely in memory. |
66 bool IsInMemory() const; | 70 bool IsInMemory() const; |
67 | 71 |
68 // This method is provided only to be used by unit tests. | 72 private: |
73 friend class SpdyHttpStreamSpdy2Test; | |
74 friend class SpdyHttpStreamSpdy3Test; | |
75 friend class SpdyNetworkTransactionSpdy2Test; | |
76 friend class SpdyNetworkTransactionSpdy3Test; | |
77 FRIEND_TEST_ALL_PREFIXES(SpdyHttpStreamSpdy2Test, SendChunkedPost); | |
78 FRIEND_TEST_ALL_PREFIXES(SpdyHttpStreamSpdy2Test, DelayedSendChunkedPost); | |
79 FRIEND_TEST_ALL_PREFIXES(SpdyHttpStreamSpdy3Test, SendChunkedPost); | |
80 FRIEND_TEST_ALL_PREFIXES(SpdyHttpStreamSpdy3Test, DelayedSendChunkedPost); | |
81 FRIEND_TEST_ALL_PREFIXES(SpdyNetworkTransactionSpdy2Test, ChunkedPost); | |
82 FRIEND_TEST_ALL_PREFIXES(SpdyNetworkTransactionSpdy3Test, ChunkedPost); | |
Ryan Sleevi
2012/07/06 23:15:49
Sorry, what I was suggesting was an either/or.
ei
ramant (doing other things)
2012/07/07 04:47:05
Done. Thanks much for your detailed comments.
| |
83 | |
84 // These methods are provided only to be used by unit tests. | |
85 static bool merge_chunks() { return merge_chunks_; } | |
69 static void set_merge_chunks(bool merge) { merge_chunks_ = merge; } | 86 static void set_merge_chunks(bool merge) { merge_chunks_ = merge; } |
70 | 87 |
71 private: | |
72 scoped_refptr<UploadData> upload_data_; | 88 scoped_refptr<UploadData> upload_data_; |
73 | 89 |
74 // Index of the current upload element (i.e. the element currently being | 90 // Index of the current upload element (i.e. the element currently being |
75 // read). The index is used as a cursor to iterate over elements in | 91 // read). The index is used as a cursor to iterate over elements in |
76 // |upload_data_|. | 92 // |upload_data_|. |
77 size_t element_index_; | 93 size_t element_index_; |
78 | 94 |
79 // Size and current read position within the upload data stream. | 95 // Size and current read position within the upload data stream. |
80 uint64 total_size_; | 96 uint64 total_size_; |
81 uint64 current_position_; | 97 uint64 current_position_; |
82 | 98 |
83 // True if the initialization was successful. | 99 // True if the initialization was successful. |
84 bool initialized_successfully_; | 100 bool initialized_successfully_; |
85 | 101 |
86 // TODO(satish): Remove this once we have a better way to unit test POST | 102 // TODO(satish): Remove this once we have a better way to unit test POST |
87 // requests with chunked uploads. | 103 // requests with chunked uploads. |
88 static bool merge_chunks_; | 104 static bool merge_chunks_; |
89 | 105 |
90 DISALLOW_COPY_AND_ASSIGN(UploadDataStream); | 106 DISALLOW_COPY_AND_ASSIGN(UploadDataStream); |
91 }; | 107 }; |
92 | 108 |
93 } // namespace net | 109 } // namespace net |
94 | 110 |
95 #endif // NET_BASE_UPLOAD_DATA_STREAM_H_ | 111 #endif // NET_BASE_UPLOAD_DATA_STREAM_H_ |
OLD | NEW |