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

Side by Side Diff: services/nacl/sfi/content_handler_main.cc

Issue 2005103003: Add implementations of mojo::{Run,Terminate}[Main]Application() for "chromium". (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
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 "base/files/file_util.h" 5 #include "base/files/file_util.h"
6 #include "base/files/scoped_file.h" 6 #include "base/files/scoped_file.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "mojo/application/application_runner_chromium.h"
10 #include "mojo/application/content_handler_factory.h" 9 #include "mojo/application/content_handler_factory.h"
11 #include "mojo/data_pipe_utils/data_pipe_utils.h" 10 #include "mojo/data_pipe_utils/data_pipe_utils.h"
12 #include "mojo/message_pump/message_pump_mojo.h" 11 #include "mojo/message_pump/message_pump_mojo.h"
13 #include "mojo/nacl/sfi/nacl_bindings/monacl_sel_main.h" 12 #include "mojo/nacl/sfi/nacl_bindings/monacl_sel_main.h"
14 #include "mojo/public/c/system/main.h" 13 #include "mojo/public/c/system/main.h"
15 #include "mojo/public/cpp/application/application_delegate.h" 14 #include "mojo/public/cpp/application/application_impl_base.h"
16 #include "mojo/public/cpp/application/application_impl.h"
17 #include "mojo/public/cpp/application/connect.h" 15 #include "mojo/public/cpp/application/connect.h"
16 #include "mojo/public/cpp/application/run_application.h"
18 #include "mojo/public/cpp/application/service_provider_impl.h" 17 #include "mojo/public/cpp/application/service_provider_impl.h"
19 #include "mojo/services/network/interfaces/network_service.mojom.h" 18 #include "mojo/services/network/interfaces/network_service.mojom.h"
20 #include "mojo/services/network/interfaces/url_loader.mojom.h" 19 #include "mojo/services/network/interfaces/url_loader.mojom.h"
21 #include "native_client/src/public/nacl_desc.h" 20 #include "native_client/src/public/nacl_desc.h"
22 #include "url/gurl.h" 21 #include "url/gurl.h"
23 22
24 namespace nacl { 23 namespace nacl {
25 namespace content_handler { 24 namespace content_handler {
26 25
27 namespace { 26 namespace {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 NaClDesc* desc = NaClDescCreateWithFilePathMetadata(fd, ""); 63 NaClDesc* desc = NaClDescCreateWithFilePathMetadata(fd, "");
65 64
66 // Clean up. 65 // Clean up.
67 CHECK_EQ(fclose(file_stream), 0) << "Failed to close temp file"; 66 CHECK_EQ(fclose(file_stream), 0) << "Failed to close temp file";
68 67
69 return desc; 68 return desc;
70 } 69 }
71 70
72 } // namespace 71 } // namespace
73 72
74 class NaClContentHandler : public mojo::ApplicationDelegate, 73 class NaClContentHandler : public mojo::ApplicationImplBase,
75 public mojo::ContentHandlerFactory::Delegate { 74 public mojo::ContentHandlerFactory::Delegate {
76 public: 75 public:
77 NaClContentHandler() {} 76 NaClContentHandler() {}
78 77
79 private: 78 private:
80 // Overridden from ApplicationDelegate: 79 // Overridden from ApplicationImplBase:
81 void Initialize(mojo::ApplicationImpl* app) override { 80 void OnInitialize() override {
82 url_ = GURL(app->url()); 81 url_ = GURL(url());
83 82
84 mojo::NetworkServicePtr network_service; 83 mojo::NetworkServicePtr network_service;
85 mojo::ConnectToService(app->shell(), "mojo:network_service", 84 mojo::ConnectToService(shell(), "mojo:network_service",
86 GetProxy(&network_service)); 85 GetProxy(&network_service));
87 86
88 network_service->CreateURLLoader(GetProxy(&url_loader_)); 87 network_service->CreateURLLoader(GetProxy(&url_loader_));
89 } 88 }
90 89
90 // Overridden from ApplicationImplBase:
91 bool OnAcceptConnection(
92 mojo::ServiceProviderImpl* service_provider_impl) override {
93 service_provider_impl->AddService<mojo::ContentHandler>(
94 mojo::ContentHandlerFactory::GetInterfaceRequestHandler(this));
95 return true;
96 }
97
91 void LoadIRT(mojo::URLLoaderPtr& url_loader) { 98 void LoadIRT(mojo::URLLoaderPtr& url_loader) {
92 // TODO(ncbray): support other architectures. 99 // TODO(ncbray): support other architectures.
93 GURL irt_url; 100 GURL irt_url;
94 #if defined(ARCH_CPU_X86_64) 101 #if defined(ARCH_CPU_X86_64)
95 irt_url = url_.Resolve("irt_x64/irt_mojo.nexe"); 102 irt_url = url_.Resolve("irt_x64/irt_mojo.nexe");
96 #else 103 #else
97 #error "Unknown / unsupported CPU architecture." 104 #error "Unknown / unsupported CPU architecture."
98 #endif 105 #endif
99 CHECK(irt_url.is_valid()) << "Cannot resolve IRT URL"; 106 CHECK(irt_url.is_valid()) << "Cannot resolve IRT URL";
100 107
101 irt_fp_ = TempFileForURL(url_loader, irt_url); 108 irt_fp_ = TempFileForURL(url_loader, irt_url);
102 CHECK(irt_fp_) << "Could not acquire the IRT"; 109 CHECK(irt_fp_) << "Could not acquire the IRT";
103 } 110 }
104 111
105 // Overridden from ApplicationDelegate:
106 bool ConfigureIncomingConnection(
107 mojo::ServiceProviderImpl* service_provider_impl) override {
108 service_provider_impl->AddService<mojo::ContentHandler>(
109 mojo::ContentHandlerFactory::GetInterfaceRequestHandler(this));
110 return true;
111 }
112
113 // Overridden from ContentHandlerFactory::Delegate: 112 // Overridden from ContentHandlerFactory::Delegate:
114 void RunApplication( 113 void RunApplication(
115 mojo::InterfaceRequest<mojo::Application> application_request, 114 mojo::InterfaceRequest<mojo::Application> application_request,
116 mojo::URLResponsePtr response) override { 115 mojo::URLResponsePtr response) override {
117 // Needed to use Mojo interfaces on this thread. 116 // Needed to use Mojo interfaces on this thread.
118 base::MessageLoop loop(mojo::common::MessagePumpMojo::Create()); 117 base::MessageLoop loop(mojo::common::MessagePumpMojo::Create());
119 118
120 // Acquire the nexe. 119 // Acquire the nexe.
121 base::ScopedFILE nexe_fp = 120 base::ScopedFILE nexe_fp =
122 mojo::common::BlockingCopyToTempFile(response->body.Pass()); 121 mojo::common::BlockingCopyToTempFile(response->body.Pass());
(...skipping 21 matching lines...) Expand all
144 143
145 mojo::URLLoaderPtr url_loader_; 144 mojo::URLLoaderPtr url_loader_;
146 145
147 DISALLOW_COPY_AND_ASSIGN(NaClContentHandler); 146 DISALLOW_COPY_AND_ASSIGN(NaClContentHandler);
148 }; 147 };
149 148
150 } // namespace content_handler 149 } // namespace content_handler
151 } // namespace nacl 150 } // namespace nacl
152 151
153 MojoResult MojoMain(MojoHandle application_request) { 152 MojoResult MojoMain(MojoHandle application_request) {
154 mojo::ApplicationRunnerChromium runner( 153 nacl::content_handler::NaClContentHandler nacl_content_handler;
155 new nacl::content_handler::NaClContentHandler()); 154 return mojo::RunMainApplication(application_request, &nacl_content_handler);
156 return runner.Run(application_request);
157 } 155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698