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