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 WEBKIT_FILEAPI_MEDIA_MTP_DEVICE_MAP_SERVICE_H_ | 5 #ifndef WEBKIT_FILEAPI_MEDIA_MTP_DEVICE_MAP_SERVICE_H_ |
6 #define WEBKIT_FILEAPI_MEDIA_MTP_DEVICE_MAP_SERVICE_H_ | 6 #define WEBKIT_FILEAPI_MEDIA_MTP_DEVICE_MAP_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
13 #include "webkit/storage/webkit_storage_export.h" | 13 #include "webkit/storage/webkit_storage_export.h" |
14 | 14 |
15 namespace fileapi { | 15 namespace fileapi { |
16 | 16 |
17 class MTPDeviceDelegate; | 17 class MTPDeviceDelegate; |
18 | 18 |
19 // This class provides media transfer protocol (MTP) device delegate to | 19 // This class provides media transfer protocol (MTP) device delegate to |
20 // complete media file system operations. ScopedMTPDeviceMapEntry class | 20 // complete media file system operations. ScopedMTPDeviceMapEntry class |
21 // manages the device map entries. | 21 // manages the device map entries. |
22 class WEBKIT_STORAGE_EXPORT MTPDeviceMapService { | 22 class WEBKIT_STORAGE_EXPORT MTPDeviceMapService { |
23 public: | 23 public: |
24 static MTPDeviceMapService* GetInstance(); | 24 static MTPDeviceMapService* GetInstance(); |
25 | 25 |
26 // Adds the MTP device delegate to the map service. |device_location| | 26 // Adds the MTP device delegate to the map service. |device_location| |
27 // specifies the mount location of the MTP device. | 27 // specifies the mount location of the MTP device. |
28 // Called on a media task runner thread. | 28 // Called on a media task runner thread. |
29 void AddDelegate(const FilePath::StringType& device_location, | 29 void AddDelegate(const base::FilePath::StringType& device_location, |
30 MTPDeviceDelegate* delegate); | 30 MTPDeviceDelegate* delegate); |
31 | 31 |
32 // Removes the MTP device delegate from the map service. |device_location| | 32 // Removes the MTP device delegate from the map service. |device_location| |
33 // specifies the mount location of the MTP device. | 33 // specifies the mount location of the MTP device. |
34 // Called on the UI thread. | 34 // Called on the UI thread. |
35 void RemoveDelegate(const FilePath::StringType& device_location); | 35 void RemoveDelegate(const base::FilePath::StringType& device_location); |
36 | 36 |
37 // Gets the media device delegate associated with |filesystem_id|. | 37 // Gets the media device delegate associated with |filesystem_id|. |
38 // Return NULL if the |filesystem_id| is no longer valid (e.g. because the | 38 // Return NULL if the |filesystem_id| is no longer valid (e.g. because the |
39 // corresponding device is detached, etc). | 39 // corresponding device is detached, etc). |
40 // Called on a media task runner thread. | 40 // Called on a media task runner thread. |
41 // TODO(thestig) DCHECK AddDelegate() and GetMTPDeviceDelegate() are actually | 41 // TODO(thestig) DCHECK AddDelegate() and GetMTPDeviceDelegate() are actually |
42 // called on the same task runner. | 42 // called on the same task runner. |
43 MTPDeviceDelegate* GetMTPDeviceDelegate(const std::string& filesystem_id); | 43 MTPDeviceDelegate* GetMTPDeviceDelegate(const std::string& filesystem_id); |
44 | 44 |
45 private: | 45 private: |
46 friend struct base::DefaultLazyInstanceTraits<MTPDeviceMapService>; | 46 friend struct base::DefaultLazyInstanceTraits<MTPDeviceMapService>; |
47 | 47 |
48 // Mapping of device_location and MTPDeviceDelegate* object. It is safe to | 48 // Mapping of device_location and MTPDeviceDelegate* object. It is safe to |
49 // store and access the raw pointer. This class operates on the IO thread. | 49 // store and access the raw pointer. This class operates on the IO thread. |
50 typedef std::map<FilePath::StringType, MTPDeviceDelegate*> DelegateMap; | 50 typedef std::map<base::FilePath::StringType, MTPDeviceDelegate*> DelegateMap; |
51 | 51 |
52 // Get access to this class using GetInstance() method. | 52 // Get access to this class using GetInstance() method. |
53 MTPDeviceMapService(); | 53 MTPDeviceMapService(); |
54 ~MTPDeviceMapService(); | 54 ~MTPDeviceMapService(); |
55 | 55 |
56 // Map of attached mtp device delegates. | 56 // Map of attached mtp device delegates. |
57 DelegateMap delegate_map_; | 57 DelegateMap delegate_map_; |
58 base::Lock lock_; | 58 base::Lock lock_; |
59 | 59 |
60 DISALLOW_COPY_AND_ASSIGN(MTPDeviceMapService); | 60 DISALLOW_COPY_AND_ASSIGN(MTPDeviceMapService); |
61 }; | 61 }; |
62 | 62 |
63 } // namespace fileapi | 63 } // namespace fileapi |
64 | 64 |
65 #endif // WEBKIT_FILEAPI_MEDIA_MTP_DEVICE_MAP_SERVICE_H_ | 65 #endif // WEBKIT_FILEAPI_MEDIA_MTP_DEVICE_MAP_SERVICE_H_ |
OLD | NEW |