OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
(...skipping 17 matching lines...) Expand all Loading... |
28 : plugin_(plugin), | 28 : plugin_(plugin), |
29 coordinator_(coordinator), | 29 coordinator_(coordinator), |
30 all_loaded_(true), | 30 all_loaded_(true), |
31 client_callback_is_valid_(false) | 31 client_callback_is_valid_(false) |
32 { } | 32 { } |
33 | 33 |
34 virtual ~PnaclResources(); | 34 virtual ~PnaclResources(); |
35 | 35 |
36 void Initialize(); | 36 void Initialize(); |
37 | 37 |
| 38 // URLs are all relative to the coordinator's resource_base_url(). |
| 39 |
| 40 // Get the wrapper for the downloaded resource. |
38 nacl::DescWrapper* WrapperForUrl(const nacl::string& url) { | 41 nacl::DescWrapper* WrapperForUrl(const nacl::string& url) { |
39 return resource_wrappers_[url]; | 42 return resource_wrappers_[url]; |
40 } | 43 } |
41 | 44 |
42 // Add an URL for download. | 45 // Add an URL for download. |
43 void AddResourceUrl(const nacl::string& url); | 46 void AddResourceUrl(const nacl::string& url); |
44 // Start fetching the URLs. | 47 // Start fetching the URLs. |
45 void StartDownloads(); | 48 void StartDownloads(); |
46 // Set the callback for what to do when all the resources are available. | 49 // Set the callback for what to do when all the resources are available. |
47 void RunWhenAllLoaded(pp::CompletionCallback& client_callback); | 50 void RunWhenAllLoaded(pp::CompletionCallback& client_callback); |
48 | 51 |
49 private: | 52 private: |
50 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclResources); | 53 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclResources); |
51 | 54 |
52 // Callback invoked each time one resource has been loaded. | 55 // Callback invoked each time one resource has been loaded. |
53 void ResourceReady(int32_t pp_error, const nacl::string& url); | 56 void ResourceReady(int32_t pp_error, |
| 57 const nacl::string& url, |
| 58 const nacl::string& full_url); |
54 // Callback invoked when all resources have been loaded. | 59 // Callback invoked when all resources have been loaded. |
55 void AllLoaded(int32_t pp_error); | 60 void AllLoaded(int32_t pp_error); |
56 | 61 |
57 Plugin* plugin_; | 62 Plugin* plugin_; |
58 PnaclCoordinator* coordinator_; | 63 PnaclCoordinator* coordinator_; |
59 std::vector<nacl::string> resource_urls_; | 64 std::vector<nacl::string> resource_urls_; |
60 std::map<nacl::string, nacl::DescWrapper*> resource_wrappers_; | 65 std::map<nacl::string, nacl::DescWrapper*> resource_wrappers_; |
61 nacl::scoped_ptr<DelayedCallback> delayed_callback_; | 66 nacl::scoped_ptr<DelayedCallback> delayed_callback_; |
62 // Set once all resources have been loaded to indicate that future calls to | 67 // Set once all resources have been loaded to indicate that future calls to |
63 // RunWhenAllLoaded should immediately invoke the client callback. This | 68 // RunWhenAllLoaded should immediately invoke the client callback. This |
64 // simplifies the client while allowing resources to be used for subsequent | 69 // simplifies the client while allowing resources to be used for subsequent |
65 // translations. | 70 // translations. |
66 bool all_loaded_; | 71 bool all_loaded_; |
67 // Callback to be invoked when all resources can be guaranteed available. | 72 // Callback to be invoked when all resources can be guaranteed available. |
68 pp::CompletionCallback client_callback_; | 73 pp::CompletionCallback client_callback_; |
69 // If RunWhenAllLoaded was called before all resources have been loaded, | 74 // If RunWhenAllLoaded was called before all resources have been loaded, |
70 // this indicates that the registered client callback should be used when | 75 // this indicates that the registered client callback should be used when |
71 // the last resource arrives. | 76 // the last resource arrives. |
72 bool client_callback_is_valid_; | 77 bool client_callback_is_valid_; |
73 // Factory for ready callbacks, etc. | 78 // Factory for ready callbacks, etc. |
74 pp::CompletionCallbackFactory<PnaclResources> callback_factory_; | 79 pp::CompletionCallbackFactory<PnaclResources> callback_factory_; |
75 }; | 80 }; |
76 | 81 |
77 } // namespace plugin; | 82 } // namespace plugin; |
78 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_ | 83 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_ |
OLD | NEW |