Commit 76e128d0 authored by teravest@chromium.org's avatar teravest@chromium.org

Pepper: Move NexeLoadManager map inside that class.

This moves the management of the global NexeLoadManager map inside the
NexeLoadManager class. This makes it so that a NexeLoadManager can be looked up
from a PP_Instance from the TrustedPluginChannel class, which is needed as part
of reporting exit status over Chromium IPC.

The change for moving exit status reporting to Chromium IPC  is
available for review at:
  https://codereview.chromium.org/484783002/

BUG=397161
R=dmichael@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#291102}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291102 0039d316-1c4b-4281-b951-d872f2087c98
parent 4d54d396
......@@ -5,6 +5,8 @@
#include "components/nacl/renderer/nexe_load_manager.h"
#include "base/command_line.h"
#include "base/containers/scoped_ptr_hash_map.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/strings/string_tokenizer.h"
......@@ -39,6 +41,8 @@
#include "third_party/WebKit/public/web/WebView.h"
#include "v8/include/v8.h"
namespace nacl {
namespace {
const char* const kTypeAttribute = "type";
......@@ -76,9 +80,11 @@ std::string LookupAttribute(const std::map<std::string, std::string>& args,
return std::string();
}
} // namespace
typedef base::ScopedPtrHashMap<PP_Instance, NexeLoadManager> NexeLoadManagerMap;
base::LazyInstance<NexeLoadManagerMap> g_load_manager_map =
LAZY_INSTANCE_INITIALIZER;
namespace nacl {
} // namespace
NexeLoadManager::NexeLoadManager(
PP_Instance pp_instance)
......@@ -108,6 +114,32 @@ NexeLoadManager::~NexeLoadManager() {
base::SharedMemory::CloseHandle(crash_info_shmem_handle_);
}
void NexeLoadManager::Create(PP_Instance instance) {
scoped_ptr<NexeLoadManager> new_load_manager(new NexeLoadManager(instance));
NexeLoadManagerMap& map = g_load_manager_map.Get();
DLOG_IF(ERROR, map.count(instance) != 0) << "Instance count should be 0";
map.add(instance, new_load_manager.Pass());
}
NexeLoadManager* NexeLoadManager::Get(PP_Instance instance) {
NexeLoadManagerMap& map = g_load_manager_map.Get();
NexeLoadManagerMap::iterator iter = map.find(instance);
if (iter != map.end())
return iter->second;
return NULL;
}
void NexeLoadManager::Delete(PP_Instance instance) {
NexeLoadManagerMap& map = g_load_manager_map.Get();
// The erase may call NexeLoadManager's destructor prior to removing it from
// the map. In that case, it is possible for the trusted Plugin to re-enter
// the NexeLoadManager (e.g., by calling ReportLoadError). Passing out the
// NexeLoadManager to a local scoped_ptr just ensures that its entry is gone
// from the map prior to the destructor being invoked.
scoped_ptr<NexeLoadManager> temp(map.take(instance));
map.erase(instance);
}
void NexeLoadManager::NexeFileDidOpen(int32_t pp_error,
const base::File& file,
int32_t http_status,
......
......@@ -30,9 +30,13 @@ class TrustedPluginChannel;
// nexe.
class NexeLoadManager {
public:
explicit NexeLoadManager(PP_Instance instance);
~NexeLoadManager();
static void Create(PP_Instance instance);
// Non-owning pointer.
static NexeLoadManager* Get(PP_Instance instance);
static void Delete(PP_Instance instance);
void NexeFileDidOpen(int32_t pp_error,
const base::File& file,
int32_t http_status,
......@@ -120,6 +124,8 @@ class NexeLoadManager {
private:
DISALLOW_COPY_AND_ASSIGN(NexeLoadManager);
explicit NexeLoadManager(PP_Instance instance);
void ReportDeadNexe();
// Copies a crash log to the console, one line at a time.
......
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