Chromium Code Reviews| Index: services/nacl/pnacl_link.cc |
| diff --git a/services/nacl/pnacl_link.cc b/services/nacl/pnacl_link.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..92f37ff092e18a58f8e25a36509c2fe4a69d876c |
| --- /dev/null |
| +++ b/services/nacl/pnacl_link.cc |
| @@ -0,0 +1,84 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <fcntl.h> |
| + |
| +#include "base/files/file_util.h" |
| +#include "mojo/nacl/nonsfi/irt_mojo_nonsfi.h" |
| +#include "mojo/nacl/nonsfi/nexe_launcher_nonsfi.h" |
| +#include "mojo/public/c/system/main.h" |
| +#include "mojo/public/cpp/application/application_connection.h" |
| +#include "mojo/public/cpp/application/application_delegate.h" |
| +#include "mojo/public/cpp/application/application_impl.h" |
| +#include "mojo/public/cpp/application/application_runner.h" |
| +#include "mojo/public/cpp/application/interface_factory.h" |
| +#include "mojo/public/cpp/bindings/strong_binding.h" |
| +#include "services/nacl/pnacl_link.mojom.h" |
| +#include "url/gurl.h" |
| + |
| +namespace mojo { |
| +namespace nacl { |
| + |
| +class PexeLinkerImpl : public PexeLinkerInit { |
| + public: |
| + void PexeLinkerStart(ScopedMessagePipeHandle handle) override { |
| + std::string path = GetBasePath(); |
| + ::nacl::MojoSetBasePath(path); |
| + path.append("pnacl_translation_files/ld.nexe"); |
| + int nexe_fd = open(path.c_str(), O_RDONLY); |
| + if (nexe_fd < 0) |
| + LOG(FATAL) << "Could not open linker nexe: " << path; |
| + ::nacl::MojoLaunchNexeNonsfi(nexe_fd, |
| + handle.release().value(), |
| + true /* enable_translate_irt */); |
| + } |
| + private: |
| + 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
|
| +}; |
| + |
| +class StrongBindingPexeLinkerImpl : public PexeLinkerImpl { |
| + public: |
| + explicit StrongBindingPexeLinkerImpl(InterfaceRequest<PexeLinkerInit> request, |
| + std::string& base_path) |
| + : base_path_(base_path), strong_binding_(this, request.Pass()) {} |
| + |
| + private: |
| + std::string GetBasePath() override { return base_path_; } |
| + std::string base_path_; |
| + StrongBinding<PexeLinkerInit> strong_binding_; |
| +}; |
| + |
| +class MultiPexeLinker : public ApplicationDelegate, |
| + public InterfaceFactory<PexeLinkerInit> { |
| + public: |
| + MultiPexeLinker() {} |
| + |
| + // From ApplicationDelegate |
| + void Initialize(ApplicationImpl* app) override { |
| + std::string app_path = GURL(app->url()).GetContent(); |
| + base_path = app_path.substr(0, app_path.find_last_of("/") + 1); |
| + } |
| + |
| + // From ApplicationDelegate |
| + bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
| + connection->AddService<PexeLinkerInit>(this); |
| + return true; |
| + } |
| + |
| + // From InterfaceFactory |
| + void Create(ApplicationConnection* connection, |
| + InterfaceRequest<PexeLinkerInit> request) override { |
| + new StrongBindingPexeLinkerImpl(request.Pass(), base_path); |
| + } |
| + |
| + 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.
|
| +}; |
| + |
| +} // namespace nacl |
| +} // namespace mojo |
| + |
| +MojoResult MojoMain(MojoHandle application_request) { |
| + mojo::ApplicationRunner runner(new mojo::nacl::MultiPexeLinker()); |
| + return runner.Run(application_request); |
| +} |