summaryrefslogtreecommitdiff
path: root/chromium/components/nacl/renderer/pnacl_translation_resource_host.h
blob: 6570cd048ed5bdc06b04494d7e6d40d7c3bf1355 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_RENDERER_PEPPER_PNACL_TRANSLATION_RESOURCE_HOST_H_
#define CHROME_RENDERER_PEPPER_PNACL_TRANSLATION_RESOURCE_HOST_H_

#include <map>

#include "ipc/ipc_channel_proxy.h"
#include "ipc/ipc_platform_file.h"
#include "ppapi/c/private/pp_file_handle.h"
#include "ppapi/shared_impl/tracked_callback.h"

namespace nacl {
struct PnaclCacheInfo;
}

// A class to keep track of requests made to the browser for resources that the
// PNaCl translator needs (e.g. descriptors for the translator nexes, temp
// files, and cached translations).

// "Resource" might not be the best name for the various things that pnacl
// needs from the browser since "Resource" is a Pepper thing...
class PnaclTranslationResourceHost : public IPC::ChannelProxy::MessageFilter {
 public:
  explicit PnaclTranslationResourceHost(
      const scoped_refptr<base::MessageLoopProxy>& io_message_loop);
  void RequestNexeFd(int render_view_id,
                     PP_Instance instance,
                     const nacl::PnaclCacheInfo& cache_info,
                     PP_Bool* is_hit,
                     PP_FileHandle* file_handle,
                     scoped_refptr<ppapi::TrackedCallback> callback);
  void ReportTranslationFinished(PP_Instance instance, PP_Bool success);

 protected:
  virtual ~PnaclTranslationResourceHost();

 private:
  class CacheRequestInfo {
   public:
    CacheRequestInfo(PP_Bool* hit,
                     PP_FileHandle* handle,
                     scoped_refptr<ppapi::TrackedCallback> cb);

    ~CacheRequestInfo();

    PP_Bool* is_hit;
    PP_FileHandle* file_handle;
    scoped_refptr<ppapi::TrackedCallback> callback;
  };

  // Maps the instance with an outstanding cache request to the info
  // about that request.
  typedef std::map<PP_Instance, CacheRequestInfo> CacheRequestInfoMap;
  // IPC::ChannelProxy::MessageFilter implementation.
  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
  virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE;
  virtual void OnFilterRemoved() OVERRIDE;
  virtual void OnChannelClosing() OVERRIDE;

  void SendRequestNexeFd(int render_view_id,
                         PP_Instance instance,
                         const nacl::PnaclCacheInfo& cache_info,
                         PP_Bool* is_hit,
                         PP_FileHandle* file_handle,
                         scoped_refptr<ppapi::TrackedCallback> callback);
  void SendReportTranslationFinished(PP_Instance instance,
                                     PP_Bool success);
  void OnNexeTempFileReply(PP_Instance instance,
                           bool is_hit,
                           IPC::PlatformFileForTransit file);
  void CleanupCacheRequests();

  scoped_refptr<base::MessageLoopProxy> io_message_loop_;

  // Should be accessed on the io thread.
  IPC::Channel* channel_;
  CacheRequestInfoMap pending_cache_requests_;
  DISALLOW_COPY_AND_ASSIGN(PnaclTranslationResourceHost);
};

#endif  // CHROME_RENDERER_PEPPER_PNACL_TRANSLATION_RESOURCE_HOST_H_