summaryrefslogtreecommitdiffstats
path: root/chrome_frame
diff options
context:
space:
mode:
authorpliard@chromium.org <pliard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-16 09:22:30 +0000
committerpliard@chromium.org <pliard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-16 09:22:30 +0000
commit36633f403b4ba6c5f592bc65d387869aa5403fc1 (patch)
tree6a2f7fef89c837ed5d390aa878439761e948085b /chrome_frame
parentead613da9d4731a38b583b2fc141ccc10bfb9e77 (diff)
downloadchromium_src-36633f403b4ba6c5f592bc65d387869aa5403fc1.zip
chromium_src-36633f403b4ba6c5f592bc65d387869aa5403fc1.tar.gz
chromium_src-36633f403b4ba6c5f592bc65d387869aa5403fc1.tar.bz2
Refactor TCPListenSocket.
This is part of Chrome for Android upstreaming. This CL adds a common base class, StreamListenSocket, providing a default implementation inherited by TCPListenSocket and the upcoming UnixDomainSocket. That lets us share the common code used by both TCPListenSocket and UnixDomainSocket. This also removes the recently introduced ListenSocket class which is unnecessary now we have StreamListenSocket. TEST=net_unittests Review URL: https://chromiumcodereview.appspot.com/10161005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137387 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame')
-rw-r--r--chrome_frame/test/test_server.cc34
-rw-r--r--chrome_frame/test/test_server.h59
-rw-r--r--chrome_frame/test/test_with_web_server.cc5
3 files changed, 56 insertions, 42 deletions
diff --git a/chrome_frame/test/test_server.cc b/chrome_frame/test/test_server.cc
index b38b143..5eaf06f 100644
--- a/chrome_frame/test/test_server.cc
+++ b/chrome_frame/test/test_server.cc
@@ -75,6 +75,12 @@ void Request::OnDataReceived(const std::string& data) {
}
}
+ResponseForPath::~ResponseForPath() {
+}
+
+SimpleResponse::~SimpleResponse() {
+}
+
bool FileResponse::GetContentType(std::string* content_type) const {
size_t length = ContentLength();
char buffer[4096];
@@ -100,7 +106,7 @@ bool FileResponse::GetContentType(std::string* content_type) const {
return content_type->length() > 0;
}
-void FileResponse::WriteContents(net::ListenSocket* socket) const {
+void FileResponse::WriteContents(net::StreamListenSocket* socket) const {
DCHECK(file_.get());
if (file_.get()) {
socket->Send(reinterpret_cast<const char*>(file_->data()),
@@ -168,7 +174,7 @@ Response* SimpleWebServer::FindResponse(const Request& request) const {
}
Connection* SimpleWebServer::FindConnection(
- const net::ListenSocket* socket) const {
+ const net::StreamListenSocket* socket) const {
ConnectionList::const_iterator it;
for (it = connections_.begin(); it != connections_.end(); it++) {
if ((*it)->IsSame(socket)) {
@@ -178,12 +184,12 @@ Connection* SimpleWebServer::FindConnection(
return NULL;
}
-void SimpleWebServer::DidAccept(net::ListenSocket* server,
- net::ListenSocket* connection) {
+void SimpleWebServer::DidAccept(net::StreamListenSocket* server,
+ net::StreamListenSocket* connection) {
connections_.push_back(new Connection(connection));
}
-void SimpleWebServer::DidRead(net::ListenSocket* connection,
+void SimpleWebServer::DidRead(net::StreamListenSocket* connection,
const char* data,
int len) {
Connection* c = FindConnection(connection);
@@ -220,7 +226,7 @@ void SimpleWebServer::DidRead(net::ListenSocket* connection,
}
}
-void SimpleWebServer::DidClose(net::ListenSocket* sock) {
+void SimpleWebServer::DidClose(net::StreamListenSocket* sock) {
// To keep the historical list of connections reasonably tidy, we delete
// 404's when the connection ends.
Connection* c = FindConnection(sock);
@@ -246,7 +252,7 @@ HTTPTestServer::~HTTPTestServer() {
}
std::list<scoped_refptr<ConfigurableConnection>>::iterator
-HTTPTestServer::FindConnection(const net::ListenSocket* socket) {
+HTTPTestServer::FindConnection(const net::StreamListenSocket* socket) {
ConnectionList::iterator it;
// Scan through the list searching for the desired socket. Along the way,
// erase any connections for which the corresponding socket has already been
@@ -266,19 +272,19 @@ HTTPTestServer::FindConnection(const net::ListenSocket* socket) {
}
scoped_refptr<ConfigurableConnection> HTTPTestServer::ConnectionFromSocket(
- const net::ListenSocket* socket) {
+ const net::StreamListenSocket* socket) {
ConnectionList::iterator it = FindConnection(socket);
if (it != connection_list_.end())
return *it;
return NULL;
}
-void HTTPTestServer::DidAccept(net::ListenSocket* server,
- net::ListenSocket* socket) {
+void HTTPTestServer::DidAccept(net::StreamListenSocket* server,
+ net::StreamListenSocket* socket) {
connection_list_.push_back(new ConfigurableConnection(socket));
}
-void HTTPTestServer::DidRead(net::ListenSocket* socket,
+void HTTPTestServer::DidRead(net::StreamListenSocket* socket,
const char* data,
int len) {
scoped_refptr<ConfigurableConnection> connection =
@@ -298,7 +304,7 @@ void HTTPTestServer::DidRead(net::ListenSocket* socket,
}
}
-void HTTPTestServer::DidClose(net::ListenSocket* socket) {
+void HTTPTestServer::DidClose(net::StreamListenSocket* socket) {
ConnectionList::iterator it = FindConnection(socket);
if (it != connection_list_.end())
connection_list_.erase(it);
@@ -373,8 +379,8 @@ void ConfigurableConnection::SendWithOptions(const std::string& headers,
socket_->Send(headers);
socket_->Send(content_length_header, true);
socket_->Send(content);
- // Post a task to close the socket since ListenSocket doesn't like instances
- // to go away from within its callbacks.
+ // Post a task to close the socket since StreamListenSocket doesn't like
+ // instances to go away from within its callbacks.
MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(&ConfigurableConnection::Close, this));
diff --git a/chrome_frame/test/test_server.h b/chrome_frame/test/test_server.h
index 2fef7d2..01ce4bb 100644
--- a/chrome_frame/test/test_server.h
+++ b/chrome_frame/test/test_server.h
@@ -41,7 +41,7 @@
#include "base/basictypes.h"
#include "base/file_util.h"
#include "base/message_loop.h"
-#include "net/base/listen_socket.h"
+#include "net/base/stream_listen_socket.h"
namespace test_server {
@@ -106,13 +106,13 @@ class Request {
// shut down.
class Connection {
public:
- explicit Connection(net::ListenSocket* sock) : socket_(sock) {
+ explicit Connection(net::StreamListenSocket* sock) : socket_(sock) {
}
~Connection() {
}
- bool IsSame(const net::ListenSocket* socket) const {
+ bool IsSame(const net::StreamListenSocket* socket) const {
return socket_ == socket;
}
@@ -129,7 +129,7 @@ class Connection {
}
protected:
- scoped_refptr<net::ListenSocket> socket_;
+ scoped_refptr<net::StreamListenSocket> socket_;
Request request_;
private:
@@ -165,7 +165,7 @@ class Response {
return 0;
}
- virtual void WriteContents(net::ListenSocket* socket) const {
+ virtual void WriteContents(net::StreamListenSocket* socket) const {
}
virtual void IncrementAccessCounter() {
@@ -192,6 +192,8 @@ class ResponseForPath : public Response {
: request_path_(request_path) {
}
+ virtual ~ResponseForPath();
+
virtual bool Matches(const Request& r) const {
std::string path = r.path();
std::string::size_type pos = path.find('?');
@@ -216,7 +218,9 @@ class SimpleResponse : public ResponseForPath {
: ResponseForPath(request_path), contents_(contents) {
}
- virtual void WriteContents(net::ListenSocket* socket) const {
+ virtual ~SimpleResponse();
+
+ virtual void WriteContents(net::StreamListenSocket* socket) const {
socket->Send(contents_.c_str(), contents_.length(), false);
}
@@ -242,7 +246,7 @@ class FileResponse : public ResponseForPath {
}
virtual bool GetContentType(std::string* content_type) const;
- virtual void WriteContents(net::ListenSocket* socket) const;
+ virtual void WriteContents(net::StreamListenSocket* socket) const;
virtual size_t ContentLength() const;
protected:
@@ -276,7 +280,7 @@ typedef std::list<Connection*> ConnectionList;
// Implementation of a simple http server.
// Before creating an instance of the server, make sure the current thread
// has a message loop.
-class SimpleWebServer : public net::ListenSocket::ListenSocketDelegate {
+class SimpleWebServer : public net::StreamListenSocket::Delegate {
public:
explicit SimpleWebServer(int port);
virtual ~SimpleWebServer();
@@ -291,13 +295,13 @@ class SimpleWebServer : public net::ListenSocket::ListenSocketDelegate {
// the cleanup process.
void DeleteAllResponses();
- // ListenSocketDelegate overrides.
- virtual void DidAccept(net::ListenSocket* server,
- net::ListenSocket* connection);
- virtual void DidRead(net::ListenSocket* connection,
+ // StreamListenSocket::Delegate overrides.
+ virtual void DidAccept(net::StreamListenSocket* server,
+ net::StreamListenSocket* connection);
+ virtual void DidRead(net::StreamListenSocket* connection,
const char* data,
int len);
- virtual void DidClose(net::ListenSocket* sock);
+ virtual void DidClose(net::StreamListenSocket* sock);
const ConnectionList& connections() const {
return connections_;
@@ -310,17 +314,17 @@ class SimpleWebServer : public net::ListenSocket::ListenSocketDelegate {
: SimpleResponse("/quit", "So long and thanks for all the fish.") {
}
- virtual void QuitResponse::WriteContents(net::ListenSocket* socket) const {
+ virtual void WriteContents(net::StreamListenSocket* socket) const {
SimpleResponse::WriteContents(socket);
MessageLoop::current()->Quit();
}
};
Response* FindResponse(const Request& request) const;
- Connection* FindConnection(const net::ListenSocket* socket) const;
+ Connection* FindConnection(const net::StreamListenSocket* socket) const;
protected:
- scoped_refptr<net::ListenSocket> server_;
+ scoped_refptr<net::StreamListenSocket> server_;
ConnectionList connections_;
std::list<Response*> responses_;
QuitResponse quit_;
@@ -345,7 +349,7 @@ class ConfigurableConnection : public base::RefCounted<ConfigurableConnection> {
int64 timeout_;
};
- explicit ConfigurableConnection(net::ListenSocket* sock)
+ explicit ConfigurableConnection(net::StreamListenSocket* sock)
: socket_(sock),
cur_pos_(0) {}
@@ -368,7 +372,7 @@ class ConfigurableConnection : public base::RefCounted<ConfigurableConnection> {
// Closes the connection by releasing this instance's reference on its socket.
void Close();
- scoped_refptr<net::ListenSocket> socket_;
+ scoped_refptr<net::StreamListenSocket> socket_;
Request r_;
SendOptions options_;
std::string data_;
@@ -380,7 +384,7 @@ class ConfigurableConnection : public base::RefCounted<ConfigurableConnection> {
// Simple class used as a base class for mock webserver.
// Override virtual functions Get and Post and use passed ConfigurableConnection
// instance to send the response.
-class HTTPTestServer : public net::ListenSocket::ListenSocketDelegate {
+class HTTPTestServer : public net::StreamListenSocket::Delegate {
public:
HTTPTestServer(int port, const std::wstring& address, FilePath root_dir);
virtual ~HTTPTestServer();
@@ -407,16 +411,19 @@ class HTTPTestServer : public net::ListenSocket::ListenSocketDelegate {
private:
typedef std::list<scoped_refptr<ConfigurableConnection> > ConnectionList;
- ConnectionList::iterator FindConnection(const net::ListenSocket* socket);
+ ConnectionList::iterator FindConnection(
+ const net::StreamListenSocket* socket);
scoped_refptr<ConfigurableConnection> ConnectionFromSocket(
- const net::ListenSocket* socket);
+ const net::StreamListenSocket* socket);
- // ListenSocketDelegate overrides.
- virtual void DidAccept(net::ListenSocket* server, net::ListenSocket* socket);
- virtual void DidRead(net::ListenSocket* socket, const char* data, int len);
- virtual void DidClose(net::ListenSocket* socket);
+ // StreamListenSocket::Delegate overrides.
+ virtual void DidAccept(net::StreamListenSocket* server,
+ net::StreamListenSocket* socket);
+ virtual void DidRead(net::StreamListenSocket* socket,
+ const char* data, int len);
+ virtual void DidClose(net::StreamListenSocket* socket);
- scoped_refptr<net::ListenSocket> server_;
+ scoped_refptr<net::StreamListenSocket> server_;
ConnectionList connection_list_;
DISALLOW_COPY_AND_ASSIGN(HTTPTestServer);
diff --git a/chrome_frame/test/test_with_web_server.cc b/chrome_frame/test/test_with_web_server.cc
index 72e854e..c56b60c 100644
--- a/chrome_frame/test/test_with_web_server.cc
+++ b/chrome_frame/test/test_with_web_server.cc
@@ -22,6 +22,7 @@
#include "chrome_frame/test/mock_ie_event_sink_test.h"
#include "chrome_frame/test/test_scrubber.h"
#include "net/base/mime_util.h"
+#include "net/base/stream_listen_socket.h"
#include "net/http/http_util.h"
using chrome_frame_test::kChromeFrameLongNavigationTimeout;
@@ -879,7 +880,7 @@ class UaTemplateFileResponse : public test_server::FileResponse {
return content_.length();
}
- virtual void WriteContents(net::ListenSocket* socket) const {
+ virtual void WriteContents(net::StreamListenSocket* socket) const {
DCHECK(content_.length());
socket->Send(content_.c_str(), content_.length(), false);
request_id_++;
@@ -1005,7 +1006,7 @@ TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_TestDownloadFromForm) {
return match;
}
- virtual void WriteContents(net::ListenSocket* socket) const {
+ virtual void WriteContents(net::StreamListenSocket* socket) const {
if (is_post_) {
socket->Send(kText, sizeof(kText) - 1, false);
} else {