| 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
| 7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
| 8 #include "mojo/common/weak_binding_set.h" | 8 #include "mojo/common/weak_binding_set.h" |
| 9 #include "mojo/public/cpp/bindings/strong_binding.h" | 9 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 10 #include "mojo/services/network/public/interfaces/network_service.mojom.h" | 10 #include "mojo/services/network/public/interfaces/network_service.mojom.h" |
| 11 #include "services/http_server/public/http_request.mojom.h" | 11 #include "services/http_server/public/http_request.mojom.h" |
| 12 #include "services/http_server/public/http_response.mojom.h" | 12 #include "services/http_server/public/http_response.mojom.h" |
| 13 #include "services/http_server/public/http_server.mojom.h" | 13 #include "services/http_server/public/http_server.mojom.h" |
| 14 #include "third_party/re2/re2/re2.h" | 14 #include "third_party/re2/re2/re2.h" |
| 15 | 15 |
| 16 namespace mojo { | 16 namespace mojo { |
| 17 class ApplicationImpl; | 17 class ApplicationImpl; |
| 18 } // namespace mojo | 18 } // namespace mojo |
| 19 | 19 |
| 20 namespace http_server { | 20 namespace http_server { |
| 21 | 21 |
| 22 class Connection; | 22 class Connection; |
| 23 | 23 |
| 24 class HttpServerImpl : public HttpServer, public mojo::ErrorHandler { | 24 class HttpServerImpl : public HttpServer, public mojo::ErrorHandler { |
| 25 public: | 25 public: |
| 26 HttpServerImpl(mojo::ApplicationImpl* app); | 26 HttpServerImpl(mojo::ApplicationImpl* app); |
| 27 ~HttpServerImpl() override; |
| 27 | 28 |
| 28 void AddBinding(mojo::InterfaceRequest<HttpServer> request); | 29 void AddBinding(mojo::InterfaceRequest<HttpServer> request); |
| 29 | 30 |
| 30 // HttpServer: | 31 // HttpServer: |
| 31 void SetHandler(const mojo::String& path, | 32 void SetHandler(const mojo::String& path, |
| 32 HttpHandlerPtr http_handler, | 33 HttpHandlerPtr http_handler, |
| 33 const mojo::Callback<void(bool)>& callback) override; | 34 const mojo::Callback<void(bool)>& callback) override; |
| 34 | 35 |
| 35 private: | 36 private: |
| 36 // ErrorHandler: | 37 // ErrorHandler: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 47 void WaitForNextConnection(); | 48 void WaitForNextConnection(); |
| 48 | 49 |
| 49 void Start(); | 50 void Start(); |
| 50 | 51 |
| 51 void HandleRequest(Connection* connection, HttpRequestPtr request); | 52 void HandleRequest(Connection* connection, HttpRequestPtr request); |
| 52 | 53 |
| 53 void OnResponse(Connection* connection, HttpResponsePtr response); | 54 void OnResponse(Connection* connection, HttpResponsePtr response); |
| 54 | 55 |
| 55 struct Handler { | 56 struct Handler { |
| 56 Handler(const std::string& pattern, HttpHandlerPtr http_handler); | 57 Handler(const std::string& pattern, HttpHandlerPtr http_handler); |
| 58 ~Handler(); |
| 57 scoped_ptr<re2::RE2> pattern; | 59 scoped_ptr<re2::RE2> pattern; |
| 58 HttpHandlerPtr http_handler; | 60 HttpHandlerPtr http_handler; |
| 59 | 61 |
| 60 private: | 62 private: |
| 61 DISALLOW_COPY_AND_ASSIGN(Handler); | 63 DISALLOW_COPY_AND_ASSIGN(Handler); |
| 62 }; | 64 }; |
| 63 | 65 |
| 64 mojo::WeakBindingSet<HttpServer> bindings_; | 66 mojo::WeakBindingSet<HttpServer> bindings_; |
| 65 | 67 |
| 66 mojo::NetworkServicePtr network_service_; | 68 mojo::NetworkServicePtr network_service_; |
| 67 mojo::TCPBoundSocketPtr bound_socket_; | 69 mojo::TCPBoundSocketPtr bound_socket_; |
| 68 mojo::TCPServerSocketPtr server_socket_; | 70 mojo::TCPServerSocketPtr server_socket_; |
| 69 | 71 |
| 70 mojo::ScopedDataPipeProducerHandle pending_send_handle_; | 72 mojo::ScopedDataPipeProducerHandle pending_send_handle_; |
| 71 mojo::ScopedDataPipeConsumerHandle pending_receive_handle_; | 73 mojo::ScopedDataPipeConsumerHandle pending_receive_handle_; |
| 72 mojo::TCPConnectedSocketPtr pending_connected_socket_; | 74 mojo::TCPConnectedSocketPtr pending_connected_socket_; |
| 73 | 75 |
| 74 ScopedVector<Handler> handlers_; | 76 ScopedVector<Handler> handlers_; |
| 75 | 77 |
| 76 base::WeakPtrFactory<HttpServerImpl> weak_ptr_factory_; | 78 base::WeakPtrFactory<HttpServerImpl> weak_ptr_factory_; |
| 77 DISALLOW_COPY_AND_ASSIGN(HttpServerImpl); | 79 DISALLOW_COPY_AND_ASSIGN(HttpServerImpl); |
| 78 }; | 80 }; |
| 79 | 81 |
| 80 } // namespace http_server | 82 } // namespace http_server |
| OLD | NEW |