Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Unified Diff: components/nacl/renderer/ppb_nacl_private_impl.cc

Issue 301013002: Pepper: Manifest ID cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix type signature Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ppapi/api/private/ppb_nacl_private.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/nacl/renderer/ppb_nacl_private_impl.cc
diff --git a/components/nacl/renderer/ppb_nacl_private_impl.cc b/components/nacl/renderer/ppb_nacl_private_impl.cc
index 539c7104d6e4cdaecce2ac3b161290f44eafaff1..2d6d1c77352505dd11e65ea3bbd95ea286233fb4 100644
--- a/components/nacl/renderer/ppb_nacl_private_impl.cc
+++ b/components/nacl/renderer/ppb_nacl_private_impl.cc
@@ -102,19 +102,11 @@ typedef base::ScopedPtrHashMap<PP_Instance, NexeLoadManager>
base::LazyInstance<NexeLoadManagerMap> g_load_manager_map =
LAZY_INSTANCE_INITIALIZER;
-typedef base::ScopedPtrHashMap<int32_t, nacl::JsonManifest> JsonManifestMap;
+typedef base::ScopedPtrHashMap<PP_Instance, nacl::JsonManifest> JsonManifestMap;
base::LazyInstance<JsonManifestMap> g_manifest_map =
LAZY_INSTANCE_INITIALIZER;
-base::LazyInstance<int32_t> g_next_manifest_id =
- LAZY_INSTANCE_INITIALIZER;
-
-// We have to define a method here since we can't use a static initializer.
-int32_t GetPNaClManifestId() {
- return std::numeric_limits<int32_t>::max();
-}
-
nacl::NexeLoadManager* GetNexeLoadManager(PP_Instance instance) {
NexeLoadManagerMap& map = g_load_manager_map.Get();
NexeLoadManagerMap::iterator iter = map.find(instance);
@@ -746,6 +738,8 @@ void InstanceCreated(PP_Instance instance) {
}
void InstanceDestroyed(PP_Instance instance) {
+ g_manifest_map.Get().erase(instance);
+
NexeLoadManagerMap& map = g_load_manager_map.Get();
DLOG_IF(ERROR, map.count(instance) == 0) << "Could not find instance ID";
// The erase may call NexeLoadManager's destructor prior to removing it from
@@ -832,16 +826,14 @@ int64_t GetNexeSize(PP_Instance instance) {
}
void DownloadManifestToBuffer(PP_Instance instance,
- int32_t* out_manifest_id,
struct PP_CompletionCallback callback);
-int32_t CreateJsonManifest(PP_Instance instance,
- const std::string& manifest_url,
- const std::string& manifest_data);
+bool CreateJsonManifest(PP_Instance instance,
+ const std::string& manifest_url,
+ const std::string& manifest_data);
void RequestNaClManifest(PP_Instance instance,
const char* url,
- int32_t* out_manifest_id,
PP_CompletionCallback callback) {
NexeLoadManager* load_manager = GetNexeLoadManager(instance);
DCHECK(load_manager);
@@ -870,8 +862,8 @@ void RequestNaClManifest(PP_Instance instance,
int32_t error = PP_ERROR_FAILED;
if (net::DataURL::Parse(gurl, &mime_type, &charset, &data)) {
if (data.size() <= ManifestDownloader::kNaClManifestMaxFileBytes) {
- error = PP_OK;
- *out_manifest_id = CreateJsonManifest(instance, base_url.spec(), data);
+ if (CreateJsonManifest(instance, base_url.spec(), data))
+ error = PP_OK;
} else {
load_manager->ReportLoadError(PP_NACL_ERROR_MANIFEST_TOO_LARGE,
"manifest file too large.");
@@ -884,7 +876,7 @@ void RequestNaClManifest(PP_Instance instance,
FROM_HERE,
base::Bind(callback.func, callback.user_data, error));
} else {
- DownloadManifestToBuffer(instance, out_manifest_id, callback);
+ DownloadManifestToBuffer(instance, callback);
}
}
@@ -923,13 +915,11 @@ PP_Bool DevInterfacesEnabled(PP_Instance instance) {
void DownloadManifestToBufferCompletion(PP_Instance instance,
struct PP_CompletionCallback callback,
- int32_t* out_manifest_id,
base::Time start_time,
PP_NaClError pp_nacl_error,
const std::string& data);
void DownloadManifestToBuffer(PP_Instance instance,
- int32_t* out_manifest_id,
struct PP_CompletionCallback callback) {
nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance);
DCHECK(load_manager);
@@ -954,13 +944,12 @@ void DownloadManifestToBuffer(PP_Instance instance,
url_loader.Pass(),
load_manager->is_installed(),
base::Bind(DownloadManifestToBufferCompletion,
- instance, callback, out_manifest_id, base::Time::Now()));
+ instance, callback, base::Time::Now()));
manifest_downloader->Load(request);
}
void DownloadManifestToBufferCompletion(PP_Instance instance,
struct PP_CompletionCallback callback,
- int32_t* out_manifest_id,
base::Time start_time,
PP_NaClError pp_nacl_error,
const std::string& data) {
@@ -1003,26 +992,21 @@ void DownloadManifestToBufferCompletion(PP_Instance instance,
if (pp_error == PP_OK) {
std::string base_url = load_manager->manifest_base_url().spec();
- *out_manifest_id = CreateJsonManifest(instance, base_url, data);
+ if (!CreateJsonManifest(instance, base_url, data))
+ pp_error = PP_ERROR_FAILED;
}
callback.func(callback.user_data, pp_error);
}
-int32_t CreatePNaClManifest(PP_Instance /* instance */) {
- return GetPNaClManifestId();
-}
-
-int32_t CreateJsonManifest(PP_Instance instance,
- const std::string& manifest_url,
- const std::string& manifest_data) {
+bool CreateJsonManifest(PP_Instance instance,
+ const std::string& manifest_url,
+ const std::string& manifest_data) {
HistogramSizeKB("NaCl.Perf.Size.Manifest",
static_cast<int32_t>(manifest_data.length() / 1024));
nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance);
if (!load_manager)
- return -1;
- int32_t manifest_id = g_next_manifest_id.Get();
- g_next_manifest_id.Get()++;
+ return false;
const char* isa_type;
if (load_manager->IsPNaCl())
@@ -1038,36 +1022,20 @@ int32_t CreateJsonManifest(PP_Instance instance,
PP_ToBool(NaClDebugEnabledForURL(manifest_url.c_str()))));
JsonManifest::ErrorInfo error_info;
if (j->Init(manifest_data.c_str(), &error_info)) {
- g_manifest_map.Get().add(manifest_id, j.Pass());
- return manifest_id;
+ g_manifest_map.Get().add(instance, j.Pass());
+ return true;
}
load_manager->ReportLoadError(error_info.error, error_info.string);
- return -1;
-}
-
-void DestroyManifest(PP_Instance /* instance */,
- int32_t manifest_id) {
- if (manifest_id == GetPNaClManifestId())
- return;
- g_manifest_map.Get().erase(manifest_id);
+ return false;
}
PP_Bool ManifestGetProgramURL(PP_Instance instance,
- int32_t manifest_id,
PP_Var* pp_full_url,
PP_PNaClOptions* pnacl_options,
PP_Bool* pp_uses_nonsfi_mode) {
nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance);
- if (manifest_id == GetPNaClManifestId()) {
- if (load_manager) {
- load_manager->ReportLoadError(
- PP_NACL_ERROR_MANIFEST_GET_NEXE_URL,
- "pnacl manifest does not contain a program.");
- }
- return PP_FALSE;
- }
- JsonManifestMap::iterator it = g_manifest_map.Get().find(manifest_id);
+ JsonManifestMap::iterator it = g_manifest_map.Get().find(instance);
if (it == g_manifest_map.Get().end())
return PP_FALSE;
@@ -1087,11 +1055,13 @@ PP_Bool ManifestGetProgramURL(PP_Instance instance,
}
PP_Bool ManifestResolveKey(PP_Instance instance,
- int32_t manifest_id,
+ PP_Bool is_helper_process,
const char* key,
PP_Var* pp_full_url,
PP_PNaClOptions* pnacl_options) {
- if (manifest_id == GetPNaClManifestId()) {
+ // For "helper" processes (llc and ld), we resolve keys manually as there is
+ // no existing .nmf file to parse.
+ if (PP_ToBool(is_helper_process)) {
pnacl_options->translate = PP_FALSE;
// We can only resolve keys in the files/ namespace.
const std::string kFilesPrefix = "files/";
@@ -1111,7 +1081,7 @@ PP_Bool ManifestResolveKey(PP_Instance instance,
return PP_TRUE;
}
- JsonManifestMap::iterator it = g_manifest_map.Get().find(manifest_id);
+ JsonManifestMap::iterator it = g_manifest_map.Get().find(instance);
if (it == g_manifest_map.Get().end())
return PP_FALSE;
@@ -1542,8 +1512,6 @@ const PPB_NaCl_Private nacl_interface = {
&ProcessNaClManifest,
&GetManifestURLArgument,
&DevInterfacesEnabled,
- &CreatePNaClManifest,
- &DestroyManifest,
&ManifestGetProgramURL,
&ManifestResolveKey,
&GetPNaClResourceInfo,
« no previous file with comments | « no previous file | ppapi/api/private/ppb_nacl_private.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698