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

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: int64_t to int64 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"
(...skipping 23 matching lines...) Expand all
34 // in file name limit error-handling-code-paths, etc. 34 // in file name limit error-handling-code-paths, etc.
35 const size_t kMaxFileLength = 40; 35 const size_t kMaxFileLength = 40;
36 36
37 void NotifyRendererOfError( 37 void NotifyRendererOfError(
38 NaClHostMessageFilter* nacl_host_message_filter, 38 NaClHostMessageFilter* nacl_host_message_filter,
39 IPC::Message* reply_msg) { 39 IPC::Message* reply_msg) {
40 reply_msg->set_reply_error(); 40 reply_msg->set_reply_error();
41 nacl_host_message_filter->Send(reply_msg); 41 nacl_host_message_filter->Send(reply_msg);
42 } 42 }
43 43
44 void ReplyEnsurePnaclInstalledOnIOThread(
45 const nacl_file_host::InstallCallback& cb,
46 bool success) {
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
48 cb.Run(success);
49 }
50
51 void PnaclCheckDone(
52 const nacl_file_host::InstallCallback& done_callback,
53 const nacl_file_host::InstallProgressCallback& progress_callback,
54 bool success) {
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
56 BrowserThread::PostTask(
57 BrowserThread::IO,
58 FROM_HERE,
59 base::Bind(&ReplyEnsurePnaclInstalledOnIOThread,
60 done_callback, success));
61 }
62
63 void TryInstallPnacl(
64 const nacl_file_host::InstallCallback& done_callback,
65 const nacl_file_host::InstallProgressCallback& progress_callback) {
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
67 // TODO(jvoung): Figure out a way to get progress events and
68 // call progress_callback.
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);
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.
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) {
90 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
91 // If already installed, return on IO thread.
92 base::FilePath pnacl_dir;
93 if (NaClBrowser::GetDelegate()->GetPnaclDirectory(&pnacl_dir) &&
94 base::PathExists(pnacl_dir)) {
95 BrowserThread::PostTask(
96 BrowserThread::IO,
97 FROM_HERE,
98 base::Bind(&ReplyEnsurePnaclInstalledOnIOThread,
99 done_callback, true));
100 return;
101 }
102
103 // Otherwise, request an install (but send some "unknown" progress first).
104 BrowserThread::PostTask(
105 BrowserThread::IO,
106 FROM_HERE,
107 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
108 }
109
44 bool PnaclDoOpenFile(const base::FilePath& file_to_open, 110 bool PnaclDoOpenFile(const base::FilePath& file_to_open,
45 base::PlatformFile* out_file) { 111 base::PlatformFile* out_file) {
46 base::PlatformFileError error_code; 112 base::PlatformFileError error_code;
47 *out_file = base::CreatePlatformFile(file_to_open, 113 *out_file = base::CreatePlatformFile(file_to_open,
48 base::PLATFORM_FILE_OPEN | 114 base::PLATFORM_FILE_OPEN |
49 base::PLATFORM_FILE_READ, 115 base::PLATFORM_FILE_READ,
50 NULL, 116 NULL,
51 &error_code); 117 &error_code);
52 if (error_code != base::PLATFORM_FILE_OK) { 118 if (error_code != base::PLATFORM_FILE_OK) {
53 return false; 119 return false;
54 } 120 }
55 return true; 121 return true;
56 } 122 }
57 123
58 void DoOpenPnaclFile( 124 void DoOpenPnaclFile(
59 scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter, 125 scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter,
60 const std::string& filename, 126 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) { 127 IPC::Message* reply_msg) {
99 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 128 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
100 base::FilePath full_filepath; 129 base::FilePath full_filepath;
101 130
102 // PNaCl must be installed. 131 // PNaCl must be installed.
103 base::FilePath pnacl_dir; 132 base::FilePath pnacl_dir;
104 if (!NaClBrowser::GetDelegate()->GetPnaclDirectory(&pnacl_dir) || 133 if (!NaClBrowser::GetDelegate()->GetPnaclDirectory(&pnacl_dir) ||
105 !base::PathExists(pnacl_dir)) { 134 !base::PathExists(pnacl_dir)) {
106 BrowserThread::PostTask( 135 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; 136 return;
113 } 137 }
114 138
115 // Do some validation. 139 // Do some validation.
116 if (!nacl_file_host::PnaclCanOpenFile(filename, &full_filepath)) { 140 if (!nacl_file_host::PnaclCanOpenFile(filename, &full_filepath)) {
117 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); 141 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg);
118 return; 142 return;
119 } 143 }
120 144
121 base::PlatformFile file_to_open; 145 base::PlatformFile file_to_open;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 } else { 265 } else {
242 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); 266 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg);
243 return; 267 return;
244 } 268 }
245 } 269 }
246 270
247 } // namespace 271 } // namespace
248 272
249 namespace nacl_file_host { 273 namespace nacl_file_host {
250 274
275 void EnsurePnaclInstalled(
276 const InstallCallback& done_callback,
277 const InstallProgressCallback& progress_callback) {
278 if (!BrowserThread::PostBlockingPoolTask(
279 FROM_HERE,
280 base::Bind(&DoEnsurePnaclInstalled,
281 done_callback,
282 progress_callback))) {
283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
284 done_callback.Run(false);
285 }
286 }
287
251 void GetReadonlyPnaclFd( 288 void GetReadonlyPnaclFd(
252 scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter, 289 scoped_refptr<NaClHostMessageFilter> nacl_host_message_filter,
253 const std::string& filename, 290 const std::string& filename,
254 IPC::Message* reply_msg) { 291 IPC::Message* reply_msg) {
255 if (!BrowserThread::PostBlockingPoolTask( 292 if (!BrowserThread::PostBlockingPoolTask(
256 FROM_HERE, 293 FROM_HERE,
257 base::Bind(&DoOpenPnaclFile, 294 base::Bind(&DoOpenPnaclFile,
258 nacl_host_message_filter, 295 nacl_host_message_filter,
259 filename, 296 filename,
260 reply_msg))) { 297 reply_msg))) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 base::Bind( 374 base::Bind(
338 &DoOpenNaClExecutableOnThreadPool, 375 &DoOpenNaClExecutableOnThreadPool,
339 nacl_host_message_filter, 376 nacl_host_message_filter,
340 extension_info_map, 377 extension_info_map,
341 file_url, reply_msg))) { 378 file_url, reply_msg))) {
342 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg); 379 NotifyRendererOfError(nacl_host_message_filter.get(), reply_msg);
343 } 380 }
344 } 381 }
345 382
346 } // namespace nacl_file_host 383 } // namespace nacl_file_host
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698