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

Side by Side Diff: services/http_server/http_server_factory_impl.cc

Issue 953513002: http_server: accept full NetAddress in CreateHttpServer. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 9 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "services/http_server/http_server_factory_impl.h" 5 #include "services/http_server/http_server_factory_impl.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "services/http_server/http_server_impl.h" 8 #include "services/http_server/http_server_impl.h"
9 #include "services/http_server/public/http_server.mojom.h" 9 #include "services/http_server/public/http_server.mojom.h"
10 10
11 namespace http_server { 11 namespace http_server {
12 12
13 HttpServerFactoryImpl::HttpServerFactoryImpl(mojo::ApplicationImpl* app) { 13 HttpServerFactoryImpl::HttpServerFactoryImpl(mojo::ApplicationImpl* app) {
14 app_ = app; 14 app_ = app;
15 } 15 }
16 16
17 HttpServerFactoryImpl::~HttpServerFactoryImpl() { 17 HttpServerFactoryImpl::~HttpServerFactoryImpl() {
18 // Free the http servers. 18 // Free the http servers.
19 STLDeleteContainerPairSecondPointers(port_indicated_servers_.begin(), 19 STLDeleteContainerPairSecondPointers(port_indicated_servers_.begin(),
20 port_indicated_servers_.end()); 20 port_indicated_servers_.end());
21 STLDeleteContainerPointers(port_any_servers_.begin(), 21 STLDeleteContainerPointers(port_any_servers_.begin(),
22 port_any_servers_.end()); 22 port_any_servers_.end());
23 } 23 }
24 24
25 void HttpServerFactoryImpl::AddBinding( 25 void HttpServerFactoryImpl::AddBinding(
26 mojo::InterfaceRequest<HttpServerFactory> request) { 26 mojo::InterfaceRequest<HttpServerFactory> request) {
27 bindings_.AddBinding(this, request.Pass()); 27 bindings_.AddBinding(this, request.Pass());
28 } 28 }
29 29
30 void HttpServerFactoryImpl::DeleteServer(HttpServerImpl* server, 30 void HttpServerFactoryImpl::DeleteServer(
31 uint16_t requested_port) { 31 HttpServerImpl* server,
32 if (requested_port) { 32 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.
33 DCHECK(port_indicated_servers_.count(requested_port)); 33 ServerKey key = GetServerKey(requested_address.Pass());
34 DCHECK_EQ(server, port_indicated_servers_[requested_port]); 34
35 if (key.second) { // If the port is non-zero.
36 DCHECK(port_indicated_servers_.count(key));
37 DCHECK_EQ(server, port_indicated_servers_[key]);
35 38
36 delete server; 39 delete server;
37 port_indicated_servers_.erase(requested_port); 40 port_indicated_servers_.erase(key);
38 } else { 41 } else {
39 DCHECK(port_any_servers_.count(server)); 42 DCHECK(port_any_servers_.count(server));
40 43
41 delete server; 44 delete server;
42 port_any_servers_.erase(server); 45 port_any_servers_.erase(server);
43 } 46 }
44 } 47 }
45 48
49 HttpServerFactoryImpl::ServerKey HttpServerFactoryImpl::GetServerKey(
50 mojo::NetAddressPtr local_address) {
51 if (!local_address) {
52 return ServerKey();
53 }
54
55 if (local_address->family == mojo::NET_ADDRESS_FAMILY_IPV6) {
56 return ServerKey(local_address->ipv6->addr, local_address->ipv6->port);
57 } else if (local_address->family == mojo::NET_ADDRESS_FAMILY_IPV4) {
58 return ServerKey(local_address->ipv4->addr, local_address->ipv4->port);
59 } else {
60 return ServerKey();
61 }
62 }
63
46 void HttpServerFactoryImpl::CreateHttpServer( 64 void HttpServerFactoryImpl::CreateHttpServer(
47 mojo::InterfaceRequest<HttpServer> server_request, 65 mojo::InterfaceRequest<HttpServer> server_request,
48 uint16_t port) { 66 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.
49 if (port) { 67 ServerKey key = GetServerKey(local_address.Clone());
50 if (!port_indicated_servers_.count(port)) { 68
51 port_indicated_servers_[port] = new HttpServerImpl(app_, this, port); 69 if (key.second) { // If the port is non-zero.
70 if (!port_indicated_servers_.count(key)) {
71 port_indicated_servers_[key] =
72 new HttpServerImpl(app_, this, local_address.Pass());
52 } 73 }
53 port_indicated_servers_[port]->AddBinding(server_request.Pass()); 74 port_indicated_servers_[key]->AddBinding(server_request.Pass());
54 } else { 75 } else {
55 HttpServerImpl* server = new HttpServerImpl(app_, this, port); 76 HttpServerImpl* server =
77 new HttpServerImpl(app_, this, local_address.Pass());
56 server->AddBinding(server_request.Pass()); 78 server->AddBinding(server_request.Pass());
57 port_any_servers_.insert(server); 79 port_any_servers_.insert(server);
58 } 80 }
59 } 81 }
60 82
61 } // namespace http_server 83 } // namespace http_server
OLDNEW
« no previous file with comments | « services/http_server/http_server_factory_impl.h ('k') | services/http_server/http_server_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698