1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // TransientDeviceIds implementation. 6 7 #include "chrome/browser/storage_monitor/transient_device_ids.h" 8 9 #include "base/guid.h" 10 #include "base/logging.h" 11 #include "base/stl_util.h" 12 #include "chrome/browser/storage_monitor/storage_info.h" 13 TransientDeviceIds()14TransientDeviceIds::TransientDeviceIds() {} 15 ~TransientDeviceIds()16TransientDeviceIds::~TransientDeviceIds() {} 17 GetTransientIdForDeviceId(const std::string & device_id)18std::string TransientDeviceIds::GetTransientIdForDeviceId( 19 const std::string& device_id) { 20 DCHECK(thread_checker_.CalledOnValidThread()); 21 22 if (!ContainsKey(device_id_map_, device_id)) { 23 std::string transient_id; 24 do { 25 transient_id = base::GenerateGUID(); 26 } while (ContainsKey(transient_id_map_, transient_id)); 27 28 device_id_map_[device_id] = transient_id; 29 transient_id_map_[transient_id] = device_id; 30 } 31 32 return device_id_map_[device_id]; 33 } 34 DeviceIdFromTransientId(const std::string & transient_id) const35std::string TransientDeviceIds::DeviceIdFromTransientId( 36 const std::string& transient_id) const { 37 IdMap::const_iterator it = transient_id_map_.find(transient_id); 38 if (it == transient_id_map_.end()) 39 return std::string(); 40 return it->second; 41 } 42