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 #include "mojo/services/network/http_server_impl.h" | 5 #include "mojo/services/network/http_server_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "mojo/services/network/http_connection_impl.h" | 10 #include "mojo/services/network/http_connection_impl.h" |
11 #include "mojo/services/network/net_adapters.h" | 11 #include "mojo/services/network/net_adapters.h" |
12 #include "mojo/services/network/net_address_type_converters.h" | 12 #include "mojo/services/network/net_address_type_converters.h" |
13 #include "net/base/ip_endpoint.h" | 13 #include "net/base/ip_endpoint.h" |
14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
15 #include "net/log/net_log.h" | 15 #include "net/log/net_log.h" |
16 #include "net/socket/tcp_server_socket.h" | 16 #include "net/socket/tcp_server_socket.h" |
17 | 17 |
18 namespace mojo { | 18 namespace mojo { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 const int kBackLog = 10; | 22 const int kBackLog = 10; |
23 | 23 |
24 } // namespace | 24 } // namespace |
25 | 25 |
26 // static | 26 // static |
27 void HttpServerImpl::Create( | 27 void HttpServerImpl::Create( |
28 NetAddressPtr local_address, | 28 NetAddressPtr local_address, |
29 HttpServerDelegatePtr delegate, | 29 HttpServerDelegatePtr delegate, |
30 scoped_ptr<mojo::AppRefCount> app_refcount, | 30 scoped_ptr<mojo::MessageLoopRef> app_refcount, |
31 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) { | 31 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) { |
32 HttpServerImpl* http_server = | 32 HttpServerImpl* http_server = |
33 new HttpServerImpl(std::move(delegate), std::move(app_refcount)); | 33 new HttpServerImpl(std::move(delegate), std::move(app_refcount)); |
34 | 34 |
35 int net_error = http_server->Start(std::move(local_address)); | 35 int net_error = http_server->Start(std::move(local_address)); |
36 if (net_error != net::OK) { | 36 if (net_error != net::OK) { |
37 callback.Run(MakeNetworkError(net_error), nullptr); | 37 callback.Run(MakeNetworkError(net_error), nullptr); |
38 delete http_server; | 38 delete http_server; |
39 return; | 39 return; |
40 } | 40 } |
41 callback.Run(MakeNetworkError(net::OK), http_server->GetLocalAddress()); | 41 callback.Run(MakeNetworkError(net::OK), http_server->GetLocalAddress()); |
42 } | 42 } |
43 | 43 |
44 HttpServerImpl::HttpServerImpl(HttpServerDelegatePtr delegate, | 44 HttpServerImpl::HttpServerImpl(HttpServerDelegatePtr delegate, |
45 scoped_ptr<mojo::AppRefCount> app_refcount) | 45 scoped_ptr<mojo::MessageLoopRef> app_refcount) |
46 : delegate_(std::move(delegate)), app_refcount_(std::move(app_refcount)) { | 46 : delegate_(std::move(delegate)), app_refcount_(std::move(app_refcount)) { |
47 DCHECK(delegate_); | 47 DCHECK(delegate_); |
48 delegate_.set_connection_error_handler([this]() { delete this; }); | 48 delegate_.set_connection_error_handler([this]() { delete this; }); |
49 } | 49 } |
50 | 50 |
51 HttpServerImpl::~HttpServerImpl() {} | 51 HttpServerImpl::~HttpServerImpl() {} |
52 | 52 |
53 int HttpServerImpl::Start(NetAddressPtr local_address) { | 53 int HttpServerImpl::Start(NetAddressPtr local_address) { |
54 DCHECK(local_address); | 54 DCHECK(local_address); |
55 | 55 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 DCHECK(connections_.find(connection_id) != connections_.end()); | 110 DCHECK(connections_.find(connection_id) != connections_.end()); |
111 connections_[connection_id]->OnReceivedWebSocketMessage(data); | 111 connections_[connection_id]->OnReceivedWebSocketMessage(data); |
112 } | 112 } |
113 | 113 |
114 void HttpServerImpl::OnClose(int connection_id) { | 114 void HttpServerImpl::OnClose(int connection_id) { |
115 DCHECK(connections_.find(connection_id) != connections_.end()); | 115 DCHECK(connections_.find(connection_id) != connections_.end()); |
116 connections_.erase(connection_id); | 116 connections_.erase(connection_id); |
117 } | 117 } |
118 | 118 |
119 } // namespace mojo | 119 } // namespace mojo |
OLD | NEW |