Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / chrome / browser / media_galleries / fileapi / mtp_device_map_service.h
blob0f24b14ef56e731c20b048301bc755ed1e19bb8d
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(const base::FilePath::StringType& device_location,
33 const std::string& filesystem_id,
34 const bool read_only);
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& filesystem_id);
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 const bool read_only,
49 MTPDeviceAsyncDelegate* delegate);
51 // Removes the MTP device delegate from the map service. |device_location|
52 // specifies the mount location of the MTP device.
53 // Called on the IO thread.
54 void RemoveAsyncDelegate(const base::FilePath::StringType& device_location,
55 const bool read_only);
57 // A key to be used in AsyncDelegateMap and MTPDeviceUsageMap.
58 typedef base::FilePath::StringType AsyncDelegateKey;
60 // Gets a key from |device_location| and |read_only|.
61 static AsyncDelegateKey GetAsyncDelegateKey(
62 const base::FilePath::StringType& device_location,
63 const bool read_only);
65 // Mapping of device_location and MTPDeviceAsyncDelegate* object. It is safe
66 // to store and access the raw pointer. This class operates on the IO thread.
67 typedef std::map<AsyncDelegateKey, MTPDeviceAsyncDelegate*> AsyncDelegateMap;
69 // Map a filesystem id (fsid) to an MTP device location.
70 typedef std::pair<base::FilePath::StringType, bool> MTPDeviceInfo;
71 typedef std::map<std::string, MTPDeviceInfo> MTPDeviceFileSystemMap;
73 // Map a MTP or PTP device location to a count of current uses of that
74 // location.
75 typedef std::map<AsyncDelegateKey, int> MTPDeviceUsageMap;
77 // Get access to this class using GetInstance() method.
78 MTPDeviceMapService();
79 ~MTPDeviceMapService();
81 // Map of attached mtp device async delegates.
82 AsyncDelegateMap async_delegate_map_;
84 MTPDeviceFileSystemMap mtp_device_map_;
86 MTPDeviceUsageMap mtp_device_usage_map_;
88 DISALLOW_COPY_AND_ASSIGN(MTPDeviceMapService);
91 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MTP_DEVICE_MAP_SERVICE_H_