This source file includes following definitions.
- GetTransientIdForDeviceId
- DeviceIdFromTransientId
#include "components/storage_monitor/transient_device_ids.h"
#include "base/guid.h"
#include "base/logging.h"
#include "base/stl_util.h"
#include "components/storage_monitor/storage_info.h"
namespace storage_monitor {
TransientDeviceIds::TransientDeviceIds() {}
TransientDeviceIds::~TransientDeviceIds() {}
std::string TransientDeviceIds::GetTransientIdForDeviceId(
const std::string& device_id) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!ContainsKey(device_id_map_, device_id)) {
std::string transient_id;
do {
transient_id = base::GenerateGUID();
} while (ContainsKey(transient_id_map_, transient_id));
device_id_map_[device_id] = transient_id;
transient_id_map_[transient_id] = device_id;
}
return device_id_map_[device_id];
}
std::string TransientDeviceIds::DeviceIdFromTransientId(
const std::string& transient_id) const {
IdMap::const_iterator it = transient_id_map_.find(transient_id);
if (it == transient_id_map_.end())
return std::string();
return it->second;
}
}