Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(730)

Side by Side Diff: net/http/http_response_body_drainer.h

Issue 1884943003: HttpStreamParser: Don't reuse sockets which receive unparsed data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix drainer test ('True' means closed...) Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/macros.h" 8 #include "base/macros.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"
11 #include "base/timer/timer.h" 11 #include "base/timer/timer.h"
12 #include "net/base/completion_callback.h" 12 #include "net/base/completion_callback.h"
13 #include "net/base/net_export.h" 13 #include "net/base/net_export.h"
14 #include "net/http/http_network_session.h" 14 #include "net/http/http_network_session.h"
15 15
16 namespace net { 16 namespace net {
17 17
18 class HttpResponseInfo;
18 class HttpStream; 19 class HttpStream;
19 class IOBuffer; 20 class IOBuffer;
20 21
21 class NET_EXPORT_PRIVATE HttpResponseBodyDrainer { 22 class NET_EXPORT_PRIVATE HttpResponseBodyDrainer {
22 public: 23 public:
23 // The size in bytes of the buffer we use to drain the response body that 24 // The size in bytes of the buffer we use to drain the response body that
24 // we want to throw away. The response body is typically a small page just a 25 // we want to throw away. The response body is typically a small page just a
25 // few hundred bytes long. We set a limit to prevent it from taking too long, 26 // few hundred bytes long. We set a limit to prevent it from taking too long,
26 // since we may as well just create a new socket then. 27 // since we may as well just create a new socket then.
27 static const int kDrainBodyBufferSize = 16384; 28 static const int kDrainBodyBufferSize = 16384;
28 static const int kTimeoutInSeconds = 5; 29 static const int kTimeoutInSeconds = 5;
29 30
30 explicit HttpResponseBodyDrainer(HttpStream* stream); 31 // |response_info| is the HttpResponseInfo passed to the |stream|, which may
32 // still be holding on to pointers to it.
33 HttpResponseBodyDrainer(HttpStream* stream,
34 scoped_ptr<HttpResponseInfo> response_info);
31 ~HttpResponseBodyDrainer(); 35 ~HttpResponseBodyDrainer();
32 36
33 // Starts reading the body until completion, or we hit the buffer limit, or we 37 // 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 38 // timeout. After Start(), |this| will eventually delete itself. If it
35 // doesn't complete immediately, it will add itself to |session|. 39 // doesn't complete immediately, it will add itself to |session|.
36 void Start(HttpNetworkSession* session); 40 void Start(HttpNetworkSession* session);
37 41
38 private: 42 private:
39 enum State { 43 enum State {
40 STATE_DRAIN_RESPONSE_BODY, 44 STATE_DRAIN_RESPONSE_BODY,
41 STATE_DRAIN_RESPONSE_BODY_COMPLETE, 45 STATE_DRAIN_RESPONSE_BODY_COMPLETE,
42 STATE_NONE, 46 STATE_NONE,
43 }; 47 };
44 48
45 int DoLoop(int result); 49 int DoLoop(int result);
46 50
47 int DoDrainResponseBody(); 51 int DoDrainResponseBody();
48 int DoDrainResponseBodyComplete(int result); 52 int DoDrainResponseBodyComplete(int result);
49 53
50 void OnIOComplete(int result); 54 void OnIOComplete(int result);
51 void OnTimerFired(); 55 void OnTimerFired();
52 void Finish(int result); 56 void Finish(int result);
53 57
54 scoped_refptr<IOBuffer> read_buf_; 58 scoped_refptr<IOBuffer> read_buf_;
59 scoped_ptr<HttpResponseInfo> response_info_;
55 const scoped_ptr<HttpStream> stream_; 60 const scoped_ptr<HttpStream> stream_;
56 State next_state_; 61 State next_state_;
57 int total_read_; 62 int total_read_;
58 CompletionCallback user_callback_; 63 CompletionCallback user_callback_;
59 base::OneShotTimer timer_; 64 base::OneShotTimer timer_;
60 HttpNetworkSession* session_; 65 HttpNetworkSession* session_;
61 66
62 DISALLOW_COPY_AND_ASSIGN(HttpResponseBodyDrainer); 67 DISALLOW_COPY_AND_ASSIGN(HttpResponseBodyDrainer);
63 }; 68 };
64 69
65 } // namespace net 70 } // namespace net
66 71
67 #endif // NET_HTTP_HTTP_RESPONSE_BODY_DRAINER_H_ 72 #endif // NET_HTTP_HTTP_RESPONSE_BODY_DRAINER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698