OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <memory> | 5 #include <memory> |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "mojo/nacl/nonsfi/file_util.h" | 8 #include "mojo/nacl/nonsfi/file_util.h" |
9 #include "mojo/nacl/nonsfi/nexe_launcher_nonsfi.h" | 9 #include "mojo/nacl/nonsfi/nexe_launcher_nonsfi.h" |
10 #include "mojo/public/c/system/main.h" | 10 #include "mojo/public/c/system/main.h" |
11 #include "mojo/public/cpp/application/application_connection.h" | 11 #include "mojo/public/cpp/application/application_connection.h" |
12 #include "mojo/public/cpp/application/application_delegate.h" | 12 #include "mojo/public/cpp/application/application_delegate.h" |
13 #include "mojo/public/cpp/application/application_runner.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" | 14 #include "mojo/public/cpp/bindings/strong_binding.h" |
16 #include "services/nacl/nonsfi/kLdNexe.h" | 15 #include "services/nacl/nonsfi/kLdNexe.h" |
17 #include "services/nacl/nonsfi/pnacl_link.mojom.h" | 16 #include "services/nacl/nonsfi/pnacl_link.mojom.h" |
18 | 17 |
19 namespace mojo { | 18 namespace mojo { |
20 namespace nacl { | 19 namespace nacl { |
21 | 20 |
22 class PexeLinkerImpl : public PexeLinkerInit { | 21 class PexeLinkerImpl : public PexeLinkerInit { |
23 public: | 22 public: |
24 void PexeLinkerStart(InterfaceRequest<PexeLinker> linker_request) override { | 23 void PexeLinkerStart(InterfaceRequest<PexeLinker> linker_request) override { |
25 int nexe_fd = ::nacl::DataToTempFileDescriptor(::nacl::kLdNexe); | 24 int nexe_fd = ::nacl::DataToTempFileDescriptor(::nacl::kLdNexe); |
26 CHECK(nexe_fd >= 0) << "Could not open linker nexe"; | 25 CHECK(nexe_fd >= 0) << "Could not open linker nexe"; |
27 ::nacl::MojoLaunchNexeNonsfi( | 26 ::nacl::MojoLaunchNexeNonsfi( |
28 nexe_fd, linker_request.PassMessagePipe().release().value(), | 27 nexe_fd, linker_request.PassMessagePipe().release().value(), |
29 true /* enable_translate_irt */); | 28 true /* enable_translate_irt */); |
30 } | 29 } |
31 }; | 30 }; |
32 | 31 |
33 class StrongBindingPexeLinkerImpl : public PexeLinkerImpl { | 32 class StrongBindingPexeLinkerImpl : public PexeLinkerImpl { |
34 public: | 33 public: |
35 explicit StrongBindingPexeLinkerImpl(InterfaceRequest<PexeLinkerInit> request) | 34 explicit StrongBindingPexeLinkerImpl(InterfaceRequest<PexeLinkerInit> request) |
36 : strong_binding_(this, request.Pass()) {} | 35 : strong_binding_(this, request.Pass()) {} |
37 | 36 |
38 private: | 37 private: |
39 StrongBinding<PexeLinkerInit> strong_binding_; | 38 StrongBinding<PexeLinkerInit> strong_binding_; |
40 }; | 39 }; |
41 | 40 |
42 class MultiPexeLinker : public ApplicationDelegate, | 41 class MultiPexeLinker : public ApplicationDelegate { |
43 public InterfaceFactory<PexeLinkerInit> { | |
44 public: | 42 public: |
45 MultiPexeLinker() {} | 43 MultiPexeLinker() {} |
46 | 44 |
47 // From ApplicationDelegate | 45 // From ApplicationDelegate |
48 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | 46 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
49 connection->AddService<PexeLinkerInit>(this); | 47 connection->GetServiceProviderImpl().AddService<PexeLinkerInit>( |
| 48 [](const ConnectionContext& connection_context, |
| 49 InterfaceRequest<PexeLinkerInit> request) { |
| 50 new StrongBindingPexeLinkerImpl(request.Pass()); |
| 51 }); |
50 return true; | 52 return true; |
51 } | 53 } |
52 | |
53 // From InterfaceFactory | |
54 void Create(const ConnectionContext& connection_context, | |
55 InterfaceRequest<PexeLinkerInit> request) override { | |
56 new StrongBindingPexeLinkerImpl(request.Pass()); | |
57 } | |
58 }; | 54 }; |
59 | 55 |
60 } // namespace nacl | 56 } // namespace nacl |
61 } // namespace mojo | 57 } // namespace mojo |
62 | 58 |
63 MojoResult MojoMain(MojoHandle application_request) { | 59 MojoResult MojoMain(MojoHandle application_request) { |
64 mojo::ApplicationRunner runner(std::unique_ptr<mojo::nacl::MultiPexeLinker>( | 60 mojo::ApplicationRunner runner(std::unique_ptr<mojo::nacl::MultiPexeLinker>( |
65 new mojo::nacl::MultiPexeLinker())); | 61 new mojo::nacl::MultiPexeLinker())); |
66 return runner.Run(application_request); | 62 return runner.Run(application_request); |
67 } | 63 } |
OLD | NEW |