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.
5 #ifndef CHROME_RENDERER_PEPPER_PNACL_TRANSLATION_RESOURCE_HOST_H_
6 #define CHROME_RENDERER_PEPPER_PNACL_TRANSLATION_RESOURCE_HOST_H_
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"
17 struct PnaclCacheInfo
;
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).
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
{
28 explicit PnaclTranslationResourceHost(
29 const scoped_refptr
<base::MessageLoopProxy
>& io_message_loop
);
30 void RequestNexeFd(int render_view_id
,
32 const nacl::PnaclCacheInfo
& cache_info
,
34 PP_FileHandle
* file_handle
,
35 scoped_refptr
<ppapi::TrackedCallback
> callback
);
36 void ReportTranslationFinished(PP_Instance instance
, PP_Bool success
);
38 // Ensure that PNaCl resources (pnacl-llc.nexe, linker, libs) are installed.
39 void EnsurePnaclInstalled(PP_Instance instance
,
40 scoped_refptr
<ppapi::TrackedCallback
> callback
);
43 virtual ~PnaclTranslationResourceHost();
46 class CacheRequestInfo
{
48 CacheRequestInfo(PP_Bool
* hit
,
49 PP_FileHandle
* handle
,
50 scoped_refptr
<ppapi::TrackedCallback
> cb
);
55 PP_FileHandle
* file_handle
;
56 scoped_refptr
<ppapi::TrackedCallback
> callback
;
59 // Maps the instance with an outstanding cache request to the info
60 // about that request.
61 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.
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
;
71 void SendRequestNexeFd(int render_view_id
,
73 const nacl::PnaclCacheInfo
& cache_info
,
75 PP_FileHandle
* file_handle
,
76 scoped_refptr
<ppapi::TrackedCallback
> callback
);
77 void SendReportTranslationFinished(PP_Instance instance
,
79 void SendEnsurePnaclInstalled(PP_Instance instance
,
80 scoped_refptr
<ppapi::TrackedCallback
> callback
);
82 void OnNexeTempFileReply(PP_Instance instance
,
84 IPC::PlatformFileForTransit file
);
85 void CleanupCacheRequests();
86 void OnEnsurePnaclInstalledReply(PP_Instance instance
, bool success
);
87 void CleanupEnsurePnaclRequests();
89 scoped_refptr
<base::MessageLoopProxy
> io_message_loop_
;
91 // Should be accessed on the io thread.
92 IPC::Channel
* channel_
;
93 CacheRequestInfoMap pending_cache_requests_
;
94 EnsurePnaclInstalledList pending_ensure_pnacl_requests_
;
95 DISALLOW_COPY_AND_ASSIGN(PnaclTranslationResourceHost
);
98 #endif // CHROME_RENDERER_PEPPER_PNACL_TRANSLATION_RESOURCE_HOST_H_