| 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 #include "components/nacl/common/nacl_host_messages.h" | 7 #include "components/nacl/common/nacl_host_messages.h" |
| 8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/shared_impl/ppapi_globals.h" | 9 #include "ppapi/shared_impl/ppapi_globals.h" |
| 10 | 10 |
| 11 using ppapi::TrackedCallback; | 11 using ppapi::TrackedCallback; |
| 12 using ppapi::PpapiGlobals; | 12 using ppapi::PpapiGlobals; |
| 13 | 13 |
| 14 PnaclTranslationResourceHost::CacheRequestInfo::CacheRequestInfo( | 14 PnaclTranslationResourceHost::CacheRequestInfo::CacheRequestInfo( |
| 15 PP_Bool* hit, | 15 PP_Bool* hit, |
| 16 PP_FileHandle* handle, | 16 PP_FileHandle* handle, |
| 17 scoped_refptr<TrackedCallback> cb) | 17 scoped_refptr<TrackedCallback> cb) |
| 18 : is_hit(hit), file_handle(handle), callback(cb) {} | 18 : is_hit(hit), file_handle(handle), callback(cb) {} |
| 19 | 19 |
| 20 PnaclTranslationResourceHost::CacheRequestInfo::~CacheRequestInfo() {} | 20 PnaclTranslationResourceHost::CacheRequestInfo::~CacheRequestInfo() {} |
| 21 | 21 |
| 22 PnaclTranslationResourceHost::PnaclTranslationResourceHost( | 22 PnaclTranslationResourceHost::PnaclTranslationResourceHost( |
| 23 const scoped_refptr<base::MessageLoopProxy>& io_message_loop) | 23 const scoped_refptr<base::MessageLoopProxy>& io_message_loop) |
| 24 : io_message_loop_(io_message_loop), channel_(NULL) {} | 24 : io_message_loop_(io_message_loop), sender_(NULL) {} |
| 25 | 25 |
| 26 PnaclTranslationResourceHost::~PnaclTranslationResourceHost() { | 26 PnaclTranslationResourceHost::~PnaclTranslationResourceHost() { |
| 27 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 27 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 28 CleanupCacheRequests(); | 28 CleanupCacheRequests(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void PnaclTranslationResourceHost::OnFilterAdded(IPC::Channel* channel) { | 31 void PnaclTranslationResourceHost::OnFilterAdded(IPC::Sender* sender) { |
| 32 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 32 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 33 channel_ = channel; | 33 sender_ = sender; |
| 34 } | 34 } |
| 35 | 35 |
| 36 void PnaclTranslationResourceHost::OnFilterRemoved() { | 36 void PnaclTranslationResourceHost::OnFilterRemoved() { |
| 37 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 37 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 38 channel_ = NULL; | 38 sender_ = NULL; |
| 39 } | 39 } |
| 40 | 40 |
| 41 void PnaclTranslationResourceHost::OnChannelClosing() { | 41 void PnaclTranslationResourceHost::OnChannelClosing() { |
| 42 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 42 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 43 channel_ = NULL; | 43 sender_ = NULL; |
| 44 } | 44 } |
| 45 | 45 |
| 46 bool PnaclTranslationResourceHost::OnMessageReceived( | 46 bool PnaclTranslationResourceHost::OnMessageReceived( |
| 47 const IPC::Message& message) { | 47 const IPC::Message& message) { |
| 48 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 48 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 49 bool handled = true; | 49 bool handled = true; |
| 50 IPC_BEGIN_MESSAGE_MAP(PnaclTranslationResourceHost, message) | 50 IPC_BEGIN_MESSAGE_MAP(PnaclTranslationResourceHost, message) |
| 51 IPC_MESSAGE_HANDLER(NaClViewMsg_NexeTempFileReply, OnNexeTempFileReply) | 51 IPC_MESSAGE_HANDLER(NaClViewMsg_NexeTempFileReply, OnNexeTempFileReply) |
| 52 IPC_MESSAGE_UNHANDLED(handled = false) | 52 IPC_MESSAGE_UNHANDLED(handled = false) |
| 53 IPC_END_MESSAGE_MAP() | 53 IPC_END_MESSAGE_MAP() |
| (...skipping 23 matching lines...) Expand all Loading... |
| 77 } | 77 } |
| 78 | 78 |
| 79 void PnaclTranslationResourceHost::SendRequestNexeFd( | 79 void PnaclTranslationResourceHost::SendRequestNexeFd( |
| 80 int render_view_id, | 80 int render_view_id, |
| 81 PP_Instance instance, | 81 PP_Instance instance, |
| 82 const nacl::PnaclCacheInfo& cache_info, | 82 const nacl::PnaclCacheInfo& cache_info, |
| 83 PP_Bool* is_hit, | 83 PP_Bool* is_hit, |
| 84 PP_FileHandle* file_handle, | 84 PP_FileHandle* file_handle, |
| 85 scoped_refptr<TrackedCallback> callback) { | 85 scoped_refptr<TrackedCallback> callback) { |
| 86 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 86 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 87 if (!channel_ || !channel_->Send(new NaClHostMsg_NexeTempFileRequest( | 87 if (!sender_ || !sender_->Send(new NaClHostMsg_NexeTempFileRequest( |
| 88 render_view_id, instance, cache_info))) { | 88 render_view_id, instance, cache_info))) { |
| 89 PpapiGlobals::Get()->GetMainThreadMessageLoop() | 89 PpapiGlobals::Get()->GetMainThreadMessageLoop() |
| 90 ->PostTask(FROM_HERE, | 90 ->PostTask(FROM_HERE, |
| 91 base::Bind(&TrackedCallback::Run, | 91 base::Bind(&TrackedCallback::Run, |
| 92 callback, | 92 callback, |
| 93 static_cast<int32_t>(PP_ERROR_FAILED))); | 93 static_cast<int32_t>(PP_ERROR_FAILED))); |
| 94 return; | 94 return; |
| 95 } | 95 } |
| 96 pending_cache_requests_.insert(std::make_pair( | 96 pending_cache_requests_.insert(std::make_pair( |
| 97 instance, CacheRequestInfo(is_hit, file_handle, callback))); | 97 instance, CacheRequestInfo(is_hit, file_handle, callback))); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void PnaclTranslationResourceHost::ReportTranslationFinished( | 100 void PnaclTranslationResourceHost::ReportTranslationFinished( |
| 101 PP_Instance instance, | 101 PP_Instance instance, |
| 102 PP_Bool success) { | 102 PP_Bool success) { |
| 103 DCHECK(PpapiGlobals::Get()-> | 103 DCHECK(PpapiGlobals::Get()-> |
| 104 GetMainThreadMessageLoop()->BelongsToCurrentThread()); | 104 GetMainThreadMessageLoop()->BelongsToCurrentThread()); |
| 105 io_message_loop_->PostTask( | 105 io_message_loop_->PostTask( |
| 106 FROM_HERE, | 106 FROM_HERE, |
| 107 base::Bind(&PnaclTranslationResourceHost::SendReportTranslationFinished, | 107 base::Bind(&PnaclTranslationResourceHost::SendReportTranslationFinished, |
| 108 this, | 108 this, |
| 109 instance, | 109 instance, |
| 110 success)); | 110 success)); |
| 111 return; | 111 return; |
| 112 } | 112 } |
| 113 | 113 |
| 114 void PnaclTranslationResourceHost::SendReportTranslationFinished( | 114 void PnaclTranslationResourceHost::SendReportTranslationFinished( |
| 115 PP_Instance instance, | 115 PP_Instance instance, |
| 116 PP_Bool success) { | 116 PP_Bool success) { |
| 117 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 117 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 118 // If the channel is closed or we have been detached, we are probably shutting | 118 // If the sender is closed or we have been detached, we are probably shutting |
| 119 // down, so just don't send anything. | 119 // down, so just don't send anything. |
| 120 if (!channel_) | 120 if (!sender_) |
| 121 return; | 121 return; |
| 122 DCHECK(pending_cache_requests_.count(instance) == 0); | 122 DCHECK(pending_cache_requests_.count(instance) == 0); |
| 123 channel_->Send(new NaClHostMsg_ReportTranslationFinished(instance, | 123 sender_->Send(new NaClHostMsg_ReportTranslationFinished(instance, |
| 124 PP_ToBool(success))); | 124 PP_ToBool(success))); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void PnaclTranslationResourceHost::OnNexeTempFileReply( | 127 void PnaclTranslationResourceHost::OnNexeTempFileReply( |
| 128 PP_Instance instance, | 128 PP_Instance instance, |
| 129 bool is_hit, | 129 bool is_hit, |
| 130 IPC::PlatformFileForTransit file) { | 130 IPC::PlatformFileForTransit file) { |
| 131 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 131 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 132 base::File base_file = IPC::PlatformFileForTransitToFile(file); | 132 base::File base_file = IPC::PlatformFileForTransitToFile(file); |
| 133 CacheRequestInfoMap::iterator it = pending_cache_requests_.find(instance); | 133 CacheRequestInfoMap::iterator it = pending_cache_requests_.find(instance); |
| 134 int32_t status = PP_ERROR_FAILED; | 134 int32_t status = PP_ERROR_FAILED; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 154 | 154 |
| 155 void PnaclTranslationResourceHost::CleanupCacheRequests() { | 155 void PnaclTranslationResourceHost::CleanupCacheRequests() { |
| 156 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 156 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 157 for (CacheRequestInfoMap::iterator it = pending_cache_requests_.begin(); | 157 for (CacheRequestInfoMap::iterator it = pending_cache_requests_.begin(); |
| 158 it != pending_cache_requests_.end(); | 158 it != pending_cache_requests_.end(); |
| 159 ++it) { | 159 ++it) { |
| 160 it->second.callback->PostAbort(); | 160 it->second.callback->PostAbort(); |
| 161 } | 161 } |
| 162 pending_cache_requests_.clear(); | 162 pending_cache_requests_.clear(); |
| 163 } | 163 } |
| OLD | NEW |