| OLD | NEW |
| 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 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 29 CleanupCacheRequests(); | 29 CleanupCacheRequests(); |
| 30 CleanupEnsurePnaclRequests(); | |
| 31 } | 30 } |
| 32 | 31 |
| 33 void PnaclTranslationResourceHost::OnFilterAdded(IPC::Channel* channel) { | 32 void PnaclTranslationResourceHost::OnFilterAdded(IPC::Channel* channel) { |
| 34 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 33 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 35 channel_ = channel; | 34 channel_ = channel; |
| 36 } | 35 } |
| 37 | 36 |
| 38 void PnaclTranslationResourceHost::OnFilterRemoved() { | 37 void PnaclTranslationResourceHost::OnFilterRemoved() { |
| 39 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 38 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 40 channel_ = NULL; | 39 channel_ = NULL; |
| 41 } | 40 } |
| 42 | 41 |
| 43 void PnaclTranslationResourceHost::OnChannelClosing() { | 42 void PnaclTranslationResourceHost::OnChannelClosing() { |
| 44 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 43 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 45 channel_ = NULL; | 44 channel_ = NULL; |
| 46 } | 45 } |
| 47 | 46 |
| 48 bool PnaclTranslationResourceHost::OnMessageReceived( | 47 bool PnaclTranslationResourceHost::OnMessageReceived( |
| 49 const IPC::Message& message) { | 48 const IPC::Message& message) { |
| 50 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 49 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 51 bool handled = true; | 50 bool handled = true; |
| 52 IPC_BEGIN_MESSAGE_MAP(PnaclTranslationResourceHost, message) | 51 IPC_BEGIN_MESSAGE_MAP(PnaclTranslationResourceHost, message) |
| 53 IPC_MESSAGE_HANDLER(NaClViewMsg_NexeTempFileReply, OnNexeTempFileReply) | 52 IPC_MESSAGE_HANDLER(NaClViewMsg_NexeTempFileReply, OnNexeTempFileReply) |
| 54 IPC_MESSAGE_HANDLER(NaClViewMsg_EnsurePnaclInstalledReply, | |
| 55 OnEnsurePnaclInstalledReply) | |
| 56 IPC_MESSAGE_UNHANDLED(handled = false) | 53 IPC_MESSAGE_UNHANDLED(handled = false) |
| 57 IPC_END_MESSAGE_MAP() | 54 IPC_END_MESSAGE_MAP() |
| 58 return handled; | 55 return handled; |
| 59 } | 56 } |
| 60 | 57 |
| 61 void PnaclTranslationResourceHost::RequestNexeFd( | 58 void PnaclTranslationResourceHost::RequestNexeFd( |
| 62 int render_view_id, | 59 int render_view_id, |
| 63 PP_Instance instance, | 60 PP_Instance instance, |
| 64 const nacl::PnaclCacheInfo& cache_info, | 61 const nacl::PnaclCacheInfo& cache_info, |
| 65 PP_Bool* is_hit, | 62 PP_Bool* is_hit, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 void PnaclTranslationResourceHost::CleanupCacheRequests() { | 158 void PnaclTranslationResourceHost::CleanupCacheRequests() { |
| 162 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 159 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 163 for (CacheRequestInfoMap::iterator it = pending_cache_requests_.begin(); | 160 for (CacheRequestInfoMap::iterator it = pending_cache_requests_.begin(); |
| 164 it != pending_cache_requests_.end(); | 161 it != pending_cache_requests_.end(); |
| 165 ++it) { | 162 ++it) { |
| 166 it->second.callback->PostAbort(); | 163 it->second.callback->PostAbort(); |
| 167 } | 164 } |
| 168 pending_cache_requests_.clear(); | 165 pending_cache_requests_.clear(); |
| 169 } | 166 } |
| 170 | 167 |
| 171 void PnaclTranslationResourceHost::EnsurePnaclInstalled( | |
| 172 PP_Instance instance, | |
| 173 scoped_refptr<TrackedCallback> callback) { | |
| 174 DCHECK(PpapiGlobals::Get()-> | |
| 175 GetMainThreadMessageLoop()->BelongsToCurrentThread()); | |
| 176 io_message_loop_->PostTask( | |
| 177 FROM_HERE, | |
| 178 base::Bind(&PnaclTranslationResourceHost::SendEnsurePnaclInstalled, | |
| 179 this, instance, callback)); | |
| 180 return; | |
| 181 } | |
| 182 | |
| 183 void PnaclTranslationResourceHost::SendEnsurePnaclInstalled( | |
| 184 PP_Instance instance, | |
| 185 scoped_refptr<TrackedCallback> callback) { | |
| 186 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
| 187 // If a request is already in, just queue this one and wait for notification. | |
| 188 // Hope that the request is not canceled. | |
| 189 if (pending_ensure_pnacl_requests_.size() > 0) { | |
| 190 pending_ensure_pnacl_requests_.push_back(callback); | |
| 191 return; | |
| 192 } | |
| 193 // Otherwise, try to send the request, then queue. | |
| 194 if (!channel_ || !channel_->Send(new NaClHostMsg_EnsurePnaclInstalled( | |
| 195 instance))) { | |
| 196 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | |
| 197 FROM_HERE, | |
| 198 base::Bind(&TrackedCallback::Run, | |
| 199 callback, | |
| 200 static_cast<int32_t>(PP_ERROR_FAILED))); | |
| 201 return; | |
| 202 } | |
| 203 pending_ensure_pnacl_requests_.push_back(callback); | |
| 204 } | |
| 205 | |
| 206 void PnaclTranslationResourceHost::OnEnsurePnaclInstalledReply( | |
| 207 PP_Instance instance, | |
| 208 bool success) { | |
| 209 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
| 210 // Broadcast to all listeners. | |
| 211 for (EnsurePnaclInstalledList::iterator | |
| 212 i = pending_ensure_pnacl_requests_.begin(), | |
| 213 e = pending_ensure_pnacl_requests_.end(); | |
| 214 i != e; ++i) { | |
| 215 if (TrackedCallback::IsPending(*i)) { | |
| 216 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | |
| 217 FROM_HERE, | |
| 218 base::Bind(&TrackedCallback::Run, | |
| 219 *i, | |
| 220 static_cast<int32_t>(success ? PP_OK : PP_ERROR_FAILED))); | |
| 221 } | |
| 222 } | |
| 223 pending_ensure_pnacl_requests_.clear(); | |
| 224 } | |
| 225 | |
| 226 void PnaclTranslationResourceHost::CleanupEnsurePnaclRequests() { | |
| 227 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
| 228 for (EnsurePnaclInstalledList::iterator | |
| 229 i = pending_ensure_pnacl_requests_.begin(), | |
| 230 e = pending_ensure_pnacl_requests_.end(); | |
| 231 i != e; ++i) { | |
| 232 (*i)->PostAbort(); | |
| 233 } | |
| 234 pending_ensure_pnacl_requests_.clear(); | |
| 235 } | |
| 236 | |
| 237 #endif // DISABLE_NACL | 168 #endif // DISABLE_NACL |
| OLD | NEW |