blob: 59585442f78da19bea8cfed4bc3377464f05c4f4 [file] [log] [blame]
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001// 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.
4
5#ifndef CHROME_RENDERER_PEPPER_PNACL_TRANSLATION_RESOURCE_HOST_H_
6#define CHROME_RENDERER_PEPPER_PNACL_TRANSLATION_RESOURCE_HOST_H_
7
8#include <map>
Ben Murdoch2385ea32013-08-06 11:01:04 +01009#include <vector>
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010010
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010011#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"
15
Ben Murdoch2385ea32013-08-06 11:01:04 +010016namespace nacl {
17struct PnaclCacheInfo;
18}
19
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010020// 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).
23
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...
26class PnaclTranslationResourceHost : public IPC::ChannelProxy::MessageFilter {
27 public:
28 explicit PnaclTranslationResourceHost(
29 const scoped_refptr<base::MessageLoopProxy>& io_message_loop);
30 void RequestNexeFd(int render_view_id,
Ben Murdochca12bfa2013-07-23 11:17:05 +010031 PP_Instance instance,
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010032 const nacl::PnaclCacheInfo& cache_info,
33 PP_Bool* is_hit,
34 PP_FileHandle* file_handle,
35 scoped_refptr<ppapi::TrackedCallback> callback);
Ben Murdochbb1529c2013-08-08 10:24:53 +010036 void ReportTranslationFinished(PP_Instance instance, PP_Bool success);
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010037
Ben Murdoch2385ea32013-08-06 11:01:04 +010038 // Ensure that PNaCl resources (pnacl-llc.nexe, linker, libs) are installed.
39 void EnsurePnaclInstalled(PP_Instance instance,
40 scoped_refptr<ppapi::TrackedCallback> callback);
41
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010042 protected:
43 virtual ~PnaclTranslationResourceHost();
44
45 private:
46 class CacheRequestInfo {
47 public:
48 CacheRequestInfo(PP_Bool* hit,
49 PP_FileHandle* handle,
50 scoped_refptr<ppapi::TrackedCallback> cb);
51
52 ~CacheRequestInfo();
53
54 PP_Bool* is_hit;
55 PP_FileHandle* file_handle;
56 scoped_refptr<ppapi::TrackedCallback> callback;
57 };
58
Ben Murdochca12bfa2013-07-23 11:17:05 +010059 // Maps the instance with an outstanding cache request to the info
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010060 // about that request.
Ben Murdochca12bfa2013-07-23 11:17:05 +010061 typedef std::map<PP_Instance, CacheRequestInfo> CacheRequestInfoMap;
Ben Murdoch2385ea32013-08-06 11:01:04 +010062 // A list of outstanding EnsurePnaclInstalled requests.
63 typedef std::vector<scoped_refptr<ppapi::TrackedCallback> >
64 EnsurePnaclInstalledList;
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010065 // 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;
70
Ben Murdoch2385ea32013-08-06 11:01:04 +010071 void SendRequestNexeFd(int render_view_id,
72 PP_Instance instance,
73 const nacl::PnaclCacheInfo& cache_info,
74 PP_Bool* is_hit,
75 PP_FileHandle* file_handle,
76 scoped_refptr<ppapi::TrackedCallback> callback);
Ben Murdochbb1529c2013-08-08 10:24:53 +010077 void SendReportTranslationFinished(PP_Instance instance,
78 PP_Bool success);
Ben Murdoch2385ea32013-08-06 11:01:04 +010079 void SendEnsurePnaclInstalled(PP_Instance instance,
80 scoped_refptr<ppapi::TrackedCallback> callback);
81
Ben Murdochca12bfa2013-07-23 11:17:05 +010082 void OnNexeTempFileReply(PP_Instance instance,
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010083 bool is_hit,
84 IPC::PlatformFileForTransit file);
85 void CleanupCacheRequests();
Ben Murdoch2385ea32013-08-06 11:01:04 +010086 void OnEnsurePnaclInstalledReply(PP_Instance instance, bool success);
87 void CleanupEnsurePnaclRequests();
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010088
89 scoped_refptr<base::MessageLoopProxy> io_message_loop_;
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010090
91 // Should be accessed on the io thread.
Ben Murdoch2385ea32013-08-06 11:01:04 +010092 IPC::Channel* channel_;
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010093 CacheRequestInfoMap pending_cache_requests_;
Ben Murdoch2385ea32013-08-06 11:01:04 +010094 EnsurePnaclInstalledList pending_ensure_pnacl_requests_;
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010095 DISALLOW_COPY_AND_ASSIGN(PnaclTranslationResourceHost);
96};
97
98#endif // CHROME_RENDERER_PEPPER_PNACL_TRANSLATION_RESOURCE_HOST_H_