Chromium Code Reviews| Index: chrome/browser/nacl_host/nacl_file_host.cc |
| diff --git a/chrome/browser/nacl_host/nacl_file_host.cc b/chrome/browser/nacl_host/nacl_file_host.cc |
| index 2610de198e21e3fceee28cba1c376e7025248087..28ff27fbbaf6f1f823ac8b88293bfe37465c45da 100644 |
| --- a/chrome/browser/nacl_host/nacl_file_host.cc |
| +++ b/chrome/browser/nacl_host/nacl_file_host.cc |
| @@ -41,6 +41,72 @@ void NotifyRendererOfError( |
| nacl_host_message_filter->Send(reply_msg); |
| } |
| +void ReplyEnsurePnaclInstalledOnIOThread( |
| + const nacl_file_host::InstallCallback& cb, |
| + bool success) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + cb.Run(success); |
| +} |
| + |
| +void PnaclCheckDone( |
| + const nacl_file_host::InstallCallback& done_callback, |
| + const nacl_file_host::InstallProgressCallback& progress_callback, |
| + bool success) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind(&ReplyEnsurePnaclInstalledOnIOThread, |
| + done_callback, success)); |
| +} |
| + |
| +void TryInstallPnacl( |
| + const nacl_file_host::InstallCallback& done_callback, |
| + const nacl_file_host::InstallProgressCallback& progress_callback) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + // TODO(jvoung): Figure out a way to get progress events and |
| + // call progress_callback. |
| + NaClBrowser::GetDelegate()->TryInstallPnacl( |
| + base::Bind(&PnaclCheckDone, |
| + done_callback, |
| + progress_callback)); |
| +} |
| + |
| +void SendNotInstalledProgress( |
| + const nacl_file_host::InstallCallback& done_callback, |
| + const nacl_file_host::InstallProgressCallback& progress_callback) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + progress_callback.Run(0, -1); |
|
dmichael (off chromium)
2013/08/01 17:33:49
It's not documented anywhere what this means ^^^
jvoung (off chromium)
2013/08/02 18:32:36
Done.
|
| + // TryInstall after sending the progress event so that they are more ordered. |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, |
| + FROM_HERE, |
| + base::Bind(&TryInstallPnacl, done_callback, progress_callback)); |
| +} |
| + |
| +void DoEnsurePnaclInstalled( |
| + const nacl_file_host::InstallCallback& done_callback, |
| + const nacl_file_host::InstallProgressCallback& progress_callback) { |
| + DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| + // If already installed, return on IO thread. |
| + base::FilePath pnacl_dir; |
| + if (NaClBrowser::GetDelegate()->GetPnaclDirectory(&pnacl_dir) && |
| + base::PathExists(pnacl_dir)) { |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind(&ReplyEnsurePnaclInstalledOnIOThread, |
| + done_callback, true)); |
| + return; |
| + } |
| + |
| + // Otherwise, request an install (but send some "unknown" progress first). |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind(&SendNotInstalledProgress, done_callback, progress_callback)); |
|
dmichael (off chromium)
2013/08/01 17:33:49
You go through a lot of work to call Send() only f
jvoung (off chromium)
2013/08/02 18:32:36
Ah, yes forgot about that. Otherwise, all the use
|
| +} |
| + |
| bool PnaclDoOpenFile(const base::FilePath& file_to_open, |
| base::PlatformFile* out_file) { |
| base::PlatformFileError error_code; |
| @@ -58,43 +124,6 @@ bool PnaclDoOpenFile(const base::FilePath& file_to_open, |
| void DoOpenPnaclFile( |
| scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter, |
| const std::string& filename, |
| - IPC::Message* reply_msg); |
| - |
| -void PnaclCheckDone( |
| - scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter, |
| - const std::string& filename, |
| - IPC::Message* reply_msg, |
| - bool success) { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - if (!success) { |
| - NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| - } else { |
| - if (!BrowserThread::PostBlockingPoolTask( |
| - FROM_HERE, |
| - base::Bind(&DoOpenPnaclFile, |
| - nacl_host_message_filter, |
| - filename, |
| - reply_msg))) { |
| - NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| - } |
| - } |
| -} |
| - |
| -void TryInstallPnacl( |
| - scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter, |
| - const std::string& filename, |
| - IPC::Message* reply_msg) { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - NaClBrowser::GetDelegate()->TryInstallPnacl( |
| - base::Bind(&PnaclCheckDone, |
| - nacl_host_message_filter, |
| - filename, |
| - reply_msg)); |
| -} |
| - |
| -void DoOpenPnaclFile( |
| - scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter, |
| - const std::string& filename, |
| IPC::Message* reply_msg) { |
| DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| base::FilePath full_filepath; |
| @@ -103,12 +132,7 @@ void DoOpenPnaclFile( |
| base::FilePath pnacl_dir; |
| if (!NaClBrowser::GetDelegate()->GetPnaclDirectory(&pnacl_dir) || |
| !base::PathExists(pnacl_dir)) { |
| - BrowserThread::PostTask( |
| - BrowserThread::UI, FROM_HERE, |
| - base::Bind(&TryInstallPnacl, |
| - nacl_host_message_filter, |
| - filename, |
| - reply_msg)); |
| + NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); |
| return; |
| } |
| @@ -248,6 +272,19 @@ void DoOpenNaClExecutableOnThreadPool( |
| namespace nacl_file_host { |
| +void EnsurePnaclInstalled( |
| + const InstallCallback& done_callback, |
| + const InstallProgressCallback& progress_callback) { |
| + if (!BrowserThread::PostBlockingPoolTask( |
| + FROM_HERE, |
| + base::Bind(&DoEnsurePnaclInstalled, |
| + done_callback, |
| + progress_callback))) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + done_callback.Run(false); |
| + } |
| +} |
| + |
| void GetReadonlyPnaclFd( |
| scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter, |
| const std::string& filename, |