| OLD | NEW |
| 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 #ifndef SERVICES_HTTP_SERVER_HTTP_SERVER_FACTORY_IMPL_H_ | 5 #ifndef SERVICES_HTTP_SERVER_HTTP_SERVER_FACTORY_IMPL_H_ |
| 6 #define SERVICES_HTTP_SERVER_HTTP_SERVER_FACTORY_IMPL_H_ | 6 #define SERVICES_HTTP_SERVER_HTTP_SERVER_FACTORY_IMPL_H_ |
| 7 | 7 |
| 8 #include <algorithm> |
| 8 #include <map> | 9 #include <map> |
| 9 #include <set> | 10 #include <set> |
| 11 #include <vector> |
| 10 | 12 |
| 11 #include "mojo/common/weak_binding_set.h" | 13 #include "mojo/common/weak_binding_set.h" |
| 12 #include "mojo/public/cpp/bindings/interface_request.h" | 14 #include "mojo/public/cpp/bindings/interface_request.h" |
| 15 #include "mojo/services/network/public/interfaces/net_address.mojom.h" |
| 13 #include "services/http_server/public/http_server_factory.mojom.h" | 16 #include "services/http_server/public/http_server_factory.mojom.h" |
| 14 | 17 |
| 15 namespace mojo { | 18 namespace mojo { |
| 16 class ApplicationImpl; | 19 class ApplicationImpl; |
| 17 } // namespace mojo | 20 } // namespace mojo |
| 18 | 21 |
| 19 namespace http_server { | 22 namespace http_server { |
| 20 | 23 |
| 21 class HttpServerImpl; | 24 class HttpServerImpl; |
| 22 | 25 |
| 23 class HttpServerFactoryImpl : public HttpServerFactory { | 26 class HttpServerFactoryImpl : public HttpServerFactory { |
| 24 public: | 27 public: |
| 25 HttpServerFactoryImpl(mojo::ApplicationImpl* app); | 28 HttpServerFactoryImpl(mojo::ApplicationImpl* app); |
| 26 ~HttpServerFactoryImpl() override; | 29 ~HttpServerFactoryImpl() override; |
| 27 | 30 |
| 28 void AddBinding(mojo::InterfaceRequest<HttpServerFactory> request); | 31 void AddBinding(mojo::InterfaceRequest<HttpServerFactory> request); |
| 29 | 32 |
| 30 // The server impl calls back here when the last of its clients disconnects. | 33 // The server impl calls back here when the last of its clients disconnects. |
| 31 void DeleteServer(HttpServerImpl* server, uint16_t port); | 34 void DeleteServer(HttpServerImpl* server, |
| 35 mojo::NetAddressPtr requested_address); |
| 32 | 36 |
| 33 private: | 37 private: |
| 38 // Servers that were requested with non-zero port are stored in a map and we |
| 39 // allow multiple clients to connect to them. We use a pair of the IP address |
| 40 // and the port as a lookup key. |
| 41 typedef std::pair<std::vector<uint8_t>, uint16_t> ServerKey; |
| 42 |
| 43 ServerKey GetServerKey(mojo::NetAddressPtr local_address); |
| 44 |
| 34 // HttpServerFactory: | 45 // HttpServerFactory: |
| 35 void CreateHttpServer(mojo::InterfaceRequest<HttpServer> server_request, | 46 void CreateHttpServer(mojo::InterfaceRequest<HttpServer> server_request, |
| 36 uint16_t port) override; | 47 mojo::NetAddressPtr local_address) override; |
| 37 | 48 |
| 38 mojo::WeakBindingSet<HttpServerFactory> bindings_; | 49 mojo::WeakBindingSet<HttpServerFactory> bindings_; |
| 39 | 50 |
| 40 // Servers that were requested with non-zero port are stored in a map and we | 51 std::map<ServerKey, HttpServerImpl*> port_indicated_servers_; |
| 41 // allow multiple clients to connect to them. | |
| 42 std::map<uint16_t, HttpServerImpl*> port_indicated_servers_; | |
| 43 | 52 |
| 44 // Servers that were requested with port = 0 (pick any) are not available to | 53 // Servers that were requested with port = 0 (pick any) are not available to |
| 45 // other clients. | 54 // other clients. |
| 46 std::set<HttpServerImpl*> port_any_servers_; | 55 std::set<HttpServerImpl*> port_any_servers_; |
| 47 | 56 |
| 48 mojo::ApplicationImpl* app_; | 57 mojo::ApplicationImpl* app_; |
| 49 }; | 58 }; |
| 50 | 59 |
| 51 } // namespace http_server | 60 } // namespace http_server |
| 52 | 61 |
| 53 #endif // SERVICES_HTTP_SERVER_HTTP_SERVER_FACTORY_IMPL_H_ | 62 #endif // SERVICES_HTTP_SERVER_HTTP_SERVER_FACTORY_IMPL_H_ |
| OLD | NEW |