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

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: indentation 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
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
jamesr 2015/08/19 05:30:55 nit: no blank line needed here
gautham 2015/08/19 17:45:51 Done.
9 #include "mojo/public/c/system/main.h"
10 #include "mojo/public/cpp/application/application_impl.h"
11 #include "mojo/public/cpp/application/application_runner.h"
12 #include "mojo/public/cpp/utility/run_loop.h"
13 #include "mojo/services/vanadium/security/public/interfaces/principal.mojom.h"
14
15 namespace mojo {
jamesr 2015/08/19 05:30:55 drop the mojo namespace
gautham 2015/08/19 17:45:51 Done.
16 namespace examples {
17
18 using namespace vanadium;
jamesr 2015/08/19 05:30:55 ditto re using-declarations
gautham 2015/08/19 17:45:51 Done.
19
20 class LoginHandler {
21 public:
22 void Run(const BlessingPtr& b) const {
23 std::string user;
24 if (b) {
25 for (size_t i = 0; i < b->chain.size(); i++) {
26 user += "/";
27 user += b->chain[i]->extension;
28 }
29 }
30 if (!user.empty()) {
31 MOJO_LOG(INFO) << "Welcome: " << user;
32 }
33 RunLoop::current()->Quit(); // All done!
jamesr 2015/08/19 05:30:55 should the login callback quit? feels like this sh
gautham 2015/08/19 17:45:51 Your right. This should not quit. I thought I'd re
34 }
35 };
36
37 class BankCustomer : public ApplicationDelegate {
38 public:
39 void Initialize(ApplicationImpl* app) override {
40 // Get user login credentials
41 app->ConnectToService("mojo:principal_service", &login_service_);
42 login_service_->Login(LoginHandler());
43 login_service_.WaitForIncomingResponse();
jamesr 2015/08/19 05:30:55 check for failure
gautham 2015/08/19 17:45:51 Done.
44
45 BankPtr bank;
46 app->ConnectToService("mojo:bank", &bank);
47 bank->Deposit(500/*usd*/);
48 bank->Withdraw(100/*usd*/);
49 auto gb_callback = [](const int32_t& balance) {
50 MOJO_LOG(INFO) << "Bank balance: " << balance;
51 };
52 bank->GetBalance(Callback<void(const int32_t&)>(gb_callback));
jamesr 2015/08/19 05:30:54 does just GetBalance(gb_callback) not work? the ty
gautham 2015/08/19 17:45:51 ../../mojo/public/cpp/bindings/callback.h: In inst
53 bank.WaitForIncomingResponse();
54 }
55 void Quit() override {
56 login_service_->Logout();
57 }
58 private:
59 PrincipalServicePtr login_service_;
60 };
61
62 } // namespace examples
63 } // namespace mojo
64
65 MojoResult MojoMain(MojoHandle application_request) {
66 mojo::ApplicationRunner runner(new mojo::examples::BankCustomer);
67 return runner.Run(application_request);
68 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698