OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "components/nacl/renderer/ppb_nacl_private_impl.h" | 5 #include "components/nacl/renderer/ppb_nacl_private_impl.h" |
6 | 6 |
7 #include <numeric> | 7 #include <numeric> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 base::LazyInstance<InstanceInfoMap> g_instance_info = | 99 base::LazyInstance<InstanceInfoMap> g_instance_info = |
100 LAZY_INSTANCE_INITIALIZER; | 100 LAZY_INSTANCE_INITIALIZER; |
101 | 101 |
102 typedef base::ScopedPtrHashMap<PP_Instance, NexeLoadManager> | 102 typedef base::ScopedPtrHashMap<PP_Instance, NexeLoadManager> |
103 NexeLoadManagerMap; | 103 NexeLoadManagerMap; |
104 | 104 |
105 base::LazyInstance<NexeLoadManagerMap> g_load_manager_map = | 105 base::LazyInstance<NexeLoadManagerMap> g_load_manager_map = |
106 LAZY_INSTANCE_INITIALIZER; | 106 LAZY_INSTANCE_INITIALIZER; |
107 | 107 |
108 typedef base::ScopedPtrHashMap<PP_Instance, nacl::JsonManifest> JsonManifestMap; | |
109 | |
110 base::LazyInstance<JsonManifestMap> g_manifest_map = | |
111 LAZY_INSTANCE_INITIALIZER; | |
112 | |
113 nacl::NexeLoadManager* GetNexeLoadManager(PP_Instance instance) { | 108 nacl::NexeLoadManager* GetNexeLoadManager(PP_Instance instance) { |
114 NexeLoadManagerMap& map = g_load_manager_map.Get(); | 109 NexeLoadManagerMap& map = g_load_manager_map.Get(); |
115 NexeLoadManagerMap::iterator iter = map.find(instance); | 110 NexeLoadManagerMap::iterator iter = map.find(instance); |
116 if (iter != map.end()) | 111 if (iter != map.end()) |
117 return iter->second; | 112 return iter->second; |
118 return NULL; | 113 return NULL; |
119 } | 114 } |
120 | 115 |
121 int GetRoutingID(PP_Instance instance) { | 116 int GetRoutingID(PP_Instance instance) { |
122 // Check that we are on the main renderer thread. | 117 // Check that we are on the main renderer thread. |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 } | 745 } |
751 | 746 |
752 void InstanceCreated(PP_Instance instance) { | 747 void InstanceCreated(PP_Instance instance) { |
753 scoped_ptr<NexeLoadManager> new_load_manager(new NexeLoadManager(instance)); | 748 scoped_ptr<NexeLoadManager> new_load_manager(new NexeLoadManager(instance)); |
754 NexeLoadManagerMap& map = g_load_manager_map.Get(); | 749 NexeLoadManagerMap& map = g_load_manager_map.Get(); |
755 DLOG_IF(ERROR, map.count(instance) != 0) << "Instance count should be 0"; | 750 DLOG_IF(ERROR, map.count(instance) != 0) << "Instance count should be 0"; |
756 map.add(instance, new_load_manager.Pass()); | 751 map.add(instance, new_load_manager.Pass()); |
757 } | 752 } |
758 | 753 |
759 void InstanceDestroyed(PP_Instance instance) { | 754 void InstanceDestroyed(PP_Instance instance) { |
760 g_manifest_map.Get().erase(instance); | 755 DeleteJsonManifest(instance); |
761 | 756 |
762 NexeLoadManagerMap& map = g_load_manager_map.Get(); | 757 NexeLoadManagerMap& map = g_load_manager_map.Get(); |
763 DLOG_IF(ERROR, map.count(instance) == 0) << "Could not find instance ID"; | 758 DLOG_IF(ERROR, map.count(instance) == 0) << "Could not find instance ID"; |
764 // The erase may call NexeLoadManager's destructor prior to removing it from | 759 // The erase may call NexeLoadManager's destructor prior to removing it from |
765 // the map. In that case, it is possible for the trusted Plugin to re-enter | 760 // the map. In that case, it is possible for the trusted Plugin to re-enter |
766 // the NexeLoadManager (e.g., by calling ReportLoadError). Passing out the | 761 // the NexeLoadManager (e.g., by calling ReportLoadError). Passing out the |
767 // NexeLoadManager to a local scoped_ptr just ensures that its entry is gone | 762 // NexeLoadManager to a local scoped_ptr just ensures that its entry is gone |
768 // from the map prior to the destructor being invoked. | 763 // from the map prior to the destructor being invoked. |
769 scoped_ptr<NexeLoadManager> temp(map.take(instance)); | 764 scoped_ptr<NexeLoadManager> temp(map.take(instance)); |
770 map.erase(instance); | 765 map.erase(instance); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 isa_type = GetSandboxArch(); | 1029 isa_type = GetSandboxArch(); |
1035 | 1030 |
1036 scoped_ptr<nacl::JsonManifest> j( | 1031 scoped_ptr<nacl::JsonManifest> j( |
1037 new nacl::JsonManifest( | 1032 new nacl::JsonManifest( |
1038 manifest_url.c_str(), | 1033 manifest_url.c_str(), |
1039 isa_type, | 1034 isa_type, |
1040 IsNonSFIModeEnabled(), | 1035 IsNonSFIModeEnabled(), |
1041 PP_ToBool(NaClDebugEnabledForURL(manifest_url.c_str())))); | 1036 PP_ToBool(NaClDebugEnabledForURL(manifest_url.c_str())))); |
1042 JsonManifest::ErrorInfo error_info; | 1037 JsonManifest::ErrorInfo error_info; |
1043 if (j->Init(manifest_data.c_str(), &error_info)) { | 1038 if (j->Init(manifest_data.c_str(), &error_info)) { |
1044 g_manifest_map.Get().add(instance, j.Pass()); | 1039 AddJsonManifest(instance, j.Pass()); |
1045 return true; | 1040 return true; |
1046 } | 1041 } |
1047 load_manager->ReportLoadError(error_info.error, error_info.string); | 1042 load_manager->ReportLoadError(error_info.error, error_info.string); |
1048 return false; | 1043 return false; |
1049 } | 1044 } |
1050 | 1045 |
1051 PP_Bool ManifestGetProgramURL(PP_Instance instance, | 1046 PP_Bool ManifestGetProgramURL(PP_Instance instance, |
1052 PP_Var* pp_full_url, | 1047 PP_Var* pp_full_url, |
1053 PP_PNaClOptions* pnacl_options, | 1048 PP_PNaClOptions* pnacl_options, |
1054 PP_Bool* pp_uses_nonsfi_mode) { | 1049 PP_Bool* pp_uses_nonsfi_mode) { |
1055 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 1050 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
1056 | 1051 |
1057 JsonManifestMap::iterator it = g_manifest_map.Get().find(instance); | 1052 JsonManifest* manifest = GetJsonManifest(instance); |
1058 if (it == g_manifest_map.Get().end()) | 1053 if (manifest == NULL) |
1059 return PP_FALSE; | 1054 return PP_FALSE; |
1060 | 1055 |
1061 bool uses_nonsfi_mode; | 1056 bool uses_nonsfi_mode; |
1062 std::string full_url; | 1057 std::string full_url; |
1063 JsonManifest::ErrorInfo error_info; | 1058 JsonManifest::ErrorInfo error_info; |
1064 if (it->second->GetProgramURL(&full_url, pnacl_options, &uses_nonsfi_mode, | 1059 if (manifest->GetProgramURL(&full_url, pnacl_options, &uses_nonsfi_mode, |
1065 &error_info)) { | 1060 &error_info)) { |
1066 *pp_full_url = ppapi::StringVar::StringToPPVar(full_url); | 1061 *pp_full_url = ppapi::StringVar::StringToPPVar(full_url); |
1067 *pp_uses_nonsfi_mode = PP_FromBool(uses_nonsfi_mode); | 1062 *pp_uses_nonsfi_mode = PP_FromBool(uses_nonsfi_mode); |
1068 return PP_TRUE; | 1063 return PP_TRUE; |
1069 } | 1064 } |
1070 | 1065 |
1071 if (load_manager) | 1066 if (load_manager) |
1072 load_manager->ReportLoadError(error_info.error, error_info.string); | 1067 load_manager->ReportLoadError(error_info.error, error_info.string); |
1073 return PP_FALSE; | 1068 return PP_FALSE; |
1074 } | 1069 } |
1075 | 1070 |
(...skipping 17 matching lines...) Expand all Loading... |
1093 return PP_FALSE; | 1088 return PP_FALSE; |
1094 } | 1089 } |
1095 std::string key_basename = key_string.substr(kFilesPrefix.length()); | 1090 std::string key_basename = key_string.substr(kFilesPrefix.length()); |
1096 std::string pnacl_url = | 1091 std::string pnacl_url = |
1097 std::string(kPNaClTranslatorBaseUrl) + GetSandboxArch() + "/" + | 1092 std::string(kPNaClTranslatorBaseUrl) + GetSandboxArch() + "/" + |
1098 key_basename; | 1093 key_basename; |
1099 *pp_full_url = ppapi::StringVar::StringToPPVar(pnacl_url); | 1094 *pp_full_url = ppapi::StringVar::StringToPPVar(pnacl_url); |
1100 return PP_TRUE; | 1095 return PP_TRUE; |
1101 } | 1096 } |
1102 | 1097 |
1103 JsonManifestMap::iterator it = g_manifest_map.Get().find(instance); | 1098 JsonManifest* manifest = GetJsonManifest(instance); |
1104 if (it == g_manifest_map.Get().end()) | 1099 if (manifest == NULL) |
1105 return PP_FALSE; | 1100 return PP_FALSE; |
1106 | 1101 |
1107 std::string full_url; | 1102 std::string full_url; |
1108 bool ok = it->second->ResolveKey(key, &full_url, pnacl_options); | 1103 bool ok = manifest->ResolveKey(key, &full_url, pnacl_options); |
1109 if (ok) | 1104 if (ok) |
1110 *pp_full_url = ppapi::StringVar::StringToPPVar(full_url); | 1105 *pp_full_url = ppapi::StringVar::StringToPPVar(full_url); |
1111 return PP_FromBool(ok); | 1106 return PP_FromBool(ok); |
1112 } | 1107 } |
1113 | 1108 |
1114 PP_Bool GetPNaClResourceInfo(PP_Instance instance, | 1109 PP_Bool GetPNaClResourceInfo(PP_Instance instance, |
1115 const char* filename, | 1110 const char* filename, |
1116 PP_Var* llc_tool_name, | 1111 PP_Var* llc_tool_name, |
1117 PP_Var* ld_tool_name) { | 1112 PP_Var* ld_tool_name) { |
1118 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 1113 NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1566 &DownloadFile | 1561 &DownloadFile |
1567 }; | 1562 }; |
1568 | 1563 |
1569 } // namespace | 1564 } // namespace |
1570 | 1565 |
1571 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 1566 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
1572 return &nacl_interface; | 1567 return &nacl_interface; |
1573 } | 1568 } |
1574 | 1569 |
1575 } // namespace nacl | 1570 } // namespace nacl |
OLD | NEW |