OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_impl.h" | 5 #include "services/http_server/http_server_impl.h" |
6 | 6 |
7 #include <utility> | |
8 | |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
9 #include "mojo/public/cpp/application/application_impl.h" | 11 #include "mojo/public/cpp/application/application_impl.h" |
10 #include "mojo/public/cpp/system/data_pipe.h" | 12 #include "mojo/public/cpp/system/data_pipe.h" |
11 #include "mojo/services/http_server/cpp/http_server_util.h" | 13 #include "mojo/services/http_server/cpp/http_server_util.h" |
12 #include "services/http_server/connection.h" | 14 #include "services/http_server/connection.h" |
13 #include "services/http_server/http_server_factory_impl.h" | 15 #include "services/http_server/http_server_factory_impl.h" |
14 | 16 |
15 namespace http_server { | 17 namespace http_server { |
16 | 18 |
17 HttpServerImpl::HttpServerImpl(mojo::ApplicationImpl* app, | 19 HttpServerImpl::HttpServerImpl(mojo::ApplicationImpl* app, |
18 HttpServerFactoryImpl* factory, | 20 HttpServerFactoryImpl* factory, |
19 mojo::NetAddressPtr requested_local_address) | 21 mojo::NetAddressPtr requested_local_address) |
20 : factory_(factory), | 22 : factory_(factory), |
21 requested_local_address_(requested_local_address.Pass()), | 23 requested_local_address_(requested_local_address.Pass()), |
22 assigned_port_(0), | 24 assigned_port_(0), |
23 weak_ptr_factory_(this) { | 25 weak_ptr_factory_(this) { |
24 app->ConnectToService("mojo:network_service", &network_service_); | 26 app->ConnectToService("mojo:network_service", &network_service_); |
25 Start(); | 27 Start(); |
26 } | 28 } |
27 | 29 |
28 HttpServerImpl::~HttpServerImpl() { | 30 HttpServerImpl::~HttpServerImpl() { |
29 } | 31 } |
30 | 32 |
31 void HttpServerImpl::AddBinding(mojo::InterfaceRequest<HttpServer> request) { | 33 void HttpServerImpl::AddBinding(mojo::InterfaceRequest<HttpServer> request) { |
32 bindings_.AddBinding(this, request.Pass()); | 34 bindings_.AddBinding(this, request.Pass()); |
33 } | 35 } |
34 | 36 |
35 void HttpServerImpl::SetHandler(const mojo::String& path, | 37 void HttpServerImpl::SetHandler(const mojo::String& path, |
36 HttpHandlerPtr http_handler, | 38 mojo::InterfaceHandle<HttpHandler> http_handler, |
37 const mojo::Callback<void(bool)>& callback) { | 39 const mojo::Callback<void(bool)>& callback) { |
38 for (const auto& handler : handlers_) { | 40 for (const auto& handler : handlers_) { |
39 if (handler->pattern->pattern() == path) | 41 if (handler->pattern->pattern() == path) |
40 callback.Run(false); | 42 callback.Run(false); |
41 } | 43 } |
42 | 44 |
43 Handler* handler = new Handler(path, http_handler.Pass()); | 45 Handler* handler = |
46 new Handler(path, HttpHandlerPtr::Create(std::move(http_handler))); | |
viettrungluu
2016/02/11 18:26:29
Maybe make Handler's ctor take an IH instead? <shr
vardhan
2016/02/11 22:47:53
Handler more or less just holds data (if you look
| |
44 handler->http_handler.set_connection_error_handler( | 47 handler->http_handler.set_connection_error_handler( |
45 [this, handler]() { OnHandlerConnectionError(handler); }); | 48 [this, handler]() { OnHandlerConnectionError(handler); }); |
46 handlers_.push_back(handler); | 49 handlers_.push_back(handler); |
47 callback.Run(true); | 50 callback.Run(true); |
48 } | 51 } |
49 | 52 |
50 void HttpServerImpl::GetPort(const GetPortCallback& callback) { | 53 void HttpServerImpl::GetPort(const GetPortCallback& callback) { |
51 if (assigned_port_) | 54 if (assigned_port_) |
52 callback.Run(assigned_port_); | 55 callback.Run(assigned_port_); |
53 else | 56 else |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 | 163 |
161 HttpServerImpl::Handler::Handler(const std::string& pattern, | 164 HttpServerImpl::Handler::Handler(const std::string& pattern, |
162 HttpHandlerPtr http_handler) | 165 HttpHandlerPtr http_handler) |
163 : pattern(new RE2(pattern.c_str())), http_handler(http_handler.Pass()) { | 166 : pattern(new RE2(pattern.c_str())), http_handler(http_handler.Pass()) { |
164 } | 167 } |
165 | 168 |
166 HttpServerImpl::Handler::~Handler() { | 169 HttpServerImpl::Handler::~Handler() { |
167 } | 170 } |
168 | 171 |
169 } // namespace http_server | 172 } // namespace http_server |
OLD | NEW |