Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / media_galleries / fileapi / mtp_device_map_service.h
blobd64742ebd03690b735bcbd66843021b55d85011e
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.
5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MTP_DEVICE_MAP_SERVICE_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MTP_DEVICE_MAP_SERVICE_H_
8 #include <map>
10 #include "base/files/file_path.h"
11 #include "base/lazy_instance.h"
12 #include "base/threading/thread_checker.h"
14 class MTPDeviceAsyncDelegate;
16 // This class provides media transfer protocol (MTP) device delegate to
17 // complete media file system operations.
18 // Lives on the IO thread in production.
19 // TODO(gbillock): Make this class owned by the MediaFileSystemRegistry.
20 class MTPDeviceMapService {
21 public:
22 static MTPDeviceMapService* GetInstance();
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
26 // corresponding device is detached, etc).
27 // Called on the IO thread.
28 MTPDeviceAsyncDelegate* GetMTPDeviceAsyncDelegate(
29 const std::string& filesystem_id);
31 // Register that an MTP filesystem is in use for the given |device_location|.
32 void RegisterMTPFileSystem(
33 const base::FilePath::StringType& device_location,
34 const std::string& fsid);
36 // Removes the MTP entry associated with the given
37 // |device_location|. Signals the MTPDeviceMapService to destroy the
38 // delegate if there are no more uses of it.
39 void RevokeMTPFileSystem(const std::string& fsid);
41 private:
42 friend struct base::DefaultLazyInstanceTraits<MTPDeviceMapService>;
44 // Adds the MTP device delegate to the map service. |device_location|
45 // specifies the mount location of the MTP device.
46 // Called on the IO thread.
47 void AddAsyncDelegate(const base::FilePath::StringType& device_location,
48 MTPDeviceAsyncDelegate* delegate);
50 // Removes the MTP device delegate from the map service. |device_location|
51 // specifies the mount location of the MTP device.
52 // Called on the IO thread.
53 void RemoveAsyncDelegate(const base::FilePath::StringType& device_location);
55 // 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.
57 typedef std::map<base::FilePath::StringType, MTPDeviceAsyncDelegate*>
58 AsyncDelegateMap;
60 // Map a filesystem id (fsid) to an MTP device location.
61 typedef std::map<std::string, base::FilePath::StringType>
62 MTPDeviceFileSystemMap;
64 // Map a MTP or PTP device location to a count of current uses of that
65 // location.
66 typedef std::map<const base::FilePath::StringType, int>
67 MTPDeviceUsageMap;
70 // Get access to this class using GetInstance() method.
71 MTPDeviceMapService();
72 ~MTPDeviceMapService();
74 // Map of attached mtp device async delegates.
75 AsyncDelegateMap async_delegate_map_;
77 MTPDeviceFileSystemMap mtp_device_map_;
79 MTPDeviceUsageMap mtp_device_usage_map_;
81 DISALLOW_COPY_AND_ASSIGN(MTPDeviceMapService);
84 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MTP_DEVICE_MAP_SERVICE_H_