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

Side by Side Diff: examples/bank_app/bank.cc

Issue 2012873003: More ApplicationDelegate/ApplicationRunner[Chromium] conversion. (Closed) Base URL: https://github.com/domokit/mojo.git@work791_run_app_options
Patch Set: Created 4 years, 7 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
« no previous file with comments | « no previous file | examples/bank_app/customer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory>
6
7 #include "examples/bank_app/bank.mojom.h" 5 #include "examples/bank_app/bank.mojom.h"
8 #include "mojo/common/binding_set.h" 6 #include "mojo/common/binding_set.h"
9 #include "mojo/public/c/system/main.h" 7 #include "mojo/public/c/system/main.h"
10 #include "mojo/public/cpp/application/application_delegate.h" 8 #include "mojo/public/cpp/application/application_impl_base.h"
11 #include "mojo/public/cpp/application/application_impl.h"
12 #include "mojo/public/cpp/application/application_runner.h"
13 #include "mojo/public/cpp/application/connect.h" 9 #include "mojo/public/cpp/application/connect.h"
10 #include "mojo/public/cpp/application/run_application.h"
14 #include "mojo/public/cpp/application/service_provider_impl.h" 11 #include "mojo/public/cpp/application/service_provider_impl.h"
15 #include "mojo/public/cpp/bindings/strong_binding.h" 12 #include "mojo/public/cpp/bindings/strong_binding.h"
16 #include "mojo/public/cpp/utility/run_loop.h" 13 #include "mojo/public/cpp/utility/run_loop.h"
17 #include "mojo/services/vanadium/security/interfaces/principal.mojom.h" 14 #include "mojo/services/vanadium/security/interfaces/principal.mojom.h"
18 15
19 namespace examples { 16 namespace examples {
20 17
21 using vanadium::PrincipalServicePtr; 18 using vanadium::PrincipalServicePtr;
22 19
23 class BankImpl : public Bank { 20 class BankImpl : public Bank {
(...skipping 14 matching lines...) Expand all
38 void Run(const vanadium::UserPtr& user) const { 35 void Run(const vanadium::UserPtr& user) const {
39 user_->clear(); 36 user_->clear();
40 if (user) { 37 if (user) {
41 *user_ = user->email; 38 *user_ = user->email;
42 } 39 }
43 } 40 }
44 private: 41 private:
45 std::string *user_; 42 std::string *user_;
46 }; 43 };
47 44
48 class BankApp : public mojo::ApplicationDelegate { 45 class BankApp : public mojo::ApplicationImplBase {
49 public: 46 public:
50 BankApp() {} 47 BankApp() {}
51 48
52 void Initialize(mojo::ApplicationImpl* app) override { 49 // ApplicationImplBase overrides:
53 mojo::ConnectToService(app->shell(), "mojo:principal_service", 50 void OnInitialize() override {
51 mojo::ConnectToService(shell(), "mojo:principal_service",
54 GetProxy(&login_service_)); 52 GetProxy(&login_service_));
55 } 53 }
56 54
57 // From ApplicationDelegate 55 bool OnAcceptConnection(
58 bool ConfigureIncomingConnection(
59 mojo::ServiceProviderImpl* service_provider_impl) override { 56 mojo::ServiceProviderImpl* service_provider_impl) override {
60 std::string url = service_provider_impl->connection_context().remote_url; 57 std::string url = service_provider_impl->connection_context().remote_url;
61 if (url.length() > 0) { 58 if (url.length() > 0) {
62 vanadium::AppInstanceNamePtr app(vanadium::AppInstanceName::New()); 59 vanadium::AppInstanceNamePtr app(vanadium::AppInstanceName::New());
63 app->url = url; 60 app->url = url;
64 std::string user; 61 std::string user;
65 login_service_->GetUser(app.Pass(), BankUser(&user)); 62 login_service_->GetUser(app.Pass(), BankUser(&user));
66 // Check and see whether we got a valid user blessing. 63 // Check and see whether we got a valid user blessing.
67 if (!login_service_.WaitForIncomingResponse()) { 64 if (!login_service_.WaitForIncomingResponse()) {
68 MOJO_LOG(INFO) << "Failed to get a valid user blessing"; 65 MOJO_LOG(INFO) << "Failed to get a valid user blessing";
(...skipping 17 matching lines...) Expand all
86 83
87 private: 84 private:
88 BankImpl bank_impl_; 85 BankImpl bank_impl_;
89 mojo::BindingSet<Bank> bindings_; 86 mojo::BindingSet<Bank> bindings_;
90 vanadium::PrincipalServicePtr login_service_; 87 vanadium::PrincipalServicePtr login_service_;
91 }; 88 };
92 89
93 } // namespace examples 90 } // namespace examples
94 91
95 MojoResult MojoMain(MojoHandle application_request) { 92 MojoResult MojoMain(MojoHandle application_request) {
96 mojo::ApplicationRunner runner( 93 examples::BankApp bank_app;
97 std::unique_ptr<examples::BankApp>(new examples::BankApp())); 94 return mojo::RunMainApplication(application_request, &bank_app);
98 return runner.Run(application_request);
99 } 95 }
OLDNEW
« no previous file with comments | « no previous file | examples/bank_app/customer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698