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_link.mojom.h" | |
18 | |
19 namespace mojo { | |
20 namespace nacl { | |
21 | |
22 class PexeLinkerImpl : public PexeLinkerInit { | |
23 public: | |
24 void PexeLinkerStart(ScopedMessagePipeHandle handle) override { | |
25 base::FilePath path; | |
26 if (!PathService::Get(base::DIR_MODULE, &path)) | |
27 LOG(FATAL) << "Could not find mojo root directory"; | |
28 path = path.Append("pnacl_translation_files/ld.nexe"); | |
29 int nexe_fd = open(path.value().c_str(), O_RDONLY); | |
30 if (nexe_fd < 0) | |
31 LOG(FATAL) << "Could not open linker nexe: " << path.value(); | |
32 ::nacl::MojoLaunchNexeNonsfi(nexe_fd, | |
33 handle.release().value(), | |
34 true /* enable_translate_irt */); | |
35 } | |
36 }; | |
37 | |
38 class StrongBindingPexeLinkerImpl : public PexeLinkerImpl { | |
39 public: | |
40 explicit StrongBindingPexeLinkerImpl(InterfaceRequest<PexeLinkerInit> request) | |
41 : strong_binding_(this, request.Pass()) {} | |
42 | |
43 private: | |
44 StrongBinding<PexeLinkerInit> strong_binding_; | |
45 }; | |
46 | |
47 class MultiPexeLinker : public ApplicationDelegate, | |
48 public InterfaceFactory<PexeLinkerInit> { | |
49 public: | |
50 MultiPexeLinker() {} | |
51 | |
52 // From ApplicationDelegate | |
53 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | |
54 connection->AddService<PexeLinkerInit>(this); | |
55 return true; | |
56 } | |
57 | |
58 // From InterfaceFactory | |
59 void Create(ApplicationConnection* connection, | |
60 InterfaceRequest<PexeLinkerInit> request) override { | |
61 new StrongBindingPexeLinkerImpl(request.Pass()); | |
62 } | |
63 }; | |
64 | |
65 } // namespace nacl | |
66 } // namespace mojo | |
67 | |
68 MojoResult MojoMain(MojoHandle application_request) { | |
69 base::AtExitManager at_exit; | |
jamesr
2015/11/02 23:00:02
what needs a base::AtExitManager? mojo::Applicatio
Sean Klein
2015/11/03 14:31:01
The base::AtExitManager is needed for the call to
| |
70 mojo::ApplicationRunner runner(new mojo::nacl::MultiPexeLinker()); | |
71 return runner.Run(application_request); | |
72 } | |
OLD | NEW |