Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/bind.h" | |
| 6 #include "mojo/application/application_runner_chromium.h" | |
| 7 #include "mojo/public/c/system/main.h" | |
| 8 #include "mojo/public/cpp/application/application_connection.h" | |
| 9 #include "mojo/public/cpp/application/application_delegate.h" | |
| 10 #include "mojo/public/cpp/application/application_impl.h" | |
| 11 #include "mojo/public/cpp/application/interface_factory_impl.h" | |
| 12 #include "mojo/public/cpp/application/service_provider_impl.h" | |
| 13 #include "services/http_server/public/http_server.mojom.h" | |
| 14 | |
| 15 namespace mojo { | |
| 16 namespace examples { | |
| 17 | |
| 18 // This is an example of a self-contained HTTP handler. It uses the HTTP Server | |
| 19 // service to handle the HTTP protocol details, and just contains the logic for | |
| 20 // handling its registered urls. | |
| 21 class HttpHandler : public ApplicationDelegate, | |
| 22 public HttpServerClient { | |
| 23 public: | |
| 24 HttpHandler() {} | |
| 25 virtual ~HttpHandler() {} | |
|
yzshen1
2014/11/12 17:38:33
nit: I think the style guide now prefers "~HttpHan
jam
2014/11/12 20:48:40
Done.
| |
| 26 | |
| 27 private: | |
| 28 // ApplicationDelegate: | |
| 29 void Initialize(ApplicationImpl* app) override { | |
| 30 app->ConnectToService("mojo:http_server", &http_server_service_); | |
| 31 | |
| 32 http_server_service_.set_client(this); | |
| 33 http_server_service_->AddHandler( | |
| 34 "/test", | |
| 35 base::Bind(&HttpHandler::AddHandlerCallback, base::Unretained(this))); | |
| 36 } | |
| 37 | |
| 38 // HttpServerClient: | |
| 39 void OnHandleRequest(HttpRequestPtr request, | |
| 40 const Callback<void(HttpResponsePtr)>& callback) { | |
|
yzshen1
2014/11/12 17:38:33
nit: override
jam
2014/11/12 20:48:40
Done.
| |
| 41 http_server_service_->CreateResponse(200, "Hello World", callback); | |
| 42 } | |
| 43 | |
| 44 void AddHandlerCallback(bool result) { | |
| 45 CHECK(result); | |
| 46 } | |
| 47 | |
| 48 HttpServerServicePtr http_server_service_; | |
| 49 | |
| 50 DISALLOW_COPY_AND_ASSIGN(HttpHandler); | |
| 51 }; | |
| 52 | |
| 53 } // namespace examples | |
| 54 } // namespace mojo | |
| 55 | |
| 56 MojoResult MojoMain(MojoHandle shell_handle) { | |
| 57 mojo::ApplicationRunnerChromium runner(new mojo::examples::HttpHandler()); | |
| 58 return runner.Run(shell_handle); | |
| 59 } | |
| OLD | NEW |