Don't preload rarely seen large images
[chromium-blink-merge.git] / components / nacl / renderer / pnacl_translation_resource_host.h
blob1de4eb62721649cdb1e930f5f0bec3496c60e632
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 "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"
17 namespace base {
18 class SingleThreadTaskRunner;
21 namespace nacl {
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 {
32 public:
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,
39 PP_Instance instance,
40 const nacl::PnaclCacheInfo& cache_info,
41 RequestNexeFdCallback callback);
42 void ReportTranslationFinished(PP_Instance instance, PP_Bool success);
44 protected:
45 ~PnaclTranslationResourceHost() override;
47 private:
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,
59 PP_Instance instance,
60 const nacl::PnaclCacheInfo& cache_info,
61 RequestNexeFdCallback callback);
62 void SendReportTranslationFinished(PP_Instance instance,
63 PP_Bool success);
64 void OnNexeTempFileReply(PP_Instance instance,
65 bool is_hit,
66 IPC::PlatformFileForTransit file);
67 void CleanupCacheRequests();
69 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
71 // Should be accessed on the io thread.
72 IPC::Sender* sender_;
73 CacheRequestInfoMap pending_cache_requests_;
74 DISALLOW_COPY_AND_ASSIGN(PnaclTranslationResourceHost);
77 #endif // CHROME_RENDERER_PEPPER_PNACL_TRANSLATION_RESOURCE_HOST_H_