Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ppapi / native_client / src / trusted / plugin / pnacl_resources.h
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
3 // found in the LICENSE file.
4
5 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_
6 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_
7
8 #include <map>
9 #include <vector>
10
11 #include "native_client/src/include/nacl_macros.h"
12 #include "native_client/src/include/nacl_string.h"
13 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
14
15 #include "ppapi/c/private/pp_file_handle.h"
16 #include "ppapi/cpp/completion_callback.h"
17
18 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h"
19
20 namespace plugin {
21
22 class Manifest;
23 class Plugin;
24 class PnaclCoordinator;
25
26 // Constants for loading LLC and LD.
27 class PnaclUrls {
28  public:
29   // Get the base URL prefix for Pnacl resources (without platform prefix).
30   static nacl::string GetBaseUrl();
31
32   static bool IsPnaclComponent(const nacl::string& full_url);
33   static nacl::string PnaclComponentURLToFilename(
34       const nacl::string& full_url);
35
36   // Get the URL for the resource info JSON file that contains information
37   // about loadable resources.
38   static nacl::string GetResourceInfoUrl();
39 };
40
41 // Loads a list of resources, providing a way to get file descriptors for
42 // these resources.  URLs for resources are resolved by the manifest
43 // and point to pnacl component filesystem resources.
44 class PnaclResources {
45  public:
46   PnaclResources(Plugin* plugin,
47                  PnaclCoordinator* coordinator)
48       : plugin_(plugin),
49         coordinator_(coordinator) {
50   }
51   virtual ~PnaclResources();
52
53   // Read the resource info JSON file.  This is the first step after
54   // construction; it has to be completed before StartLoad is called.
55   virtual void ReadResourceInfo(
56       const nacl::string& resource_info_url,
57       const pp::CompletionCallback& resource_info_read_cb);
58
59   // Start loading the resources.
60   virtual void StartLoad(
61       const pp::CompletionCallback& all_loaded_callback);
62
63   const nacl::string& GetLlcUrl() { return llc_tool_name_; }
64   const nacl::string& GetLdUrl() { return ld_tool_name_; }
65
66   nacl::string GetFullUrl(const nacl::string& partial_url,
67                           const nacl::string& sandbox_arch) const;
68
69   // Get file descs by name. Only valid after StartLoad's completion callback
70   // fired.
71   nacl::DescWrapper* WrapperForUrl(const nacl::string& url);
72
73   static int32_t GetPnaclFD(Plugin* plugin, const char* filename);
74
75  private:
76   NACL_DISALLOW_COPY_AND_ASSIGN(PnaclResources);
77
78   // The plugin requesting the resource loading.
79   Plugin* plugin_;
80   // The coordinator responsible for reporting errors, etc.
81   PnaclCoordinator* coordinator_;
82   // The descriptor wrappers for the downloaded URLs.  Only valid
83   // once all_loaded_callback_ has been invoked.
84   std::map<nacl::string, nacl::DescWrapper*> resource_wrappers_;
85
86   // Tool names for llc and ld; read from the resource info file.
87   nacl::string llc_tool_name_;
88   nacl::string ld_tool_name_;
89 };
90
91 }  // namespace plugin;
92 #endif  // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_RESOURCES_H_