Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 // in file name limit error-handling-code-paths, etc. | 36 // in file name limit error-handling-code-paths, etc. |
| 37 const size_t kMaxFileLength = 40; | 37 const size_t kMaxFileLength = 40; |
| 38 | 38 |
| 39 void NotifyRendererOfError( | 39 void NotifyRendererOfError( |
| 40 NaClHostMessageFilter* nacl_host_message_filter, | 40 NaClHostMessageFilter* nacl_host_message_filter, |
| 41 IPC::Message* reply_msg) { | 41 IPC::Message* reply_msg) { |
| 42 reply_msg->set_reply_error(); | 42 reply_msg->set_reply_error(); |
| 43 nacl_host_message_filter->Send(reply_msg); | 43 nacl_host_message_filter->Send(reply_msg); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void ReplyEnsurePnaclInstalledOnIOThread( | |
| 47 const nacl_file_host::InstallCallback& cb, | |
| 48 bool success) { | |
| 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 50 cb.Run(success); | |
| 51 } | |
| 52 | |
| 53 void PnaclCheckDone( | |
| 54 const nacl_file_host::InstallCallback& done_callback, | |
| 55 const nacl_file_host::InstallProgressCallback& progress_callback, | |
| 56 bool success) { | |
| 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 58 BrowserThread::PostTask( | |
| 59 BrowserThread::IO, | |
| 60 FROM_HERE, | |
| 61 base::Bind(&ReplyEnsurePnaclInstalledOnIOThread, | |
| 62 done_callback, success)); | |
| 63 } | |
| 64 | |
| 65 void TryInstallPnacl( | |
| 66 const nacl_file_host::InstallCallback& done_callback, | |
| 67 const nacl_file_host::InstallProgressCallback& progress_callback) { | |
| 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 69 NaClBrowser::GetDelegate()->TryInstallPnacl( | |
| 70 base::Bind(&PnaclCheckDone, | |
| 71 done_callback, | |
| 72 progress_callback)); | |
| 73 } | |
| 74 | |
| 75 void SendNotInstalledProgress( | |
| 76 const nacl_file_host::InstallCallback& done_callback, | |
| 77 const nacl_file_host::InstallProgressCallback& progress_callback) { | |
| 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 79 progress_callback.Run(0, -1); | |
| 80 // TryInstall after sending the progress event so that they are more ordered. | |
| 81 BrowserThread::PostTask( | |
| 82 BrowserThread::UI, | |
| 83 FROM_HERE, | |
| 84 base::Bind(&TryInstallPnacl, done_callback, progress_callback)); | |
| 85 } | |
| 86 | |
| 87 void DoEnsurePnaclInstalled( | |
| 88 const nacl_file_host::InstallCallback& done_callback, | |
| 89 const nacl_file_host::InstallProgressCallback& progress_callback) { | |
|
Derek Schuff
2013/07/23 21:39:29
maybe DCHECK(BrowserThread::GetBlockingPool()->Run
jvoung (off chromium)
2013/07/31 21:41:07
Done.
| |
| 90 // If already installed, return on IO thread. | |
| 91 base::FilePath pnacl_dir; | |
| 92 if (NaClBrowser::GetDelegate()->GetPnaclDirectory(&pnacl_dir) && | |
|
Derek Schuff
2013/07/23 21:39:29
actually, I think we may have to call NaClBrowser
jvoung (off chromium)
2013/07/31 21:41:07
NaClBrowser does get called in during early browse
| |
| 93 base::PathExists(pnacl_dir)) { | |
| 94 BrowserThread::PostTask( | |
| 95 BrowserThread::IO, | |
| 96 FROM_HERE, | |
| 97 base::Bind(&ReplyEnsurePnaclInstalledOnIOThread, | |
| 98 done_callback, true)); | |
| 99 return; | |
| 100 } | |
| 101 | |
| 102 // Otherwise, request an install (but send some "unknown" progress first). | |
| 103 BrowserThread::PostTask( | |
| 104 BrowserThread::IO, | |
| 105 FROM_HERE, | |
| 106 base::Bind(&SendNotInstalledProgress, done_callback, progress_callback)); | |
| 107 } | |
| 108 | |
| 46 bool PnaclDoOpenFile(const base::FilePath& file_to_open, | 109 bool PnaclDoOpenFile(const base::FilePath& file_to_open, |
| 47 base::PlatformFile* out_file) { | 110 base::PlatformFile* out_file) { |
| 48 base::PlatformFileError error_code; | 111 base::PlatformFileError error_code; |
| 49 *out_file = base::CreatePlatformFile(file_to_open, | 112 *out_file = base::CreatePlatformFile(file_to_open, |
| 50 base::PLATFORM_FILE_OPEN | | 113 base::PLATFORM_FILE_OPEN | |
| 51 base::PLATFORM_FILE_READ, | 114 base::PLATFORM_FILE_READ, |
| 52 NULL, | 115 NULL, |
| 53 &error_code); | 116 &error_code); |
| 54 if (error_code != base::PLATFORM_FILE_OK) { | 117 if (error_code != base::PLATFORM_FILE_OK) { |
| 55 return false; | 118 return false; |
| 56 } | 119 } |
| 57 return true; | 120 return true; |
| 58 } | 121 } |
| 59 | 122 |
| 60 void DoOpenPnaclFile( | 123 void DoOpenPnaclFile( |
| 61 scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter, | 124 scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter, |
| 62 const std::string& filename, | 125 const std::string& filename, |
| 63 IPC::Message* reply_msg); | |
| 64 | |
| 65 void PnaclCheckDone( | |
| 66 scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter, | |
| 67 const std::string& filename, | |
| 68 IPC::Message* reply_msg, | |
| 69 bool success) { | |
| 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 71 if (!success) { | |
| 72 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); | |
| 73 } else { | |
| 74 if (!BrowserThread::PostBlockingPoolTask( | |
| 75 FROM_HERE, | |
| 76 base::Bind(&DoOpenPnaclFile, | |
| 77 nacl_host_message_filter, | |
| 78 filename, | |
| 79 reply_msg))) { | |
| 80 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); | |
| 81 } | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 void TryInstallPnacl( | |
| 86 scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter, | |
| 87 const std::string& filename, | |
| 88 IPC::Message* reply_msg) { | |
| 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 90 ComponentUpdateService* cus = g_browser_process->component_updater(); | |
| 91 PnaclComponentInstaller* pci = | |
| 92 g_browser_process->pnacl_component_installer(); | |
| 93 RequestFirstInstall(cus, | |
| 94 pci, | |
| 95 base::Bind(&PnaclCheckDone, | |
| 96 nacl_host_message_filter, | |
| 97 filename, | |
| 98 reply_msg)); | |
| 99 } | |
| 100 | |
| 101 void DoOpenPnaclFile( | |
| 102 scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter, | |
| 103 const std::string& filename, | |
| 104 IPC::Message* reply_msg) { | 126 IPC::Message* reply_msg) { |
| 105 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 127 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 106 base::FilePath full_filepath; | 128 base::FilePath full_filepath; |
| 107 | 129 |
| 108 // PNaCl must be installed. | 130 // PNaCl must be installed. |
| 109 base::FilePath pnacl_dir; | 131 base::FilePath pnacl_dir; |
| 110 if (!NaClBrowser::GetDelegate()->GetPnaclDirectory(&pnacl_dir) || | 132 if (!NaClBrowser::GetDelegate()->GetPnaclDirectory(&pnacl_dir) || |
| 111 !base::PathExists(pnacl_dir)) { | 133 !base::PathExists(pnacl_dir)) { |
| 112 BrowserThread::PostTask( | 134 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| 113 BrowserThread::UI, FROM_HERE, | |
| 114 base::Bind(&TryInstallPnacl, | |
| 115 nacl_host_message_filter, | |
| 116 filename, | |
| 117 reply_msg)); | |
| 118 return; | 135 return; |
| 119 } | 136 } |
| 120 | 137 |
| 121 // Do some validation. | 138 // Do some validation. |
| 122 if (!nacl_file_host::PnaclCanOpenFile(filename, &full_filepath)) { | 139 if (!nacl_file_host::PnaclCanOpenFile(filename, &full_filepath)) { |
| 123 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); | 140 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| 124 return; | 141 return; |
| 125 } | 142 } |
| 126 | 143 |
| 127 base::PlatformFile file_to_open; | 144 base::PlatformFile file_to_open; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 } else { | 264 } else { |
| 248 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); | 265 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| 249 return; | 266 return; |
| 250 } | 267 } |
| 251 } | 268 } |
| 252 | 269 |
| 253 } // namespace | 270 } // namespace |
| 254 | 271 |
| 255 namespace nacl_file_host { | 272 namespace nacl_file_host { |
| 256 | 273 |
| 274 void EnsurePnaclInstalled( | |
| 275 const InstallCallback& done_callback, | |
| 276 const InstallProgressCallback& progress_callback) { | |
| 277 if (!BrowserThread::PostBlockingPoolTask( | |
| 278 FROM_HERE, | |
| 279 base::Bind(&DoEnsurePnaclInstalled, | |
| 280 done_callback, | |
| 281 progress_callback))) { | |
| 282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 283 done_callback.Run(false); | |
| 284 } | |
| 285 } | |
| 286 | |
| 257 void GetReadonlyPnaclFd( | 287 void GetReadonlyPnaclFd( |
| 258 scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter, | 288 scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter, |
| 259 const std::string& filename, | 289 const std::string& filename, |
| 260 IPC::Message* reply_msg) { | 290 IPC::Message* reply_msg) { |
| 261 if (!BrowserThread::PostBlockingPoolTask( | 291 if (!BrowserThread::PostBlockingPoolTask( |
| 262 FROM_HERE, | 292 FROM_HERE, |
| 263 base::Bind(&DoOpenPnaclFile, | 293 base::Bind(&DoOpenPnaclFile, |
| 264 nacl_host_message_filter, | 294 nacl_host_message_filter, |
| 265 filename, | 295 filename, |
| 266 reply_msg))) { | 296 reply_msg))) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 base::Bind( | 373 base::Bind( |
| 344 &DoOpenNaClExecutableOnThreadPool, | 374 &DoOpenNaClExecutableOnThreadPool, |
| 345 nacl_host_message_filter, | 375 nacl_host_message_filter, |
| 346 extension_info_map, | 376 extension_info_map, |
| 347 file_url, reply_msg))) { | 377 file_url, reply_msg))) { |
| 348 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); | 378 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| 349 } | 379 } |
| 350 } | 380 } |
| 351 | 381 |
| 352 } // namespace nacl_file_host | 382 } // namespace nacl_file_host |
| OLD | NEW |