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

Unified 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: const ref Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
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 ca1feb9f67c81f6242837d4b032acf9e45d3d298..9f3651154fab9143925d8b5362d601f43f3a1429 100644
--- a/chrome/browser/nacl_host/nacl_file_host.cc
+++ b/chrome/browser/nacl_host/nacl_file_host.cc
@@ -43,6 +43,69 @@ 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));
+ 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);
+ // 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) {
Derek Schuff 2013/07/23 21:39:29 maybe DCHECK(BrowserThread::GetBlockingPool()->Run
jvoung (off chromium) 2013/07/31 21:41:07 Done.
+ // If already installed, return on IO thread.
+ base::FilePath pnacl_dir;
+ 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
+ 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));
+}
+
bool PnaclDoOpenFile(const base::FilePath& file_to_open,
base::PlatformFile* out_file) {
base::PlatformFileError error_code;
@@ -60,47 +123,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));
- ComponentUpdateService* cus = g_browser_process->component_updater();
- PnaclComponentInstaller* pci =
- g_browser_process->pnacl_component_installer();
- RequestFirstInstall(cus,
- pci,
- 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;
@@ -109,12 +131,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;
}
@@ -254,6 +271,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,

Powered by Google App Engine
This is Rietveld 408576698