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

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

Issue 1418013004: Principal Service: Add support for multiple user accounts (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 1 month 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 "examples/bank_app/bank.mojom.h" 5 #include "examples/bank_app/bank.mojom.h"
6 #include "mojo/common/binding_set.h" 6 #include "mojo/common/binding_set.h"
7 #include "mojo/public/c/system/main.h" 7 #include "mojo/public/c/system/main.h"
8 #include "mojo/public/cpp/application/application_connection.h" 8 #include "mojo/public/cpp/application/application_connection.h"
9 #include "mojo/public/cpp/application/application_delegate.h" 9 #include "mojo/public/cpp/application/application_delegate.h"
10 #include "mojo/public/cpp/application/application_impl.h" 10 #include "mojo/public/cpp/application/application_impl.h"
(...skipping 15 matching lines...) Expand all
26 void GetBalance(const GetBalanceCallback& callback) override { 26 void GetBalance(const GetBalanceCallback& callback) override {
27 callback.Run(balance_); 27 callback.Run(balance_);
28 } 28 }
29 private: 29 private:
30 int32_t balance_; 30 int32_t balance_;
31 }; 31 };
32 32
33 class BankUser { 33 class BankUser {
34 public: 34 public:
35 explicit BankUser(std::string* user) : user_(user) { } 35 explicit BankUser(std::string* user) : user_(user) { }
36 void Run(const vanadium::BlessingPtr& b) const { 36 void Run(const vanadium::UserPtr& u) const {
jamesr 2015/10/28 21:45:51 our style guide says to avoid one-letter variable
ataly 2015/10/28 21:59:14 Ah, I see. Thanks for pointing that out. Done.
37 user_->clear(); 37 user_->clear();
38 if (b && b->chain.size() > 0) { 38 if (u) {
39 user_->append(b->chain[0]->extension); 39 user_->append(u->email);
40 for (size_t i = 1; i < b->chain.size(); i++) {
41 user_->append(vanadium::ChainSeparator);
42 user_->append(b->chain[i]->extension);
43 }
44 } 40 }
45 } 41 }
46 private: 42 private:
47 std::string *user_; 43 std::string *user_;
48 }; 44 };
49 45
50 class BankApp : public mojo::ApplicationDelegate, 46 class BankApp : public mojo::ApplicationDelegate,
51 public mojo::InterfaceFactory<Bank> { 47 public mojo::InterfaceFactory<Bank> {
52 public: 48 public:
53 BankApp() { 49 BankApp() {
54 } 50 }
55 void Initialize(mojo::ApplicationImpl* app) override { 51 void Initialize(mojo::ApplicationImpl* app) override {
56 app->ConnectToService("mojo:principal_service", &login_service_); 52 app->ConnectToService("mojo:principal_service", &login_service_);
57 } 53 }
58 54
59 // From ApplicationDelegate 55 // From ApplicationDelegate
60 bool ConfigureIncomingConnection( 56 bool ConfigureIncomingConnection(
61 mojo::ApplicationConnection* connection) override { 57 mojo::ApplicationConnection* connection) override {
62 std::string url = connection->GetRemoteApplicationURL(); 58 std::string url = connection->GetRemoteApplicationURL();
63 if (url.length() > 0) { 59 if (url.length() > 0) {
64 vanadium::AppInstanceNamePtr app(vanadium::AppInstanceName::New()); 60 vanadium::AppInstanceNamePtr app(vanadium::AppInstanceName::New());
65 app->url = url; 61 app->url = url;
66 std::string user; 62 std::string user;
67 login_service_->GetUserBlessing(app.Pass(), BankUser(&user)); 63 login_service_->GetUser(app.Pass(), BankUser(&user));
68 // Check and see whether we got a valid user blessing. 64 // Check and see whether we got a valid user blessing.
69 if (!login_service_.WaitForIncomingResponse()) { 65 if (!login_service_.WaitForIncomingResponse()) {
70 MOJO_LOG(INFO) << "Failed to get a valid user blessing"; 66 MOJO_LOG(INFO) << "Failed to get a valid user blessing";
71 return false; 67 return false;
72 } 68 }
73 // Record user access to the bank and reject customers that 69 // Record user access to the bank and reject customers that
74 // don't have a user identity. 70 // don't have a user identity.
75 if (user.empty()) { 71 if (user.empty()) {
76 MOJO_LOG(INFO) << "Rejecting customer without a user identity"; 72 MOJO_LOG(INFO) << "Rejecting customer without a user identity";
77 return false; 73 return false;
(...skipping 14 matching lines...) Expand all
92 mojo::BindingSet<Bank> bindings_; 88 mojo::BindingSet<Bank> bindings_;
93 vanadium::PrincipalServicePtr login_service_; 89 vanadium::PrincipalServicePtr login_service_;
94 }; 90 };
95 91
96 } // namespace examples 92 } // namespace examples
97 93
98 MojoResult MojoMain(MojoHandle application_request) { 94 MojoResult MojoMain(MojoHandle application_request) {
99 mojo::ApplicationRunner runner(new examples::BankApp()); 95 mojo::ApplicationRunner runner(new examples::BankApp());
100 return runner.Run(application_request); 96 return runner.Run(application_request);
101 } 97 }
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