OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // TransientDeviceIds keep track of transient IDs for removable devices, so | 5 // TransientDeviceIds keep track of transient IDs for removable devices, so |
6 // persistent device IDs are not exposed to renderers. Once a removable device | 6 // persistent device IDs are not exposed to renderers. Once a removable device |
7 // gets mapped to a transient ID, the mapping remains valid for the duration of | 7 // gets mapped to a transient ID, the mapping remains valid for the duration of |
8 // TransientDeviceIds' lifetime. | 8 // TransientDeviceIds' lifetime. |
9 | 9 |
10 #ifndef CHROME_BROWSER_STORAGE_MONITOR_TRANSIENT_DEVICE_IDS_H_ | 10 #ifndef CHROME_BROWSER_STORAGE_MONITOR_TRANSIENT_DEVICE_IDS_H_ |
11 #define CHROME_BROWSER_STORAGE_MONITOR_TRANSIENT_DEVICE_IDS_H_ | 11 #define CHROME_BROWSER_STORAGE_MONITOR_TRANSIENT_DEVICE_IDS_H_ |
12 | 12 |
13 #include <map> | 13 #include <map> |
14 #include <string> | 14 #include <string> |
15 | 15 |
16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
18 | 18 |
19 namespace chrome { | |
20 | |
21 class TransientDeviceIds { | 19 class TransientDeviceIds { |
22 public: | 20 public: |
23 TransientDeviceIds(); | 21 TransientDeviceIds(); |
24 ~TransientDeviceIds(); | 22 ~TransientDeviceIds(); |
25 | 23 |
26 // Returns the transient ID for a given |device_id|. | 24 // Returns the transient ID for a given |device_id|. |
27 // |device_id| must be for a fixed or removable storage device. | 25 // |device_id| must be for a fixed or removable storage device. |
28 // If |device_id| has never been seen before, a new, unique transient id will | 26 // If |device_id| has never been seen before, a new, unique transient id will |
29 // be assigned. | 27 // be assigned. |
30 std::string GetTransientIdForDeviceId(const std::string& device_id); | 28 std::string GetTransientIdForDeviceId(const std::string& device_id); |
31 | 29 |
32 // Get the reverse mapping for a transient ID. Returns an empty string if the | 30 // Get the reverse mapping for a transient ID. Returns an empty string if the |
33 // |transient_id| cannot be found. | 31 // |transient_id| cannot be found. |
34 std::string DeviceIdFromTransientId(const std::string& transient_id) const; | 32 std::string DeviceIdFromTransientId(const std::string& transient_id) const; |
35 | 33 |
36 private: | 34 private: |
37 typedef std::map<std::string, std::string> IdMap; | 35 typedef std::map<std::string, std::string> IdMap; |
38 | 36 |
39 IdMap device_id_map_; | 37 IdMap device_id_map_; |
40 IdMap transient_id_map_; | 38 IdMap transient_id_map_; |
41 | 39 |
42 base::ThreadChecker thread_checker_; | 40 base::ThreadChecker thread_checker_; |
43 | 41 |
44 DISALLOW_COPY_AND_ASSIGN(TransientDeviceIds); | 42 DISALLOW_COPY_AND_ASSIGN(TransientDeviceIds); |
45 }; | 43 }; |
46 | 44 |
47 } // namespace chrome | |
48 | |
49 #endif // CHROME_BROWSER_STORAGE_MONITOR_TRANSIENT_DEVICE_IDS_H_ | 45 #endif // CHROME_BROWSER_STORAGE_MONITOR_TRANSIENT_DEVICE_IDS_H_ |
OLD | NEW |