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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « examples/bank_app/bank.mojom ('k') | mojo/services/mojo_services.gni » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/bank_app/customer.cc
diff --git a/examples/bank_app/customer.cc b/examples/bank_app/customer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ef0a950774cdab1f89953af3614726af2c89c5ba
--- /dev/null
+++ b/examples/bank_app/customer.cc
@@ -0,0 +1,64 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stdio.h>
+
+#include "examples/bank_app/bank.mojom.h"
+#include "mojo/public/c/system/main.h"
+#include "mojo/public/cpp/application/application_impl.h"
+#include "mojo/public/cpp/application/application_runner.h"
+#include "mojo/public/cpp/utility/run_loop.h"
+#include "mojo/services/vanadium/security/public/interfaces/principal.mojom.h"
+
+namespace examples {
+
+class LoginHandler {
+ public:
+ void Run(const vanadium::BlessingPtr& b) const {
+ std::string user;
+ if (b) {
+ for (size_t i = 0; i < b->chain.size(); i++) {
+ user += vanadium::ChainSeparator;
+ user += b->chain[i]->extension;
+ }
+ }
+ if (!user.empty()) {
+ MOJO_LOG(INFO) << "Welcome: " << user;
+ }
+ }
+};
+
+class BankCustomer : public mojo::ApplicationDelegate {
+ public:
+ void Initialize(mojo::ApplicationImpl* app) override {
+ // Get user login credentials
+ app->ConnectToService("mojo:principal_service", &login_service_);
+ login_service_->Login(LoginHandler());
+ // Check and see whether we got a valid user blessing.
+ if (!login_service_.WaitForIncomingResponse()) {
+ MOJO_LOG(INFO) << "Login() to the principal service failed\n";
+ }
+ BankPtr bank;
+ app->ConnectToService("mojo:bank", &bank);
+ bank->Deposit(500/*usd*/);
+ bank->Withdraw(100/*usd*/);
+ auto gb_callback = [](const int32_t& balance) {
+ MOJO_LOG(INFO) << "Bank balance: " << balance;
+ };
+ bank->GetBalance(mojo::Callback<void(const int32_t&)>(gb_callback));
+ bank.WaitForIncomingResponse();
+ }
+ void Quit() override {
+ login_service_->Logout();
+ }
+ private:
+ vanadium::PrincipalServicePtr login_service_;
+};
+
+} // namespace examples
+
+MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ApplicationRunner runner(new examples::BankCustomer);
+ return runner.Run(application_request);
+}
« 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