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 |
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/plugin_error.h" | 16 #include "native_client/src/trusted/plugin/plugin_error.h" |
17 | 17 |
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 Plugin; | 22 class Plugin; |
23 class PnaclCoordinator; | 23 class PnaclCoordinator; |
24 | 24 |
25 class PnaclResources { | 25 class PnaclResources { |
robertm
2011/12/13 17:06:39
pre-existing but since this is a central class: ad
sehr (please use chromium)
2011/12/13 20:05:04
As this CL removes most of the need for the PnaclR
| |
26 public: | 26 public: |
27 PnaclResources(Plugin* plugin, PnaclCoordinator* coordinator) | 27 PnaclResources(Plugin* plugin, |
28 PnaclCoordinator* coordinator, | |
29 const nacl::string& resource_base_url) | |
28 : plugin_(plugin), | 30 : plugin_(plugin), |
robertm
2011/12/13 17:06:39
pre-existing
the dependency on both the plugin and
sehr (please use chromium)
2011/12/13 20:05:04
See above.
| |
29 coordinator_(coordinator), | 31 coordinator_(coordinator), |
30 all_loaded_(true), | 32 all_loaded_(true), |
31 client_callback_is_valid_(false) | 33 client_callback_is_valid_(false), |
32 { } | 34 resource_base_url_(resource_base_url) { |
35 callback_factory_.Initialize(this); | |
36 } | |
33 | 37 |
34 virtual ~PnaclResources(); | 38 virtual ~PnaclResources(); |
35 | 39 |
36 void Initialize(); | |
37 | |
38 // URLs are all relative to the coordinator's resource_base_url(). | 40 // URLs are all relative to the coordinator's resource_base_url(). |
39 | 41 |
40 // Get the wrapper for the downloaded resource. | 42 // Get the wrapper for the downloaded resource. |
robertm
2011/12/13 17:06:39
when is it ok to call this function?
sehr (please use chromium)
2011/12/13 20:05:04
Comment added.
| |
41 nacl::DescWrapper* WrapperForUrl(const nacl::string& url) { | 43 nacl::DescWrapper* WrapperForUrl(const nacl::string& url) { |
42 return resource_wrappers_[url]; | 44 return resource_wrappers_[url]; |
43 } | 45 } |
44 | 46 |
45 // Add an URL for download. | 47 // Add an URL for download. |
robertm
2011/12/13 17:06:39
mention: do not call this after StartDownloads() h
sehr (please use chromium)
2011/12/13 20:05:04
I removed this interface, adding a vector of URLs
| |
46 void AddResourceUrl(const nacl::string& url); | 48 void AddResourceUrl(const nacl::string& url); |
47 // Start fetching the URLs. | 49 // Start fetching the URLs. |
48 void StartDownloads(); | 50 void StartDownloads(); |
49 // Set the callback for what to do when all the resources are available. | 51 // Set the callback for what to do when all the resources are available. |
50 void RunWhenAllLoaded(pp::CompletionCallback& client_callback); | 52 void RunWhenAllLoaded(pp::CompletionCallback& client_callback); |
robertm
2011/12/13 17:06:39
This maybe irrelevant once the class protocol has
sehr (please use chromium)
2011/12/13 20:05:04
Done.
| |
51 | 53 |
52 private: | 54 private: |
53 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclResources); | 55 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclResources); |
54 | 56 |
55 // Callback invoked each time one resource has been loaded. | 57 // Callback invoked each time one resource has been loaded. |
56 void ResourceReady(int32_t pp_error, | 58 void ResourceReady(int32_t pp_error, |
57 const nacl::string& url, | 59 const nacl::string& url, |
58 const nacl::string& full_url); | 60 const nacl::string& full_url); |
59 // Callback invoked when all resources have been loaded. | 61 // Callback invoked when all resources have been loaded. |
60 void AllLoaded(int32_t pp_error); | 62 void AllLoaded(int32_t pp_error); |
61 | 63 |
62 Plugin* plugin_; | 64 Plugin* plugin_; |
63 PnaclCoordinator* coordinator_; | 65 PnaclCoordinator* coordinator_; |
64 std::vector<nacl::string> resource_urls_; | 66 std::vector<nacl::string> resource_urls_; |
65 std::map<nacl::string, nacl::DescWrapper*> resource_wrappers_; | 67 std::map<nacl::string, nacl::DescWrapper*> resource_wrappers_; |
66 nacl::scoped_ptr<DelayedCallback> delayed_callback_; | 68 nacl::scoped_ptr<DelayedCallback> delayed_callback_; |
67 // Set once all resources have been loaded to indicate that future calls to | 69 // Set once all resources have been loaded to indicate that future calls to |
68 // RunWhenAllLoaded should immediately invoke the client callback. This | 70 // RunWhenAllLoaded should immediately invoke the client callback. This |
69 // simplifies the client while allowing resources to be used for subsequent | 71 // simplifies the client while allowing resources to be used for subsequent |
70 // translations. | 72 // translations. |
71 bool all_loaded_; | 73 bool all_loaded_; |
72 // Callback to be invoked when all resources can be guaranteed available. | 74 // Callback to be invoked when all resources can be guaranteed available. |
73 pp::CompletionCallback client_callback_; | 75 pp::CompletionCallback client_callback_; |
74 // If RunWhenAllLoaded was called before all resources have been loaded, | 76 // If RunWhenAllLoaded was called before all resources have been loaded, |
75 // this indicates that the registered client callback should be used when | 77 // this indicates that the registered client callback should be used when |
76 // the last resource arrives. | 78 // the last resource arrives. |
77 bool client_callback_is_valid_; | 79 bool client_callback_is_valid_; |
80 // The base url for looking up resources. | |
81 nacl::string resource_base_url_; | |
78 // Factory for ready callbacks, etc. | 82 // Factory for ready callbacks, etc. |
79 pp::CompletionCallbackFactory<PnaclResources> callback_factory_; | 83 pp::CompletionCallbackFactory<PnaclResources> callback_factory_; |
80 }; | 84 }; |
81 | 85 |
82 } // namespace plugin; | 86 } // namespace plugin; |
83 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_ | 87 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_ |
OLD | NEW |