15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// TransientDeviceIds keep track of transient IDs for removable devices, so
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// persistent device IDs are not exposed to renderers. Once a removable device
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// gets mapped to a transient ID, the mapping remains valid for the duration of
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// TransientDeviceIds' lifetime.
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifndef COMPONENTS_STORAGE_MONITOR_TRANSIENT_DEVICE_IDS_H_
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define COMPONENTS_STORAGE_MONITOR_TRANSIENT_DEVICE_IDS_H_
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <map>
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string>
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/basictypes.h"
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/threading/thread_checker.h"
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace storage_monitor {
20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TransientDeviceIds {
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TransientDeviceIds();
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ~TransientDeviceIds();
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns the transient ID for a given |device_id|.
277dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // |device_id| must be for a fixed or removable storage device.
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // If |device_id| has never been seen before, a new, unique transient id will
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // be assigned.
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::string GetTransientIdForDeviceId(const std::string& device_id);
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Get the reverse mapping for a transient ID. Returns an empty string if the
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // |transient_id| cannot be found.
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::string DeviceIdFromTransientId(const std::string& transient_id) const;
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  typedef std::map<std::string, std::string> IdMap;
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  IdMap device_id_map_;
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  IdMap transient_id_map_;
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::ThreadChecker thread_checker_;
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TransientDeviceIds);
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}  // namespace storage_monitor
48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif  // COMPONENTS_STORAGE_MONITOR_TRANSIENT_DEVICE_IDS_H_
50