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

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

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