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

Side by Side Diff: services/nacl/nonsfi/content_handler_main_nexe.cc

Issue 1993053002: Simplify ContentHandlerFactory a bit. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 7 months 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
« no previous file with comments | « services/js/content_handler_main.cc ('k') | services/nacl/nonsfi/content_handler_main_pexe.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <fcntl.h> 5 #include <fcntl.h>
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "mojo/application/application_runner_chromium.h" 8 #include "mojo/application/application_runner_chromium.h"
9 #include "mojo/application/content_handler_factory.h" 9 #include "mojo/application/content_handler_factory.h"
10 #include "mojo/data_pipe_utils/data_pipe_utils.h" 10 #include "mojo/data_pipe_utils/data_pipe_utils.h"
11 #include "mojo/message_pump/message_pump_mojo.h" 11 #include "mojo/message_pump/message_pump_mojo.h"
12 #include "mojo/nacl/nonsfi/nexe_launcher_nonsfi.h" 12 #include "mojo/nacl/nonsfi/nexe_launcher_nonsfi.h"
13 #include "mojo/public/c/system/main.h" 13 #include "mojo/public/c/system/main.h"
14 #include "mojo/public/cpp/application/application_delegate.h" 14 #include "mojo/public/cpp/application/application_delegate.h"
15 #include "mojo/public/cpp/application/application_impl.h" 15 #include "mojo/public/cpp/application/application_impl.h"
16 16
17 namespace nacl { 17 namespace nacl {
18 namespace content_handler { 18 namespace content_handler {
19 19
20 class NaClContentHandler : public mojo::ApplicationDelegate, 20 class NaClContentHandler : public mojo::ApplicationDelegate,
21 public mojo::ContentHandlerFactory::Delegate { 21 public mojo::ContentHandlerFactory::Delegate {
22 public: 22 public:
23 NaClContentHandler() : content_handler_factory_(this) {} 23 NaClContentHandler() {}
24 24
25 private: 25 private:
26 // Overridden from ApplicationDelegate: 26 // Overridden from ApplicationDelegate:
27 void Initialize(mojo::ApplicationImpl* app) override {} 27 void Initialize(mojo::ApplicationImpl* app) override {}
28 28
29 // Overridden from ApplicationDelegate: 29 // Overridden from ApplicationDelegate:
30 bool ConfigureIncomingConnection( 30 bool ConfigureIncomingConnection(
31 mojo::ServiceProviderImpl* service_provider_impl) override { 31 mojo::ServiceProviderImpl* service_provider_impl) override {
32 service_provider_impl->AddService<mojo::ContentHandler>( 32 service_provider_impl->AddService<mojo::ContentHandler>(
33 content_handler_factory_.GetInterfaceRequestHandler()); 33 mojo::ContentHandlerFactory::GetInterfaceRequestHandler(this));
34 return true; 34 return true;
35 } 35 }
36 36
37 // Overridden from ContentHandlerFactory::Delegate: 37 // Overridden from ContentHandlerFactory::Delegate:
38 void RunApplication( 38 void RunApplication(
39 mojo::InterfaceRequest<mojo::Application> application_request, 39 mojo::InterfaceRequest<mojo::Application> application_request,
40 mojo::URLResponsePtr response) override { 40 mojo::URLResponsePtr response) override {
41 // Needed to use Mojo interfaces on this thread. 41 // Needed to use Mojo interfaces on this thread.
42 base::MessageLoop loop(mojo::common::MessagePumpMojo::Create()); 42 base::MessageLoop loop(mojo::common::MessagePumpMojo::Create());
43 // Acquire the nexe. 43 // Acquire the nexe.
44 base::ScopedFILE nexe_fp = 44 base::ScopedFILE nexe_fp =
45 mojo::common::BlockingCopyToTempFile(response->body.Pass()); 45 mojo::common::BlockingCopyToTempFile(response->body.Pass());
46 CHECK(nexe_fp) << "Could not redirect nexe to temp file"; 46 CHECK(nexe_fp) << "Could not redirect nexe to temp file";
47 FILE* nexe_file_stream = nexe_fp.release(); 47 FILE* nexe_file_stream = nexe_fp.release();
48 int fd = fileno(nexe_file_stream); 48 int fd = fileno(nexe_file_stream);
49 CHECK_NE(fd, -1) << "Could not open the stream pointer's file descriptor"; 49 CHECK_NE(fd, -1) << "Could not open the stream pointer's file descriptor";
50 fd = dup(fd); 50 fd = dup(fd);
51 CHECK_NE(fd, -1) << "Could not dup the file descriptor"; 51 CHECK_NE(fd, -1) << "Could not dup the file descriptor";
52 CHECK_EQ(fclose(nexe_file_stream), 0) << "Failed to close temp file"; 52 CHECK_EQ(fclose(nexe_file_stream), 0) << "Failed to close temp file";
53 53
54 MojoHandle handle = 54 MojoHandle handle =
55 application_request.PassMessagePipe().release().value(); 55 application_request.PassMessagePipe().release().value();
56 // MojoLaunchNexeNonsfi takes ownership of the fd. 56 // MojoLaunchNexeNonsfi takes ownership of the fd.
57 MojoLaunchNexeNonsfi(fd, handle, false /* enable_translation_irt */); 57 MojoLaunchNexeNonsfi(fd, handle, false /* enable_translation_irt */);
58 } 58 }
59 59
60 mojo::ContentHandlerFactory content_handler_factory_;
61
62 DISALLOW_COPY_AND_ASSIGN(NaClContentHandler); 60 DISALLOW_COPY_AND_ASSIGN(NaClContentHandler);
63 }; 61 };
64 62
65 } // namespace content_handler 63 } // namespace content_handler
66 } // namespace nacl 64 } // namespace nacl
67 65
68 MojoResult MojoMain(MojoHandle application_request) { 66 MojoResult MojoMain(MojoHandle application_request) {
69 mojo::ApplicationRunnerChromium runner( 67 mojo::ApplicationRunnerChromium runner(
70 new nacl::content_handler::NaClContentHandler()); 68 new nacl::content_handler::NaClContentHandler());
71 return runner.Run(application_request); 69 return runner.Run(application_request);
72 } 70 }
OLDNEW
« no previous file with comments | « services/js/content_handler_main.cc ('k') | services/nacl/nonsfi/content_handler_main_pexe.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698