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 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MTP_DEVICE_MAP_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MTP_DEVICE_MAP_SERVICE_H_ |
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MTP_DEVICE_MAP_SERVICE_H_ | 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MTP_DEVICE_MAP_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 static MTPDeviceMapService* GetInstance(); | 22 static MTPDeviceMapService* GetInstance(); |
23 | 23 |
24 // Gets the media device delegate associated with |filesystem_id|. | 24 // Gets the media device delegate associated with |filesystem_id|. |
25 // Return NULL if the |filesystem_id| is no longer valid (e.g. because the | 25 // Return NULL if the |filesystem_id| is no longer valid (e.g. because the |
26 // corresponding device is detached, etc). | 26 // corresponding device is detached, etc). |
27 // Called on the IO thread. | 27 // Called on the IO thread. |
28 MTPDeviceAsyncDelegate* GetMTPDeviceAsyncDelegate( | 28 MTPDeviceAsyncDelegate* GetMTPDeviceAsyncDelegate( |
29 const std::string& filesystem_id); | 29 const std::string& filesystem_id); |
30 | 30 |
31 // Register that an MTP filesystem is in use for the given |device_location|. | 31 // Register that an MTP filesystem is in use for the given |device_location|. |
32 void RegisterMTPFileSystem( | 32 void RegisterMTPFileSystem(const base::FilePath::StringType& device_location, |
33 const base::FilePath::StringType& device_location, | 33 const std::string& filesystem_id, |
34 const std::string& fsid); | 34 const bool read_only); |
35 | 35 |
36 // Removes the MTP entry associated with the given | 36 // Removes the MTP entry associated with the given |
37 // |device_location|. Signals the MTPDeviceMapService to destroy the | 37 // |device_location|. Signals the MTPDeviceMapService to destroy the |
38 // delegate if there are no more uses of it. | 38 // delegate if there are no more uses of it. |
39 void RevokeMTPFileSystem(const std::string& fsid); | 39 void RevokeMTPFileSystem(const std::string& filesystem_id); |
40 | 40 |
41 private: | 41 private: |
42 friend struct base::DefaultLazyInstanceTraits<MTPDeviceMapService>; | 42 friend struct base::DefaultLazyInstanceTraits<MTPDeviceMapService>; |
43 | 43 |
44 // Adds the MTP device delegate to the map service. |device_location| | 44 // Adds the MTP device delegate to the map service. |device_location| |
45 // specifies the mount location of the MTP device. | 45 // specifies the mount location of the MTP device. |
46 // Called on the IO thread. | 46 // Called on the IO thread. |
47 void AddAsyncDelegate(const base::FilePath::StringType& device_location, | 47 void AddAsyncDelegate(const base::FilePath::StringType& device_location, |
| 48 const bool read_only, |
48 MTPDeviceAsyncDelegate* delegate); | 49 MTPDeviceAsyncDelegate* delegate); |
49 | 50 |
50 // Removes the MTP device delegate from the map service. |device_location| | 51 // Removes the MTP device delegate from the map service. |device_location| |
51 // specifies the mount location of the MTP device. | 52 // specifies the mount location of the MTP device. |
52 // Called on the IO thread. | 53 // Called on the IO thread. |
53 void RemoveAsyncDelegate(const base::FilePath::StringType& device_location); | 54 void RemoveAsyncDelegate(const base::FilePath::StringType& device_location, |
| 55 const bool read_only); |
| 56 |
| 57 // A key to be used in AsyncDelegateMap and MTPDeviceUsageMap. |
| 58 typedef base::FilePath::StringType AsyncDelegateKey; |
| 59 |
| 60 // Gets a key from |device_location| and |read_only|. |
| 61 static AsyncDelegateKey GetAsyncDelegateKey( |
| 62 const base::FilePath::StringType& device_location, |
| 63 const bool read_only); |
54 | 64 |
55 // Mapping of device_location and MTPDeviceAsyncDelegate* object. It is safe | 65 // Mapping of device_location and MTPDeviceAsyncDelegate* object. It is safe |
56 // to store and access the raw pointer. This class operates on the IO thread. | 66 // to store and access the raw pointer. This class operates on the IO thread. |
57 typedef std::map<base::FilePath::StringType, MTPDeviceAsyncDelegate*> | 67 typedef std::map<AsyncDelegateKey, MTPDeviceAsyncDelegate*> AsyncDelegateMap; |
58 AsyncDelegateMap; | |
59 | 68 |
60 // Map a filesystem id (fsid) to an MTP device location. | 69 // Map a filesystem id (fsid) to an MTP device location. |
61 typedef std::map<std::string, base::FilePath::StringType> | 70 typedef std::pair<base::FilePath::StringType, bool> MTPDeviceInfo; |
62 MTPDeviceFileSystemMap; | 71 typedef std::map<std::string, MTPDeviceInfo> MTPDeviceFileSystemMap; |
63 | 72 |
64 // Map a MTP or PTP device location to a count of current uses of that | 73 // Map a MTP or PTP device location to a count of current uses of that |
65 // location. | 74 // location. |
66 typedef std::map<const base::FilePath::StringType, int> | 75 typedef std::map<AsyncDelegateKey, int> MTPDeviceUsageMap; |
67 MTPDeviceUsageMap; | |
68 | |
69 | 76 |
70 // Get access to this class using GetInstance() method. | 77 // Get access to this class using GetInstance() method. |
71 MTPDeviceMapService(); | 78 MTPDeviceMapService(); |
72 ~MTPDeviceMapService(); | 79 ~MTPDeviceMapService(); |
73 | 80 |
74 // Map of attached mtp device async delegates. | 81 // Map of attached mtp device async delegates. |
75 AsyncDelegateMap async_delegate_map_; | 82 AsyncDelegateMap async_delegate_map_; |
76 | 83 |
77 MTPDeviceFileSystemMap mtp_device_map_; | 84 MTPDeviceFileSystemMap mtp_device_map_; |
78 | 85 |
79 MTPDeviceUsageMap mtp_device_usage_map_; | 86 MTPDeviceUsageMap mtp_device_usage_map_; |
80 | 87 |
81 DISALLOW_COPY_AND_ASSIGN(MTPDeviceMapService); | 88 DISALLOW_COPY_AND_ASSIGN(MTPDeviceMapService); |
82 }; | 89 }; |
83 | 90 |
84 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MTP_DEVICE_MAP_SERVICE_H_ | 91 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MTP_DEVICE_MAP_SERVICE_H_ |
OLD | NEW |