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