Chromium Code Reviews| Index: services/http_server/http_server_factory_impl.cc |
| diff --git a/services/http_server/http_server_factory_impl.cc b/services/http_server/http_server_factory_impl.cc |
| index 8dce240b04ad24a3b3bb5c0211d421203ff6f540..de59741a875ef7d3d70de38e9b2bdf714afb508a 100644 |
| --- a/services/http_server/http_server_factory_impl.cc |
| +++ b/services/http_server/http_server_factory_impl.cc |
| @@ -27,14 +27,17 @@ void HttpServerFactoryImpl::AddBinding( |
| bindings_.AddBinding(this, request.Pass()); |
| } |
| -void HttpServerFactoryImpl::DeleteServer(HttpServerImpl* server, |
| - uint16_t requested_port) { |
| - if (requested_port) { |
| - DCHECK(port_indicated_servers_.count(requested_port)); |
| - DCHECK_EQ(server, port_indicated_servers_[requested_port]); |
| +void HttpServerFactoryImpl::DeleteServer( |
| + HttpServerImpl* server, |
| + mojo::NetAddressPtr requested_address) { |
|
qsr
2015/02/23 17:14:01
Take a mojo::NetAddress* instead, so you do not ne
ppi
2015/02/24 10:59:54
Done.
|
| + ServerKey key = GetServerKey(requested_address.Pass()); |
| + |
| + if (key.second) { // If the port is non-zero. |
| + DCHECK(port_indicated_servers_.count(key)); |
| + DCHECK_EQ(server, port_indicated_servers_[key]); |
| delete server; |
| - port_indicated_servers_.erase(requested_port); |
| + port_indicated_servers_.erase(key); |
| } else { |
| DCHECK(port_any_servers_.count(server)); |
| @@ -43,16 +46,35 @@ void HttpServerFactoryImpl::DeleteServer(HttpServerImpl* server, |
| } |
| } |
| +HttpServerFactoryImpl::ServerKey HttpServerFactoryImpl::GetServerKey( |
| + mojo::NetAddressPtr local_address) { |
| + if (!local_address) { |
| + return ServerKey(); |
| + } |
| + |
| + if (local_address->family == mojo::NET_ADDRESS_FAMILY_IPV6) { |
| + return ServerKey(local_address->ipv6->addr, local_address->ipv6->port); |
| + } else if (local_address->family == mojo::NET_ADDRESS_FAMILY_IPV4) { |
| + return ServerKey(local_address->ipv4->addr, local_address->ipv4->port); |
| + } else { |
| + return ServerKey(); |
| + } |
| +} |
| + |
| void HttpServerFactoryImpl::CreateHttpServer( |
| mojo::InterfaceRequest<HttpServer> server_request, |
| - uint16_t port) { |
| - if (port) { |
| - if (!port_indicated_servers_.count(port)) { |
| - port_indicated_servers_[port] = new HttpServerImpl(app_, this, port); |
| + mojo::NetAddressPtr local_address) { |
|
qsr
2015/02/23 17:14:01
local_address is optional, what about making it 0.
ppi
2015/02/24 10:59:54
Done.
|
| + ServerKey key = GetServerKey(local_address.Clone()); |
| + |
| + if (key.second) { // If the port is non-zero. |
| + if (!port_indicated_servers_.count(key)) { |
| + port_indicated_servers_[key] = |
| + new HttpServerImpl(app_, this, local_address.Pass()); |
| } |
| - port_indicated_servers_[port]->AddBinding(server_request.Pass()); |
| + port_indicated_servers_[key]->AddBinding(server_request.Pass()); |
| } else { |
| - HttpServerImpl* server = new HttpServerImpl(app_, this, port); |
| + HttpServerImpl* server = |
| + new HttpServerImpl(app_, this, local_address.Pass()); |
| server->AddBinding(server_request.Pass()); |
| port_any_servers_.insert(server); |
| } |