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/files/file_util.h" | |
| 8 #include "mojo/nacl/nonsfi/irt_mojo_nonsfi.h" | |
| 9 #include "mojo/nacl/nonsfi/nexe_launcher_nonsfi.h" | |
| 10 #include "mojo/public/c/system/main.h" | |
| 11 #include "mojo/public/cpp/application/application_connection.h" | |
| 12 #include "mojo/public/cpp/application/application_delegate.h" | |
| 13 #include "mojo/public/cpp/application/application_impl.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_link.mojom.h" | |
| 18 #include "url/gurl.h" | |
| 19 | |
| 20 namespace mojo { | |
| 21 namespace nacl { | |
| 22 | |
| 23 class PexeLinkerImpl : public PexeLinkerInit { | |
| 24 public: | |
| 25 void PexeLinkerStart(ScopedMessagePipeHandle handle) override { | |
| 26 std::string path = GetBasePath(); | |
| 27 ::nacl::MojoSetBasePath(path); | |
| 28 path.append("pnacl_translation_files/ld.nexe"); | |
| 29 int nexe_fd = open(path.c_str(), O_RDONLY); | |
| 30 if (nexe_fd < 0) | |
| 31 LOG(FATAL) << "Could not open linker nexe: " << path; | |
| 32 ::nacl::MojoLaunchNexeNonsfi(nexe_fd, | |
| 33 handle.release().value(), | |
| 34 true /* enable_translate_irt */); | |
| 35 } | |
| 36 private: | |
| 37 virtual std::string GetBasePath() { return ""; } | |
|
Mark Seaborn
2015/10/28 18:31:43
This could presumably be "virtual ... = 0"?
But I
Sean Klein
2015/10/28 21:39:59
Replaced with PathService, so this has been remove
| |
| 38 }; | |
| 39 | |
| 40 class StrongBindingPexeLinkerImpl : public PexeLinkerImpl { | |
| 41 public: | |
| 42 explicit StrongBindingPexeLinkerImpl(InterfaceRequest<PexeLinkerInit> request, | |
| 43 std::string& base_path) | |
| 44 : base_path_(base_path), strong_binding_(this, request.Pass()) {} | |
| 45 | |
| 46 private: | |
| 47 std::string GetBasePath() override { return base_path_; } | |
| 48 std::string base_path_; | |
| 49 StrongBinding<PexeLinkerInit> strong_binding_; | |
| 50 }; | |
| 51 | |
| 52 class MultiPexeLinker : public ApplicationDelegate, | |
| 53 public InterfaceFactory<PexeLinkerInit> { | |
| 54 public: | |
| 55 MultiPexeLinker() {} | |
| 56 | |
| 57 // From ApplicationDelegate | |
| 58 void Initialize(ApplicationImpl* app) override { | |
| 59 std::string app_path = GURL(app->url()).GetContent(); | |
| 60 base_path = app_path.substr(0, app_path.find_last_of("/") + 1); | |
| 61 } | |
| 62 | |
| 63 // From ApplicationDelegate | |
| 64 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | |
| 65 connection->AddService<PexeLinkerInit>(this); | |
| 66 return true; | |
| 67 } | |
| 68 | |
| 69 // From InterfaceFactory | |
| 70 void Create(ApplicationConnection* connection, | |
| 71 InterfaceRequest<PexeLinkerInit> request) override { | |
| 72 new StrongBindingPexeLinkerImpl(request.Pass(), base_path); | |
| 73 } | |
| 74 | |
| 75 std::string base_path; | |
|
Mark Seaborn
2015/10/28 18:31:43
This could be private.
Sean Klein
2015/10/28 21:39:59
Removed.
| |
| 76 }; | |
| 77 | |
| 78 } // namespace nacl | |
| 79 } // namespace mojo | |
| 80 | |
| 81 MojoResult MojoMain(MojoHandle application_request) { | |
| 82 mojo::ApplicationRunner runner(new mojo::nacl::MultiPexeLinker()); | |
| 83 return runner.Run(application_request); | |
| 84 } | |
| OLD | NEW |