This source file includes following definitions.
- data
- SetIOSUserData
- GetUserData
- SetUserData
- RemoveUserData
- DetachUserDataThread
#include "ios/public/consumer/base/supports_user_data.h"
#include "base/memory/scoped_ptr.h"
#include "base/supports_user_data.h"
namespace ios {
class DataAdaptor : public base::SupportsUserData::Data {
public:
DataAdaptor(SupportsUserData::Data* data);
virtual ~DataAdaptor();
SupportsUserData::Data* data() { return data_.get(); }
private:
scoped_ptr<SupportsUserData::Data> data_;
};
DataAdaptor::DataAdaptor(SupportsUserData::Data* data)
: data_(data) {}
DataAdaptor::~DataAdaptor() {}
class SupportsUserDataInternal : public base::SupportsUserData {
public:
ios::SupportsUserData::Data* GetIOSUserData(const void* key);
void SetIOSUserData(const void* key, ios::SupportsUserData::Data* data);
private:
SupportsUserDataInternal() {}
virtual ~SupportsUserDataInternal() {}
friend class ios::SupportsUserData;
};
ios::SupportsUserData::Data* SupportsUserDataInternal::GetIOSUserData(
const void* key) {
DataAdaptor* adaptor = static_cast<DataAdaptor*>(
base::SupportsUserData::GetUserData(key));
if (!adaptor)
return NULL;
return adaptor->data();
}
void SupportsUserDataInternal::SetIOSUserData(
const void* key, ios::SupportsUserData::Data* data) {
base::SupportsUserData::SetUserData(key, new DataAdaptor(data));
}
SupportsUserData::SupportsUserData()
: internal_helper_(new SupportsUserDataInternal()) {
}
SupportsUserData::~SupportsUserData() {
delete internal_helper_;
}
SupportsUserData::Data* SupportsUserData::GetUserData(const void* key) const {
return internal_helper_->GetIOSUserData(key);
}
void SupportsUserData::SetUserData(const void* key, Data* data) {
internal_helper_->SetIOSUserData(key, data);
}
void SupportsUserData::RemoveUserData(const void* key) {
internal_helper_->RemoveUserData(key);
}
void SupportsUserData::DetachUserDataThread() {
internal_helper_->DetachUserDataThread();
}
}