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 |
Lei Zhang
2012/11/21 01:33:30
nit: space after protocol
kmadhusu
2012/11/21 04:09:53
Done.
| |
21 // devices to complete media file system operations. | 21 // complete media file system operations. ScopedMTPDeviceMapEntry class |
Lei Zhang
2012/11/21 01:33:30
I think it's fine to mention related classes, but
kmadhusu
2012/11/21 04:09:53
Done.
| |
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 // Called from ScopedMTPDeviceMapEntry constructor to add the delegate for the |
27 // IO thread. | 28 // MTP device specified by |device_location|. Called on the IO thread. |
28 void AddDelegate(const FilePath::StringType& device_location, | 29 void AddDelegate(const FilePath::StringType& device_location, |
29 scoped_refptr<MTPDeviceDelegate> delegate); | 30 MTPDeviceDelegate* delegate); |
30 | 31 |
31 // Removes the media device delegate for the given |device_location| if | 32 // Called from ScopedMTPDeviceMapEntry destructor to remove the delegate for |
32 // exists. Called on IO thread. | 33 // the MTP device specified by |device_location|. Called on the IO thread. |
33 void RemoveDelegate(const FilePath::StringType& device_location); | 34 void RemoveDelegate(const FilePath::StringType& device_location); |
34 | 35 |
35 // Gets the media device delegate associated with |filesystem_id|. | 36 // Gets the media device delegate associated with |filesystem_id|. |
36 // Return NULL if the |filesystem_id| is no longer valid (e.g. because the | 37 // Return NULL if the |filesystem_id| is no longer valid (e.g. because the |
37 // corresponding device is detached etc). Called on IO thread. | 38 // corresponding device is detached etc). Called by |
38 MTPDeviceDelegate* GetMTPDeviceDelegate(const std::string& filesystem_id); | 39 // IsolatedMountPointProvider::CreateFileSystemOperation() on IO thread. |
40 MTPDeviceDelegate* GetMTPDeviceDelegate(const std::string& filesystem_id); | |
39 | 41 |
40 private: | 42 private: |
41 friend struct DefaultSingletonTraits<MTPDeviceMapService>; | 43 friend struct DefaultSingletonTraits<MTPDeviceMapService>; |
42 | 44 |
43 typedef scoped_refptr<MTPDeviceDelegate> MTPDeviceDelegateObj; | 45 // Mapping of device_location and MTPDeviceDelegate* object. It is safe to |
44 | 46 // store and access the raw pointer. This class operates on the IO thread. |
45 // Mapping of device_location and MTPDeviceDelegate object. | 47 typedef std::map<FilePath::StringType, MTPDeviceDelegate*> DelegateMap; |
46 typedef std::map<FilePath::StringType, MTPDeviceDelegateObj> DelegateMap; | |
47 | 48 |
48 // Get access to this class using GetInstance() method. | 49 // Get access to this class using GetInstance() method. |
49 MTPDeviceMapService(); | 50 MTPDeviceMapService(); |
50 ~MTPDeviceMapService(); | 51 ~MTPDeviceMapService(); |
51 | 52 |
52 // Stores a map of attached mtp device delegates. | 53 // Map of attached mtp device delegates. |
53 DelegateMap delegate_map_; | 54 DelegateMap delegate_map_; |
54 | 55 |
55 // Stores a |thread_checker_| object to verify all methods of this class are | 56 // Object to verify all methods of this class are called on the same thread. |
56 // called on same thread. | |
57 base::ThreadChecker thread_checker_; | 57 base::ThreadChecker thread_checker_; |
58 | 58 |
59 DISALLOW_COPY_AND_ASSIGN(MTPDeviceMapService); | 59 DISALLOW_COPY_AND_ASSIGN(MTPDeviceMapService); |
60 }; | 60 }; |
61 | 61 |
62 } // namespace fileapi | 62 } // namespace fileapi |
63 | 63 |
64 #endif // WEBKIT_FILEAPI_MEDIA_MTP_DEVICE_MAP_SERVICE_H_ | 64 #endif // WEBKIT_FILEAPI_MEDIA_MTP_DEVICE_MAP_SERVICE_H_ |
OLD | NEW |