OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "net/socket/tcp_client_socket_pool.h" | 5 #include "net/socket/tcp_client_socket_pool.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "net/base/mock_host_resolver.h" | 10 #include "net/base/mock_host_resolver.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 const int kMaxSockets = 32; | 24 const int kMaxSockets = 32; |
25 const int kMaxSocketsPerGroup = 6; | 25 const int kMaxSocketsPerGroup = 6; |
26 const net::RequestPriority kDefaultPriority = LOW; | 26 const net::RequestPriority kDefaultPriority = LOW; |
27 | 27 |
28 class MockClientSocket : public ClientSocket { | 28 class MockClientSocket : public ClientSocket { |
29 public: | 29 public: |
30 MockClientSocket() : connected_(false) {} | 30 MockClientSocket() : connected_(false) {} |
31 | 31 |
32 // ClientSocket methods: | 32 // ClientSocket methods: |
33 virtual int Connect(CompletionCallback* callback, LoadLog* /* load_log */) { | 33 virtual int Connect(CompletionCallback* callback, const BoundNetLog& /* net_lo
g */) { |
34 connected_ = true; | 34 connected_ = true; |
35 return OK; | 35 return OK; |
36 } | 36 } |
37 virtual void Disconnect() { | 37 virtual void Disconnect() { |
38 connected_ = false; | 38 connected_ = false; |
39 } | 39 } |
40 virtual bool IsConnected() const { | 40 virtual bool IsConnected() const { |
41 return connected_; | 41 return connected_; |
42 } | 42 } |
43 virtual bool IsConnectedAndIdle() const { | 43 virtual bool IsConnectedAndIdle() const { |
(...skipping 17 matching lines...) Expand all Loading... |
61 | 61 |
62 private: | 62 private: |
63 bool connected_; | 63 bool connected_; |
64 }; | 64 }; |
65 | 65 |
66 class MockFailingClientSocket : public ClientSocket { | 66 class MockFailingClientSocket : public ClientSocket { |
67 public: | 67 public: |
68 MockFailingClientSocket() {} | 68 MockFailingClientSocket() {} |
69 | 69 |
70 // ClientSocket methods: | 70 // ClientSocket methods: |
71 virtual int Connect(CompletionCallback* callback, LoadLog* /* load_log */) { | 71 virtual int Connect(CompletionCallback* callback, const BoundNetLog& /* net_lo
g */) { |
72 return ERR_CONNECTION_FAILED; | 72 return ERR_CONNECTION_FAILED; |
73 } | 73 } |
74 | 74 |
75 virtual void Disconnect() {} | 75 virtual void Disconnect() {} |
76 | 76 |
77 virtual bool IsConnected() const { | 77 virtual bool IsConnected() const { |
78 return false; | 78 return false; |
79 } | 79 } |
80 virtual bool IsConnectedAndIdle() const { | 80 virtual bool IsConnectedAndIdle() const { |
81 return false; | 81 return false; |
(...skipping 23 matching lines...) Expand all Loading... |
105 // |should_stall| indicates that this socket should never connect. | 105 // |should_stall| indicates that this socket should never connect. |
106 // |delay_ms| is the delay, in milliseconds, before simulating a connect. | 106 // |delay_ms| is the delay, in milliseconds, before simulating a connect. |
107 MockPendingClientSocket(bool should_connect, bool should_stall, int delay_ms) | 107 MockPendingClientSocket(bool should_connect, bool should_stall, int delay_ms) |
108 : method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 108 : method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
109 should_connect_(should_connect), | 109 should_connect_(should_connect), |
110 should_stall_(should_stall), | 110 should_stall_(should_stall), |
111 delay_ms_(delay_ms), | 111 delay_ms_(delay_ms), |
112 is_connected_(false) {} | 112 is_connected_(false) {} |
113 | 113 |
114 // ClientSocket methods: | 114 // ClientSocket methods: |
115 virtual int Connect(CompletionCallback* callback, LoadLog* /* load_log */) { | 115 virtual int Connect(CompletionCallback* callback, const BoundNetLog& /* net_lo
g */) { |
116 MessageLoop::current()->PostDelayedTask( | 116 MessageLoop::current()->PostDelayedTask( |
117 FROM_HERE, | 117 FROM_HERE, |
118 method_factory_.NewRunnableMethod( | 118 method_factory_.NewRunnableMethod( |
119 &MockPendingClientSocket::DoCallback, callback), delay_ms_); | 119 &MockPendingClientSocket::DoCallback, callback), delay_ms_); |
120 return ERR_IO_PENDING; | 120 return ERR_IO_PENDING; |
121 } | 121 } |
122 | 122 |
123 virtual void Disconnect() {} | 123 virtual void Disconnect() {} |
124 | 124 |
125 virtual bool IsConnected() const { | 125 virtual bool IsConnected() const { |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 EXPECT_FALSE(handle.socket()); | 753 EXPECT_FALSE(handle.socket()); |
754 | 754 |
755 // One socket is stalled, the other is active. | 755 // One socket is stalled, the other is active. |
756 EXPECT_EQ(0, pool_->IdleSocketCount()); | 756 EXPECT_EQ(0, pool_->IdleSocketCount()); |
757 } | 757 } |
758 } | 758 } |
759 | 759 |
760 } // namespace | 760 } // namespace |
761 | 761 |
762 } // namespace net | 762 } // namespace net |
OLD | NEW |