OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_ | 5 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_ |
6 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_ | 6 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "native_client/src/include/nacl_macros.h" | 11 #include "native_client/src/include/nacl_macros.h" |
12 #include "native_client/src/include/nacl_string.h" | 12 #include "native_client/src/include/nacl_string.h" |
13 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" | 13 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" |
14 #include "native_client/src/trusted/plugin/nexe_arch.h" | 14 #include "native_client/src/trusted/plugin/nexe_arch.h" |
15 #include "native_client/src/trusted/plugin/plugin_error.h" | 15 #include "native_client/src/trusted/plugin/plugin_error.h" |
16 | 16 |
17 #include "ppapi/c/private/pp_file_handle.h" | 17 #include "ppapi/c/private/pp_file_handle.h" |
18 #include "ppapi/cpp/completion_callback.h" | 18 #include "ppapi/cpp/completion_callback.h" |
19 | 19 |
20 namespace plugin { | 20 namespace plugin { |
21 | 21 |
22 class Manifest; | 22 class Manifest; |
23 class Plugin; | 23 class Plugin; |
24 class PnaclCoordinator; | 24 class PnaclCoordinator; |
25 | 25 |
26 // Constants for loading LLC and LD. | 26 // Constants for loading LLC and LD. |
27 class PnaclUrls { | 27 class PnaclUrls { |
28 public: | 28 public: |
| 29 // Get the base URL prefix for Pnacl resources (without platform prefix). |
29 static nacl::string GetBaseUrl(); | 30 static nacl::string GetBaseUrl(); |
| 31 |
| 32 // Return {platform_prefix}/url |
| 33 static nacl::string PrependPlatformPrefix(const nacl::string& url); |
| 34 |
30 static bool IsPnaclComponent(const nacl::string& full_url); | 35 static bool IsPnaclComponent(const nacl::string& full_url); |
31 static nacl::string PnaclComponentURLToFilename( | 36 static nacl::string PnaclComponentURLToFilename( |
32 const nacl::string& full_url); | 37 const nacl::string& full_url); |
33 static const nacl::string GetLlcUrl() { return nacl::string(kLlcUrl); } | 38 |
34 static const nacl::string GetLdUrl() { return nacl::string(kLdUrl); } | 39 // Get the URL for the resource info JSON file that contains information |
| 40 // about loadable resources. |
| 41 static const nacl::string GetResourceInfoUrl() { |
| 42 return nacl::string(kResourceInfoUrl); |
| 43 } |
35 private: | 44 private: |
36 static const char kLlcUrl[]; | 45 static const char kResourceInfoUrl[]; |
37 static const char kLdUrl[]; | |
38 }; | 46 }; |
39 | 47 |
40 // Loads a list of resources, providing a way to get file descriptors for | 48 // Loads a list of resources, providing a way to get file descriptors for |
41 // these resources. URLs for resources are resolved by the manifest | 49 // these resources. URLs for resources are resolved by the manifest |
42 // and point to pnacl component filesystem resources. | 50 // and point to pnacl component filesystem resources. |
43 class PnaclResources { | 51 class PnaclResources { |
44 public: | 52 public: |
45 PnaclResources(Plugin* plugin, | 53 PnaclResources(Plugin* plugin, |
46 PnaclCoordinator* coordinator, | 54 PnaclCoordinator* coordinator, |
47 const Manifest* manifest, | 55 const Manifest* manifest) |
48 const std::vector<nacl::string>& resource_urls, | |
49 const pp::CompletionCallback& all_loaded_callback) | |
50 : plugin_(plugin), | 56 : plugin_(plugin), |
51 coordinator_(coordinator), | 57 coordinator_(coordinator), |
52 manifest_(manifest), | 58 manifest_(manifest), |
53 resource_urls_(resource_urls), | 59 llc_tool_name(kDefaultLlcName), |
54 all_loaded_callback_(all_loaded_callback) { | 60 ld_tool_name(kDefaultLdName) { |
55 } | 61 } |
56 virtual ~PnaclResources(); | 62 virtual ~PnaclResources(); |
57 | 63 |
58 // Start loading the resources. After construction, this is the first step. | 64 // Read the resource info JSON file. This is the first step after |
59 virtual void StartLoad(); | 65 // construction; it has to be completed before StartLoad is called. |
60 // Get file descs by name. Only valid after all_loaded_callback_ has been run. | 66 virtual void ReadResourceInfo( |
| 67 const nacl::string& resource_info_url, |
| 68 const pp::CompletionCallback& resource_info_read_cb); |
| 69 |
| 70 // Start loading the resources. |
| 71 virtual void StartLoad( |
| 72 const pp::CompletionCallback& all_loaded_callback); |
| 73 |
| 74 const nacl::string& GetLlcUrl() { |
| 75 return llc_tool_name; |
| 76 } |
| 77 |
| 78 const nacl::string& GetLdUrl() { |
| 79 return ld_tool_name; |
| 80 } |
| 81 |
| 82 // Get file descs by name. Only valid after StartLoad's completion callback |
| 83 // fired. |
61 nacl::DescWrapper* WrapperForUrl(const nacl::string& url); | 84 nacl::DescWrapper* WrapperForUrl(const nacl::string& url); |
62 | 85 |
63 static int32_t GetPnaclFD(Plugin* plugin, const char* filename); | 86 static int32_t GetPnaclFD(Plugin* plugin, const char* filename); |
64 | 87 |
65 private: | 88 private: |
66 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclResources); | 89 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclResources); |
67 | 90 |
68 // The plugin requesting the resource loading. | 91 // The plugin requesting the resource loading. |
69 Plugin* plugin_; | 92 Plugin* plugin_; |
70 // The coordinator responsible for reporting errors, etc. | 93 // The coordinator responsible for reporting errors, etc. |
71 PnaclCoordinator* coordinator_; | 94 PnaclCoordinator* coordinator_; |
72 // The manifest for looking up resource URLs. | 95 // The manifest for looking up resource URLs. |
73 const Manifest* manifest_; | 96 const Manifest* manifest_; |
74 // The list of resource URLs (relative to resource_base_url_) to load. | |
75 std::vector<nacl::string> resource_urls_; | |
76 // Callback to be invoked when all resources can be guaranteed available. | |
77 pp::CompletionCallback all_loaded_callback_; | |
78 // The descriptor wrappers for the downloaded URLs. Only valid | 97 // The descriptor wrappers for the downloaded URLs. Only valid |
79 // once all_loaded_callback_ has been invoked. | 98 // once all_loaded_callback_ has been invoked. |
80 std::map<nacl::string, nacl::DescWrapper*> resource_wrappers_; | 99 std::map<nacl::string, nacl::DescWrapper*> resource_wrappers_; |
| 100 |
| 101 // The names of the llc and ld nexes are read from the resource info file. |
| 102 // These are default values if the resource file does not contain the names. |
| 103 // TODO(eliben): this should be eventually removed, once all nacl deps |
| 104 // propagate - the names should always exist in the resource info JSON file. |
| 105 static const char kDefaultLlcName[]; |
| 106 static const char kDefaultLdName[]; |
| 107 |
| 108 // Tool names for llc and ld; read from the resource info file. |
| 109 nacl::string llc_tool_name; |
| 110 nacl::string ld_tool_name; |
| 111 |
| 112 // Parses resource info json data in |buf|. Returns true if successful. |
| 113 // Otherwise returns false and places an error message in |errmsg|. |
| 114 bool ParseResourceInfo(const nacl::string& buf, nacl::string& errmsg); |
| 115 |
| 116 // Convenience function for reporting an error while reading the resource |
| 117 // info file. |
| 118 void ReadResourceInfoError(const nacl::string& msg); |
81 }; | 119 }; |
82 | 120 |
83 } // namespace plugin; | 121 } // namespace plugin; |
84 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_ | 122 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_ |
OLD | NEW |