This source file includes following definitions.
- GetInstance
- SetData
- GetData
#include "mojo/common/environment_data.h"
#include "base/stl_util.h"
namespace mojo {
namespace common {
EnvironmentData* EnvironmentData::instance_ = NULL;
EnvironmentData::EnvironmentData() {
DCHECK(!instance_);
instance_ = this;
}
EnvironmentData::~EnvironmentData() {
instance_ = NULL;
DataMap data_map;
data_map.swap(data_map_);
STLDeleteContainerPairSecondPointers(data_map.begin(), data_map.end());
}
EnvironmentData* EnvironmentData::GetInstance() {
return instance_;
}
void EnvironmentData::SetData(const void* key, scoped_ptr<Data> data) {
Data* old = NULL;
{
base::AutoLock auto_lock(data_lock_);
old = data_map_[key];
if (data)
data_map_[key] = data.release();
else
data_map_.erase(key);
}
delete old;
}
EnvironmentData::Data* EnvironmentData::GetData(const void* key) {
base::AutoLock auto_lock(data_lock_);
return data_map_.count(key) > 0 ? data_map_[key] : NULL;
}
}
}