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

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: Add a new example for user authorization 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
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..b71e38da4daea17a1e71bed4c979862179552728
--- /dev/null
+++ b/examples/bank_app/customer.cc
@@ -0,0 +1,47 @@
+// Copyright 2014 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_delegate.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 mojo {
+namespace examples {
+
+class BankCustomer : public ApplicationDelegate {
+ public:
+ void Initialize(ApplicationImpl* app) override {
+ // Get user login credentials
+ app->ConnectToService("mojo:principal_service", &login_service_);
+ login_service_->Login(PrincipalService::LoginCallback());
+
+ // Deposit some money and check the balance
+ app->ConnectToService("mojo:bank", &bank_);
+ bank_->Deposit(500/*usd*/);
+ bank_->Withdraw(100/*usd*/);
+ bank_->GetBalance(Bank::GetBalanceCallback());
+ }
+
+ void Quit() override {
+ login_service_->Logout();
+ }
+
+ private:
+ BankPtr bank_;
+ PrincipalServicePtr login_service_;
+};
+
+} // namespace examples
+} // namespace mojo
+
+MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ApplicationRunner runner(new mojo::examples::BankCustomer);
+ return runner.Run(application_request);
+}

Powered by Google App Engine
This is Rietveld 408576698