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/shared/srpc/nacl_srpc.h" | 13 #include "native_client/src/shared/srpc/nacl_srpc.h" |
14 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" | 14 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" |
15 #include "native_client/src/trusted/plugin/delayed_callback.h" | 15 #include "native_client/src/trusted/plugin/delayed_callback.h" |
16 #include "native_client/src/trusted/plugin/nexe_arch.h" | 16 #include "native_client/src/trusted/plugin/nexe_arch.h" |
17 #include "native_client/src/trusted/plugin/plugin_error.h" | 17 #include "native_client/src/trusted/plugin/plugin_error.h" |
18 | |
18 #include "ppapi/utility/completion_callback_factory.h" | 19 #include "ppapi/utility/completion_callback_factory.h" |
20 #include "ppapi/c/private/pp_file_handle.h" | |
19 | 21 |
20 namespace plugin { | 22 namespace plugin { |
21 | 23 |
22 class Manifest; | 24 class Manifest; |
23 class Plugin; | 25 class Plugin; |
24 class PnaclCoordinator; | 26 class PnaclCoordinator; |
25 | 27 |
28 // Constants for loading LLC and LD. | |
26 class PnaclUrls { | 29 class PnaclUrls { |
27 public: | 30 public: |
28 static nacl::string GetExtensionUrl() { | 31 static bool UsePnaclExtension(const Plugin* plugin); |
29 return nacl::string(kExtensionOrigin) + GetSandboxISA() + "/"; | 32 static nacl::string GetBaseUrl(bool use_extension); |
30 } | 33 static bool IsPnaclComponent(const nacl::string& full_url); |
34 static nacl::string StripPnaclComponentPrefix(const nacl::string& full_url); | |
31 static const nacl::string GetLlcUrl() { return nacl::string(kLlcUrl); } | 35 static const nacl::string GetLlcUrl() { return nacl::string(kLlcUrl); } |
32 static const nacl::string GetLdUrl() { return nacl::string(kLdUrl); } | 36 static const nacl::string GetLdUrl() { return nacl::string(kLdUrl); } |
33 private: | 37 private: |
34 static const char kExtensionOrigin[]; | 38 static const char kExtensionOrigin[]; |
39 static const char kPnaclComponentID[]; | |
35 static const char kLlcUrl[]; | 40 static const char kLlcUrl[]; |
36 static const char kLdUrl[]; | 41 static const char kLdUrl[]; |
37 }; | 42 }; |
38 | 43 |
39 // Loads a list of remote resources, providing a way to get file descriptors for | 44 // Loads a list of resources, providing a way to get file descriptors |
40 // thse resources. All URLs in relative to resource_base_url_. | 45 // these resources. URLs for resources are resolved by the manifest |
robertm
2012/08/08 21:51:11
some typo
jvoung - send to chromium...
2012/08/08 22:47:04
Done.
| |
46 // and may point to filesystem resources. | |
41 class PnaclResources { | 47 class PnaclResources { |
42 public: | 48 public: |
43 PnaclResources(Plugin* plugin, | 49 PnaclResources(Plugin* plugin, |
44 PnaclCoordinator* coordinator, | 50 PnaclCoordinator* coordinator, |
45 const Manifest* manifest, | 51 const Manifest* manifest, |
46 const std::vector<nacl::string>& resource_urls, | 52 const std::vector<nacl::string>& resource_urls, |
47 const pp::CompletionCallback& all_loaded_callback) | 53 const pp::CompletionCallback& all_loaded_callback) |
48 : plugin_(plugin), | 54 : plugin_(plugin), |
49 coordinator_(coordinator), | 55 coordinator_(coordinator), |
50 manifest_(manifest), | 56 manifest_(manifest), |
51 resource_urls_(resource_urls), | 57 resource_urls_(resource_urls), |
52 all_loaded_callback_(all_loaded_callback) { | 58 all_loaded_callback_(all_loaded_callback) { |
53 callback_factory_.Initialize(this); | 59 callback_factory_.Initialize(this); |
54 } | 60 } |
55 | |
56 virtual ~PnaclResources(); | 61 virtual ~PnaclResources(); |
57 | 62 |
58 // Start fetching the URLs. After construction, this is the first step. | 63 // Start loading the resources. After construction, this is the first step. |
59 void StartDownloads(); | 64 virtual void StartLoad(); |
60 // Get the wrapper for the downloaded resource. | 65 // Get file descs by name. Only valid after all_loaded_callback_ has been run. |
robertm
2012/08/08 21:51:11
would CHECK( resource_wrappers_.size() != 0)
be to
jvoung - send to chromium...
2012/08/08 22:47:04
Probably good to know. Could also/instead check t
| |
61 // Only valid after all_loaded_callback_ has been run. | |
62 nacl::DescWrapper* WrapperForUrl(const nacl::string& url) { | 66 nacl::DescWrapper* WrapperForUrl(const nacl::string& url) { |
63 return resource_wrappers_[url]; | 67 return resource_wrappers_[url]; |
64 } | 68 } |
65 | 69 |
70 static int32_t GetPnaclFD(Plugin* plugin, const char* filename); | |
71 | |
66 private: | 72 private: |
67 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclResources); | 73 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclResources); |
68 | 74 |
69 // Callback invoked each time one resource has been loaded. | 75 // Callback invoked each time one resource has been loaded. |
70 void ResourceReady(int32_t pp_error, | 76 void ResourceReady(int32_t pp_error, |
71 const nacl::string& url, | 77 const nacl::string& url, |
72 const nacl::string& full_url); | 78 const nacl::string& full_url); |
73 | 79 |
74 // The plugin requesting the resource loading. | 80 // The plugin requesting the resource loading. |
75 Plugin* plugin_; | 81 Plugin* plugin_; |
(...skipping 11 matching lines...) Expand all Loading... | |
87 // Because we may be loading multiple resources, we need a callback that | 93 // Because we may be loading multiple resources, we need a callback that |
88 // is invoked each time a resource arrives, and finally invokes | 94 // is invoked each time a resource arrives, and finally invokes |
89 // all_loaded_callback_ when done. | 95 // all_loaded_callback_ when done. |
90 nacl::scoped_ptr<DelayedCallback> delayed_callback_; | 96 nacl::scoped_ptr<DelayedCallback> delayed_callback_; |
91 // Factory for ready callbacks, etc. | 97 // Factory for ready callbacks, etc. |
92 pp::CompletionCallbackFactory<PnaclResources> callback_factory_; | 98 pp::CompletionCallbackFactory<PnaclResources> callback_factory_; |
93 }; | 99 }; |
94 | 100 |
95 } // namespace plugin; | 101 } // namespace plugin; |
96 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_ | 102 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_ |
OLD | NEW |