xref: /aosp_15_r20/external/cronet/components/nacl/renderer/plugin/pnacl_resources.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2012 The Chromium Authors
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 COMPONENTS_NACL_RENDERER_PLUGIN_PNACL_RESOURCES_H_
6 #define COMPONENTS_NACL_RENDERER_PLUGIN_PNACL_RESOURCES_H_
7 
8 #include "base/memory/raw_ptr.h"
9 #include "components/nacl/renderer/ppb_nacl_private.h"
10 #include "ppapi/cpp/completion_callback.h"
11 
12 namespace plugin {
13 
14 class Plugin;
15 
16 // PNaCl tool files / resources, which are opened by the browser.
17 struct PnaclResourceEntry {
18   // The name of the tool that corresponds to the opened file.
19   std::string tool_name;
20 
21   // File info for the executables, after they've been opened.
22   // Only valid after StartLoad() has been called, and until
23   // TakeFileInfo(ResourceType) is called.
24   PP_NaClFileInfo file_info;
25 };
26 
27 // Loads a list of resources, providing a way to get file descriptors for
28 // these resources.  URLs for resources are resolved by the manifest
29 // and point to PNaCl component filesystem resources.
30 class PnaclResources {
31  public:
32   PnaclResources(Plugin* plugin, bool use_subzero);
33 
34   PnaclResources(const PnaclResources&) = delete;
35   PnaclResources& operator=(const PnaclResources&) = delete;
36 
37   virtual ~PnaclResources();
38 
39   // Read the resource info JSON file.  This is the first step after
40   // construction; it has to be completed before StartLoad is called.
41   bool ReadResourceInfo();
42 
43   // Start loading the resources.
44   bool StartLoad();
45 
46   enum ResourceType { LLC, LD, SUBZERO, NUM_TYPES };
47 
48   const std::string& GetUrl(ResourceType type) const;
49 
50   PP_NaClFileInfo TakeFileInfo(ResourceType type);
51 
52  private:
53   // The plugin requesting the resource loading.
54   raw_ptr<Plugin> plugin_;
55   bool use_subzero_;
56 
57   PnaclResourceEntry resources_[NUM_TYPES + 1];
58 };
59 
60 }  // namespace plugin
61 #endif  // COMPONENTS_NACL_RENDERER_PLUGIN_PNACL_RESOURCES_H_
62