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_
10 #include "base/callback.h"
11 #include "base/message_loop/message_loop_proxy.h"
12 #include "ipc/ipc_platform_file.h"
13 #include "ipc/message_filter.h"
14 #include "ppapi/c/pp_bool.h"
15 #include "ppapi/c/pp_instance.h"
16 #include "ppapi/c/private/pp_file_handle.h"
19 struct PnaclCacheInfo
;
22 // A class to keep track of requests made to the browser for resources that the
23 // PNaCl translator needs (e.g. descriptors for the translator nexes, temp
24 // files, and cached translations).
26 // "Resource" might not be the best name for the various things that pnacl
27 // needs from the browser since "Resource" is a Pepper thing...
28 class PnaclTranslationResourceHost
: public IPC::MessageFilter
{
30 typedef base::Callback
<void(int32_t, bool, PP_FileHandle
)>
31 RequestNexeFdCallback
;
33 explicit PnaclTranslationResourceHost(
34 const scoped_refptr
<base::MessageLoopProxy
>& io_message_loop
);
35 void RequestNexeFd(int render_view_id
,
37 const nacl::PnaclCacheInfo
& cache_info
,
38 RequestNexeFdCallback callback
);
39 void ReportTranslationFinished(PP_Instance instance
, PP_Bool success
);
42 ~PnaclTranslationResourceHost() override
;
45 // Maps the instance with an outstanding cache request to the info
46 // about that request.
47 typedef std::map
<PP_Instance
, RequestNexeFdCallback
> CacheRequestInfoMap
;
49 // IPC::MessageFilter implementation.
50 bool OnMessageReceived(const IPC::Message
& message
) override
;
51 void OnFilterAdded(IPC::Sender
* sender
) override
;
52 void OnFilterRemoved() override
;
53 void OnChannelClosing() override
;
55 void SendRequestNexeFd(int render_view_id
,
57 const nacl::PnaclCacheInfo
& cache_info
,
58 RequestNexeFdCallback callback
);
59 void SendReportTranslationFinished(PP_Instance instance
,
61 void OnNexeTempFileReply(PP_Instance instance
,
63 IPC::PlatformFileForTransit file
);
64 void CleanupCacheRequests();
66 scoped_refptr
<base::MessageLoopProxy
> io_message_loop_
;
68 // Should be accessed on the io thread.
70 CacheRequestInfoMap pending_cache_requests_
;
71 DISALLOW_COPY_AND_ASSIGN(PnaclTranslationResourceHost
);
74 #endif // CHROME_RENDERER_PEPPER_PNACL_TRANSLATION_RESOURCE_HOST_H_