• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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 NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_
6 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_
7 
8 #include <map>
9 #include <vector>
10 
11 #include "native_client/src/include/nacl_macros.h"
12 #include "native_client/src/include/nacl_string.h"
13 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
14 
15 #include "ppapi/c/private/pp_file_handle.h"
16 #include "ppapi/cpp/completion_callback.h"
17 
18 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h"
19 
20 namespace plugin {
21 
22 class Plugin;
23 
24 // Loads a list of resources, providing a way to get file descriptors for
25 // these resources.  URLs for resources are resolved by the manifest
26 // and point to pnacl component filesystem resources.
27 class PnaclResources {
28  public:
PnaclResources(Plugin * plugin)29   explicit PnaclResources(Plugin* plugin)
30       : plugin_(plugin),
31         llc_file_handle_(PP_kInvalidFileHandle),
32         ld_file_handle_(PP_kInvalidFileHandle) {
33   }
34   virtual ~PnaclResources();
35 
36   // Read the resource info JSON file.  This is the first step after
37   // construction; it has to be completed before StartLoad is called.
38   virtual void ReadResourceInfo(
39       const pp::CompletionCallback& resource_info_read_cb);
40 
41   // Start loading the resources.
42   virtual void StartLoad(
43       const pp::CompletionCallback& all_loaded_callback);
44 
GetLlcUrl()45   const nacl::string& GetLlcUrl() { return llc_tool_name_; }
GetLdUrl()46   const nacl::string& GetLdUrl() { return ld_tool_name_; }
47 
48   PP_FileHandle TakeLlcFileHandle();
49   PP_FileHandle TakeLdFileHandle();
50 
51  private:
52   NACL_DISALLOW_COPY_AND_ASSIGN(PnaclResources);
53 
54   // The plugin requesting the resource loading.
55   Plugin* plugin_;
56 
57   // Tool names for llc and ld; read from the resource info file.
58   nacl::string llc_tool_name_;
59   nacl::string ld_tool_name_;
60 
61   // File handles for llc and ld executables, after they've been opened.
62   // Only valid after the callback for StartLoad() has been called, and until
63   // TakeLlcFileHandle()/TakeLdFileHandle() is called.
64   PP_FileHandle llc_file_handle_;
65   PP_FileHandle ld_file_handle_;
66 };
67 
68 }  // namespace plugin;
69 #endif  // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_
70