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 static const nacl::string GetResourceInfoUrl() { |
jvoung (off chromium)
2013/05/23 20:33:19
Document the resource info also.
eliben
2013/05/23 20:54:25
Done.
| |
34 static const nacl::string GetLdUrl() { return nacl::string(kLdUrl); } | 39 return nacl::string(kResourceInfoUrl); |
40 } | |
35 private: | 41 private: |
36 static const char kLlcUrl[]; | 42 static const char kResourceInfoUrl[]; |
37 static const char kLdUrl[]; | |
38 }; | 43 }; |
39 | 44 |
40 // Loads a list of resources, providing a way to get file descriptors for | 45 // Loads a list of resources, providing a way to get file descriptors for |
41 // these resources. URLs for resources are resolved by the manifest | 46 // these resources. URLs for resources are resolved by the manifest |
42 // and point to pnacl component filesystem resources. | 47 // and point to pnacl component filesystem resources. |
43 class PnaclResources { | 48 class PnaclResources { |
44 public: | 49 public: |
45 PnaclResources(Plugin* plugin, | 50 PnaclResources(Plugin* plugin, |
46 PnaclCoordinator* coordinator, | 51 PnaclCoordinator* coordinator, |
47 const Manifest* manifest, | 52 const Manifest* manifest) |
48 const std::vector<nacl::string>& resource_urls, | |
49 const pp::CompletionCallback& all_loaded_callback) | |
50 : plugin_(plugin), | 53 : plugin_(plugin), |
51 coordinator_(coordinator), | 54 coordinator_(coordinator), |
52 manifest_(manifest), | 55 manifest_(manifest), |
53 resource_urls_(resource_urls), | 56 llc_tool_name(kDefaultLlcName), |
54 all_loaded_callback_(all_loaded_callback) { | 57 ld_tool_name(kDefaultLdName) { |
55 } | 58 } |
56 virtual ~PnaclResources(); | 59 virtual ~PnaclResources(); |
57 | 60 |
58 // Start loading the resources. After construction, this is the first step. | 61 // Read the resource info JSON file. This is the first step after |
59 virtual void StartLoad(); | 62 // 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. | 63 virtual void ReadResourceInfo( |
64 const nacl::string& resource_info_url, | |
65 const pp::CompletionCallback& resource_info_read_cb); | |
66 | |
67 // Start loading the resources. | |
68 virtual void StartLoad( | |
69 const pp::CompletionCallback& all_loaded_callback); | |
70 | |
71 const nacl::string& GetLlcUrl() { | |
72 return llc_tool_name; | |
73 } | |
74 | |
75 const nacl::string& GetLdUrl() { | |
76 return ld_tool_name; | |
77 } | |
78 | |
79 // Get file descs by name. Only valid after StartLoad's completion callback | |
80 // fired. | |
61 nacl::DescWrapper* WrapperForUrl(const nacl::string& url); | 81 nacl::DescWrapper* WrapperForUrl(const nacl::string& url); |
62 | 82 |
63 static int32_t GetPnaclFD(Plugin* plugin, const char* filename); | 83 static int32_t GetPnaclFD(Plugin* plugin, const char* filename); |
64 | 84 |
65 private: | 85 private: |
66 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclResources); | 86 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclResources); |
67 | 87 |
68 // The plugin requesting the resource loading. | 88 // The plugin requesting the resource loading. |
69 Plugin* plugin_; | 89 Plugin* plugin_; |
70 // The coordinator responsible for reporting errors, etc. | 90 // The coordinator responsible for reporting errors, etc. |
71 PnaclCoordinator* coordinator_; | 91 PnaclCoordinator* coordinator_; |
72 // The manifest for looking up resource URLs. | 92 // The manifest for looking up resource URLs. |
73 const Manifest* manifest_; | 93 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 | 94 // The descriptor wrappers for the downloaded URLs. Only valid |
79 // once all_loaded_callback_ has been invoked. | 95 // once all_loaded_callback_ has been invoked. |
80 std::map<nacl::string, nacl::DescWrapper*> resource_wrappers_; | 96 std::map<nacl::string, nacl::DescWrapper*> resource_wrappers_; |
97 | |
98 // The names of the llc and ld nexes are read from the resource info file. | |
99 // These are default values if the resource file does not contain the names. | |
100 // TODO(eliben): this should be eventually removed, once all nacl deps | |
101 // propagate - the names should always exist in the resource info JSON file. | |
102 static const char kDefaultLlcName[]; | |
103 static const char kDefaultLdName[]; | |
104 | |
105 // Tool names for llc and ld; read from the resource info file. | |
106 nacl::string llc_tool_name; | |
107 nacl::string ld_tool_name; | |
108 | |
109 // Parses resource info json data in buf. Returns true if successful. | |
jvoung (off chromium)
2013/05/23 20:33:19
Could put pipes around argument names like |buf| a
eliben
2013/05/23 20:54:25
Done.
| |
110 // Otherwise returns false and places an error message in errmsg. | |
111 bool ParseResourceInfo(const nacl::string& buf, nacl::string& errmsg); | |
112 | |
113 // Convenience function for reporting an error while reading the resource | |
114 // info file. | |
115 void ReadResourceInfoError(const nacl::string& msg); | |
81 }; | 116 }; |
82 | 117 |
83 } // namespace plugin; | 118 } // namespace plugin; |
84 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_ | 119 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_ |
OLD | NEW |