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

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

Issue 1261403003: Initial skeletal implementation of the PrincipalService. Also, use the Login()/GetUserBlessing() (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: code-review comments Created 5 years, 4 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 | « examples/bank_app/bank.mojom ('k') | mojo/services/mojo_services.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stdio.h>
6
7 #include "examples/bank_app/bank.mojom.h"
8 #include "mojo/public/c/system/main.h"
9 #include "mojo/public/cpp/application/application_impl.h"
10 #include "mojo/public/cpp/application/application_runner.h"
11 #include "mojo/public/cpp/utility/run_loop.h"
12 #include "mojo/services/vanadium/security/public/interfaces/principal.mojom.h"
13
14 namespace examples {
15
16 class LoginHandler {
17 public:
18 void Run(const vanadium::BlessingPtr& b) const {
19 std::string user;
20 if (b) {
21 for (size_t i = 0; i < b->chain.size(); i++) {
22 user += vanadium::ChainSeparator;
23 user += b->chain[i]->extension;
24 }
25 }
26 if (!user.empty()) {
27 MOJO_LOG(INFO) << "Welcome: " << user;
28 }
29 }
30 };
31
32 class BankCustomer : public mojo::ApplicationDelegate {
33 public:
34 void Initialize(mojo::ApplicationImpl* app) override {
35 // Get user login credentials
36 app->ConnectToService("mojo:principal_service", &login_service_);
37 login_service_->Login(LoginHandler());
38 // Check and see whether we got a valid user blessing.
39 if (!login_service_.WaitForIncomingResponse()) {
40 MOJO_LOG(INFO) << "Login() to the principal service failed\n";
41 }
42 BankPtr bank;
43 app->ConnectToService("mojo:bank", &bank);
44 bank->Deposit(500/*usd*/);
45 bank->Withdraw(100/*usd*/);
46 auto gb_callback = [](const int32_t& balance) {
47 MOJO_LOG(INFO) << "Bank balance: " << balance;
48 };
49 bank->GetBalance(mojo::Callback<void(const int32_t&)>(gb_callback));
50 bank.WaitForIncomingResponse();
51 }
52 void Quit() override {
53 login_service_->Logout();
54 }
55 private:
56 vanadium::PrincipalServicePtr login_service_;
57 };
58
59 } // namespace examples
60
61 MojoResult MojoMain(MojoHandle application_request) {
62 mojo::ApplicationRunner runner(new examples::BankCustomer);
63 return runner.Run(application_request);
64 }
OLDNEW
« no previous file with comments | « examples/bank_app/bank.mojom ('k') | mojo/services/mojo_services.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698