| Index: services/nacl/pnacl_compile.cc
|
| diff --git a/services/nacl/pnacl_compile.cc b/services/nacl/pnacl_compile.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ebe7738810dff95b7ccc543edc7132a02f11e28f
|
| --- /dev/null
|
| +++ b/services/nacl/pnacl_compile.cc
|
| @@ -0,0 +1,82 @@
|
| +// 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/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_compile.mojom.h"
|
| +#include "url/gurl.h"
|
| +
|
| +namespace mojo {
|
| +namespace nacl {
|
| +
|
| +class PexeCompilerImpl : public PexeCompilerInit {
|
| + public:
|
| + void PexeCompilerStart(ScopedMessagePipeHandle handle) override {
|
| + std::string path = GetBasePath();
|
| + path.append("pnacl_translation_files/pnacl-llc.nexe");
|
| + int nexe_fd = open(path.c_str(), O_RDONLY);
|
| + if (nexe_fd < 0)
|
| + LOG(FATAL) << "Could not open compiler nexe: " << path;
|
| + ::nacl::MojoLaunchNexeNonsfi(nexe_fd,
|
| + handle.release().value(),
|
| + true /* enable_translate_irt */);
|
| + }
|
| + private:
|
| + virtual std::string GetBasePath() { return ""; }
|
| +};
|
| +
|
| +class StrongBindingPexeCompilerImpl : public PexeCompilerImpl {
|
| + public:
|
| + explicit StrongBindingPexeCompilerImpl(InterfaceRequest<PexeCompilerInit>
|
| + 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<PexeCompilerInit> strong_binding_;
|
| +};
|
| +
|
| +class MultiPexeCompiler : public ApplicationDelegate,
|
| + public InterfaceFactory<PexeCompilerInit> {
|
| + public:
|
| + MultiPexeCompiler() {}
|
| +
|
| + // 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<PexeCompilerInit>(this);
|
| + return true;
|
| + }
|
| +
|
| + // From InterfaceFactory
|
| + void Create(ApplicationConnection* connection,
|
| + InterfaceRequest<PexeCompilerInit> request) override {
|
| + new StrongBindingPexeCompilerImpl(request.Pass(), base_path);
|
| + }
|
| +
|
| + std::string base_path;
|
| +};
|
| +
|
| +} // namespace nacl
|
| +} // namespace mojo
|
| +
|
| +MojoResult MojoMain(MojoHandle application_request) {
|
| + mojo::ApplicationRunner runner(new mojo::nacl::MultiPexeCompiler());
|
| + return runner.Run(application_request);
|
| +}
|
|
|