| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "mojo/application/application_runner_chromium.h" | |
| 6 #include "mojo/common/binding_set.h" | 5 #include "mojo/common/binding_set.h" |
| 7 #include "mojo/public/c/system/main.h" | 6 #include "mojo/public/c/system/main.h" |
| 8 #include "mojo/public/cpp/application/application_delegate.h" | 7 #include "mojo/public/cpp/application/application_impl_base.h" |
| 9 #include "mojo/public/cpp/application/application_impl.h" | |
| 10 #include "mojo/public/cpp/application/connect.h" | 8 #include "mojo/public/cpp/application/connect.h" |
| 9 #include "mojo/public/cpp/application/run_application.h" |
| 11 #include "mojo/public/cpp/application/service_provider_impl.h" | 10 #include "mojo/public/cpp/application/service_provider_impl.h" |
| 12 #include "mojo/public/cpp/bindings/strong_binding.h" | 11 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 13 #include "mojo/public/cpp/system/macros.h" | 12 #include "mojo/public/cpp/system/macros.h" |
| 14 #include "mojo/services/authentication/interfaces/authentication.mojom.h" | 13 #include "mojo/services/authentication/interfaces/authentication.mojom.h" |
| 15 #include "mojo/services/network/interfaces/network_service.mojom.h" | 14 #include "mojo/services/network/interfaces/network_service.mojom.h" |
| 16 #include "services/authentication/google_authentication_impl.h" | 15 #include "services/authentication/google_authentication_impl.h" |
| 17 | 16 |
| 18 namespace authentication { | 17 namespace authentication { |
| 19 | 18 |
| 20 class GoogleAccountManagerApp : public mojo::ApplicationDelegate { | 19 class GoogleAccountManagerApp : public mojo::ApplicationImplBase { |
| 21 public: | 20 public: |
| 22 GoogleAccountManagerApp() {} | 21 GoogleAccountManagerApp() {} |
| 23 ~GoogleAccountManagerApp() override {} | 22 ~GoogleAccountManagerApp() override {} |
| 24 | 23 |
| 25 void Initialize(mojo::ApplicationImpl* app) override { | 24 void OnInitialize() override { |
| 26 mojo::ConnectToService(app->shell(), "mojo:network_service", | 25 mojo::ConnectToService(shell(), "mojo:network_service", |
| 27 GetProxy(&network_service_)); | 26 GetProxy(&network_service_)); |
| 28 mojo::ConnectToService(app->shell(), "mojo:files", GetProxy(&files_)); | 27 mojo::ConnectToService(shell(), "mojo:files", GetProxy(&files_)); |
| 29 | |
| 30 app_url_ = app->url(); | |
| 31 } | 28 } |
| 32 | 29 |
| 33 bool ConfigureIncomingConnection( | 30 bool OnAcceptConnection( |
| 34 mojo::ServiceProviderImpl* service_provider_impl) override { | 31 mojo::ServiceProviderImpl* service_provider_impl) override { |
| 35 service_provider_impl->AddService<AuthenticationService>( | 32 service_provider_impl->AddService<AuthenticationService>( |
| 36 [this](const mojo::ConnectionContext& connection_context, | 33 [this](const mojo::ConnectionContext& connection_context, |
| 37 mojo::InterfaceRequest<AuthenticationService> request) { | 34 mojo::InterfaceRequest<AuthenticationService> request) { |
| 38 mojo::files::Error error = mojo::files::Error::INTERNAL; | 35 mojo::files::Error error = mojo::files::Error::INTERNAL; |
| 39 mojo::files::DirectoryPtr directory; | 36 mojo::files::DirectoryPtr directory; |
| 40 files_->OpenFileSystem("app_persistent_cache", GetProxy(&directory), | 37 files_->OpenFileSystem("app_persistent_cache", GetProxy(&directory), |
| 41 [&error](mojo::files::Error e) { error = e; }); | 38 [&error](mojo::files::Error e) { error = e; }); |
| 42 CHECK(files_.WaitForIncomingResponse()); | 39 CHECK(files_.WaitForIncomingResponse()); |
| 43 if (mojo::files::Error::OK != error) { | 40 if (mojo::files::Error::OK != error) { |
| 44 LOG(FATAL) << "Unable to initialize accounts DB"; | 41 LOG(FATAL) << "Unable to initialize accounts DB"; |
| 45 } | 42 } |
| 46 new authentication::GoogleAuthenticationServiceImpl( | 43 new authentication::GoogleAuthenticationServiceImpl( |
| 47 request.Pass(), app_url_, network_service_, directory); | 44 request.Pass(), url(), network_service_, directory); |
| 48 }); | 45 }); |
| 49 return true; | 46 return true; |
| 50 } | 47 } |
| 51 | 48 |
| 52 private: | 49 private: |
| 53 mojo::NetworkServicePtr network_service_; | 50 mojo::NetworkServicePtr network_service_; |
| 54 mojo::files::FilesPtr files_; | 51 mojo::files::FilesPtr files_; |
| 55 std::string app_url_; | |
| 56 | 52 |
| 57 DISALLOW_COPY_AND_ASSIGN(GoogleAccountManagerApp); | 53 DISALLOW_COPY_AND_ASSIGN(GoogleAccountManagerApp); |
| 58 }; | 54 }; |
| 59 | 55 |
| 60 } // namespace authentication | 56 } // namespace authentication |
| 61 | 57 |
| 62 MojoResult MojoMain(MojoHandle application_request) { | 58 MojoResult MojoMain(MojoHandle application_request) { |
| 63 mojo::ApplicationRunnerChromium runner( | 59 authentication::GoogleAccountManagerApp google_account_manager_app; |
| 64 new authentication::GoogleAccountManagerApp()); | 60 return mojo::RunMainApplication(application_request, |
| 65 return runner.Run(application_request); | 61 &google_account_manager_app); |
| 66 } | 62 } |
| OLD | NEW |