| 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 <fcntl.h> | 5 #include <fcntl.h> |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/sha1.h" | 8 #include "base/sha1.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "mojo/application/application_runner_chromium.h" | 10 #include "mojo/application/application_runner_chromium.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "mojo/services/files/interfaces/files.mojom.h" | 24 #include "mojo/services/files/interfaces/files.mojom.h" |
| 25 #include "services/nacl/nonsfi/pnacl_compile.mojom-sync.h" | 25 #include "services/nacl/nonsfi/pnacl_compile.mojom-sync.h" |
| 26 #include "services/nacl/nonsfi/pnacl_link.mojom-sync.h" | 26 #include "services/nacl/nonsfi/pnacl_link.mojom-sync.h" |
| 27 | 27 |
| 28 namespace nacl { | 28 namespace nacl { |
| 29 namespace content_handler { | 29 namespace content_handler { |
| 30 | 30 |
| 31 class PexeContentHandler : public mojo::ApplicationDelegate, | 31 class PexeContentHandler : public mojo::ApplicationDelegate, |
| 32 public mojo::ContentHandlerFactory::Delegate { | 32 public mojo::ContentHandlerFactory::Delegate { |
| 33 public: | 33 public: |
| 34 PexeContentHandler() : content_handler_factory_(this) {} | 34 PexeContentHandler() {} |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 // Overridden from ApplicationDelegate: | 37 // Overridden from ApplicationDelegate: |
| 38 void Initialize(mojo::ApplicationImpl* app) override { | 38 void Initialize(mojo::ApplicationImpl* app) override { |
| 39 mojo::ConnectToService(app->shell(), "mojo:pnacl_compile", | 39 mojo::ConnectToService(app->shell(), "mojo:pnacl_compile", |
| 40 GetSynchronousProxy(&compiler_init_)); | 40 GetSynchronousProxy(&compiler_init_)); |
| 41 mojo::ConnectToService(app->shell(), "mojo:pnacl_link", | 41 mojo::ConnectToService(app->shell(), "mojo:pnacl_link", |
| 42 GetSynchronousProxy(&linker_init_)); | 42 GetSynchronousProxy(&linker_init_)); |
| 43 mojo::ConnectToService(app->shell(), "mojo:files", GetProxy(&files_)); | 43 mojo::ConnectToService(app->shell(), "mojo:files", GetProxy(&files_)); |
| 44 mojo::files::Error error = mojo::files::Error::INTERNAL; | 44 mojo::files::Error error = mojo::files::Error::INTERNAL; |
| 45 files_->OpenFileSystem("app_persistent_cache", | 45 files_->OpenFileSystem("app_persistent_cache", |
| 46 GetSynchronousProxy(&nexe_cache_directory_), | 46 GetSynchronousProxy(&nexe_cache_directory_), |
| 47 [&error](mojo::files::Error e) { error = e; }); | 47 [&error](mojo::files::Error e) { error = e; }); |
| 48 CHECK(files_.WaitForIncomingResponse()); | 48 CHECK(files_.WaitForIncomingResponse()); |
| 49 CHECK_EQ(mojo::files::Error::OK, error); | 49 CHECK_EQ(mojo::files::Error::OK, error); |
| 50 } | 50 } |
| 51 | 51 |
| 52 // Overridden from ApplicationDelegate: | 52 // Overridden from ApplicationDelegate: |
| 53 bool ConfigureIncomingConnection( | 53 bool ConfigureIncomingConnection( |
| 54 mojo::ServiceProviderImpl* service_provider_impl) override { | 54 mojo::ServiceProviderImpl* service_provider_impl) override { |
| 55 service_provider_impl->AddService<mojo::ContentHandler>( | 55 service_provider_impl->AddService<mojo::ContentHandler>( |
| 56 content_handler_factory_.GetInterfaceRequestHandler()); | 56 mojo::ContentHandlerFactory::GetInterfaceRequestHandler(this)); |
| 57 return true; | 57 return true; |
| 58 } | 58 } |
| 59 | 59 |
| 60 int AccessFileFromCache(std::string& digest) { | 60 int AccessFileFromCache(std::string& digest) { |
| 61 mojo::files::Error error = mojo::files::Error::INTERNAL; | 61 mojo::files::Error error = mojo::files::Error::INTERNAL; |
| 62 mojo::files::FilePtr nexe_cache_file; | 62 mojo::files::FilePtr nexe_cache_file; |
| 63 CHECK(nexe_cache_directory_->OpenFile(digest, GetProxy(&nexe_cache_file), | 63 CHECK(nexe_cache_directory_->OpenFile(digest, GetProxy(&nexe_cache_file), |
| 64 mojo::files::kOpenFlagRead, &error)); | 64 mojo::files::kOpenFlagRead, &error)); |
| 65 if (mojo::files::Error::OK == error) | 65 if (mojo::files::Error::OK == error) |
| 66 // Copy the mojo cached file into an open temporary file. | 66 // Copy the mojo cached file into an open temporary file. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 145 |
| 146 // Pass the handle connecting us with mojo_shell to the nexe. | 146 // Pass the handle connecting us with mojo_shell to the nexe. |
| 147 MojoHandle handle = application_request.PassMessagePipe().release().value(); | 147 MojoHandle handle = application_request.PassMessagePipe().release().value(); |
| 148 ::nacl::MojoLaunchNexeNonsfi(nexe_fd, handle, | 148 ::nacl::MojoLaunchNexeNonsfi(nexe_fd, handle, |
| 149 false /* enable_translation_irt */); | 149 false /* enable_translation_irt */); |
| 150 } | 150 } |
| 151 | 151 |
| 152 private: | 152 private: |
| 153 mojo::SynchronousInterfacePtr<mojo::files::Directory> nexe_cache_directory_; | 153 mojo::SynchronousInterfacePtr<mojo::files::Directory> nexe_cache_directory_; |
| 154 mojo::files::FilesPtr files_; | 154 mojo::files::FilesPtr files_; |
| 155 mojo::ContentHandlerFactory content_handler_factory_; | |
| 156 mojo::SynchronousInterfacePtr<mojo::nacl::PexeCompilerInit> compiler_init_; | 155 mojo::SynchronousInterfacePtr<mojo::nacl::PexeCompilerInit> compiler_init_; |
| 157 mojo::SynchronousInterfacePtr<mojo::nacl::PexeLinkerInit> linker_init_; | 156 mojo::SynchronousInterfacePtr<mojo::nacl::PexeLinkerInit> linker_init_; |
| 158 | 157 |
| 159 DISALLOW_COPY_AND_ASSIGN(PexeContentHandler); | 158 DISALLOW_COPY_AND_ASSIGN(PexeContentHandler); |
| 160 }; | 159 }; |
| 161 | 160 |
| 162 } // namespace content_handler | 161 } // namespace content_handler |
| 163 } // namespace nacl | 162 } // namespace nacl |
| 164 | 163 |
| 165 MojoResult MojoMain(MojoHandle application_request) { | 164 MojoResult MojoMain(MojoHandle application_request) { |
| 166 mojo::ApplicationRunnerChromium runner( | 165 mojo::ApplicationRunnerChromium runner( |
| 167 new nacl::content_handler::PexeContentHandler()); | 166 new nacl::content_handler::PexeContentHandler()); |
| 168 return runner.Run(application_request); | 167 return runner.Run(application_request); |
| 169 } | 168 } |
| OLD | NEW |