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