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

Side by Side Diff: chrome/renderer/pepper/pnacl_translation_resource_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: struct 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "pnacl_translation_resource_host.h" 5 #include "pnacl_translation_resource_host.h"
6 6
7 #ifndef DISABLE_NACL 7 #ifndef DISABLE_NACL
8 #include "components/nacl/common/nacl_host_messages.h" 8 #include "components/nacl/common/nacl_host_messages.h"
9 #include "ppapi/c/pp_errors.h" 9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/shared_impl/ppapi_globals.h" 10 #include "ppapi/shared_impl/ppapi_globals.h"
11 11
12 using ppapi::TrackedCallback; 12 using ppapi::TrackedCallback;
13 using ppapi::PpapiGlobals; 13 using ppapi::PpapiGlobals;
14 14
15 PnaclTranslationResourceHost::CacheRequestInfo::CacheRequestInfo( 15 PnaclTranslationResourceHost::CacheRequestInfo::CacheRequestInfo(
16 PP_Bool* hit, 16 PP_Bool* hit,
17 PP_FileHandle* handle, 17 PP_FileHandle* handle,
18 scoped_refptr<TrackedCallback> cb) 18 scoped_refptr<TrackedCallback> cb)
19 : is_hit(hit), file_handle(handle), callback(cb) {} 19 : is_hit(hit), file_handle(handle), callback(cb) {}
20 20
21 PnaclTranslationResourceHost::CacheRequestInfo::~CacheRequestInfo() {} 21 PnaclTranslationResourceHost::CacheRequestInfo::~CacheRequestInfo() {}
22 22
23 PnaclTranslationResourceHost::PnaclTranslationResourceHost( 23 PnaclTranslationResourceHost::PnaclTranslationResourceHost(
24 const scoped_refptr<base::MessageLoopProxy>& io_message_loop) 24 const scoped_refptr<base::MessageLoopProxy>& io_message_loop)
25 : io_message_loop_(io_message_loop), channel_(NULL) {} 25 : io_message_loop_(io_message_loop), channel_(NULL) {}
26 26
27 PnaclTranslationResourceHost::~PnaclTranslationResourceHost() { 27 PnaclTranslationResourceHost::~PnaclTranslationResourceHost() {
28 DCHECK(io_message_loop_->BelongsToCurrentThread());
28 CleanupCacheRequests(); 29 CleanupCacheRequests();
30 CleanupEnsurePnaclRequests();
29 } 31 }
30 32
31 void PnaclTranslationResourceHost::OnFilterAdded(IPC::Channel* channel) { 33 void PnaclTranslationResourceHost::OnFilterAdded(IPC::Channel* channel) {
32 DCHECK(io_message_loop_->BelongsToCurrentThread()); 34 DCHECK(io_message_loop_->BelongsToCurrentThread());
33 channel_ = channel; 35 channel_ = channel;
34 } 36 }
35 37
36 void PnaclTranslationResourceHost::OnFilterRemoved() { 38 void PnaclTranslationResourceHost::OnFilterRemoved() {
37 DCHECK(io_message_loop_->BelongsToCurrentThread()); 39 DCHECK(io_message_loop_->BelongsToCurrentThread());
38 channel_ = NULL; 40 channel_ = NULL;
39 } 41 }
40 42
41 void PnaclTranslationResourceHost::OnChannelClosing() { 43 void PnaclTranslationResourceHost::OnChannelClosing() {
42 DCHECK(io_message_loop_->BelongsToCurrentThread()); 44 DCHECK(io_message_loop_->BelongsToCurrentThread());
43 channel_ = NULL; 45 channel_ = NULL;
44 } 46 }
45 47
46 bool PnaclTranslationResourceHost::OnMessageReceived( 48 bool PnaclTranslationResourceHost::OnMessageReceived(
47 const IPC::Message& message) { 49 const IPC::Message& message) {
48 DCHECK(io_message_loop_->BelongsToCurrentThread()); 50 DCHECK(io_message_loop_->BelongsToCurrentThread());
49 bool handled = true; 51 bool handled = true;
50 IPC_BEGIN_MESSAGE_MAP(PnaclTranslationResourceHost, message) 52 IPC_BEGIN_MESSAGE_MAP(PnaclTranslationResourceHost, message)
51 IPC_MESSAGE_HANDLER(NaClViewMsg_NexeTempFileReply, OnNexeTempFileReply) 53 IPC_MESSAGE_HANDLER(NaClViewMsg_NexeTempFileReply, OnNexeTempFileReply)
54 IPC_MESSAGE_HANDLER(NaClViewMsg_EnsurePnaclInstalledReply,
55 OnEnsurePnaclInstalledReply)
56 IPC_MESSAGE_HANDLER(NaClViewMsg_EnsurePnaclInstalledProgress,
57 OnEnsurePnaclInstalledProgress)
52 IPC_MESSAGE_UNHANDLED(handled = false) 58 IPC_MESSAGE_UNHANDLED(handled = false)
53 IPC_END_MESSAGE_MAP() 59 IPC_END_MESSAGE_MAP()
54 return handled; 60 return handled;
55 } 61 }
56 62
57 void PnaclTranslationResourceHost::RequestNexeFd( 63 void PnaclTranslationResourceHost::RequestNexeFd(
58 int render_view_id, 64 int render_view_id,
59 PP_Instance instance, 65 PP_Instance instance,
60 const nacl::PnaclCacheInfo& cache_info, 66 const nacl::PnaclCacheInfo& cache_info,
61 PP_Bool* is_hit, 67 PP_Bool* is_hit,
62 PP_FileHandle* file_handle, 68 PP_FileHandle* file_handle,
63 scoped_refptr<TrackedCallback> callback) { 69 scoped_refptr<TrackedCallback> callback) {
70 DCHECK(PpapiGlobals::Get()->
71 GetMainThreadMessageLoop()->BelongsToCurrentThread());
72 io_message_loop_->PostTask(
73 FROM_HERE,
74 base::Bind(&PnaclTranslationResourceHost::SendRequestNexeFd,
75 this,
76 render_view_id,
77 instance,
78 cache_info,
79 is_hit,
80 file_handle,
81 callback));
82 return;
83 }
64 84
65 if (!io_message_loop_->BelongsToCurrentThread()) { 85 void PnaclTranslationResourceHost::SendRequestNexeFd(
66 io_message_loop_->PostTask( 86 int render_view_id,
67 FROM_HERE, 87 PP_Instance instance,
68 base::Bind(&PnaclTranslationResourceHost::RequestNexeFd, 88 const nacl::PnaclCacheInfo& cache_info,
69 this, 89 PP_Bool* is_hit,
70 render_view_id, 90 PP_FileHandle* file_handle,
71 instance, 91 scoped_refptr<TrackedCallback> callback) {
72 cache_info, 92 DCHECK(io_message_loop_->BelongsToCurrentThread());
73 is_hit,
74 file_handle,
75 callback));
76 return;
77 }
78 if (!channel_ || !channel_->Send(new NaClHostMsg_NexeTempFileRequest( 93 if (!channel_ || !channel_->Send(new NaClHostMsg_NexeTempFileRequest(
79 render_view_id, instance, cache_info))) { 94 render_view_id, instance, cache_info))) {
80 PpapiGlobals::Get()->GetMainThreadMessageLoop() 95 PpapiGlobals::Get()->GetMainThreadMessageLoop()
81 ->PostTask(FROM_HERE, 96 ->PostTask(FROM_HERE,
82 base::Bind(&TrackedCallback::Run, 97 base::Bind(&TrackedCallback::Run,
83 callback, 98 callback,
84 static_cast<int32_t>(PP_ERROR_FAILED))); 99 static_cast<int32_t>(PP_ERROR_FAILED)));
85 return; 100 return;
86 } 101 }
87 pending_cache_requests_.insert(std::make_pair( 102 pending_cache_requests_.insert(std::make_pair(
88 instance, CacheRequestInfo(is_hit, file_handle, callback))); 103 instance, CacheRequestInfo(is_hit, file_handle, callback)));
89 } 104 }
90 105
91 void PnaclTranslationResourceHost::ReportTranslationFinished( 106 void PnaclTranslationResourceHost::ReportTranslationFinished(
92 PP_Instance instance) { 107 PP_Instance instance) {
93 if (!io_message_loop_->BelongsToCurrentThread()) { 108 DCHECK(PpapiGlobals::Get()->
94 io_message_loop_->PostTask( 109 GetMainThreadMessageLoop()->BelongsToCurrentThread());
95 FROM_HERE, 110 io_message_loop_->PostTask(
96 base::Bind(&PnaclTranslationResourceHost::ReportTranslationFinished, 111 FROM_HERE,
97 this, 112 base::Bind(&PnaclTranslationResourceHost::SendReportTranslationFinished,
98 instance)); 113 this,
99 return; 114 instance));
100 } 115 return;
116 }
117
118 void PnaclTranslationResourceHost::SendReportTranslationFinished(
119 PP_Instance instance) {
120 DCHECK(io_message_loop_->BelongsToCurrentThread());
101 // If the channel is closed or we have been detached, we are probably shutting 121 // If the channel is closed or we have been detached, we are probably shutting
102 // down, so just don't send anything. 122 // down, so just don't send anything.
103 if (!channel_) 123 if (!channel_)
104 return; 124 return;
105 DCHECK(pending_cache_requests_.count(instance) == 0); 125 DCHECK(pending_cache_requests_.count(instance) == 0);
106 channel_->Send(new NaClHostMsg_ReportTranslationFinished(instance)); 126 channel_->Send(new NaClHostMsg_ReportTranslationFinished(instance));
107 } 127 }
108 128
109 void PnaclTranslationResourceHost::OnNexeTempFileReply( 129 void PnaclTranslationResourceHost::OnNexeTempFileReply(
110 PP_Instance instance, 130 PP_Instance instance,
111 bool is_hit, 131 bool is_hit,
112 IPC::PlatformFileForTransit file) { 132 IPC::PlatformFileForTransit file) {
133 DCHECK(io_message_loop_->BelongsToCurrentThread());
113 CacheRequestInfoMap::iterator it = pending_cache_requests_.find(instance); 134 CacheRequestInfoMap::iterator it = pending_cache_requests_.find(instance);
114 int32_t status = PP_ERROR_FAILED; 135 int32_t status = PP_ERROR_FAILED;
115 // Handle the expected successful case first. 136 // Handle the expected successful case first.
116 if (it != pending_cache_requests_.end() && 137 if (it != pending_cache_requests_.end() &&
117 !(file == IPC::InvalidPlatformFileForTransit()) && 138 !(file == IPC::InvalidPlatformFileForTransit()) &&
118 TrackedCallback::IsPending(it->second.callback)) { 139 TrackedCallback::IsPending(it->second.callback)) {
119 *it->second.is_hit = PP_FromBool(is_hit); 140 *it->second.is_hit = PP_FromBool(is_hit);
120 *it->second.file_handle = IPC::PlatformFileForTransitToPlatformFile(file); 141 *it->second.file_handle = IPC::PlatformFileForTransitToPlatformFile(file);
121 status = PP_OK; 142 status = PP_OK;
122 } 143 }
123 if (it == pending_cache_requests_.end()) { 144 if (it == pending_cache_requests_.end()) {
124 DLOG(ERROR) << "Could not find pending request for reply"; 145 DLOG(ERROR) << "Could not find pending request for reply";
125 } else { 146 } else {
126 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( 147 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
127 FROM_HERE, 148 FROM_HERE,
128 base::Bind(&TrackedCallback::Run, it->second.callback, status)); 149 base::Bind(&TrackedCallback::Run, it->second.callback, status));
129 pending_cache_requests_.erase(it); 150 pending_cache_requests_.erase(it);
130 } 151 }
131 if (file == IPC::InvalidPlatformFileForTransit()) { 152 if (file == IPC::InvalidPlatformFileForTransit()) {
132 DLOG(ERROR) << "Got invalid platformfilefortransit"; 153 DLOG(ERROR) << "Got invalid platformfilefortransit";
133 } else if (status != PP_OK) { 154 } else if (status != PP_OK) {
134 base::ClosePlatformFile(IPC::PlatformFileForTransitToPlatformFile(file)); 155 base::ClosePlatformFile(IPC::PlatformFileForTransitToPlatformFile(file));
135 } 156 }
136 } 157 }
137 158
138 void PnaclTranslationResourceHost::CleanupCacheRequests() { 159 void PnaclTranslationResourceHost::CleanupCacheRequests() {
160 DCHECK(io_message_loop_->BelongsToCurrentThread());
139 for (CacheRequestInfoMap::iterator it = pending_cache_requests_.begin(); 161 for (CacheRequestInfoMap::iterator it = pending_cache_requests_.begin();
140 it != pending_cache_requests_.end(); 162 it != pending_cache_requests_.end();
141 ++it) { 163 ++it) {
142 it->second.callback->PostAbort(); 164 it->second.callback->PostAbort();
143 } 165 }
144 pending_cache_requests_.clear(); 166 pending_cache_requests_.clear();
145 } 167 }
146 168
169 void PnaclTranslationResourceHost::EnsurePnaclInstalled(
170 PP_Instance instance,
171 scoped_refptr<TrackedCallback> callback) {
172 DCHECK(PpapiGlobals::Get()->
173 GetMainThreadMessageLoop()->BelongsToCurrentThread());
174 io_message_loop_->PostTask(
175 FROM_HERE,
176 base::Bind(&PnaclTranslationResourceHost::SendEnsurePnaclInstalled,
177 this, instance, callback));
178 return;
179 }
180
181 void PnaclTranslationResourceHost::SendEnsurePnaclInstalled(
182 PP_Instance instance,
183 scoped_refptr<TrackedCallback> callback) {
184 DCHECK(io_message_loop_->BelongsToCurrentThread());
185 // If a request is already in, just queue this one and wait for notification.
186 // Hope that the request is not canceled.
187 if (pending_ensure_pnacl_requests_.size() > 0) {
188 pending_ensure_pnacl_requests_.push_back(callback);
189 return;
190 }
191 // Otherwise, try to send the request, then queue.
192 if (!channel_ || !channel_->Send(new NaClHostMsg_EnsurePnaclInstalled(
193 instance))) {
194 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
195 FROM_HERE,
196 base::Bind(&TrackedCallback::Run,
197 callback,
198 static_cast<int32_t>(PP_ERROR_FAILED)));
199 return;
200 }
201 pending_ensure_pnacl_requests_.push_back(callback);
202 }
203
204 void PnaclTranslationResourceHost::OnEnsurePnaclInstalledReply(
205 PP_Instance instance,
206 bool success) {
207 DCHECK(io_message_loop_->BelongsToCurrentThread());
208 // Broadcast to all listeners.
209 for (EnsurePnaclInstalledList::iterator
210 i = pending_ensure_pnacl_requests_.begin(),
211 e = pending_ensure_pnacl_requests_.end();
212 i != e; ++i) {
213 if (TrackedCallback::IsPending(*i)) {
214 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
215 FROM_HERE,
216 base::Bind(&TrackedCallback::Run,
217 *i,
218 static_cast<int32_t>(success ? PP_OK : PP_ERROR_FAILED)));
219 }
220 }
221 pending_ensure_pnacl_requests_.clear();
222 }
223
224 void PnaclTranslationResourceHost::OnEnsurePnaclInstalledProgress(
jln (very slow on Chromium) 2013/08/05 23:58:28 1. This is not a great way to do things as far as
jvoung (off chromium) 2013/08/06 01:11:13 Ok, I'll take it out for now, and stub out earlier
225 PP_Instance instance,
226 const nacl::PnaclInstallProgress& progress) {
227 // TODO(jvoung): Issue a progress event w/ dmichael's new DispatchEvent
228 // interface: https://codereview.chromium.org/14588009/
229 }
230
231 void PnaclTranslationResourceHost::CleanupEnsurePnaclRequests() {
232 DCHECK(io_message_loop_->BelongsToCurrentThread());
233 for (EnsurePnaclInstalledList::iterator
234 i = pending_ensure_pnacl_requests_.begin(),
235 e = pending_ensure_pnacl_requests_.end();
236 i != e; ++i) {
237 (*i)->PostAbort();
238 }
239 pending_ensure_pnacl_requests_.clear();
240 }
241
147 #endif // DISABLE_NACL 242 #endif // DISABLE_NACL
OLDNEW
« no previous file with comments | « chrome/renderer/pepper/pnacl_translation_resource_host.h ('k') | chrome/renderer/pepper/ppb_nacl_private_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698