Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_RENDERER_PEPPER_PNACL_TRANSLATION_RESOURCE_HOST_H_ |
| 6 | #define CHROME_RENDERER_PEPPER_PNACL_TRANSLATION_RESOURCE_HOST_H_ |
| 7 | |
| 8 | #include <map> |
Ben Murdoch | 2385ea3 | 2013-08-06 11:01:04 +0100 | [diff] [blame] | 9 | #include <vector> |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 10 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 11 | #include "ipc/ipc_channel_proxy.h" |
| 12 | #include "ipc/ipc_platform_file.h" |
| 13 | #include "ppapi/c/private/pp_file_handle.h" |
| 14 | #include "ppapi/shared_impl/tracked_callback.h" |
| 15 | |
Ben Murdoch | 2385ea3 | 2013-08-06 11:01:04 +0100 | [diff] [blame] | 16 | namespace nacl { |
| 17 | struct PnaclCacheInfo; |
| 18 | } |
| 19 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 20 | // A class to keep track of requests made to the browser for resources that the |
| 21 | // PNaCl translator needs (e.g. descriptors for the translator nexes, temp |
| 22 | // files, and cached translations). |
| 23 | |
| 24 | // "Resource" might not be the best name for the various things that pnacl |
| 25 | // needs from the browser since "Resource" is a Pepper thing... |
| 26 | class PnaclTranslationResourceHost : public IPC::ChannelProxy::MessageFilter { |
| 27 | public: |
| 28 | explicit PnaclTranslationResourceHost( |
| 29 | const scoped_refptr<base::MessageLoopProxy>& io_message_loop); |
| 30 | void RequestNexeFd(int render_view_id, |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 31 | PP_Instance instance, |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 32 | const nacl::PnaclCacheInfo& cache_info, |
| 33 | PP_Bool* is_hit, |
| 34 | PP_FileHandle* file_handle, |
| 35 | scoped_refptr<ppapi::TrackedCallback> callback); |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 36 | void ReportTranslationFinished(PP_Instance instance, PP_Bool success); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 37 | |
Ben Murdoch | 2385ea3 | 2013-08-06 11:01:04 +0100 | [diff] [blame] | 38 | // Ensure that PNaCl resources (pnacl-llc.nexe, linker, libs) are installed. |
| 39 | void EnsurePnaclInstalled(PP_Instance instance, |
| 40 | scoped_refptr<ppapi::TrackedCallback> callback); |
| 41 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 42 | protected: |
| 43 | virtual ~PnaclTranslationResourceHost(); |
| 44 | |
| 45 | private: |
| 46 | class CacheRequestInfo { |
| 47 | public: |
| 48 | CacheRequestInfo(PP_Bool* hit, |
| 49 | PP_FileHandle* handle, |
| 50 | scoped_refptr<ppapi::TrackedCallback> cb); |
| 51 | |
| 52 | ~CacheRequestInfo(); |
| 53 | |
| 54 | PP_Bool* is_hit; |
| 55 | PP_FileHandle* file_handle; |
| 56 | scoped_refptr<ppapi::TrackedCallback> callback; |
| 57 | }; |
| 58 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 59 | // Maps the instance with an outstanding cache request to the info |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 60 | // about that request. |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 61 | typedef std::map<PP_Instance, CacheRequestInfo> CacheRequestInfoMap; |
Ben Murdoch | 2385ea3 | 2013-08-06 11:01:04 +0100 | [diff] [blame] | 62 | // A list of outstanding EnsurePnaclInstalled requests. |
| 63 | typedef std::vector<scoped_refptr<ppapi::TrackedCallback> > |
| 64 | EnsurePnaclInstalledList; |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 65 | // IPC::ChannelProxy::MessageFilter implementation. |
| 66 | virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 67 | virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE; |
| 68 | virtual void OnFilterRemoved() OVERRIDE; |
| 69 | virtual void OnChannelClosing() OVERRIDE; |
| 70 | |
Ben Murdoch | 2385ea3 | 2013-08-06 11:01:04 +0100 | [diff] [blame] | 71 | void SendRequestNexeFd(int render_view_id, |
| 72 | PP_Instance instance, |
| 73 | const nacl::PnaclCacheInfo& cache_info, |
| 74 | PP_Bool* is_hit, |
| 75 | PP_FileHandle* file_handle, |
| 76 | scoped_refptr<ppapi::TrackedCallback> callback); |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 77 | void SendReportTranslationFinished(PP_Instance instance, |
| 78 | PP_Bool success); |
Ben Murdoch | 2385ea3 | 2013-08-06 11:01:04 +0100 | [diff] [blame] | 79 | void SendEnsurePnaclInstalled(PP_Instance instance, |
| 80 | scoped_refptr<ppapi::TrackedCallback> callback); |
| 81 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 82 | void OnNexeTempFileReply(PP_Instance instance, |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 83 | bool is_hit, |
| 84 | IPC::PlatformFileForTransit file); |
| 85 | void CleanupCacheRequests(); |
Ben Murdoch | 2385ea3 | 2013-08-06 11:01:04 +0100 | [diff] [blame] | 86 | void OnEnsurePnaclInstalledReply(PP_Instance instance, bool success); |
| 87 | void CleanupEnsurePnaclRequests(); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 88 | |
| 89 | scoped_refptr<base::MessageLoopProxy> io_message_loop_; |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 90 | |
| 91 | // Should be accessed on the io thread. |
Ben Murdoch | 2385ea3 | 2013-08-06 11:01:04 +0100 | [diff] [blame] | 92 | IPC::Channel* channel_; |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 93 | CacheRequestInfoMap pending_cache_requests_; |
Ben Murdoch | 2385ea3 | 2013-08-06 11:01:04 +0100 | [diff] [blame] | 94 | EnsurePnaclInstalledList pending_ensure_pnacl_requests_; |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 95 | DISALLOW_COPY_AND_ASSIGN(PnaclTranslationResourceHost); |
| 96 | }; |
| 97 | |
| 98 | #endif // CHROME_RENDERER_PEPPER_PNACL_TRANSLATION_RESOURCE_HOST_H_ |