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