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/pnacl_file_host.h" | 5 #include "chrome/browser/nacl_host/pnacl_file_host.h" |
6 | 6 |
| 7 #include <iostream> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" |
8 #include "base/file_path.h" | 11 #include "base/file_path.h" |
9 #include "base/file_util.h" | 12 #include "base/file_util.h" |
10 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
11 #include "base/path_service.h" | 14 #include "base/path_service.h" |
12 #include "base/platform_file.h" | 15 #include "base/platform_file.h" |
13 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h" |
14 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" | 19 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
15 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
16 #include "chrome/common/render_messages.h" | 21 #include "chrome/common/render_messages.h" |
17 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
18 #include "ipc/ipc_platform_file.h" | 23 #include "ipc/ipc_platform_file.h" |
19 | 24 |
20 using content::BrowserThread; | 25 using content::BrowserThread; |
21 | 26 |
22 namespace { | 27 namespace { |
23 | 28 |
(...skipping 18 matching lines...) Expand all Loading... |
42 base::PLATFORM_FILE_OPEN | | 47 base::PLATFORM_FILE_OPEN | |
43 base::PLATFORM_FILE_READ, | 48 base::PLATFORM_FILE_READ, |
44 NULL, | 49 NULL, |
45 &error_code); | 50 &error_code); |
46 if (error_code != base::PLATFORM_FILE_OK) { | 51 if (error_code != base::PLATFORM_FILE_OK) { |
47 return false; | 52 return false; |
48 } | 53 } |
49 return true; | 54 return true; |
50 } | 55 } |
51 | 56 |
52 void DoOpenPnaclFile( | 57 void DoOpenPnaclFile(ChromeRenderMessageFilter* chrome_render_message_filter, |
53 ChromeRenderMessageFilter* chrome_render_message_filter, | 58 const std::string& filename, |
54 const std::string& filename, | 59 IPC::Message* reply_msg); |
55 IPC::Message* reply_msg) { | 60 |
| 61 void PnaclCheckDone(ChromeRenderMessageFilter* chrome_render_message_filter, |
| 62 const std::string& filename, |
| 63 IPC::Message* reply_msg, |
| 64 bool success) { |
| 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 66 if (!success) { |
| 67 NotifyRendererOfError(chrome_render_message_filter, reply_msg); |
| 68 } else { |
| 69 BrowserThread::PostTask( |
| 70 BrowserThread::FILE, FROM_HERE, |
| 71 base::Bind(&DoOpenPnaclFile, |
| 72 make_scoped_refptr(chrome_render_message_filter), |
| 73 filename, |
| 74 reply_msg)); |
| 75 } |
| 76 } |
| 77 |
| 78 void TryInstallPnacl(ChromeRenderMessageFilter* chrome_render_message_filter, |
| 79 const std::string& filename, |
| 80 IPC::Message* reply_msg) { |
| 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 82 ComponentUpdateService* cus = g_browser_process->component_updater(); |
| 83 CheckUpdatesForPnacl(cus, |
| 84 base::Bind(&PnaclCheckDone, |
| 85 make_scoped_refptr( |
| 86 chrome_render_message_filter), |
| 87 filename, |
| 88 reply_msg)); |
| 89 } |
| 90 |
| 91 void DoOpenPnaclFile(ChromeRenderMessageFilter* chrome_render_message_filter, |
| 92 const std::string& filename, |
| 93 IPC::Message* reply_msg) { |
56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
57 base::FilePath full_filepath; | |
58 | 95 |
| 96 // PNaCl must be installed. |
| 97 base::FilePath pnacl_dir; |
| 98 if (!PathService::Get(chrome::DIR_PNACL_COMPONENT, &pnacl_dir) || |
| 99 !file_util::PathExists(pnacl_dir)) { |
| 100 BrowserThread::PostTask( |
| 101 BrowserThread::UI, FROM_HERE, |
| 102 base::Bind(&TryInstallPnacl, |
| 103 make_scoped_refptr(chrome_render_message_filter), |
| 104 filename, |
| 105 reply_msg)); |
| 106 return; |
| 107 } |
| 108 |
| 109 FilePath full_filepath; |
59 // Do some validation. | 110 // Do some validation. |
60 if (!pnacl_file_host::PnaclCanOpenFile(filename, &full_filepath)) { | 111 if (!pnacl_file_host::PnaclCanOpenFile(filename, &full_filepath)) { |
61 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | 112 NotifyRendererOfError(chrome_render_message_filter, reply_msg); |
62 return; | 113 return; |
63 } | 114 } |
64 | 115 |
65 base::PlatformFile file_to_open; | 116 base::PlatformFile file_to_open; |
66 if (!PnaclDoOpenFile(full_filepath, &file_to_open)) { | 117 if (!PnaclDoOpenFile(full_filepath, &file_to_open)) { |
67 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | 118 NotifyRendererOfError(chrome_render_message_filter, reply_msg); |
68 return; | 119 return; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 if (!BrowserThread::PostTask( | 231 if (!BrowserThread::PostTask( |
181 BrowserThread::FILE, FROM_HERE, | 232 BrowserThread::FILE, FROM_HERE, |
182 base::Bind(&DoCreateTemporaryFile, | 233 base::Bind(&DoCreateTemporaryFile, |
183 make_scoped_refptr(chrome_render_message_filter), | 234 make_scoped_refptr(chrome_render_message_filter), |
184 reply_msg))) { | 235 reply_msg))) { |
185 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | 236 NotifyRendererOfError(chrome_render_message_filter, reply_msg); |
186 } | 237 } |
187 } | 238 } |
188 | 239 |
189 } // namespace pnacl_file_host | 240 } // namespace pnacl_file_host |
OLD | NEW |