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

Side by Side Diff: chrome/browser/nacl_host/nacl_file_host.cc

Issue 17001003: Replace early check for PNaCl with an on-demand check. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: observer instead of timeout Created 7 years, 6 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"
11 #include "base/platform_file.h" 11 #include "base/platform_file.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/threading/sequenced_worker_pool.h" 13 #include "base/threading/sequenced_worker_pool.h"
14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h"
14 #include "chrome/browser/extensions/extension_info_map.h" 16 #include "chrome/browser/extensions/extension_info_map.h"
15 #include "chrome/browser/nacl_host/nacl_browser.h" 17 #include "chrome/browser/nacl_host/nacl_browser.h"
16 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" 18 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
17 #include "chrome/common/chrome_paths.h" 19 #include "chrome/common/chrome_paths.h"
18 #include "chrome/common/extensions/manifest_handlers/shared_module_info.h" 20 #include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
19 #include "chrome/common/render_messages.h" 21 #include "chrome/common/render_messages.h"
20 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/render_view_host.h" 23 #include "content/public/browser/render_view_host.h"
22 #include "content/public/browser/site_instance.h" 24 #include "content/public/browser/site_instance.h"
23 #include "ipc/ipc_platform_file.h" 25 #include "ipc/ipc_platform_file.h"
(...skipping 27 matching lines...) Expand all
51 &error_code); 53 &error_code);
52 if (error_code != base::PLATFORM_FILE_OK) { 54 if (error_code != base::PLATFORM_FILE_OK) {
53 return false; 55 return false;
54 } 56 }
55 return true; 57 return true;
56 } 58 }
57 59
58 void DoOpenPnaclFile( 60 void DoOpenPnaclFile(
59 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter, 61 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter,
60 const std::string& filename, 62 const std::string& filename,
63 IPC::Message* reply_msg);
64
65 void PnaclCheckDone(
66 scoped_refptr<ChromeRenderMessageFilter> chrome_render_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(chrome_render_message_filter, reply_msg);
73 } else {
74 if (!BrowserThread::PostBlockingPoolTask(
75 FROM_HERE,
76 base::Bind(&DoOpenPnaclFile,
77 chrome_render_message_filter,
78 filename,
79 reply_msg))) {
80 NotifyRendererOfError(chrome_render_message_filter, reply_msg);
81 }
82 }
83 }
84
85 void TryInstallPnacl(
86 scoped_refptr<ChromeRenderMessageFilter> chrome_render_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 chrome_render_message_filter,
97 filename,
98 reply_msg));
99 }
100
101 void DoOpenPnaclFile(
102 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter,
103 const std::string& filename,
61 IPC::Message* reply_msg) { 104 IPC::Message* reply_msg) {
62 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 105 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
63 base::FilePath full_filepath; 106 base::FilePath full_filepath;
64 107
108 // PNaCl must be installed.
109 base::FilePath pnacl_dir;
110 if (!PathService::Get(chrome::DIR_PNACL_COMPONENT, &pnacl_dir) ||
111 !file_util::PathExists(pnacl_dir)) {
112 BrowserThread::PostTask(
113 BrowserThread::UI, FROM_HERE,
114 base::Bind(&TryInstallPnacl,
115 chrome_render_message_filter,
116 filename,
117 reply_msg));
118 return;
119 }
120
65 // Do some validation. 121 // Do some validation.
66 if (!nacl_file_host::PnaclCanOpenFile(filename, &full_filepath)) { 122 if (!nacl_file_host::PnaclCanOpenFile(filename, &full_filepath)) {
67 NotifyRendererOfError(chrome_render_message_filter.get(), reply_msg); 123 NotifyRendererOfError(chrome_render_message_filter.get(), reply_msg);
68 return; 124 return;
69 } 125 }
70 126
71 base::PlatformFile file_to_open; 127 base::PlatformFile file_to_open;
72 if (!PnaclDoOpenFile(full_filepath, &file_to_open)) { 128 if (!PnaclDoOpenFile(full_filepath, &file_to_open)) {
73 NotifyRendererOfError(chrome_render_message_filter.get(), reply_msg); 129 NotifyRendererOfError(chrome_render_message_filter.get(), reply_msg);
74 return; 130 return;
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 base::Bind( 396 base::Bind(
341 &DoOpenNaClExecutableOnThreadPool, 397 &DoOpenNaClExecutableOnThreadPool,
342 chrome_render_message_filter, 398 chrome_render_message_filter,
343 extension_info_map, 399 extension_info_map,
344 file_url, reply_msg))) { 400 file_url, reply_msg))) {
345 NotifyRendererOfError(chrome_render_message_filter.get(), reply_msg); 401 NotifyRendererOfError(chrome_render_message_filter.get(), reply_msg);
346 } 402 }
347 } 403 }
348 404
349 } // namespace nacl_file_host 405 } // namespace nacl_file_host
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698