Pepper: Use base::Callback in RequestNexeFd.
[chromium-blink-merge.git] / components / nacl / renderer / pnacl_translation_resource_host.h
blob18441ce0e87245ecfb07e4b27452a3ef921cd0ce
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_
8 #include <map>
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"
18 namespace nacl {
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 {
29 public:
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,
36 PP_Instance instance,
37 const nacl::PnaclCacheInfo& cache_info,
38 RequestNexeFdCallback callback);
39 void ReportTranslationFinished(PP_Instance instance, PP_Bool success);
41 protected:
42 virtual ~PnaclTranslationResourceHost();
44 private:
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 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
51 virtual void OnFilterAdded(IPC::Sender* sender) OVERRIDE;
52 virtual void OnFilterRemoved() OVERRIDE;
53 virtual void OnChannelClosing() OVERRIDE;
55 void SendRequestNexeFd(int render_view_id,
56 PP_Instance instance,
57 const nacl::PnaclCacheInfo& cache_info,
58 RequestNexeFdCallback callback);
59 void SendReportTranslationFinished(PP_Instance instance,
60 PP_Bool success);
61 void OnNexeTempFileReply(PP_Instance instance,
62 bool is_hit,
63 IPC::PlatformFileForTransit file);
64 void CleanupCacheRequests();
66 scoped_refptr<base::MessageLoopProxy> io_message_loop_;
68 // Should be accessed on the io thread.
69 IPC::Sender* sender_;
70 CacheRequestInfoMap pending_cache_requests_;
71 DISALLOW_COPY_AND_ASSIGN(PnaclTranslationResourceHost);
74 #endif // CHROME_RENDERER_PEPPER_PNACL_TRANSLATION_RESOURCE_HOST_H_