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

Side by Side Diff: shell/test/pingable_app.cc

Issue 943053003: Simple multi-url support for mojo apps (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: hate Created 5 years, 9 months 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 2015 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 "mojo/public/c/system/main.h"
6 #include "mojo/public/cpp/application/application_delegate.h"
7 #include "mojo/public/cpp/application/application_impl.h"
8 #include "mojo/public/cpp/application/application_runner.h"
9 #include "mojo/public/cpp/application/interface_factory.h"
10 #include "mojo/public/cpp/bindings/callback.h"
11 #include "mojo/public/cpp/bindings/interface_request.h"
12 #include "mojo/public/cpp/bindings/strong_binding.h"
13 #include "shell/test/pingable.mojom.h"
14
15 namespace mojo {
16
17 class PingableImpl : public Pingable {
18 public:
19 PingableImpl(InterfaceRequest<Pingable> request, const std::string& app_url)
20 : binding_(this, request.Pass()), app_url_(app_url) {}
21
22 ~PingableImpl() override {}
23
24 private:
25 void Ping(const String& message,
26 const Callback<void(String, String)>& callback) override {
27 callback.Run(app_url_, message);
28 }
29
30 StrongBinding<Pingable> binding_;
31 std::string app_url_;
32 };
33
34 class PingableApp : public mojo::ApplicationDelegate,
35 public mojo::InterfaceFactory<Pingable> {
36 public:
37 PingableApp() {}
38 ~PingableApp() {}
39
40 private:
41 // ApplicationDelegate:
42 void Initialize(ApplicationImpl* impl) override { app_url_ = impl->url(); }
43
44 bool ConfigureIncomingConnection(
45 mojo::ApplicationConnection* connection,
46 const std::string& url) override {
47 connection->AddService(this);
48 return true;
49 }
50
51 // InterfaceFactory<Pingable>:
52 void Create(mojo::ApplicationConnection* connection,
53 mojo::InterfaceRequest<Pingable> request) override {
54 new PingableImpl(request.Pass(), app_url_);
55 }
56
57 std::string app_url_;
58 };
59
60 } // namespace mojo
61
62 MojoResult MojoMain(MojoHandle shell_handle) {
63 mojo::ApplicationRunner runner(new mojo::PingableApp);
64 return runner.Run(shell_handle);
65 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698