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

Side by Side Diff: chrome_frame/test/test_server.cc

Issue 10108015: Upstream changes making ListenSocket an abstract class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Matt's comments Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <windows.h> 5 #include <windows.h>
6 #include <objbase.h> 6 #include <objbase.h>
7 #include <urlmon.h> 7 #include <urlmon.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
12 #include "base/string_piece.h" 12 #include "base/string_piece.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/stringprintf.h" 14 #include "base/stringprintf.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome_frame/test/test_server.h" 16 #include "chrome_frame/test/test_server.h"
17 #include "net/base/tcp_listen_socket.h"
17 #include "net/base/winsock_init.h" 18 #include "net/base/winsock_init.h"
18 #include "net/http/http_util.h" 19 #include "net/http/http_util.h"
19 20
20 namespace test_server { 21 namespace test_server {
21 const char kDefaultHeaderTemplate[] = 22 const char kDefaultHeaderTemplate[] =
22 "HTTP/1.1 %hs\r\n" 23 "HTTP/1.1 %hs\r\n"
23 "Connection: close\r\n" 24 "Connection: close\r\n"
24 "Content-Type: %hs\r\n" 25 "Content-Type: %hs\r\n"
25 "Content-Length: %i\r\n\r\n"; 26 "Content-Length: %i\r\n\r\n";
26 const char kStatusOk[] = "200 OK"; 27 const char kStatusOk[] = "200 OK";
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 "Content-Type: text/html\r\n" 126 "Content-Type: text/html\r\n"
126 "Location: %hs\r\n\r\n", 127 "Location: %hs\r\n\r\n",
127 redirect_url_.c_str()); 128 redirect_url_.c_str());
128 return true; 129 return true;
129 } 130 }
130 131
131 SimpleWebServer::SimpleWebServer(int port) { 132 SimpleWebServer::SimpleWebServer(int port) {
132 CHECK(MessageLoop::current()) << "SimpleWebServer requires a message loop"; 133 CHECK(MessageLoop::current()) << "SimpleWebServer requires a message loop";
133 net::EnsureWinsockInit(); 134 net::EnsureWinsockInit();
134 AddResponse(&quit_); 135 AddResponse(&quit_);
135 server_ = net::ListenSocket::Listen("127.0.0.1", port, this); 136 server_ = net::TCPListenSocket::CreateAndListen("127.0.0.1", port, this);
136 DCHECK(server_.get() != NULL); 137 DCHECK(server_.get() != NULL);
137 } 138 }
138 139
139 SimpleWebServer::~SimpleWebServer() { 140 SimpleWebServer::~SimpleWebServer() {
140 ConnectionList::const_iterator it; 141 ConnectionList::const_iterator it;
141 for (it = connections_.begin(); it != connections_.end(); ++it) 142 for (it = connections_.begin(); it != connections_.end(); ++it)
142 delete (*it); 143 delete (*it);
143 connections_.clear(); 144 connections_.clear();
144 } 145 }
145 146
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // extremely inefficient, but in one line and not that common... :) 230 // extremely inefficient, but in one line and not that common... :)
230 connections_.erase(std::find(connections_.begin(), connections_.end(), c)); 231 connections_.erase(std::find(connections_.begin(), connections_.end(), c));
231 delete c; 232 delete c;
232 } 233 }
233 } 234 }
234 235
235 HTTPTestServer::HTTPTestServer(int port, const std::wstring& address, 236 HTTPTestServer::HTTPTestServer(int port, const std::wstring& address,
236 FilePath root_dir) 237 FilePath root_dir)
237 : port_(port), address_(address), root_dir_(root_dir) { 238 : port_(port), address_(address), root_dir_(root_dir) {
238 net::EnsureWinsockInit(); 239 net::EnsureWinsockInit();
239 server_ = net::ListenSocket::Listen(WideToUTF8(address), port, this); 240 server_ =
241 net::TCPListenSocket::CreateAndListen(WideToUTF8(address), port, this);
240 } 242 }
241 243
242 HTTPTestServer::~HTTPTestServer() { 244 HTTPTestServer::~HTTPTestServer() {
243 server_ = NULL; 245 server_ = NULL;
244 } 246 }
245 247
246 std::list<scoped_refptr<ConfigurableConnection>>::iterator 248 std::list<scoped_refptr<ConfigurableConnection>>::iterator
247 HTTPTestServer::FindConnection(const net::ListenSocket* socket) { 249 HTTPTestServer::FindConnection(const net::ListenSocket* socket) {
248 ConnectionList::iterator it; 250 ConnectionList::iterator it;
249 // Scan through the list searching for the desired socket. Along the way, 251 // Scan through the list searching for the desired socket. Along the way,
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 data_.append(content_length_header); 393 data_.append(content_length_header);
392 data_.append("\r\n"); 394 data_.append("\r\n");
393 } 395 }
394 396
395 MessageLoop::current()->PostDelayedTask( 397 MessageLoop::current()->PostDelayedTask(
396 FROM_HERE, base::Bind(&ConfigurableConnection::SendChunk, this), 398 FROM_HERE, base::Bind(&ConfigurableConnection::SendChunk, this),
397 options.timeout_); 399 options.timeout_);
398 } 400 }
399 401
400 } // namespace test_server 402 } // namespace test_server
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698