Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <fcntl.h> | |
| 6 | |
| 7 #include "base/at_exit.h" | |
| 8 #include "base/files/file_util.h" | |
| 9 #include "base/path_service.h" | |
| 10 #include "mojo/nacl/nonsfi/nexe_launcher_nonsfi.h" | |
| 11 #include "mojo/public/c/system/main.h" | |
| 12 #include "mojo/public/cpp/application/application_connection.h" | |
| 13 #include "mojo/public/cpp/application/application_delegate.h" | |
| 14 #include "mojo/public/cpp/application/application_runner.h" | |
| 15 #include "mojo/public/cpp/application/interface_factory.h" | |
| 16 #include "mojo/public/cpp/bindings/strong_binding.h" | |
| 17 #include "services/nacl/pnacl_compile.mojom.h" | |
| 18 | |
| 19 namespace mojo { | |
| 20 namespace nacl { | |
| 21 | |
| 22 class PexeCompilerImpl : public PexeCompilerInit { | |
| 23 public: | |
| 24 void PexeCompilerStart(ScopedMessagePipeHandle handle) override { | |
| 25 base::FilePath base_path; | |
| 26 PathService::Get(base::DIR_MODULE, &base_path); | |
|
Mark Seaborn
2015/10/28 21:53:01
Ideally should check for failure here.
Sean Klein
2015/10/28 22:22:16
Done.
| |
| 27 std::string path = base_path.value(); | |
| 28 path.append("/pnacl_translation_files/pnacl-llc.nexe"); | |
| 29 int nexe_fd = open(path.c_str(), O_RDONLY); | |
| 30 if (nexe_fd < 0) | |
| 31 LOG(FATAL) << "Could not open compiler nexe: " << path; | |
| 32 ::nacl::MojoLaunchNexeNonsfi(nexe_fd, | |
| 33 handle.release().value(), | |
| 34 true /* enable_translate_irt */); | |
| 35 } | |
| 36 }; | |
| 37 | |
| 38 class StrongBindingPexeCompilerImpl : public PexeCompilerImpl { | |
| 39 public: | |
| 40 explicit StrongBindingPexeCompilerImpl(InterfaceRequest<PexeCompilerInit> | |
| 41 request) | |
| 42 : strong_binding_(this, request.Pass()) {} | |
| 43 | |
| 44 private: | |
| 45 StrongBinding<PexeCompilerInit> strong_binding_; | |
| 46 }; | |
| 47 | |
| 48 class MultiPexeCompiler : public ApplicationDelegate, | |
| 49 public InterfaceFactory<PexeCompilerInit> { | |
| 50 public: | |
| 51 MultiPexeCompiler() {} | |
| 52 | |
| 53 // From ApplicationDelegate | |
| 54 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | |
| 55 connection->AddService<PexeCompilerInit>(this); | |
| 56 return true; | |
| 57 } | |
| 58 | |
| 59 // From InterfaceFactory | |
| 60 void Create(ApplicationConnection* connection, | |
| 61 InterfaceRequest<PexeCompilerInit> request) override { | |
| 62 new StrongBindingPexeCompilerImpl(request.Pass()); | |
| 63 } | |
| 64 }; | |
| 65 | |
| 66 } // namespace nacl | |
| 67 } // namespace mojo | |
| 68 | |
| 69 MojoResult MojoMain(MojoHandle application_request) { | |
| 70 base::AtExitManager at_exit; | |
| 71 mojo::ApplicationRunner runner(new mojo::nacl::MultiPexeCompiler()); | |
| 72 return runner.Run(application_request); | |
| 73 } | |
| OLD | NEW |