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

Side by Side Diff: net/socket/client_socket_pool_base_unittest.cc

Issue 176024: Make GetLoadState virtual in ConnectJob(). (Closed)
Patch Set: Created 11 years, 3 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
« no previous file with comments | « net/socket/client_socket_pool_base.cc ('k') | net/socket/tcp_client_socket_pool.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/client_socket_pool_base.h" 5 #include "net/socket/client_socket_pool_base.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/platform_thread.h" 9 #include "base/platform_thread.h"
10 #include "base/scoped_vector.h" 10 #include "base/scoped_vector.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 const std::string& group_name, 111 const std::string& group_name,
112 const TestClientSocketPoolBase::Request& request, 112 const TestClientSocketPoolBase::Request& request,
113 base::TimeDelta timeout_duration, 113 base::TimeDelta timeout_duration,
114 ConnectJob::Delegate* delegate, 114 ConnectJob::Delegate* delegate,
115 MockClientSocketFactory* client_socket_factory, 115 MockClientSocketFactory* client_socket_factory,
116 LoadLog* load_log) 116 LoadLog* load_log)
117 : ConnectJob(group_name, request.handle(), timeout_duration, 117 : ConnectJob(group_name, request.handle(), timeout_duration,
118 delegate, load_log), 118 delegate, load_log),
119 job_type_(job_type), 119 job_type_(job_type),
120 client_socket_factory_(client_socket_factory), 120 client_socket_factory_(client_socket_factory),
121 method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} 121 method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
122 load_state_(LOAD_STATE_IDLE) {}
122 123
123 void Signal() { 124 void Signal() {
124 DoConnect(waiting_success_, true /* async */); 125 DoConnect(waiting_success_, true /* async */);
125 } 126 }
126 127
128 virtual LoadState GetLoadState() const { return load_state_; }
129
127 private: 130 private:
128 // ConnectJob methods: 131 // ConnectJob methods:
129 132
130 virtual int ConnectInternal() { 133 virtual int ConnectInternal() {
131 AddressList ignored; 134 AddressList ignored;
132 client_socket_factory_->CreateTCPClientSocket(ignored); 135 client_socket_factory_->CreateTCPClientSocket(ignored);
133 set_socket(new MockClientSocket()); 136 set_socket(new MockClientSocket());
134 switch (job_type_) { 137 switch (job_type_) {
135 case kMockJob: 138 case kMockJob:
136 return DoConnect(true /* successful */, false /* sync */); 139 return DoConnect(true /* successful */, false /* sync */);
(...skipping 18 matching lines...) Expand all
155 true /* async */)); 158 true /* async */));
156 return ERR_IO_PENDING; 159 return ERR_IO_PENDING;
157 case kMockWaitingJob: 160 case kMockWaitingJob:
158 client_socket_factory_->WaitForSignal(this); 161 client_socket_factory_->WaitForSignal(this);
159 waiting_success_ = true; 162 waiting_success_ = true;
160 return ERR_IO_PENDING; 163 return ERR_IO_PENDING;
161 case kMockAdvancingLoadStateJob: 164 case kMockAdvancingLoadStateJob:
162 MessageLoop::current()->PostTask( 165 MessageLoop::current()->PostTask(
163 FROM_HERE, 166 FROM_HERE,
164 method_factory_.NewRunnableMethod( 167 method_factory_.NewRunnableMethod(
165 &TestConnectJob::AdvanceLoadState, load_state())); 168 &TestConnectJob::AdvanceLoadState, load_state_));
166 return ERR_IO_PENDING; 169 return ERR_IO_PENDING;
167 default: 170 default:
168 NOTREACHED(); 171 NOTREACHED();
169 set_socket(NULL); 172 set_socket(NULL);
170 return ERR_FAILED; 173 return ERR_FAILED;
171 } 174 }
172 } 175 }
173 176
177 void set_load_state(LoadState load_state) { load_state_ = load_state; }
178
174 int DoConnect(bool succeed, bool was_async) { 179 int DoConnect(bool succeed, bool was_async) {
175 int result = ERR_CONNECTION_FAILED; 180 int result = ERR_CONNECTION_FAILED;
176 if (succeed) { 181 if (succeed) {
177 result = OK; 182 result = OK;
178 socket()->Connect(NULL); 183 socket()->Connect(NULL);
179 } else { 184 } else {
180 set_socket(NULL); 185 set_socket(NULL);
181 } 186 }
182 187
183 if (was_async) 188 if (was_async)
(...skipping 11 matching lines...) Expand all
195 FROM_HERE, 200 FROM_HERE,
196 method_factory_.NewRunnableMethod(&TestConnectJob::AdvanceLoadState, 201 method_factory_.NewRunnableMethod(&TestConnectJob::AdvanceLoadState,
197 state), 202 state),
198 1 /* 1ms delay */); 203 1 /* 1ms delay */);
199 } 204 }
200 205
201 bool waiting_success_; 206 bool waiting_success_;
202 const JobType job_type_; 207 const JobType job_type_;
203 MockClientSocketFactory* const client_socket_factory_; 208 MockClientSocketFactory* const client_socket_factory_;
204 ScopedRunnableMethodFactory<TestConnectJob> method_factory_; 209 ScopedRunnableMethodFactory<TestConnectJob> method_factory_;
210 LoadState load_state_;
205 211
206 DISALLOW_COPY_AND_ASSIGN(TestConnectJob); 212 DISALLOW_COPY_AND_ASSIGN(TestConnectJob);
207 }; 213 };
208 214
209 class TestConnectJobFactory 215 class TestConnectJobFactory
210 : public TestClientSocketPoolBase::ConnectJobFactory { 216 : public TestClientSocketPoolBase::ConnectJobFactory {
211 public: 217 public:
212 explicit TestConnectJobFactory(MockClientSocketFactory* client_socket_factory) 218 explicit TestConnectJobFactory(MockClientSocketFactory* client_socket_factory)
213 : job_type_(TestConnectJob::kMockJob), 219 : job_type_(TestConnectJob::kMockJob),
214 client_socket_factory_(client_socket_factory) {} 220 client_socket_factory_(client_socket_factory) {}
(...skipping 1541 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 // Closing idle sockets should not get us into trouble, but in the bug 1762 // Closing idle sockets should not get us into trouble, but in the bug
1757 // we were hitting a CHECK here. 1763 // we were hitting a CHECK here.
1758 EXPECT_EQ(2, pool_->IdleSocketCountInGroup("a")); 1764 EXPECT_EQ(2, pool_->IdleSocketCountInGroup("a"));
1759 pool_->CloseIdleSockets(); 1765 pool_->CloseIdleSockets();
1760 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); 1766 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a"));
1761 } 1767 }
1762 1768
1763 } // namespace 1769 } // namespace
1764 1770
1765 } // namespace net 1771 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/client_socket_pool_base.cc ('k') | net/socket/tcp_client_socket_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698