OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_HTTP_HTTP_RESPONSE_BODY_DRAINER_H_ | 5 #ifndef NET_HTTP_HTTP_RESPONSE_BODY_DRAINER_H_ |
6 #define NET_HTTP_HTTP_RESPONSE_BODY_DRAINER_H_ | 6 #define NET_HTTP_HTTP_RESPONSE_BODY_DRAINER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 static const int kTimeoutInSeconds = 5; | 28 static const int kTimeoutInSeconds = 5; |
29 | 29 |
30 explicit HttpResponseBodyDrainer(HttpStreamBase* stream); | 30 explicit HttpResponseBodyDrainer(HttpStreamBase* stream); |
31 ~HttpResponseBodyDrainer(); | 31 ~HttpResponseBodyDrainer(); |
32 | 32 |
33 // Starts reading the body until completion, or we hit the buffer limit, or we | 33 // Starts reading the body until completion, or we hit the buffer limit, or we |
34 // timeout. After Start(), |this| will eventually delete itself. If it | 34 // timeout. After Start(), |this| will eventually delete itself. If it |
35 // doesn't complete immediately, it will add itself to |session|. | 35 // doesn't complete immediately, it will add itself to |session|. |
36 void Start(HttpNetworkSession* session); | 36 void Start(HttpNetworkSession* session); |
37 | 37 |
38 // As above, but stop reading once |num_bytes_to_drain| has been reached. | |
39 void StartWithSize(HttpNetworkSession* session, int num_bytes_to_drain); | |
40 | |
41 private: | 38 private: |
42 enum State { | 39 enum State { |
43 STATE_DRAIN_RESPONSE_BODY, | 40 STATE_DRAIN_RESPONSE_BODY, |
44 STATE_DRAIN_RESPONSE_BODY_COMPLETE, | 41 STATE_DRAIN_RESPONSE_BODY_COMPLETE, |
45 STATE_NONE, | 42 STATE_NONE, |
46 }; | 43 }; |
47 | 44 |
48 int DoLoop(int result); | 45 int DoLoop(int result); |
49 | 46 |
50 int DoDrainResponseBody(); | 47 int DoDrainResponseBody(); |
51 int DoDrainResponseBodyComplete(int result); | 48 int DoDrainResponseBodyComplete(int result); |
52 | 49 |
53 void OnIOComplete(int result); | 50 void OnIOComplete(int result); |
54 void OnTimerFired(); | 51 void OnTimerFired(); |
55 void Finish(int result); | 52 void Finish(int result); |
56 | 53 |
57 int read_size_; | |
58 scoped_refptr<IOBuffer> read_buf_; | 54 scoped_refptr<IOBuffer> read_buf_; |
59 const scoped_ptr<HttpStreamBase> stream_; | 55 const scoped_ptr<HttpStreamBase> stream_; |
60 State next_state_; | 56 State next_state_; |
61 int total_read_; | 57 int total_read_; |
62 CompletionCallback user_callback_; | 58 CompletionCallback user_callback_; |
63 base::OneShotTimer<HttpResponseBodyDrainer> timer_; | 59 base::OneShotTimer<HttpResponseBodyDrainer> timer_; |
64 HttpNetworkSession* session_; | 60 HttpNetworkSession* session_; |
65 | 61 |
66 DISALLOW_COPY_AND_ASSIGN(HttpResponseBodyDrainer); | 62 DISALLOW_COPY_AND_ASSIGN(HttpResponseBodyDrainer); |
67 }; | 63 }; |
68 | 64 |
69 } // namespace net | 65 } // namespace net |
70 | 66 |
71 #endif // NET_HTTP_HTTP_RESPONSE_BODY_DRAINER_H_ | 67 #endif // NET_HTTP_HTTP_RESPONSE_BODY_DRAINER_H_ |
OLD | NEW |