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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MTP_DEVICE_MAP_SERVICE_H_ 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MTP_DEVICE_MAP_SERVICE_H_ 7 8 #include <map> 9 10 #include "base/files/file_path.h" 11 #include "base/lazy_instance.h" 12 #include "base/threading/thread_checker.h" 13 14 namespace chrome { 15 16 class MTPDeviceAsyncDelegate; 17 18 // This class provides media transfer protocol (MTP) device delegate to 19 // complete media file system operations. ScopedMTPDeviceMapEntry class 20 // manages the device map entries. 21 class MTPDeviceMapService { 22 public: 23 static MTPDeviceMapService* GetInstance(); 24 25 ///////////////////////////////////////////////////////////////////////////// 26 // Following methods are used to manage MTPDeviceAsyncDelegate objects. // 27 ///////////////////////////////////////////////////////////////////////////// 28 // Adds the MTP device delegate to the map service. |device_location| 29 // specifies the mount location of the MTP device. 30 // Called on the IO thread. 31 void AddAsyncDelegate(const base::FilePath::StringType& device_location, 32 MTPDeviceAsyncDelegate* delegate); 33 34 // Removes the MTP device delegate from the map service. |device_location| 35 // specifies the mount location of the MTP device. 36 // Called on the IO thread. 37 void RemoveAsyncDelegate(const base::FilePath::StringType& device_location); 38 39 // Gets the media device delegate associated with |filesystem_id|. 40 // Return NULL if the |filesystem_id| is no longer valid (e.g. because the 41 // corresponding device is detached, etc). 42 // Called on the IO thread. 43 MTPDeviceAsyncDelegate* GetMTPDeviceAsyncDelegate( 44 const std::string& filesystem_id); 45 46 private: 47 friend struct base::DefaultLazyInstanceTraits<MTPDeviceMapService>; 48 49 // Mapping of device_location and MTPDeviceAsyncDelegate* object. It is safe 50 // to store and access the raw pointer. This class operates on the IO thread. 51 typedef std::map<base::FilePath::StringType, MTPDeviceAsyncDelegate*> 52 AsyncDelegateMap; 53 54 // Get access to this class using GetInstance() method. 55 MTPDeviceMapService(); 56 ~MTPDeviceMapService(); 57 58 ///////////////////////////////////////////////////////////////////////////// 59 // Following member variables are used to manage asynchronous // 60 // MTP device delegate objects. // 61 ///////////////////////////////////////////////////////////////////////////// 62 // Map of attached mtp device async delegates. 63 AsyncDelegateMap async_delegate_map_; 64 base::ThreadChecker thread_checker_; 65 66 DISALLOW_COPY_AND_ASSIGN(MTPDeviceMapService); 67 }; 68 69 } // namespace chrome 70 71 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MTP_DEVICE_MAP_SERVICE_H_ 72