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 "ipc/ipc_channel_proxy.h"
11 #include "ipc/ipc_platform_file.h"
12 #include "ppapi/c/private/pp_file_handle.h"
13 #include "ppapi/shared_impl/tracked_callback.h"
16 struct PnaclCacheInfo;
19 // A class to keep track of requests made to the browser for resources that the
20 // PNaCl translator needs (e.g. descriptors for the translator nexes, temp
21 // files, and cached translations).
23 // "Resource" might not be the best name for the various things that pnacl
24 // needs from the browser since "Resource" is a Pepper thing...
25 class PnaclTranslationResourceHost : public IPC::ChannelProxy::MessageFilter {
27 explicit PnaclTranslationResourceHost(
28 const scoped_refptr<base::MessageLoopProxy>& io_message_loop);
29 void RequestNexeFd(int render_view_id,
31 const nacl::PnaclCacheInfo& cache_info,
33 PP_FileHandle* file_handle,
34 scoped_refptr<ppapi::TrackedCallback> callback);
35 void ReportTranslationFinished(PP_Instance instance, PP_Bool success);
38 virtual ~PnaclTranslationResourceHost();
41 class CacheRequestInfo {
43 CacheRequestInfo(PP_Bool* hit,
44 PP_FileHandle* handle,
45 scoped_refptr<ppapi::TrackedCallback> cb);
50 PP_FileHandle* file_handle;
51 scoped_refptr<ppapi::TrackedCallback> callback;
54 // Maps the instance with an outstanding cache request to the info
55 // about that request.
56 typedef std::map<PP_Instance, CacheRequestInfo> CacheRequestInfoMap;
57 // IPC::ChannelProxy::MessageFilter implementation.
58 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
59 virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE;
60 virtual void OnFilterRemoved() OVERRIDE;
61 virtual void OnChannelClosing() OVERRIDE;
63 void SendRequestNexeFd(int render_view_id,
65 const nacl::PnaclCacheInfo& cache_info,
67 PP_FileHandle* file_handle,
68 scoped_refptr<ppapi::TrackedCallback> callback);
69 void SendReportTranslationFinished(PP_Instance instance,
71 void OnNexeTempFileReply(PP_Instance instance,
73 IPC::PlatformFileForTransit file);
74 void CleanupCacheRequests();
76 scoped_refptr<base::MessageLoopProxy> io_message_loop_;
78 // Should be accessed on the io thread.
79 IPC::Channel* channel_;
80 CacheRequestInfoMap pending_cache_requests_;
81 DISALLOW_COPY_AND_ASSIGN(PnaclTranslationResourceHost);
84 #endif // CHROME_RENDERER_PEPPER_PNACL_TRANSLATION_RESOURCE_HOST_H_