| 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 CHROME_BROWSER_CHROMEOS_MTP_MEDIA_TRANSFER_PROTOCOL_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_MTP_MEDIA_TRANSFER_PROTOCOL_MANAGER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_MTP_MEDIA_TRANSFER_PROTOCOL_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_MTP_MEDIA_TRANSFER_PROTOCOL_MANAGER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" |
| 11 #include "chromeos/dbus/media_transfer_protocol_daemon_client.h" | 12 #include "chromeos/dbus/media_transfer_protocol_daemon_client.h" |
| 12 | 13 |
| 14 class MtpFileEntry; |
| 15 class MtpStorageInfo; |
| 16 |
| 13 namespace chromeos { | 17 namespace chromeos { |
| 14 namespace mtp { | 18 namespace mtp { |
| 15 | 19 |
| 16 // This class handles the interaction with mtpd. | 20 // This class handles the interaction with mtpd. |
| 17 // Other classes can add themselves as observers. | 21 // Other classes can add themselves as observers. |
| 18 class MediaTransferProtocolManager { | 22 class MediaTransferProtocolManager { |
| 19 public: | 23 public: |
| 20 // A callback to handle the result of OpenStorage. | 24 // A callback to handle the result of OpenStorage. |
| 21 // The first argument is the returned handle. | 25 // The first argument is the returned handle. |
| 22 // The second argument is true if there was an error. | 26 // The second argument is true if there was an error. |
| 23 typedef base::Callback<void(const std::string& handle, | 27 typedef base::Callback<void(const std::string& handle, |
| 24 bool error)> OpenStorageCallback; | 28 bool error)> OpenStorageCallback; |
| 25 | 29 |
| 26 // A callback to handle the result of CloseStorage. | 30 // A callback to handle the result of CloseStorage. |
| 27 // The argument is true if there was an error. | 31 // The argument is true if there was an error. |
| 28 typedef base::Callback<void(bool error)> CloseStorageCallback; | 32 typedef base::Callback<void(bool error)> CloseStorageCallback; |
| 29 | 33 |
| 30 // A callback to handle the result of ReadDirectoryByPath/Id. | 34 // A callback to handle the result of ReadDirectoryByPath/Id. |
| 31 // The first argument is a vector of file entries. | 35 // The first argument is a vector of file entries. |
| 32 // The second argument is true if there was an error. | 36 // The second argument is true if there was an error. |
| 33 typedef base::Callback<void(const std::vector<FileEntry>& file_entries, | 37 typedef base::Callback<void(const std::vector<MtpFileEntry>& file_entries, |
| 34 bool error)> ReadDirectoryCallback; | 38 bool error)> ReadDirectoryCallback; |
| 35 | 39 |
| 36 // A callback to handle the result of ReadFileByPath/Id. | 40 // A callback to handle the result of ReadFileByPath/Id. |
| 37 // The first argument is a string containing the file data. | 41 // The first argument is a string containing the file data. |
| 38 // The second argument is true if there was an error. | 42 // The second argument is true if there was an error. |
| 39 // TODO(thestig) Consider using a file descriptor instead of the data. | 43 // TODO(thestig) Consider using a file descriptor instead of the data. |
| 40 typedef base::Callback<void(const std::string& data, | 44 typedef base::Callback<void(const std::string& data, |
| 41 bool error)> ReadFileCallback; | 45 bool error)> ReadFileCallback; |
| 42 | 46 |
| 43 // A callback to handle the result of GetFileInfoByPath/Id. | 47 // A callback to handle the result of GetFileInfoByPath/Id. |
| 44 // The first argument is a file entry. | 48 // The first argument is a file entry. |
| 45 // The second argument is true if there was an error. | 49 // The second argument is true if there was an error. |
| 46 typedef base::Callback<void(const FileEntry& file_entry, | 50 typedef base::Callback<void(const MtpFileEntry& file_entry, |
| 47 bool error)> GetFileInfoCallback; | 51 bool error)> GetFileInfoCallback; |
| 48 | 52 |
| 49 // Implement this interface to be notified about MTP storage | 53 // Implement this interface to be notified about MTP storage |
| 50 // attachment / detachment events. | 54 // attachment / detachment events. |
| 51 class Observer { | 55 class Observer { |
| 52 public: | 56 public: |
| 53 virtual ~Observer() {} | 57 virtual ~Observer() {} |
| 54 | 58 |
| 55 // A function called after a MTP storage has been attached / detached. | 59 // A function called after a MTP storage has been attached / detached. |
| 56 virtual void StorageChanged(bool is_attached, | 60 virtual void StorageChanged(bool is_attached, |
| 57 const std::string& storage_name) = 0; | 61 const std::string& storage_name) = 0; |
| 58 }; | 62 }; |
| 59 | 63 |
| 60 virtual ~MediaTransferProtocolManager() {} | 64 virtual ~MediaTransferProtocolManager() {} |
| 61 | 65 |
| 62 // Adds an observer. | 66 // Adds an observer. |
| 63 virtual void AddObserver(Observer* observer) = 0; | 67 virtual void AddObserver(Observer* observer) = 0; |
| 64 | 68 |
| 65 // Removes an observer. | 69 // Removes an observer. |
| 66 virtual void RemoveObserver(Observer* observer) = 0; | 70 virtual void RemoveObserver(Observer* observer) = 0; |
| 67 | 71 |
| 68 // Returns a vector of available MTP storages. | 72 // Returns a vector of available MTP storages. |
| 69 virtual const std::vector<std::string> GetStorages() const = 0; | 73 virtual const std::vector<std::string> GetStorages() const = 0; |
| 70 | 74 |
| 71 // On success, returns the the metadata for |storage_name|. | 75 // On success, returns the the metadata for |storage_name|. |
| 72 // Otherwise returns NULL. | 76 // Otherwise returns NULL. |
| 73 virtual const StorageInfo* GetStorageInfo( | 77 virtual const MtpStorageInfo* GetStorageInfo( |
| 74 const std::string& storage_name) const = 0; | 78 const std::string& storage_name) const = 0; |
| 75 | 79 |
| 76 // Opens |storage_name| in |mode| and runs |callback|. | 80 // Opens |storage_name| in |mode| and runs |callback|. |
| 77 virtual void OpenStorage(const std::string& storage_name, | 81 virtual void OpenStorage(const std::string& storage_name, |
| 78 OpenStorageMode mode, | 82 OpenStorageMode mode, |
| 79 const OpenStorageCallback& callback) = 0; | 83 const OpenStorageCallback& callback) = 0; |
| 80 | 84 |
| 81 // Close |storage_handle| and runs |callback|. | 85 // Close |storage_handle| and runs |callback|. |
| 82 virtual void CloseStorage(const std::string& storage_handle, | 86 virtual void CloseStorage(const std::string& storage_handle, |
| 83 const CloseStorageCallback& callback) = 0; | 87 const CloseStorageCallback& callback) = 0; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 127 |
| 124 // Returns a pointer to the global MediaTransferProtocolManager instance. | 128 // Returns a pointer to the global MediaTransferProtocolManager instance. |
| 125 // Initialize() should already have been called. | 129 // Initialize() should already have been called. |
| 126 static MediaTransferProtocolManager* GetInstance(); | 130 static MediaTransferProtocolManager* GetInstance(); |
| 127 }; | 131 }; |
| 128 | 132 |
| 129 } // namespace mtp | 133 } // namespace mtp |
| 130 } // namespace chromeos | 134 } // namespace chromeos |
| 131 | 135 |
| 132 #endif // CHROME_BROWSER_CHROMEOS_MTP_MEDIA_TRANSFER_PROTOCOL_MANAGER_H_ | 136 #endif // CHROME_BROWSER_CHROMEOS_MTP_MEDIA_TRANSFER_PROTOCOL_MANAGER_H_ |
| OLD | NEW |