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 "ipc/ipc_platform_file.h"
12 #include "ipc/message_filter.h"
13 #include "ppapi/c/pp_bool.h"
14 #include "ppapi/c/pp_instance.h"
15 #include "ppapi/c/private/pp_file_handle.h"
18 class SingleThreadTaskRunner
;
22 struct PnaclCacheInfo
;
25 // A class to keep track of requests made to the browser for resources that the
26 // PNaCl translator needs (e.g. descriptors for the translator nexes, temp
27 // files, and cached translations).
29 // "Resource" might not be the best name for the various things that pnacl
30 // needs from the browser since "Resource" is a Pepper thing...
31 class PnaclTranslationResourceHost
: public IPC::MessageFilter
{
33 typedef base::Callback
<void(int32_t, bool, PP_FileHandle
)>
34 RequestNexeFdCallback
;
36 explicit PnaclTranslationResourceHost(
37 scoped_refptr
<base::SingleThreadTaskRunner
> io_task_runner
);
38 void RequestNexeFd(int render_view_id
,
40 const nacl::PnaclCacheInfo
& cache_info
,
41 RequestNexeFdCallback callback
);
42 void ReportTranslationFinished(PP_Instance instance
, PP_Bool success
);
45 ~PnaclTranslationResourceHost() override
;
48 // Maps the instance with an outstanding cache request to the info
49 // about that request.
50 typedef std::map
<PP_Instance
, RequestNexeFdCallback
> CacheRequestInfoMap
;
52 // IPC::MessageFilter implementation.
53 bool OnMessageReceived(const IPC::Message
& message
) override
;
54 void OnFilterAdded(IPC::Sender
* sender
) override
;
55 void OnFilterRemoved() override
;
56 void OnChannelClosing() override
;
58 void SendRequestNexeFd(int render_view_id
,
60 const nacl::PnaclCacheInfo
& cache_info
,
61 RequestNexeFdCallback callback
);
62 void SendReportTranslationFinished(PP_Instance instance
,
64 void OnNexeTempFileReply(PP_Instance instance
,
66 IPC::PlatformFileForTransit file
);
67 void CleanupCacheRequests();
69 scoped_refptr
<base::SingleThreadTaskRunner
> io_task_runner_
;
71 // Should be accessed on the io thread.
73 CacheRequestInfoMap pending_cache_requests_
;
74 DISALLOW_COPY_AND_ASSIGN(PnaclTranslationResourceHost
);
77 #endif // CHROME_RENDERER_PEPPER_PNACL_TRANSLATION_RESOURCE_HOST_H_