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

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

Issue 19863003: PNaCl on-demand installs: Make a separate async IPC to check if PNaCl is installed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: take out progress IPC for now Created 7 years, 4 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 | 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/extensions/extension_info_map.h" 14 #include "chrome/browser/extensions/extension_info_map.h"
15 #include "chrome/browser/nacl_host/nacl_browser.h" 15 #include "chrome/browser/nacl_host/nacl_browser.h"
16 #include "chrome/browser/nacl_host/nacl_host_message_filter.h" 16 #include "chrome/browser/nacl_host/nacl_host_message_filter.h"
17 #include "chrome/common/extensions/manifest_handlers/shared_module_info.h" 17 #include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
18 #include "components/nacl/common/nacl_browser_delegate.h" 18 #include "components/nacl/common/nacl_browser_delegate.h"
19 #include "components/nacl/common/nacl_host_messages.h" 19 #include "components/nacl/common/nacl_host_messages.h"
20 #include "components/nacl/common/pnacl_types.h"
20 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/render_view_host.h" 22 #include "content/public/browser/render_view_host.h"
22 #include "content/public/browser/site_instance.h" 23 #include "content/public/browser/site_instance.h"
23 #include "ipc/ipc_platform_file.h" 24 #include "ipc/ipc_platform_file.h"
24 25
25 using content::BrowserThread; 26 using content::BrowserThread;
26 using extensions::SharedModuleInfo; 27 using extensions::SharedModuleInfo;
27 28
28 namespace { 29 namespace {
29 30
30 // Force a prefix to prevent user from opening "magic" files. 31 // Force a prefix to prevent user from opening "magic" files.
31 const char* kExpectedFilePrefix = "pnacl_public_"; 32 const char* kExpectedFilePrefix = "pnacl_public_";
32 33
33 // Restrict PNaCl file lengths to reduce likelyhood of hitting bugs 34 // Restrict PNaCl file lengths to reduce likelyhood of hitting bugs
34 // in file name limit error-handling-code-paths, etc. 35 // in file name limit error-handling-code-paths, etc.
35 const size_t kMaxFileLength = 40; 36 const size_t kMaxFileLength = 40;
36 37
37 void NotifyRendererOfError( 38 void NotifyRendererOfError(
38 NaClHostMessageFilter* nacl_host_message_filter, 39 NaClHostMessageFilter* nacl_host_message_filter,
39 IPC::Message* reply_msg) { 40 IPC::Message* reply_msg) {
40 reply_msg->set_reply_error(); 41 reply_msg->set_reply_error();
41 nacl_host_message_filter->Send(reply_msg); 42 nacl_host_message_filter->Send(reply_msg);
42 } 43 }
43 44
45 void TryInstallPnacl(
46 const nacl_file_host::InstallCallback& done_callback,
47 const nacl_file_host::InstallProgressCallback& progress_callback) {
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
49 // TODO(jvoung): Figure out a way to get progress events and
50 // call progress_callback.
51 NaClBrowser::GetDelegate()->TryInstallPnacl(done_callback);
52 }
53
54 void DoEnsurePnaclInstalled(
55 const nacl_file_host::InstallCallback& done_callback,
56 const nacl_file_host::InstallProgressCallback& progress_callback) {
57 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
58 // If already installed, return reply w/ success immediately.
59 base::FilePath pnacl_dir;
60 if (NaClBrowser::GetDelegate()->GetPnaclDirectory(&pnacl_dir)
61 && !pnacl_dir.empty()
62 && base::PathExists(pnacl_dir)) {
63 done_callback.Run(true);
64 return;
65 }
66
67 // Otherwise, request an install (but send some "unknown" progress first).
68 progress_callback.Run(nacl::PnaclInstallProgress::Unknown());
69 // TryInstall after sending the progress event so that they are more ordered.
70 BrowserThread::PostTask(
71 BrowserThread::UI,
72 FROM_HERE,
73 base::Bind(&TryInstallPnacl, done_callback, progress_callback));
74 }
75
44 bool PnaclDoOpenFile(const base::FilePath& file_to_open, 76 bool PnaclDoOpenFile(const base::FilePath& file_to_open,
45 base::PlatformFile* out_file) { 77 base::PlatformFile* out_file) {
46 base::PlatformFileError error_code; 78 base::PlatformFileError error_code;
47 *out_file = base::CreatePlatformFile(file_to_open, 79 *out_file = base::CreatePlatformFile(file_to_open,
48 base::PLATFORM_FILE_OPEN | 80 base::PLATFORM_FILE_OPEN |
49 base::PLATFORM_FILE_READ, 81 base::PLATFORM_FILE_READ,
50 NULL, 82 NULL,
51 &error_code); 83 &error_code);
52 if (error_code != base::PLATFORM_FILE_OK) { 84 if (error_code != base::PLATFORM_FILE_OK) {
53 return false; 85 return false;
54 } 86 }
55 return true; 87 return true;
56 } 88 }
57 89
58 void DoOpenPnaclFile( 90 void DoOpenPnaclFile(
59 scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter, 91 scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter,
60 const std::string& filename, 92 const std::string& filename,
61 IPC::Message* reply_msg);
62
63 void PnaclCheckDone(
64 scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter,
65 const std::string& filename,
66 IPC::Message* reply_msg,
67 bool success) {
68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
69 if (!success) {
70 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg);
71 } else {
72 if (!BrowserThread::PostBlockingPoolTask(
73 FROM_HERE,
74 base::Bind(&DoOpenPnaclFile,
75 nacl_host_message_filter,
76 filename,
77 reply_msg))) {
78 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg);
79 }
80 }
81 }
82
83 void TryInstallPnacl(
84 scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter,
85 const std::string& filename,
86 IPC::Message* reply_msg) {
87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
88 NaClBrowser::GetDelegate()->TryInstallPnacl(
89 base::Bind(&PnaclCheckDone,
90 nacl_host_message_filter,
91 filename,
92 reply_msg));
93 }
94
95 void DoOpenPnaclFile(
96 scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter,
97 const std::string& filename,
98 IPC::Message* reply_msg) { 93 IPC::Message* reply_msg) {
99 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 94 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
100 base::FilePath full_filepath; 95 base::FilePath full_filepath;
101 96
102 // PNaCl must be installed. 97 // PNaCl must be installed.
103 base::FilePath pnacl_dir; 98 base::FilePath pnacl_dir;
104 if (!NaClBrowser::GetDelegate()->GetPnaclDirectory(&pnacl_dir) || 99 if (!NaClBrowser::GetDelegate()->GetPnaclDirectory(&pnacl_dir) ||
105 !base::PathExists(pnacl_dir)) { 100 !base::PathExists(pnacl_dir)) {
106 BrowserThread::PostTask( 101 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg);
107 BrowserThread::UI, FROM_HERE,
108 base::Bind(&TryInstallPnacl,
109 nacl_host_message_filter,
110 filename,
111 reply_msg));
112 return; 102 return;
113 } 103 }
114 104
115 // Do some validation. 105 // Do some validation.
116 if (!nacl_file_host::PnaclCanOpenFile(filename, &full_filepath)) { 106 if (!nacl_file_host::PnaclCanOpenFile(filename, &full_filepath)) {
117 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); 107 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg);
118 return; 108 return;
119 } 109 }
120 110
121 base::PlatformFile file_to_open; 111 base::PlatformFile file_to_open;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 } else { 231 } else {
242 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); 232 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg);
243 return; 233 return;
244 } 234 }
245 } 235 }
246 236
247 } // namespace 237 } // namespace
248 238
249 namespace nacl_file_host { 239 namespace nacl_file_host {
250 240
241 void EnsurePnaclInstalled(
242 const InstallCallback& done_callback,
243 const InstallProgressCallback& progress_callback) {
244 if (!BrowserThread::PostBlockingPoolTask(
245 FROM_HERE,
246 base::Bind(&DoEnsurePnaclInstalled,
247 done_callback,
248 progress_callback))) {
249 done_callback.Run(false);
250 }
251 }
252
251 void GetReadonlyPnaclFd( 253 void GetReadonlyPnaclFd(
252 scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter, 254 scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter,
253 const std::string& filename, 255 const std::string& filename,
254 IPC::Message* reply_msg) { 256 IPC::Message* reply_msg) {
255 if (!BrowserThread::PostBlockingPoolTask( 257 if (!BrowserThread::PostBlockingPoolTask(
256 FROM_HERE, 258 FROM_HERE,
257 base::Bind(&DoOpenPnaclFile, 259 base::Bind(&DoOpenPnaclFile,
258 nacl_host_message_filter, 260 nacl_host_message_filter,
259 filename, 261 filename,
260 reply_msg))) { 262 reply_msg))) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 base::Bind( 339 base::Bind(
338 &DoOpenNaClExecutableOnThreadPool, 340 &DoOpenNaClExecutableOnThreadPool,
339 nacl_host_message_filter, 341 nacl_host_message_filter,
340 extension_info_map, 342 extension_info_map,
341 file_url, reply_msg))) { 343 file_url, reply_msg))) {
342 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); 344 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg);
343 } 345 }
344 } 346 }
345 347
346 } // namespace nacl_file_host 348 } // 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