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

Side by Side Diff: chrome/browser/nacl_host/nacl_process_host.cc

Issue 8591035: Clean up disable_nacl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/renderer_host/chrome_render_message_filter.h » ('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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/nacl_host/nacl_process_host.h" 7 #include "chrome/browser/nacl_host/nacl_process_host.h"
8 8
9 #if defined(OS_POSIX) 9 #if defined(OS_POSIX)
10 #include <fcntl.h> 10 #include <fcntl.h>
(...skipping 18 matching lines...) Expand all
29 #if defined(OS_POSIX) 29 #if defined(OS_POSIX)
30 #include "ipc/ipc_channel_posix.h" 30 #include "ipc/ipc_channel_posix.h"
31 #elif defined(OS_WIN) 31 #elif defined(OS_WIN)
32 #include "chrome/browser/nacl_host/nacl_broker_service_win.h" 32 #include "chrome/browser/nacl_host/nacl_broker_service_win.h"
33 #endif 33 #endif
34 34
35 using content::BrowserThread; 35 using content::BrowserThread;
36 36
37 namespace { 37 namespace {
38 38
39 #if !defined(DISABLE_NACL)
40 void SetCloseOnExec(nacl::Handle fd) { 39 void SetCloseOnExec(nacl::Handle fd) {
41 #if defined(OS_POSIX) 40 #if defined(OS_POSIX)
42 int flags = fcntl(fd, F_GETFD); 41 int flags = fcntl(fd, F_GETFD);
43 CHECK_NE(flags, -1); 42 CHECK_NE(flags, -1);
44 int rc = fcntl(fd, F_SETFD, flags | FD_CLOEXEC); 43 int rc = fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
45 CHECK_EQ(rc, 0); 44 CHECK_EQ(rc, 0);
46 #endif 45 #endif
47 } 46 }
48 #endif
49 47
50 // Represents shared state for all NaClProcessHost objects in the browser. 48 // Represents shared state for all NaClProcessHost objects in the browser.
51 // Currently this just handles holding onto the file descriptor for the IRT. 49 // Currently this just handles holding onto the file descriptor for the IRT.
52 class NaClBrowser { 50 class NaClBrowser {
53 public: 51 public:
54 static NaClBrowser* GetInstance() { 52 static NaClBrowser* GetInstance() {
55 return Singleton<NaClBrowser>::get(); 53 return Singleton<NaClBrowser>::get();
56 } 54 }
57 55
58 bool IrtAvailable() const { 56 bool IrtAvailable() const {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 109
112 NaClProcessHost::NaClProcessHost(const std::wstring& url) 110 NaClProcessHost::NaClProcessHost(const std::wstring& url)
113 : BrowserChildProcessHost(NACL_LOADER_PROCESS), 111 : BrowserChildProcessHost(NACL_LOADER_PROCESS),
114 reply_msg_(NULL), 112 reply_msg_(NULL),
115 internal_(new NaClInternal()), 113 internal_(new NaClInternal()),
116 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 114 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
117 set_name(WideToUTF16Hack(url)); 115 set_name(WideToUTF16Hack(url));
118 } 116 }
119 117
120 NaClProcessHost::~NaClProcessHost() { 118 NaClProcessHost::~NaClProcessHost() {
121 // nacl::Close() is not available at link time if DISABLE_NACL is
122 // defined, but we still compile a bunch of other code from this
123 // file anyway. TODO(mseaborn): Make this less messy.
124 #ifndef DISABLE_NACL
125 for (size_t i = 0; i < internal_->sockets_for_renderer.size(); i++) { 119 for (size_t i = 0; i < internal_->sockets_for_renderer.size(); i++) {
126 if (nacl::Close(internal_->sockets_for_renderer[i]) != 0) { 120 if (nacl::Close(internal_->sockets_for_renderer[i]) != 0) {
127 LOG(ERROR) << "nacl::Close() failed"; 121 LOG(ERROR) << "nacl::Close() failed";
128 } 122 }
129 } 123 }
130 for (size_t i = 0; i < internal_->sockets_for_sel_ldr.size(); i++) { 124 for (size_t i = 0; i < internal_->sockets_for_sel_ldr.size(); i++) {
131 if (nacl::Close(internal_->sockets_for_sel_ldr[i]) != 0) { 125 if (nacl::Close(internal_->sockets_for_sel_ldr[i]) != 0) {
132 LOG(ERROR) << "nacl::Close() failed"; 126 LOG(ERROR) << "nacl::Close() failed";
133 } 127 }
134 } 128 }
135 #endif
136 129
137 if (reply_msg_) { 130 if (reply_msg_) {
138 // The process failed to launch for some reason. 131 // The process failed to launch for some reason.
139 // Don't keep the renderer hanging. 132 // Don't keep the renderer hanging.
140 reply_msg_->set_reply_error(); 133 reply_msg_->set_reply_error();
141 chrome_render_message_filter_->Send(reply_msg_); 134 chrome_render_message_filter_->Send(reply_msg_);
142 } 135 }
143 } 136 }
144 137
145 // Attempt to ensure the IRT will be available when we need it, but don't wait. 138 // Attempt to ensure the IRT will be available when we need it, but don't wait.
(...skipping 21 matching lines...) Expand all
167 // Open the IRT file early to make sure that it isn't replaced out from 160 // Open the IRT file early to make sure that it isn't replaced out from
168 // under us by autoupdate. 161 // under us by autoupdate.
169 NaClBrowser::GetInstance()->EnsureIrtAvailable(); 162 NaClBrowser::GetInstance()->EnsureIrtAvailable();
170 #endif 163 #endif
171 } 164 }
172 165
173 bool NaClProcessHost::Launch( 166 bool NaClProcessHost::Launch(
174 ChromeRenderMessageFilter* chrome_render_message_filter, 167 ChromeRenderMessageFilter* chrome_render_message_filter,
175 int socket_count, 168 int socket_count,
176 IPC::Message* reply_msg) { 169 IPC::Message* reply_msg) {
177 #ifdef DISABLE_NACL
178 NOTIMPLEMENTED() << "Native Client disabled at build time";
179 return false;
180 #else
181 // Place an arbitrary limit on the number of sockets to limit 170 // Place an arbitrary limit on the number of sockets to limit
182 // exposure in case the renderer is compromised. We can increase 171 // exposure in case the renderer is compromised. We can increase
183 // this if necessary. 172 // this if necessary.
184 if (socket_count > 8) { 173 if (socket_count > 8) {
185 return false; 174 return false;
186 } 175 }
187 176
188 // Start getting the IRT open asynchronously while we launch the NaCl process. 177 // Start getting the IRT open asynchronously while we launch the NaCl process.
189 // We'll make sure this actually finished in OnProcessLaunched, below. 178 // We'll make sure this actually finished in OnProcessLaunched, below.
190 if (!NaClBrowser::GetInstance()->EnsureIrtAvailable()) { 179 if (!NaClBrowser::GetInstance()->EnsureIrtAvailable()) {
(...skipping 22 matching lines...) Expand all
213 } 202 }
214 203
215 // Launch the process 204 // Launch the process
216 if (!LaunchSelLdr()) { 205 if (!LaunchSelLdr()) {
217 return false; 206 return false;
218 } 207 }
219 chrome_render_message_filter_ = chrome_render_message_filter; 208 chrome_render_message_filter_ = chrome_render_message_filter;
220 reply_msg_ = reply_msg; 209 reply_msg_ = reply_msg;
221 210
222 return true; 211 return true;
223 #endif // DISABLE_NACL
224 } 212 }
225 213
226 bool NaClProcessHost::LaunchSelLdr() { 214 bool NaClProcessHost::LaunchSelLdr() {
227 if (!CreateChannel()) 215 if (!CreateChannel())
228 return false; 216 return false;
229 217
230 CommandLine::StringType nacl_loader_prefix; 218 CommandLine::StringType nacl_loader_prefix;
231 #if defined(OS_POSIX) 219 #if defined(OS_POSIX)
232 nacl_loader_prefix = CommandLine::ForCurrentProcess()->GetSwitchValueNative( 220 nacl_loader_prefix = CommandLine::ForCurrentProcess()->GetSwitchValueNative(
233 switches::kNaClLoaderCmdPrefix); 221 switches::kNaClLoaderCmdPrefix);
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 } 513 }
526 514
527 bool NaClProcessHost::OnMessageReceived(const IPC::Message& msg) { 515 bool NaClProcessHost::OnMessageReceived(const IPC::Message& msg) {
528 NOTREACHED() << "Invalid message with type = " << msg.type(); 516 NOTREACHED() << "Invalid message with type = " << msg.type();
529 return false; 517 return false;
530 } 518 }
531 519
532 bool NaClProcessHost::CanShutdown() { 520 bool NaClProcessHost::CanShutdown() {
533 return true; 521 return true;
534 } 522 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/renderer_host/chrome_render_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698