Commit 1243f469 authored by teravest@chromium.org's avatar teravest@chromium.org

Pepper: Move JsonManifestMap to json_manifest.h

I'd like to break out OpenManifestEntry and some other functions out of
ppb_nacl_private_impl.cc so they're easier to reuse and less tightly-bound to
the PPB_NaCl_Private interface.

BUG=239656
R=dmichael@chromium.org

Review URL: https://codereview.chromium.org/310113002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274860 0039d316-1c4b-4281-b951-d872f2087c98
parent 0d08eb4c
......@@ -6,6 +6,8 @@
#include <set>
#include "base/containers/scoped_ptr_hash_map.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/macros.h"
#include "components/nacl/renderer/nexe_load_manager.h"
......@@ -378,6 +380,21 @@ void GrabUrlAndPnaclOptions(const Json::Value& url_spec,
} // namespace
typedef base::ScopedPtrHashMap<PP_Instance, nacl::JsonManifest> JsonManifestMap;
base::LazyInstance<JsonManifestMap> g_manifest_map = LAZY_INSTANCE_INITIALIZER;
void AddJsonManifest(PP_Instance instance, scoped_ptr<JsonManifest> manifest) {
g_manifest_map.Get().add(instance, manifest.Pass());
}
JsonManifest* GetJsonManifest(PP_Instance instance) {
return g_manifest_map.Get().get(instance);
}
void DeleteJsonManifest(PP_Instance instance) {
g_manifest_map.Get().erase(instance);
}
JsonManifest::JsonManifest(const std::string& manifest_base_url,
const std::string& sandbox_isa,
bool nonsfi_enabled,
......
......@@ -8,13 +8,25 @@
#include <set>
#include <string>
#include "base/memory/scoped_ptr.h"
#include "ppapi/c/pp_array_output.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/private/ppb_nacl_private.h"
#include "third_party/jsoncpp/source/include/json/value.h"
namespace nacl {
class JsonManifest;
class NexeLoadManager;
// There is at most one JsonManifest per PP_Instance. This adds a one-to-one
// mapping.
void AddJsonManifest(PP_Instance instance, scoped_ptr<JsonManifest> manifest);
// Returns a non-owning pointer to the JsonManifest for the given instance.
// Returns NULL if no such JsonManifest exists.
JsonManifest* GetJsonManifest(PP_Instance instance);
void DeleteJsonManifest(PP_Instance instance);
class JsonManifest {
public:
struct ErrorInfo {
......
......@@ -105,11 +105,6 @@ typedef base::ScopedPtrHashMap<PP_Instance, NexeLoadManager>
base::LazyInstance<NexeLoadManagerMap> g_load_manager_map =
LAZY_INSTANCE_INITIALIZER;
typedef base::ScopedPtrHashMap<PP_Instance, nacl::JsonManifest> JsonManifestMap;
base::LazyInstance<JsonManifestMap> g_manifest_map =
LAZY_INSTANCE_INITIALIZER;
nacl::NexeLoadManager* GetNexeLoadManager(PP_Instance instance) {
NexeLoadManagerMap& map = g_load_manager_map.Get();
NexeLoadManagerMap::iterator iter = map.find(instance);
......@@ -757,7 +752,7 @@ void InstanceCreated(PP_Instance instance) {
}
void InstanceDestroyed(PP_Instance instance) {
g_manifest_map.Get().erase(instance);
DeleteJsonManifest(instance);
NexeLoadManagerMap& map = g_load_manager_map.Get();
DLOG_IF(ERROR, map.count(instance) == 0) << "Could not find instance ID";
......@@ -1041,7 +1036,7 @@ bool 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(instance, j.Pass());
AddJsonManifest(instance, j.Pass());
return true;
}
load_manager->ReportLoadError(error_info.error, error_info.string);
......@@ -1054,15 +1049,15 @@ PP_Bool ManifestGetProgramURL(PP_Instance instance,
PP_Bool* pp_uses_nonsfi_mode) {
nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance);
JsonManifestMap::iterator it = g_manifest_map.Get().find(instance);
if (it == g_manifest_map.Get().end())
JsonManifest* manifest = GetJsonManifest(instance);
if (manifest == NULL)
return PP_FALSE;
bool uses_nonsfi_mode;
std::string full_url;
JsonManifest::ErrorInfo error_info;
if (it->second->GetProgramURL(&full_url, pnacl_options, &uses_nonsfi_mode,
&error_info)) {
if (manifest->GetProgramURL(&full_url, pnacl_options, &uses_nonsfi_mode,
&error_info)) {
*pp_full_url = ppapi::StringVar::StringToPPVar(full_url);
*pp_uses_nonsfi_mode = PP_FromBool(uses_nonsfi_mode);
return PP_TRUE;
......@@ -1100,12 +1095,12 @@ PP_Bool ManifestResolveKey(PP_Instance instance,
return PP_TRUE;
}
JsonManifestMap::iterator it = g_manifest_map.Get().find(instance);
if (it == g_manifest_map.Get().end())
JsonManifest* manifest = GetJsonManifest(instance);
if (manifest == NULL)
return PP_FALSE;
std::string full_url;
bool ok = it->second->ResolveKey(key, &full_url, pnacl_options);
bool ok = manifest->ResolveKey(key, &full_url, pnacl_options);
if (ok)
*pp_full_url = ppapi::StringVar::StringToPPVar(full_url);
return PP_FromBool(ok);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment