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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "mojo/application/application_runner_chromium.h" | |
7 #include "mojo/public/c/system/main.h" | 6 #include "mojo/public/c/system/main.h" |
8 #include "mojo/public/cpp/application/application_delegate.h" | 7 #include "mojo/public/cpp/application/application_impl_base.h" |
9 #include "mojo/public/cpp/application/application_impl.h" | |
10 #include "mojo/public/cpp/application/connect.h" | 8 #include "mojo/public/cpp/application/connect.h" |
| 9 #include "mojo/public/cpp/application/run_application.h" |
11 #include "mojo/public/cpp/bindings/interface_ptr.h" | 10 #include "mojo/public/cpp/bindings/interface_ptr.h" |
12 #include "mojo/public/cpp/system/message_pipe.h" | 11 #include "mojo/public/cpp/system/message_pipe.h" |
13 #include "mojo/services/http_server/cpp/http_server_util.h" | 12 #include "mojo/services/http_server/cpp/http_server_util.h" |
14 #include "mojo/services/http_server/interfaces/http_server.mojom.h" | 13 #include "mojo/services/http_server/interfaces/http_server.mojom.h" |
15 #include "mojo/services/http_server/interfaces/http_server_factory.mojom.h" | 14 #include "mojo/services/http_server/interfaces/http_server_factory.mojom.h" |
16 #include "mojo/services/network/interfaces/net_address.mojom.h" | 15 #include "mojo/services/network/interfaces/net_address.mojom.h" |
17 | 16 |
18 namespace mojo { | 17 namespace mojo { |
19 namespace examples { | 18 namespace examples { |
20 | 19 |
21 // This is an example of a self-contained HTTP handler. It uses the HTTP Server | 20 // This is an example of a self-contained HTTP handler. It uses the HTTP Server |
22 // service to handle the HTTP protocol details, and just contains the logic for | 21 // service to handle the HTTP protocol details, and just contains the logic for |
23 // handling its registered urls. | 22 // handling its registered urls. |
24 class HttpHandler : public ApplicationDelegate, | 23 class HttpHandler : public ApplicationImplBase, |
25 public http_server::HttpHandler { | 24 public http_server::HttpHandler { |
26 public: | 25 public: |
27 HttpHandler() : binding_(this) {} | 26 HttpHandler() : binding_(this) {} |
28 ~HttpHandler() override {} | 27 ~HttpHandler() override {} |
29 | 28 |
30 private: | 29 private: |
31 // ApplicationDelegate: | 30 // ApplicationImplBase override: |
32 void Initialize(ApplicationImpl* app) override { | 31 void OnInitialize() override { |
33 http_server::HttpHandlerPtr http_handler_ptr; | 32 http_server::HttpHandlerPtr http_handler_ptr; |
34 binding_.Bind(GetProxy(&http_handler_ptr)); | 33 binding_.Bind(GetProxy(&http_handler_ptr)); |
35 | 34 |
36 http_server::HttpServerFactoryPtr http_server_factory; | 35 http_server::HttpServerFactoryPtr http_server_factory; |
37 ConnectToService(app->shell(), "mojo:http_server", | 36 ConnectToService(shell(), "mojo:http_server", |
38 GetProxy(&http_server_factory)); | 37 GetProxy(&http_server_factory)); |
39 | 38 |
40 mojo::NetAddressPtr local_address(mojo::NetAddress::New()); | 39 mojo::NetAddressPtr local_address(mojo::NetAddress::New()); |
41 local_address->family = mojo::NetAddressFamily::IPV4; | 40 local_address->family = mojo::NetAddressFamily::IPV4; |
42 local_address->ipv4 = mojo::NetAddressIPv4::New(); | 41 local_address->ipv4 = mojo::NetAddressIPv4::New(); |
43 local_address->ipv4->addr.resize(4); | 42 local_address->ipv4->addr.resize(4); |
44 local_address->ipv4->addr[0] = 0; | 43 local_address->ipv4->addr[0] = 0; |
45 local_address->ipv4->addr[1] = 0; | 44 local_address->ipv4->addr[1] = 0; |
46 local_address->ipv4->addr[2] = 0; | 45 local_address->ipv4->addr[2] = 0; |
47 local_address->ipv4->addr[3] = 0; | 46 local_address->ipv4->addr[3] = 0; |
(...skipping 21 matching lines...) Expand all Loading... |
69 Binding<http_server::HttpHandler> binding_; | 68 Binding<http_server::HttpHandler> binding_; |
70 http_server::HttpServerPtr http_server_; | 69 http_server::HttpServerPtr http_server_; |
71 | 70 |
72 DISALLOW_COPY_AND_ASSIGN(HttpHandler); | 71 DISALLOW_COPY_AND_ASSIGN(HttpHandler); |
73 }; | 72 }; |
74 | 73 |
75 } // namespace examples | 74 } // namespace examples |
76 } // namespace mojo | 75 } // namespace mojo |
77 | 76 |
78 MojoResult MojoMain(MojoHandle application_request) { | 77 MojoResult MojoMain(MojoHandle application_request) { |
79 mojo::ApplicationRunnerChromium runner(new mojo::examples::HttpHandler()); | 78 mojo::examples::HttpHandler http_handler; |
80 return runner.Run(application_request); | 79 return mojo::RunMainApplication(application_request, &http_handler); |
81 } | 80 } |
OLD | NEW |