| OLD | NEW | 
|    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  Loading... | 
|   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 } | 
| OLD | NEW |