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

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

Issue 3112034: Attempting to re-land CL 3110006 which turned out to have ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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 | Annotate | Revision Log
« no previous file with comments | « net/socket/socket_test_util.h ('k') | net/socket/ssl_client_socket_pool.cc » ('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) 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/socket_test_util.h" 5 #include "net/socket/socket_test_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 10
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 const int kSOCKS5GreetResponseLength = arraysize(kSOCKS5GreetResponse); 1171 const int kSOCKS5GreetResponseLength = arraysize(kSOCKS5GreetResponse);
1172 1172
1173 const char kSOCKS5OkRequest[] = 1173 const char kSOCKS5OkRequest[] =
1174 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; 1174 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 };
1175 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); 1175 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest);
1176 1176
1177 const char kSOCKS5OkResponse[] = 1177 const char kSOCKS5OkResponse[] =
1178 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; 1178 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 };
1179 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); 1179 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse);
1180 1180
1181 MockSSLClientSocketPool::MockSSLClientSocketPool(
1182 int max_sockets,
1183 int max_sockets_per_group,
1184 const scoped_refptr<ClientSocketPoolHistograms>& histograms,
1185 ClientSocketFactory* socket_factory)
1186 : SSLClientSocketPool(max_sockets, max_sockets_per_group, histograms,
1187 NULL, socket_factory,
1188 new MockTCPClientSocketPool(max_sockets,
1189 max_sockets_per_group,
1190 histograms,
1191 socket_factory),
1192 NULL, NULL, NULL),
1193 client_socket_factory_(socket_factory),
1194 release_count_(0),
1195 cancel_count_(0) {
1196 }
1197
1198 int MockSSLClientSocketPool::RequestSocket(const std::string& group_name,
1199 const void* socket_params,
1200 RequestPriority priority,
1201 ClientSocketHandle* handle,
1202 CompletionCallback* callback,
1203 const BoundNetLog& net_log) {
1204 ClientSocket* socket = client_socket_factory_->CreateTCPClientSocket(
1205 AddressList(), net_log.net_log(), net::NetLog::Source());
1206 MockConnectJob* job = new MockConnectJob(socket, handle, callback);
1207 job_list_.push_back(job);
1208 handle->set_pool_id(1);
1209 return job->Connect();
1210 }
1211
1212 void MockSSLClientSocketPool::CancelRequest(const std::string& group_name,
1213 ClientSocketHandle* handle) {
1214 std::vector<MockConnectJob*>::iterator i;
1215 for (i = job_list_.begin(); i != job_list_.end(); ++i) {
1216 if ((*i)->CancelHandle(handle)) {
1217 cancel_count_++;
1218 break;
1219 }
1220 }
1221 }
1222
1223 void MockSSLClientSocketPool::ReleaseSocket(const std::string& group_name,
1224 ClientSocket* socket, int id) {
1225 EXPECT_EQ(1, id);
1226 release_count_++;
1227 delete socket;
1228 }
1229
1230 MockSSLClientSocketPool::~MockSSLClientSocketPool() {}
1231
1232 MockSSLClientSocketPool::MockConnectJob::MockConnectJob(
1233 ClientSocket* socket,
1234 ClientSocketHandle* handle,
1235 CompletionCallback* callback)
1236 : socket_(socket),
1237 handle_(handle),
1238 user_callback_(callback),
1239 ALLOW_THIS_IN_INITIALIZER_LIST(
1240 connect_callback_(this, &MockConnectJob::OnConnect)) {
1241 }
1242
1243 int MockSSLClientSocketPool::MockConnectJob::Connect() {
1244 int rv = socket_->Connect(&connect_callback_);
1245 if (rv == OK) {
1246 user_callback_ = NULL;
1247 OnConnect(OK);
1248 }
1249 return rv;
1250 }
1251
1252 bool MockSSLClientSocketPool::MockConnectJob::CancelHandle(
1253 const ClientSocketHandle* handle) {
1254 if (handle != handle_)
1255 return false;
1256 socket_.reset();
1257 handle_ = NULL;
1258 user_callback_ = NULL;
1259 return true;
1260 }
1261
1262 void MockSSLClientSocketPool::MockConnectJob::OnConnect(int rv) {
1263 if (!socket_.get())
1264 return;
1265 if (rv == OK) {
1266 handle_->set_socket(socket_.release());
1267 } else {
1268 socket_.reset();
1269 }
1270
1271 handle_ = NULL;
1272
1273 if (user_callback_) {
1274 CompletionCallback* callback = user_callback_;
1275 user_callback_ = NULL;
1276 callback->Run(rv);
1277 }
1278 }
1181 } // namespace net 1279 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/socket_test_util.h ('k') | net/socket/ssl_client_socket_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698