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.
5 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_
6 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_
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"
15 #include "ppapi/c/private/pp_file_handle.h"
16 #include "ppapi/cpp/completion_callback.h"
18 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h"
24 class PnaclCoordinator;
26 // Constants for loading LLC and LD.
29 // Get the base URL prefix for Pnacl resources (without platform prefix).
30 static nacl::string GetBaseUrl();
32 static bool IsPnaclComponent(const nacl::string& full_url);
33 static nacl::string PnaclComponentURLToFilename(
34 const nacl::string& full_url);
36 // Get the URL for the resource info JSON file that contains information
37 // about loadable resources.
38 static nacl::string GetResourceInfoUrl();
41 // Loads a list of resources, providing a way to get file descriptors for
42 // these resources. URLs for resources are resolved by the manifest
43 // and point to pnacl component filesystem resources.
44 class PnaclResources {
46 PnaclResources(Plugin* plugin,
47 PnaclCoordinator* coordinator)
49 coordinator_(coordinator) {
51 virtual ~PnaclResources();
53 // Read the resource info JSON file. This is the first step after
54 // construction; it has to be completed before StartLoad is called.
55 virtual void ReadResourceInfo(
56 const nacl::string& resource_info_url,
57 const pp::CompletionCallback& resource_info_read_cb);
59 // Start loading the resources.
60 virtual void StartLoad(
61 const pp::CompletionCallback& all_loaded_callback);
63 const nacl::string& GetLlcUrl() { return llc_tool_name_; }
64 const nacl::string& GetLdUrl() { return ld_tool_name_; }
66 nacl::string GetFullUrl(const nacl::string& partial_url,
67 const nacl::string& sandbox_arch) const;
69 // Get file descs by name. Only valid after StartLoad's completion callback
71 nacl::DescWrapper* WrapperForUrl(const nacl::string& url);
73 static int32_t GetPnaclFD(Plugin* plugin, const char* filename);
76 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclResources);
78 // The plugin requesting the resource loading.
80 // The coordinator responsible for reporting errors, etc.
81 PnaclCoordinator* coordinator_;
82 // The descriptor wrappers for the downloaded URLs. Only valid
83 // once all_loaded_callback_ has been invoked.
84 std::map<nacl::string, nacl::DescWrapper*> resource_wrappers_;
86 // Tool names for llc and ld; read from the resource info file.
87 nacl::string llc_tool_name_;
88 nacl::string ld_tool_name_;
91 } // namespace plugin;
92 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_