1 // Copyright 2013 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_NACL_RENDERER_PNACL_TRANSLATION_RESOURCE_HOST_H_ 6 #define COMPONENTS_NACL_RENDERER_PNACL_TRANSLATION_RESOURCE_HOST_H_ 7 8 #include <stdint.h> 9 10 #include <map> 11 12 #include "base/functional/callback.h" 13 #include "ipc/ipc_platform_file.h" 14 #include "ipc/message_filter.h" 15 #include "ppapi/c/pp_bool.h" 16 #include "ppapi/c/pp_instance.h" 17 #include "ppapi/c/private/pp_file_handle.h" 18 19 namespace base { 20 class SingleThreadTaskRunner; 21 } 22 23 namespace nacl { 24 struct PnaclCacheInfo; 25 } 26 27 // A class to keep track of requests made to the browser for resources that the 28 // PNaCl translator needs (e.g. descriptors for the translator nexes, temp 29 // files, and cached translations). 30 31 // "Resource" might not be the best name for the various things that pnacl 32 // needs from the browser since "Resource" is a Pepper thing... 33 class PnaclTranslationResourceHost : public IPC::MessageFilter { 34 public: 35 typedef base::OnceCallback<void(int32_t, bool, PP_FileHandle)> 36 RequestNexeFdCallback; 37 38 explicit PnaclTranslationResourceHost( 39 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); 40 41 PnaclTranslationResourceHost(const PnaclTranslationResourceHost&) = delete; 42 PnaclTranslationResourceHost& operator=(const PnaclTranslationResourceHost&) = 43 delete; 44 45 void RequestNexeFd(PP_Instance instance, 46 const nacl::PnaclCacheInfo& cache_info, 47 RequestNexeFdCallback callback); 48 void ReportTranslationFinished(PP_Instance instance, PP_Bool success); 49 50 protected: 51 ~PnaclTranslationResourceHost() override; 52 53 private: 54 // Maps the instance with an outstanding cache request to the info 55 // about that request. 56 typedef std::map<PP_Instance, RequestNexeFdCallback> CacheRequestInfoMap; 57 58 // IPC::MessageFilter implementation. 59 bool OnMessageReceived(const IPC::Message& message) override; 60 void OnFilterAdded(IPC::Channel* channel) override; 61 void OnFilterRemoved() override; 62 void OnChannelClosing() override; 63 64 void SendRequestNexeFd(PP_Instance instance, 65 const nacl::PnaclCacheInfo& cache_info, 66 RequestNexeFdCallback callback); 67 void SendReportTranslationFinished(PP_Instance instance, 68 PP_Bool success); 69 void OnNexeTempFileReply(PP_Instance instance, 70 bool is_hit, 71 IPC::PlatformFileForTransit file); 72 void CleanupCacheRequests(); 73 74 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 75 76 // Should be accessed on the io thread. 77 IPC::Sender* sender_; 78 CacheRequestInfoMap pending_cache_requests_; 79 }; 80 81 #endif // COMPONENTS_NACL_RENDERER_PNACL_TRANSLATION_RESOURCE_HOST_H_ 82