Index: components/nacl/renderer/pnacl_translation_resource_host.cc |
diff --git a/components/nacl/renderer/pnacl_translation_resource_host.cc b/components/nacl/renderer/pnacl_translation_resource_host.cc |
index 03b65a57fbf0bc151996f8e55493f66322ac24c8..fb90cee769c0112c7c13c684219ff12b0bec7377 100644 |
--- a/components/nacl/renderer/pnacl_translation_resource_host.cc |
+++ b/components/nacl/renderer/pnacl_translation_resource_host.cc |
@@ -4,80 +4,45 @@ |
#include "pnacl_translation_resource_host.h" |
-#include "base/single_thread_task_runner.h" |
-#include "components/nacl/common/nacl_host_messages.h" |
#include "ppapi/c/pp_errors.h" |
#include "ppapi/shared_impl/ppapi_globals.h" |
using ppapi::PpapiGlobals; |
-PnaclTranslationResourceHost::PnaclTranslationResourceHost( |
- scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
- : io_task_runner_(io_task_runner), sender_(NULL) { |
-} |
+namespace { |
-PnaclTranslationResourceHost::~PnaclTranslationResourceHost() { |
- DCHECK(io_task_runner_->BelongsToCurrentThread()); |
- CleanupCacheRequests(); |
-} |
+void OnNexeTempFileReply( |
+ const PnaclTranslationResourceHost::RequestNexeFdCallback& callback, |
+ PP_Instance instance, |
+ base::File file, |
+ bool is_hit) { |
+ DCHECK(PpapiGlobals::Get() |
+ ->GetMainThreadMessageLoop() |
+ ->BelongsToCurrentThread()); |
-void PnaclTranslationResourceHost::OnFilterAdded(IPC::Channel* channel) { |
- DCHECK(io_task_runner_->BelongsToCurrentThread()); |
- sender_ = channel; |
+ callback.Run(instance, is_hit, file.TakePlatformFile()); |
} |
-void PnaclTranslationResourceHost::OnFilterRemoved() { |
- DCHECK(io_task_runner_->BelongsToCurrentThread()); |
- sender_ = NULL; |
-} |
+} // namespace |
-void PnaclTranslationResourceHost::OnChannelClosing() { |
- DCHECK(io_task_runner_->BelongsToCurrentThread()); |
- sender_ = NULL; |
+PnaclTranslationResourceHost::PnaclTranslationResourceHost( |
+ nacl::mojom::NaClHost* host) |
+ : host_(host) { |
+ DCHECK(host_); |
} |
-bool PnaclTranslationResourceHost::OnMessageReceived( |
- const IPC::Message& message) { |
- DCHECK(io_task_runner_->BelongsToCurrentThread()); |
- bool handled = true; |
- IPC_BEGIN_MESSAGE_MAP(PnaclTranslationResourceHost, message) |
- IPC_MESSAGE_HANDLER(NaClViewMsg_NexeTempFileReply, OnNexeTempFileReply) |
- IPC_MESSAGE_UNHANDLED(handled = false) |
- IPC_END_MESSAGE_MAP() |
- return handled; |
-} |
+PnaclTranslationResourceHost::~PnaclTranslationResourceHost() = default; |
void PnaclTranslationResourceHost::RequestNexeFd( |
int render_view_id, |
PP_Instance instance, |
const nacl::PnaclCacheInfo& cache_info, |
RequestNexeFdCallback callback) { |
- DCHECK(PpapiGlobals::Get()-> |
- GetMainThreadMessageLoop()->BelongsToCurrentThread()); |
- io_task_runner_->PostTask( |
- FROM_HERE, |
- base::Bind(&PnaclTranslationResourceHost::SendRequestNexeFd, this, |
- render_view_id, instance, cache_info, callback)); |
- return; |
-} |
- |
-void PnaclTranslationResourceHost::SendRequestNexeFd( |
- int render_view_id, |
- PP_Instance instance, |
- const nacl::PnaclCacheInfo& cache_info, |
- RequestNexeFdCallback callback) { |
- DCHECK(io_task_runner_->BelongsToCurrentThread()); |
- if (!sender_ || !sender_->Send(new NaClHostMsg_NexeTempFileRequest( |
- render_view_id, instance, cache_info))) { |
- PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
- FROM_HERE, |
- base::Bind(callback, |
- static_cast<int32_t>(PP_ERROR_FAILED), |
- false, |
- PP_kInvalidFileHandle)); |
- return; |
- } |
- pending_cache_requests_.insert(std::make_pair(instance, callback)); |
+ DCHECK(PpapiGlobals::Get() |
+ ->GetMainThreadMessageLoop() |
+ ->BelongsToCurrentThread()); |
+ host_->NexeTempFileRequest(render_view_id, instance, cache_info, |
+ base::Bind(&OnNexeTempFileReply, callback)); |
} |
void PnaclTranslationResourceHost::ReportTranslationFinished( |
@@ -85,63 +50,5 @@ void PnaclTranslationResourceHost::ReportTranslationFinished( |
PP_Bool success) { |
DCHECK(PpapiGlobals::Get()-> |
GetMainThreadMessageLoop()->BelongsToCurrentThread()); |
- io_task_runner_->PostTask( |
- FROM_HERE, |
- base::Bind(&PnaclTranslationResourceHost::SendReportTranslationFinished, |
- this, instance, success)); |
- return; |
-} |
- |
-void PnaclTranslationResourceHost::SendReportTranslationFinished( |
- PP_Instance instance, |
- PP_Bool success) { |
- DCHECK(io_task_runner_->BelongsToCurrentThread()); |
- // If the sender is closed or we have been detached, we are probably shutting |
- // down, so just don't send anything. |
- if (!sender_) |
- return; |
- DCHECK(pending_cache_requests_.count(instance) == 0); |
- sender_->Send(new NaClHostMsg_ReportTranslationFinished(instance, |
- PP_ToBool(success))); |
-} |
- |
-void PnaclTranslationResourceHost::OnNexeTempFileReply( |
- PP_Instance instance, |
- bool is_hit, |
- IPC::PlatformFileForTransit file) { |
- DCHECK(io_task_runner_->BelongsToCurrentThread()); |
- base::File base_file = IPC::PlatformFileForTransitToFile(file); |
- CacheRequestInfoMap::iterator it = pending_cache_requests_.find(instance); |
- if (!base_file.IsValid()) { |
- DLOG(ERROR) << "Got invalid platformfilefortransit"; |
- } |
- if (it != pending_cache_requests_.end()) { |
- PP_FileHandle file_handle = PP_kInvalidFileHandle; |
- int32_t status = PP_ERROR_FAILED; |
- if (base_file.IsValid()) { |
- file_handle = base_file.TakePlatformFile(); |
- status = PP_OK; |
- } |
- PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
- FROM_HERE, |
- base::Bind(it->second, status, is_hit, file_handle)); |
- pending_cache_requests_.erase(it); |
- } else { |
- DLOG(ERROR) << "Could not find pending request for reply"; |
- } |
-} |
- |
-void PnaclTranslationResourceHost::CleanupCacheRequests() { |
- DCHECK(io_task_runner_->BelongsToCurrentThread()); |
- for (CacheRequestInfoMap::iterator it = pending_cache_requests_.begin(); |
- it != pending_cache_requests_.end(); |
- ++it) { |
- PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
- FROM_HERE, |
- base::Bind(it->second, |
- static_cast<int32_t>(PP_ERROR_ABORTED), |
- false, |
- PP_kInvalidFileHandle)); |
- } |
- pending_cache_requests_.clear(); |
+ host_->ReportTranslationFinished(instance, PP_ToBool(success)); |
} |