| 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; | |
| 12 using ppapi::PpapiGlobals; | 11 using ppapi::PpapiGlobals; |
| 13 | 12 |
| 14 PnaclTranslationResourceHost::CacheRequestInfo::CacheRequestInfo( | |
| 15 PP_Bool* hit, | |
| 16 PP_FileHandle* handle, | |
| 17 scoped_refptr<TrackedCallback> cb) | |
| 18 : is_hit(hit), file_handle(handle), callback(cb) {} | |
| 19 | |
| 20 PnaclTranslationResourceHost::CacheRequestInfo::~CacheRequestInfo() {} | |
| 21 | |
| 22 PnaclTranslationResourceHost::PnaclTranslationResourceHost( | 13 PnaclTranslationResourceHost::PnaclTranslationResourceHost( |
| 23 const scoped_refptr<base::MessageLoopProxy>& io_message_loop) | 14 const scoped_refptr<base::MessageLoopProxy>& io_message_loop) |
| 24 : io_message_loop_(io_message_loop), sender_(NULL) {} | 15 : io_message_loop_(io_message_loop), sender_(NULL) {} |
| 25 | 16 |
| 26 PnaclTranslationResourceHost::~PnaclTranslationResourceHost() { | 17 PnaclTranslationResourceHost::~PnaclTranslationResourceHost() { |
| 27 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 18 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 28 CleanupCacheRequests(); | 19 CleanupCacheRequests(); |
| 29 } | 20 } |
| 30 | 21 |
| 31 void PnaclTranslationResourceHost::OnFilterAdded(IPC::Sender* sender) { | 22 void PnaclTranslationResourceHost::OnFilterAdded(IPC::Sender* sender) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 51 IPC_MESSAGE_HANDLER(NaClViewMsg_NexeTempFileReply, OnNexeTempFileReply) | 42 IPC_MESSAGE_HANDLER(NaClViewMsg_NexeTempFileReply, OnNexeTempFileReply) |
| 52 IPC_MESSAGE_UNHANDLED(handled = false) | 43 IPC_MESSAGE_UNHANDLED(handled = false) |
| 53 IPC_END_MESSAGE_MAP() | 44 IPC_END_MESSAGE_MAP() |
| 54 return handled; | 45 return handled; |
| 55 } | 46 } |
| 56 | 47 |
| 57 void PnaclTranslationResourceHost::RequestNexeFd( | 48 void PnaclTranslationResourceHost::RequestNexeFd( |
| 58 int render_view_id, | 49 int render_view_id, |
| 59 PP_Instance instance, | 50 PP_Instance instance, |
| 60 const nacl::PnaclCacheInfo& cache_info, | 51 const nacl::PnaclCacheInfo& cache_info, |
| 61 PP_Bool* is_hit, | 52 RequestNexeFdCallback callback) { |
| 62 PP_FileHandle* file_handle, | |
| 63 scoped_refptr<TrackedCallback> callback) { | |
| 64 DCHECK(PpapiGlobals::Get()-> | 53 DCHECK(PpapiGlobals::Get()-> |
| 65 GetMainThreadMessageLoop()->BelongsToCurrentThread()); | 54 GetMainThreadMessageLoop()->BelongsToCurrentThread()); |
| 66 io_message_loop_->PostTask( | 55 io_message_loop_->PostTask( |
| 67 FROM_HERE, | 56 FROM_HERE, |
| 68 base::Bind(&PnaclTranslationResourceHost::SendRequestNexeFd, | 57 base::Bind(&PnaclTranslationResourceHost::SendRequestNexeFd, |
| 69 this, | 58 this, |
| 70 render_view_id, | 59 render_view_id, |
| 71 instance, | 60 instance, |
| 72 cache_info, | 61 cache_info, |
| 73 is_hit, | |
| 74 file_handle, | |
| 75 callback)); | 62 callback)); |
| 76 return; | 63 return; |
| 77 } | 64 } |
| 78 | 65 |
| 79 void PnaclTranslationResourceHost::SendRequestNexeFd( | 66 void PnaclTranslationResourceHost::SendRequestNexeFd( |
| 80 int render_view_id, | 67 int render_view_id, |
| 81 PP_Instance instance, | 68 PP_Instance instance, |
| 82 const nacl::PnaclCacheInfo& cache_info, | 69 const nacl::PnaclCacheInfo& cache_info, |
| 83 PP_Bool* is_hit, | 70 RequestNexeFdCallback callback) { |
| 84 PP_FileHandle* file_handle, | |
| 85 scoped_refptr<TrackedCallback> callback) { | |
| 86 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 71 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 87 if (!sender_ || !sender_->Send(new NaClHostMsg_NexeTempFileRequest( | 72 if (!sender_ || !sender_->Send(new NaClHostMsg_NexeTempFileRequest( |
| 88 render_view_id, instance, cache_info))) { | 73 render_view_id, instance, cache_info))) { |
| 89 PpapiGlobals::Get()->GetMainThreadMessageLoop() | 74 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 90 ->PostTask(FROM_HERE, | 75 FROM_HERE, |
| 91 base::Bind(&TrackedCallback::Run, | 76 base::Bind(callback, |
| 92 callback, | 77 static_cast<int32_t>(PP_ERROR_FAILED), |
| 93 static_cast<int32_t>(PP_ERROR_FAILED))); | 78 false, |
| 79 PP_kInvalidFileHandle)); |
| 94 return; | 80 return; |
| 95 } | 81 } |
| 96 pending_cache_requests_.insert(std::make_pair( | 82 pending_cache_requests_.insert(std::make_pair(instance, callback)); |
| 97 instance, CacheRequestInfo(is_hit, file_handle, callback))); | |
| 98 } | 83 } |
| 99 | 84 |
| 100 void PnaclTranslationResourceHost::ReportTranslationFinished( | 85 void PnaclTranslationResourceHost::ReportTranslationFinished( |
| 101 PP_Instance instance, | 86 PP_Instance instance, |
| 102 PP_Bool success) { | 87 PP_Bool success) { |
| 103 DCHECK(PpapiGlobals::Get()-> | 88 DCHECK(PpapiGlobals::Get()-> |
| 104 GetMainThreadMessageLoop()->BelongsToCurrentThread()); | 89 GetMainThreadMessageLoop()->BelongsToCurrentThread()); |
| 105 io_message_loop_->PostTask( | 90 io_message_loop_->PostTask( |
| 106 FROM_HERE, | 91 FROM_HERE, |
| 107 base::Bind(&PnaclTranslationResourceHost::SendReportTranslationFinished, | 92 base::Bind(&PnaclTranslationResourceHost::SendReportTranslationFinished, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 126 | 111 |
| 127 void PnaclTranslationResourceHost::OnNexeTempFileReply( | 112 void PnaclTranslationResourceHost::OnNexeTempFileReply( |
| 128 PP_Instance instance, | 113 PP_Instance instance, |
| 129 bool is_hit, | 114 bool is_hit, |
| 130 IPC::PlatformFileForTransit file) { | 115 IPC::PlatformFileForTransit file) { |
| 131 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 116 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 132 base::File base_file = IPC::PlatformFileForTransitToFile(file); | 117 base::File base_file = IPC::PlatformFileForTransitToFile(file); |
| 133 CacheRequestInfoMap::iterator it = pending_cache_requests_.find(instance); | 118 CacheRequestInfoMap::iterator it = pending_cache_requests_.find(instance); |
| 134 int32_t status = PP_ERROR_FAILED; | 119 int32_t status = PP_ERROR_FAILED; |
| 135 // Handle the expected successful case first. | 120 // Handle the expected successful case first. |
| 136 if (it != pending_cache_requests_.end() && base_file.IsValid() && | 121 PP_FileHandle file_handle = PP_kInvalidFileHandle; |
| 137 TrackedCallback::IsPending(it->second.callback)) { | 122 if (it != pending_cache_requests_.end() && base_file.IsValid()) { |
| 138 *it->second.is_hit = PP_FromBool(is_hit); | 123 file_handle = base_file.TakePlatformFile(); |
| 139 *it->second.file_handle = base_file.TakePlatformFile(); | |
| 140 status = PP_OK; | 124 status = PP_OK; |
| 141 } | 125 } |
| 142 if (it == pending_cache_requests_.end()) { | 126 if (it == pending_cache_requests_.end()) { |
| 143 DLOG(ERROR) << "Could not find pending request for reply"; | 127 DLOG(ERROR) << "Could not find pending request for reply"; |
| 144 } else { | 128 } else { |
| 145 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 129 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 146 FROM_HERE, | 130 FROM_HERE, |
| 147 base::Bind(&TrackedCallback::Run, it->second.callback, status)); | 131 base::Bind(it->second, status, is_hit, file_handle)); |
| 148 pending_cache_requests_.erase(it); | 132 pending_cache_requests_.erase(it); |
| 149 } | 133 } |
| 150 if (!base_file.IsValid()) { | 134 if (!base_file.IsValid()) { |
| 151 DLOG(ERROR) << "Got invalid platformfilefortransit"; | 135 DLOG(ERROR) << "Got invalid platformfilefortransit"; |
| 152 } | 136 } |
| 153 } | 137 } |
| 154 | 138 |
| 155 void PnaclTranslationResourceHost::CleanupCacheRequests() { | 139 void PnaclTranslationResourceHost::CleanupCacheRequests() { |
| 156 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 140 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 157 for (CacheRequestInfoMap::iterator it = pending_cache_requests_.begin(); | 141 for (CacheRequestInfoMap::iterator it = pending_cache_requests_.begin(); |
| 158 it != pending_cache_requests_.end(); | 142 it != pending_cache_requests_.end(); |
| 159 ++it) { | 143 ++it) { |
| 160 it->second.callback->PostAbort(); | 144 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 145 FROM_HERE, |
| 146 base::Bind(it->second, |
| 147 static_cast<int32_t>(PP_ERROR_ABORTED), |
| 148 false, |
| 149 PP_kInvalidFileHandle)); |
| 161 } | 150 } |
| 162 pending_cache_requests_.clear(); | 151 pending_cache_requests_.clear(); |
| 163 } | 152 } |
| OLD | NEW |