Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: services/nacl/pnacl_compile.cc

Issue 1382713002: Creating a pexe content handler to translate and run pexes. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Response to Code reviews Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/nexe_launcher_nonsfi.h"
9 #include "mojo/public/c/system/main.h"
10 #include "mojo/public/cpp/application/application_connection.h"
11 #include "mojo/public/cpp/application/application_delegate.h"
12 #include "mojo/public/cpp/application/application_impl.h"
13 #include "mojo/public/cpp/application/application_runner.h"
14 #include "mojo/public/cpp/application/interface_factory.h"
15 #include "mojo/public/cpp/bindings/strong_binding.h"
16 #include "services/nacl/pnacl_compile.mojom.h"
17 #include "url/gurl.h"
18
19 namespace mojo {
20 namespace nacl {
21
22 class PexeCompilerImpl : public PexeCompilerInit {
23 public:
24 void PexeCompilerStart(ScopedMessagePipeHandle handle) override {
25 std::string path = GetBasePath();
26 path.append("pnacl_translation_files/pnacl-llc.nexe");
27 int nexe_fd = open(path.c_str(), O_RDONLY);
28 if (nexe_fd < 0)
29 LOG(FATAL) << "Could not open compiler nexe: " << path;
30 ::nacl::MojoLaunchNexeNonsfi(nexe_fd,
31 handle.release().value(),
32 true /* enable_translate_irt */);
33 }
34 private:
35 virtual std::string GetBasePath() { return ""; }
36 };
37
38 class StrongBindingPexeCompilerImpl : public PexeCompilerImpl {
39 public:
40 explicit StrongBindingPexeCompilerImpl(InterfaceRequest<PexeCompilerInit>
41 request, std::string& base_path)
42 : base_path_(base_path), strong_binding_(this, request.Pass()) {}
43
44 private:
45 std::string GetBasePath() override { return base_path_; }
46 std::string base_path_;
47 StrongBinding<PexeCompilerInit> strong_binding_;
48 };
49
50 class MultiPexeCompiler : public ApplicationDelegate,
51 public InterfaceFactory<PexeCompilerInit> {
52 public:
53 MultiPexeCompiler() {}
54
55 // From ApplicationDelegate
56 void Initialize(ApplicationImpl* app) override {
57 std::string app_path = GURL(app->url()).GetContent();
58 base_path = app_path.substr(0, app_path.find_last_of("/") + 1);
59 }
60
61 // From ApplicationDelegate
62 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
63 connection->AddService<PexeCompilerInit>(this);
64 return true;
65 }
66
67 // From InterfaceFactory
68 void Create(ApplicationConnection* connection,
69 InterfaceRequest<PexeCompilerInit> request) override {
70 new StrongBindingPexeCompilerImpl(request.Pass(), base_path);
71 }
72
73 std::string base_path;
74 };
75
76 } // namespace nacl
77 } // namespace mojo
78
79 MojoResult MojoMain(MojoHandle application_request) {
80 mojo::ApplicationRunner runner(new mojo::nacl::MultiPexeCompiler());
81 return runner.Run(application_request);
82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698