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

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

Issue 1979723002: ApplicationConnection devolution, part 3. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 7 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
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 <memory> 5 #include <memory>
6 6
7 #include "examples/bank_app/bank.mojom.h" 7 #include "examples/bank_app/bank.mojom.h"
8 #include "mojo/common/binding_set.h" 8 #include "mojo/common/binding_set.h"
9 #include "mojo/public/c/system/main.h" 9 #include "mojo/public/c/system/main.h"
10 #include "mojo/public/cpp/application/application_connection.h" 10 #include "mojo/public/cpp/application/application_connection.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 public: 49 public:
50 BankApp() {} 50 BankApp() {}
51 51
52 void Initialize(mojo::ApplicationImpl* app) override { 52 void Initialize(mojo::ApplicationImpl* app) override {
53 mojo::ConnectToService(app->shell(), "mojo:principal_service", 53 mojo::ConnectToService(app->shell(), "mojo:principal_service",
54 GetProxy(&login_service_)); 54 GetProxy(&login_service_));
55 } 55 }
56 56
57 // From ApplicationDelegate 57 // From ApplicationDelegate
58 bool ConfigureIncomingConnection( 58 bool ConfigureIncomingConnection(
59 mojo::ApplicationConnection* connection) override { 59 mojo::ServiceProviderImpl* service_provider_impl) override {
60 std::string url = 60 std::string url = service_provider_impl->connection_context().remote_url;
61 connection->GetServiceProviderImpl().connection_context().remote_url;
62 if (url.length() > 0) { 61 if (url.length() > 0) {
63 vanadium::AppInstanceNamePtr app(vanadium::AppInstanceName::New()); 62 vanadium::AppInstanceNamePtr app(vanadium::AppInstanceName::New());
64 app->url = url; 63 app->url = url;
65 std::string user; 64 std::string user;
66 login_service_->GetUser(app.Pass(), BankUser(&user)); 65 login_service_->GetUser(app.Pass(), BankUser(&user));
67 // Check and see whether we got a valid user blessing. 66 // Check and see whether we got a valid user blessing.
68 if (!login_service_.WaitForIncomingResponse()) { 67 if (!login_service_.WaitForIncomingResponse()) {
69 MOJO_LOG(INFO) << "Failed to get a valid user blessing"; 68 MOJO_LOG(INFO) << "Failed to get a valid user blessing";
70 return false; 69 return false;
71 } 70 }
72 // Record user access to the bank and reject customers that 71 // Record user access to the bank and reject customers that
73 // don't have a user identity. 72 // don't have a user identity.
74 if (user.empty()) { 73 if (user.empty()) {
75 MOJO_LOG(INFO) << "Rejecting customer without a user identity"; 74 MOJO_LOG(INFO) << "Rejecting customer without a user identity";
76 return false; 75 return false;
77 } 76 }
78 MOJO_LOG(INFO) << "Customer " << user << " accessing bank"; 77 MOJO_LOG(INFO) << "Customer " << user << " accessing bank";
79 } 78 }
80 connection->GetServiceProviderImpl().AddService<Bank>( 79 service_provider_impl->AddService<Bank>(
81 [this](const mojo::ConnectionContext& connection_context, 80 [this](const mojo::ConnectionContext& connection_context,
82 mojo::InterfaceRequest<Bank> bank_request) { 81 mojo::InterfaceRequest<Bank> bank_request) {
83 bindings_.AddBinding(&bank_impl_, bank_request.Pass()); 82 bindings_.AddBinding(&bank_impl_, bank_request.Pass());
84 }); 83 });
85 return true; 84 return true;
86 } 85 }
87 86
88 private: 87 private:
89 BankImpl bank_impl_; 88 BankImpl bank_impl_;
90 mojo::BindingSet<Bank> bindings_; 89 mojo::BindingSet<Bank> bindings_;
91 vanadium::PrincipalServicePtr login_service_; 90 vanadium::PrincipalServicePtr login_service_;
92 }; 91 };
93 92
94 } // namespace examples 93 } // namespace examples
95 94
96 MojoResult MojoMain(MojoHandle application_request) { 95 MojoResult MojoMain(MojoHandle application_request) {
97 mojo::ApplicationRunner runner( 96 mojo::ApplicationRunner runner(
98 std::unique_ptr<examples::BankApp>(new examples::BankApp())); 97 std::unique_ptr<examples::BankApp>(new examples::BankApp()));
99 return runner.Run(application_request); 98 return runner.Run(application_request);
100 } 99 }
OLDNEW
« no previous file with comments | « examples/apptest/example_service_application.cc ('k') | examples/content_handler_demo/content_handler_demo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698