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/memory/ref_counted.h" | |
12 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "base/memory/weak_ptr.h" |
13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
14 #include "webkit/storage/webkit_storage_export.h" | 14 #include "webkit/storage/webkit_storage_export.h" |
15 | 15 |
16 namespace fileapi { | 16 namespace fileapi { |
17 | 17 |
18 class MTPDeviceDelegate; | 18 class MTPDeviceDelegate; |
19 | 19 |
20 // Helper class to manage media device delegates which can communicate with mtp | 20 // This class provides media transfer protocol (MTP) device delegate to |
21 // devices to complete media file system operations. | 21 // complete media file system operations. ScopedMTPDeviceMapEntry class |
| 22 // manages the device map entries. This class operates on the IO thread. |
22 class WEBKIT_STORAGE_EXPORT MTPDeviceMapService { | 23 class WEBKIT_STORAGE_EXPORT MTPDeviceMapService { |
23 public: | 24 public: |
24 static MTPDeviceMapService* GetInstance(); | 25 static MTPDeviceMapService* GetInstance(); |
25 | 26 |
26 // Adds the media device delegate for the given |device_location|. Called on | 27 // Adds the MTP device delegate to the map service. |device_location| |
27 // IO thread. | 28 // specifies the mount location of the MTP device. |
| 29 // Called on the IO thread. |
28 void AddDelegate(const FilePath::StringType& device_location, | 30 void AddDelegate(const FilePath::StringType& device_location, |
29 scoped_refptr<MTPDeviceDelegate> delegate); | 31 MTPDeviceDelegate* delegate); |
30 | 32 |
31 // Removes the media device delegate for the given |device_location| if | 33 // Removes the MTP device delegate from the map service. |device_location| |
32 // exists. Called on IO thread. | 34 // specifies the mount location of the MTP device. |
| 35 // Called on the IO thread. |
33 void RemoveDelegate(const FilePath::StringType& device_location); | 36 void RemoveDelegate(const FilePath::StringType& device_location); |
34 | 37 |
35 // Gets the media device delegate associated with |filesystem_id|. | 38 // Gets the media device delegate associated with |filesystem_id|. |
36 // Return NULL if the |filesystem_id| is no longer valid (e.g. because the | 39 // Return NULL if the |filesystem_id| is no longer valid (e.g. because the |
37 // corresponding device is detached etc). Called on IO thread. | 40 // corresponding device is detached etc). |
| 41 // Called on the IO thread. |
38 MTPDeviceDelegate* GetMTPDeviceDelegate(const std::string& filesystem_id); | 42 MTPDeviceDelegate* GetMTPDeviceDelegate(const std::string& filesystem_id); |
39 | 43 |
40 private: | 44 private: |
41 friend struct DefaultSingletonTraits<MTPDeviceMapService>; | 45 friend struct DefaultSingletonTraits<MTPDeviceMapService>; |
42 | 46 |
43 typedef scoped_refptr<MTPDeviceDelegate> MTPDeviceDelegateObj; | 47 // Mapping of device_location and MTPDeviceDelegate* object. It is safe to |
44 | 48 // store and access the raw pointer. This class operates on the IO thread. |
45 // Mapping of device_location and MTPDeviceDelegate object. | 49 typedef std::map<FilePath::StringType, MTPDeviceDelegate*> DelegateMap; |
46 typedef std::map<FilePath::StringType, MTPDeviceDelegateObj> DelegateMap; | |
47 | 50 |
48 // Get access to this class using GetInstance() method. | 51 // Get access to this class using GetInstance() method. |
49 MTPDeviceMapService(); | 52 MTPDeviceMapService(); |
50 ~MTPDeviceMapService(); | 53 ~MTPDeviceMapService(); |
51 | 54 |
52 // Stores a map of attached mtp device delegates. | 55 // Map of attached mtp device delegates. |
53 DelegateMap delegate_map_; | 56 DelegateMap delegate_map_; |
54 | 57 |
55 // Stores a |thread_checker_| object to verify all methods of this class are | 58 // Object to verify all methods of this class are called on the same thread. |
56 // called on same thread. | |
57 base::ThreadChecker thread_checker_; | 59 base::ThreadChecker thread_checker_; |
58 | 60 |
59 DISALLOW_COPY_AND_ASSIGN(MTPDeviceMapService); | 61 DISALLOW_COPY_AND_ASSIGN(MTPDeviceMapService); |
60 }; | 62 }; |
61 | 63 |
62 } // namespace fileapi | 64 } // namespace fileapi |
63 | 65 |
64 #endif // WEBKIT_FILEAPI_MEDIA_MTP_DEVICE_MAP_SERVICE_H_ | 66 #endif // WEBKIT_FILEAPI_MEDIA_MTP_DEVICE_MAP_SERVICE_H_ |
OLD | NEW |