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