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

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

Issue 55463002: Remove PNaCl's RequestFirstInstall, use resource throttle instead (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reorder functions Created 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/nacl_host/nacl_file_host.h" 5 #include "chrome/browser/nacl_host/nacl_file_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/platform_file.h" 11 #include "base/platform_file.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/threading/sequenced_worker_pool.h" 13 #include "base/threading/sequenced_worker_pool.h"
14 #include "chrome/browser/nacl_host/nacl_host_message_filter.h" 14 #include "chrome/browser/nacl_host/nacl_host_message_filter.h"
15 #include "components/nacl/browser/nacl_browser.h" 15 #include "components/nacl/browser/nacl_browser.h"
16 #include "components/nacl/common/nacl_browser_delegate.h" 16 #include "components/nacl/common/nacl_browser_delegate.h"
17 #include "components/nacl/common/nacl_host_messages.h" 17 #include "components/nacl/common/nacl_host_messages.h"
18 #include "components/nacl/common/pnacl_types.h"
19 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/render_view_host.h" 19 #include "content/public/browser/render_view_host.h"
21 #include "content/public/browser/site_instance.h" 20 #include "content/public/browser/site_instance.h"
22 #include "ipc/ipc_platform_file.h" 21 #include "ipc/ipc_platform_file.h"
23 22
24 using content::BrowserThread; 23 using content::BrowserThread;
25 24
26 namespace { 25 namespace {
27 26
28 // Force a prefix to prevent user from opening "magic" files. 27 // Force a prefix to prevent user from opening "magic" files.
29 const char* kExpectedFilePrefix = "pnacl_public_"; 28 const char* kExpectedFilePrefix = "pnacl_public_";
30 29
31 // Restrict PNaCl file lengths to reduce likelyhood of hitting bugs 30 // Restrict PNaCl file lengths to reduce likelyhood of hitting bugs
32 // in file name limit error-handling-code-paths, etc. 31 // in file name limit error-handling-code-paths, etc.
33 const size_t kMaxFileLength = 40; 32 const size_t kMaxFileLength = 40;
34 33
35 void NotifyRendererOfError( 34 void NotifyRendererOfError(
36 NaClHostMessageFilter* nacl_host_message_filter, 35 NaClHostMessageFilter* nacl_host_message_filter,
37 IPC::Message* reply_msg) { 36 IPC::Message* reply_msg) {
38 reply_msg->set_reply_error(); 37 reply_msg->set_reply_error();
39 nacl_host_message_filter->Send(reply_msg); 38 nacl_host_message_filter->Send(reply_msg);
40 } 39 }
41 40
42 void TryInstallPnacl(
43 const nacl_file_host::InstallCallback& done_callback,
44 const nacl_file_host::InstallProgressCallback& progress_callback) {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
46 // TODO(jvoung): Figure out a way to get progress events and
47 // call progress_callback.
48 nacl::NaClBrowser::GetDelegate()->TryInstallPnacl(done_callback);
49 }
50
51 void DoEnsurePnaclInstalled(
52 const nacl_file_host::InstallCallback& done_callback,
53 const nacl_file_host::InstallProgressCallback& progress_callback) {
54 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
55 // If already installed, return reply w/ success immediately.
56 base::FilePath pnacl_dir;
57 if (nacl::NaClBrowser::GetDelegate()->GetPnaclDirectory(&pnacl_dir)
58 && !pnacl_dir.empty()
59 && base::PathExists(pnacl_dir)) {
60 done_callback.Run(true);
61 return;
62 }
63
64 // Otherwise, request an install (but send some "unknown" progress first).
65 progress_callback.Run(nacl::PnaclInstallProgress::Unknown());
66 // TryInstall after sending the progress event so that they are more ordered.
67 BrowserThread::PostTask(
68 BrowserThread::UI,
69 FROM_HERE,
70 base::Bind(&TryInstallPnacl, done_callback, progress_callback));
71 }
72
73 bool PnaclDoOpenFile(const base::FilePath& file_to_open, 41 bool PnaclDoOpenFile(const base::FilePath& file_to_open,
74 base::PlatformFile* out_file) { 42 base::PlatformFile* out_file) {
75 base::PlatformFileError error_code; 43 base::PlatformFileError error_code;
76 *out_file = base::CreatePlatformFile(file_to_open, 44 *out_file = base::CreatePlatformFile(file_to_open,
77 base::PLATFORM_FILE_OPEN | 45 base::PLATFORM_FILE_OPEN |
78 base::PLATFORM_FILE_READ, 46 base::PLATFORM_FILE_READ,
79 NULL, 47 NULL,
80 &error_code); 48 &error_code);
81 if (error_code != base::PLATFORM_FILE_OK) { 49 if (error_code != base::PLATFORM_FILE_OK) {
82 return false; 50 return false;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } else { 147 } else {
180 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); 148 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg);
181 return; 149 return;
182 } 150 }
183 } 151 }
184 152
185 } // namespace 153 } // namespace
186 154
187 namespace nacl_file_host { 155 namespace nacl_file_host {
188 156
189 void EnsurePnaclInstalled(
190 const InstallCallback& done_callback,
191 const InstallProgressCallback& progress_callback) {
192 if (!BrowserThread::PostBlockingPoolTask(
193 FROM_HERE,
194 base::Bind(&DoEnsurePnaclInstalled,
195 done_callback,
196 progress_callback))) {
197 done_callback.Run(false);
198 }
199 }
200
201 void GetReadonlyPnaclFd( 157 void GetReadonlyPnaclFd(
202 scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter, 158 scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter,
203 const std::string& filename, 159 const std::string& filename,
204 IPC::Message* reply_msg) { 160 IPC::Message* reply_msg) {
205 if (!BrowserThread::PostBlockingPoolTask( 161 if (!BrowserThread::PostBlockingPoolTask(
206 FROM_HERE, 162 FROM_HERE,
207 base::Bind(&DoOpenPnaclFile, 163 base::Bind(&DoOpenPnaclFile,
208 nacl_host_message_filter, 164 nacl_host_message_filter,
209 filename, 165 filename,
210 reply_msg))) { 166 reply_msg))) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 FROM_HERE, 240 FROM_HERE,
285 base::Bind( 241 base::Bind(
286 &DoOpenNaClExecutableOnThreadPool, 242 &DoOpenNaClExecutableOnThreadPool,
287 nacl_host_message_filter, 243 nacl_host_message_filter,
288 file_url, reply_msg))) { 244 file_url, reply_msg))) {
289 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); 245 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg);
290 } 246 }
291 } 247 }
292 248
293 } // namespace nacl_file_host 249 } // namespace nacl_file_host
OLDNEW
« no previous file with comments | « chrome/browser/nacl_host/nacl_file_host.h ('k') | chrome/browser/nacl_host/nacl_file_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698