[M120 Migration][VD] Enable direct rendering for TVPlus
[platform/framework/web/chromium-efl.git] / components / storage_monitor / mtp_manager_client_chromeos.h
1 // Copyright 2018 The Chromium Authors
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 COMPONENTS_STORAGE_MONITOR_MTP_MANAGER_CLIENT_CHROMEOS_H_
6 #define COMPONENTS_STORAGE_MONITOR_MTP_MANAGER_CLIENT_CHROMEOS_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/memory/raw_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "components/storage_monitor/storage_monitor.h"
15 #include "mojo/public/cpp/bindings/associated_receiver.h"
16 #include "services/device/public/mojom/mtp_manager.mojom.h"
17
18 namespace base {
19 class FilePath;
20 }
21
22 namespace storage_monitor {
23
24 // This client listens for MTP storage attachment and detachment events
25 // from MtpManager and forwards them to StorageMonitor.
26 class MtpManagerClientChromeOS : public device::mojom::MtpManagerClient {
27  public:
28   MtpManagerClientChromeOS(StorageMonitor::Receiver* receiver,
29                            device::mojom::MtpManager* mtp_manager);
30
31   MtpManagerClientChromeOS(const MtpManagerClientChromeOS&) = delete;
32   MtpManagerClientChromeOS& operator=(const MtpManagerClientChromeOS&) = delete;
33
34   ~MtpManagerClientChromeOS() override;
35
36   // Finds the storage that contains |path| and populates |storage_info|.
37   // Returns false if unable to find the storage.
38   bool GetStorageInfoForPath(const base::FilePath& path,
39                              StorageInfo* storage_info) const;
40
41   void EjectDevice(
42       const std::string& device_id,
43       base::OnceCallback<void(StorageMonitor::EjectStatus)> callback);
44
45  protected:
46   // device::mojom::MtpManagerClient implementation.
47   // Exposed for unit tests.
48   void StorageAttached(device::mojom::MtpStorageInfoPtr storage_info) override;
49   void StorageDetached(const std::string& storage_name) override;
50
51  private:
52   // Mapping of storage location and MTP storage info object.
53   using StorageLocationToInfoMap = std::map<std::string, StorageInfo>;
54
55   // Enumerate existing MTP storage devices.
56   void OnReceivedStorages(
57       std::vector<device::mojom::MtpStorageInfoPtr> storage_info_list);
58
59   // Find the |storage_map_| key for the record with this |device_id|. Returns
60   // true on success, false on failure.
61   bool GetLocationForDeviceId(const std::string& device_id,
62                               std::string* location) const;
63
64   // Map of all attached MTP devices.
65   StorageLocationToInfoMap storage_map_;
66
67   // Pointer to the MTP manager. Not owned. Client must ensure the MTP
68   // manager outlives this object.
69   const raw_ptr<device::mojom::MtpManager, ExperimentalAsh> mtp_manager_;
70
71   mojo::AssociatedReceiver<device::mojom::MtpManagerClient> receiver_{this};
72
73   // The notifications object to use to signal newly attached devices.
74   // Guaranteed to outlive this class.
75   const raw_ptr<StorageMonitor::Receiver, ExperimentalAsh> notifications_;
76
77   base::WeakPtrFactory<MtpManagerClientChromeOS> weak_ptr_factory_{this};
78 };
79
80 }  // namespace storage_monitor
81
82 #endif  // COMPONENTS_STORAGE_MONITOR_MTP_MANAGER_CLIENT_CHROMEOS_H_