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