Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: examples/http_handler/http_handler.cc

Issue 715153004: Add support for HTTP handlers that are in self-contained apps. Also add an example app. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: review comments Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #include "services/http_server/public/http_server_util.h"
15
16 namespace mojo {
17 namespace examples {
18
19 // This is an example of a self-contained HTTP handler. It uses the HTTP Server
20 // service to handle the HTTP protocol details, and just contains the logic for
21 // handling its registered urls.
22 class HttpHandler : public ApplicationDelegate,
23 public HttpServerClient {
24 public:
25 HttpHandler() {}
26 ~HttpHandler() override {}
27
28 private:
29 // ApplicationDelegate:
30 void Initialize(ApplicationImpl* app) override {
31 app->ConnectToService("mojo:http_server", &http_server_service_);
32
33 http_server_service_.set_client(this);
34 http_server_service_->AddHandler(
35 "/test",
36 base::Bind(&HttpHandler::AddHandlerCallback, base::Unretained(this)));
37 }
38
39 // HttpServerClient:
40 void OnHandleRequest(
41 HttpRequestPtr request,
42 const Callback<void(HttpResponsePtr)>& callback) override {
43 callback.Run(CreateHttpResponse(200, "Hello World"));
44 }
45
46 void AddHandlerCallback(bool result) {
47 CHECK(result);
48 }
49
50 HttpServerServicePtr http_server_service_;
51
52 DISALLOW_COPY_AND_ASSIGN(HttpHandler);
53 };
54
55 } // namespace examples
56 } // namespace mojo
57
58 MojoResult MojoMain(MojoHandle shell_handle) {
59 mojo::ApplicationRunnerChromium runner(new mojo::examples::HttpHandler());
60 return runner.Run(shell_handle);
61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698