| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |