Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / storage_monitor / transient_device_ids.cc
blob6027044f84cda57d187261c89ff4fead95190d05
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.
5 // TransientDeviceIds implementation.
7 #include "chrome/browser/storage_monitor/transient_device_ids.h"
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"
14 TransientDeviceIds::TransientDeviceIds() {}
16 TransientDeviceIds::~TransientDeviceIds() {}
18 std::string TransientDeviceIds::GetTransientIdForDeviceId(
19 const std::string& device_id) {
20 DCHECK(thread_checker_.CalledOnValidThread());
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));
28 device_id_map_[device_id] = transient_id;
29 transient_id_map_[transient_id] = device_id;
32 return device_id_map_[device_id];
35 std::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;