Commit 50826e07 authored by yzshen's avatar yzshen Committed by Commit bot

Add HTTP server mojo interfaces.

The reasons for adding such interfaces:
- There'll be code in src/mandoline that creates an http server which enables
communication between html_viewer/mandoline ui and external applications. One
use case is to support telemetry.

- We would like to use the C++ http server and websocket impl in net/, and don't
want to link net/ into anything other than the network service.

BUG=478249
TEST=None

Review URL: https://codereview.chromium.org/1136773002

Cr-Commit-Position: refs/heads/master@{#329338}
parent 77de231e
...@@ -42,7 +42,7 @@ void NetworkServiceImpl::CreateWebSocket(InterfaceRequest<WebSocket> socket) { ...@@ -42,7 +42,7 @@ void NetworkServiceImpl::CreateWebSocket(InterfaceRequest<WebSocket> socket) {
void NetworkServiceImpl::CreateTCPBoundSocket( void NetworkServiceImpl::CreateTCPBoundSocket(
NetAddressPtr local_address, NetAddressPtr local_address,
InterfaceRequest<TCPBoundSocket> bound_socket, InterfaceRequest<TCPBoundSocket> bound_socket,
const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) { const CreateTCPBoundSocketCallback& callback) {
scoped_ptr<TCPBoundSocketImpl> bound(new TCPBoundSocketImpl); scoped_ptr<TCPBoundSocketImpl> bound(new TCPBoundSocketImpl);
int net_error = bound->Bind(local_address.Pass()); int net_error = bound->Bind(local_address.Pass());
if (net_error != net::OK) { if (net_error != net::OK) {
...@@ -59,7 +59,7 @@ void NetworkServiceImpl::CreateTCPConnectedSocket( ...@@ -59,7 +59,7 @@ void NetworkServiceImpl::CreateTCPConnectedSocket(
ScopedDataPipeConsumerHandle send_stream, ScopedDataPipeConsumerHandle send_stream,
ScopedDataPipeProducerHandle receive_stream, ScopedDataPipeProducerHandle receive_stream,
InterfaceRequest<TCPConnectedSocket> client_socket, InterfaceRequest<TCPConnectedSocket> client_socket,
const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) { const CreateTCPConnectedSocketCallback& callback) {
// TODO(brettw) implement this. We need to know what type of socket to use // TODO(brettw) implement this. We need to know what type of socket to use
// so we can create the right one (i.e. to pass to TCPSocket::Open) before // so we can create the right one (i.e. to pass to TCPSocket::Open) before
// doing the connect. // doing the connect.
...@@ -71,4 +71,12 @@ void NetworkServiceImpl::CreateUDPSocket(InterfaceRequest<UDPSocket> request) { ...@@ -71,4 +71,12 @@ void NetworkServiceImpl::CreateUDPSocket(InterfaceRequest<UDPSocket> request) {
new UDPSocketImpl(request.Pass()); new UDPSocketImpl(request.Pass());
} }
void NetworkServiceImpl::CreateHttpServer(
NetAddressPtr local_address,
HttpServerDelegatePtr delegate,
const CreateHttpServerCallback& callback) {
// TODO(yzshen): implement this.
callback.Run(MakeNetworkError(net::ERR_NOT_IMPLEMENTED), nullptr);
}
} // namespace mojo } // namespace mojo
...@@ -27,14 +27,17 @@ class NetworkServiceImpl : public InterfaceImpl<NetworkService> { ...@@ -27,14 +27,17 @@ class NetworkServiceImpl : public InterfaceImpl<NetworkService> {
void CreateTCPBoundSocket( void CreateTCPBoundSocket(
NetAddressPtr local_address, NetAddressPtr local_address,
InterfaceRequest<TCPBoundSocket> bound_socket, InterfaceRequest<TCPBoundSocket> bound_socket,
const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) override; const CreateTCPBoundSocketCallback& callback) override;
void CreateTCPConnectedSocket( void CreateTCPConnectedSocket(
NetAddressPtr remote_address, NetAddressPtr remote_address,
ScopedDataPipeConsumerHandle send_stream, ScopedDataPipeConsumerHandle send_stream,
ScopedDataPipeProducerHandle receive_stream, ScopedDataPipeProducerHandle receive_stream,
InterfaceRequest<TCPConnectedSocket> client_socket, InterfaceRequest<TCPConnectedSocket> client_socket,
const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) override; const CreateTCPConnectedSocketCallback& callback) override;
void CreateUDPSocket(InterfaceRequest<UDPSocket> socket) override; void CreateUDPSocket(InterfaceRequest<UDPSocket> socket) override;
void CreateHttpServer(NetAddressPtr local_address,
HttpServerDelegatePtr delegate,
const CreateHttpServerCallback& callback) override;
private: private:
NetworkContext* context_; NetworkContext* context_;
......
...@@ -8,6 +8,8 @@ import("//third_party/mojo/src/mojo/public/tools/bindings/mojom.gni") ...@@ -8,6 +8,8 @@ import("//third_party/mojo/src/mojo/public/tools/bindings/mojom.gni")
mojom("interfaces") { mojom("interfaces") {
sources = [ sources = [
"cookie_store.mojom", "cookie_store.mojom",
"http_connection.mojom",
"http_server.mojom",
"net_address.mojom", "net_address.mojom",
"network_error.mojom", "network_error.mojom",
"network_service.mojom", "network_service.mojom",
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module mojo;
import "network/public/interfaces/url_loader.mojom";
import "network/public/interfaces/network_error.mojom";
import "network/public/interfaces/web_socket.mojom";
interface HttpConnection {
// Sets the OS send buffer size (in bytes) for the underlying socket.
SetSendBufferSize(uint32 size) => (NetworkError result);
// Sets the OS receive buffer size (in bytes) for the underlying socket.
SetReceiveBufferSize(uint32 size) => (NetworkError result);
};
interface HttpConnectionDelegate {
// Called when an HTTP request is received.
OnReceivedRequest(URLRequest request) => (URLResponse response);
// Called with an WebSocket request is received.
//
// If the delegate decides to accept the request, it should respond with
// non-null arguments in the callback. |send_stream| is a data pipe which
// should remain open for the lifetime of the WebSocket. Data to send over the
// WebSocket should be written to the producer end of the |send_stream|.
// |web_socket| will be already connected. There is no need to call Connect()
// on it. But |client| will still receive a DidConnect() notification.
OnReceivedWebSocketRequest(URLRequest request)
=> (WebSocket&? web_socket,
handle<data_pipe_consumer>? send_stream,
WebSocketClient? client);
};
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module mojo;
import "network/public/interfaces/http_connection.mojom";
interface HttpServerDelegate {
// Called when a connection is established.
OnConnected(HttpConnection connection, HttpConnectionDelegate& delegate);
};
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
module mojo; module mojo;
import "network/public/interfaces/cookie_store.mojom"; import "network/public/interfaces/cookie_store.mojom";
import "network/public/interfaces/http_server.mojom";
import "network/public/interfaces/net_address.mojom"; import "network/public/interfaces/net_address.mojom";
import "network/public/interfaces/network_error.mojom"; import "network/public/interfaces/network_error.mojom";
import "network/public/interfaces/tcp_bound_socket.mojom"; import "network/public/interfaces/tcp_bound_socket.mojom";
...@@ -58,4 +59,17 @@ interface NetworkService { ...@@ -58,4 +59,17 @@ interface NetworkService {
NetAddress? local_address); NetAddress? local_address);
CreateUDPSocket(UDPSocket& socket); CreateUDPSocket(UDPSocket& socket);
// Starts an HTTP server running on the given local address. The delegate will
// be notified with incoming connections.
//
// The local address can specify 0 for the port to specify that the OS should
// pick an available port for the given address, or it can pass 0 for the
// address and port for the OS to pick both the local address and port. In
// all success cases, the resulting local address will be passed to the
// callback as bound_to.
CreateHttpServer(NetAddress local_address,
HttpServerDelegate delegate)
=> (NetworkError result,
NetAddress? bound_to);
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment