summaryrefslogtreecommitdiffstats
path: root/net/server
diff options
context:
space:
mode:
authorrsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-28 09:29:28 +0000
committerrsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-28 09:29:28 +0000
commita981330295415845ef13cd85afeff42032d782df (patch)
tree46ad72c4cabd094a5f4dea2faa1bde6fb7d3677f /net/server
parent20eef6d14fce11a57949d052db064e56242c4c82 (diff)
downloadchromium_src-a981330295415845ef13cd85afeff42032d782df.zip
chromium_src-a981330295415845ef13cd85afeff42032d782df.tar.gz
chromium_src-a981330295415845ef13cd85afeff42032d782df.tar.bz2
RefCounted types should not have public destructors, net/
BUG=123295 TEST=none Review URL: http://codereview.chromium.org/10066045 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134460 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/server')
-rw-r--r--net/server/http_server.cc176
-rw-r--r--net/server/http_server.h15
2 files changed, 97 insertions, 94 deletions
diff --git a/net/server/http_server.cc b/net/server/http_server.cc
index ad1fa6e..c9d8ac75 100644
--- a/net/server/http_server.cc
+++ b/net/server/http_server.cc
@@ -24,12 +24,24 @@ HttpServer::HttpServer(const std::string& host,
server_ = TCPListenSocket::CreateAndListen(host, port, this);
}
-HttpServer::~HttpServer() {
- IdToConnectionMap copy = id_to_connection_;
- for (IdToConnectionMap::iterator it = copy.begin(); it != copy.end(); ++it)
- delete it->second;
+void HttpServer::AcceptWebSocket(
+ int connection_id,
+ const HttpServerRequestInfo& request) {
+ HttpConnection* connection = FindConnection(connection_id);
+ if (connection == NULL)
+ return;
- server_ = NULL;
+ DCHECK(connection->web_socket_.get());
+ connection->web_socket_->Accept(request);
+}
+
+void HttpServer::SendOverWebSocket(int connection_id,
+ const std::string& data) {
+ HttpConnection* connection = FindConnection(connection_id);
+ if (connection == NULL)
+ return;
+ DCHECK(connection->web_socket_.get());
+ connection->web_socket_->Send(data);
}
void HttpServer::Send(int connection_id, const std::string& data) {
@@ -81,6 +93,77 @@ void HttpServer::Close(int connection_id)
DidClose(connection->socket_);
}
+void HttpServer::DidAccept(ListenSocket* server,
+ ListenSocket* socket) {
+ HttpConnection* connection = new HttpConnection(this, socket);
+ id_to_connection_[connection->id()] = connection;
+ socket_to_connection_[socket] = connection;
+}
+
+void HttpServer::DidRead(ListenSocket* socket,
+ const char* data,
+ int len) {
+ HttpConnection* connection = FindConnection(socket);
+ DCHECK(connection != NULL);
+ if (connection == NULL)
+ return;
+
+ connection->recv_data_.append(data, len);
+ while (connection->recv_data_.length()) {
+ if (connection->web_socket_.get()) {
+ std::string message;
+ WebSocket::ParseResult result = connection->web_socket_->Read(&message);
+ if (result == WebSocket::FRAME_INCOMPLETE)
+ break;
+
+ if (result == WebSocket::FRAME_CLOSE ||
+ result == WebSocket::FRAME_ERROR) {
+ Close(connection->id());
+ break;
+ }
+ delegate_->OnWebSocketMessage(connection->id(), message);
+ continue;
+ }
+
+ HttpServerRequestInfo request;
+ size_t pos = 0;
+ if (!ParseHeaders(connection, &request, &pos))
+ break;
+
+ std::string connection_header = request.GetHeaderValue("Connection");
+ if (connection_header == "Upgrade") {
+ connection->web_socket_.reset(WebSocket::CreateWebSocket(connection,
+ request,
+ &pos));
+
+ if (!connection->web_socket_.get()) // Not enought data was received.
+ break;
+ delegate_->OnWebSocketRequest(connection->id(), request);
+ connection->Shift(pos);
+ continue;
+ }
+ // Request body is not supported. It is always empty.
+ delegate_->OnHttpRequest(connection->id(), request);
+ connection->Shift(pos);
+ }
+}
+
+void HttpServer::DidClose(ListenSocket* socket) {
+ HttpConnection* connection = FindConnection(socket);
+ DCHECK(connection != NULL);
+ id_to_connection_.erase(connection->id());
+ socket_to_connection_.erase(connection->socket_);
+ delete connection;
+}
+
+HttpServer::~HttpServer() {
+ IdToConnectionMap copy = id_to_connection_;
+ for (IdToConnectionMap::iterator it = copy.begin(); it != copy.end(); ++it)
+ delete it->second;
+
+ server_ = NULL;
+}
+
//
// HTTP Request Parser
// This HTTP request parser uses a simple state machine to quickly parse
@@ -212,69 +295,6 @@ bool HttpServer::ParseHeaders(HttpConnection* connection,
return false;
}
-void HttpServer::DidAccept(ListenSocket* server,
- ListenSocket* socket) {
- HttpConnection* connection = new HttpConnection(this, socket);
- id_to_connection_[connection->id()] = connection;
- socket_to_connection_[socket] = connection;
-}
-
-void HttpServer::DidRead(ListenSocket* socket,
- const char* data,
- int len) {
- HttpConnection* connection = FindConnection(socket);
- DCHECK(connection != NULL);
- if (connection == NULL)
- return;
-
- connection->recv_data_.append(data, len);
- while (connection->recv_data_.length()) {
- if (connection->web_socket_.get()) {
- std::string message;
- WebSocket::ParseResult result = connection->web_socket_->Read(&message);
- if (result == WebSocket::FRAME_INCOMPLETE)
- break;
-
- if (result == WebSocket::FRAME_CLOSE ||
- result == WebSocket::FRAME_ERROR) {
- Close(connection->id());
- break;
- }
- delegate_->OnWebSocketMessage(connection->id(), message);
- continue;
- }
-
- HttpServerRequestInfo request;
- size_t pos = 0;
- if (!ParseHeaders(connection, &request, &pos))
- break;
-
- std::string connection_header = request.GetHeaderValue("Connection");
- if (connection_header == "Upgrade") {
- connection->web_socket_.reset(WebSocket::CreateWebSocket(connection,
- request,
- &pos));
-
- if (!connection->web_socket_.get()) // Not enought data was received.
- break;
- delegate_->OnWebSocketRequest(connection->id(), request);
- connection->Shift(pos);
- continue;
- }
- // Request body is not supported. It is always empty.
- delegate_->OnHttpRequest(connection->id(), request);
- connection->Shift(pos);
- }
-}
-
-void HttpServer::DidClose(ListenSocket* socket) {
- HttpConnection* connection = FindConnection(socket);
- DCHECK(connection != NULL);
- id_to_connection_.erase(connection->id());
- socket_to_connection_.erase(connection->socket_);
- delete connection;
-}
-
HttpConnection* HttpServer::FindConnection(int connection_id) {
IdToConnectionMap::iterator it = id_to_connection_.find(connection_id);
if (it == id_to_connection_.end())
@@ -289,24 +309,4 @@ HttpConnection* HttpServer::FindConnection(ListenSocket* socket) {
return it->second;
}
-void HttpServer::AcceptWebSocket(
- int connection_id,
- const HttpServerRequestInfo& request) {
- HttpConnection* connection = FindConnection(connection_id);
- if (connection == NULL)
- return;
-
- DCHECK(connection->web_socket_.get());
- connection->web_socket_->Accept(request);
-}
-
-void HttpServer::SendOverWebSocket(int connection_id,
- const std::string& data) {
- HttpConnection* connection = FindConnection(connection_id);
- if (connection == NULL)
- return;
- DCHECK(connection->web_socket_.get());
- connection->web_socket_->Send(data);
-}
-
} // namespace net
diff --git a/net/server/http_server.h b/net/server/http_server.h
index 589d887..526558e 100644
--- a/net/server/http_server.h
+++ b/net/server/http_server.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -34,12 +34,12 @@ class HttpServer : public ListenSocket::ListenSocketDelegate,
const std::string& data) = 0;
virtual void OnClose(int connection_id) = 0;
+
protected:
virtual ~Delegate() {}
};
HttpServer(const std::string& host, int port, HttpServer::Delegate* del);
- virtual ~HttpServer();
void AcceptWebSocket(int connection_id,
const HttpServerRequestInfo& request);
@@ -53,10 +53,6 @@ class HttpServer : public ListenSocket::ListenSocketDelegate,
void Send500(int connection_id, const std::string& message);
void Close(int connection_id);
-private:
- friend class base::RefCountedThreadSafe<HttpServer>;
- friend class HttpConnection;
-
// ListenSocketDelegate
virtual void DidAccept(ListenSocket* server, ListenSocket* socket) OVERRIDE;
virtual void DidRead(ListenSocket* socket,
@@ -64,6 +60,13 @@ private:
int len) OVERRIDE;
virtual void DidClose(ListenSocket* socket) OVERRIDE;
+ protected:
+ virtual ~HttpServer();
+
+ private:
+ friend class base::RefCountedThreadSafe<HttpServer>;
+ friend class HttpConnection;
+
// Expects the raw data to be stored in recv_data_. If parsing is successful,
// will remove the data parsed from recv_data_, leaving only the unused
// recv data.