| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 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 WEBKIT_FILEAPI_MEDIA_MTP_DEVICE_ASYNC_DELEGATE_H_ | |
| 6 #define WEBKIT_FILEAPI_MEDIA_MTP_DEVICE_ASYNC_DELEGATE_H_ | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "base/platform_file.h" | |
| 11 #include "webkit/fileapi/async_file_util.h" | |
| 12 | |
| 13 namespace base { | |
| 14 class FilePath; | |
| 15 } | |
| 16 | |
| 17 namespace fileapi { | |
| 18 | |
| 19 // Asynchronous delegate for media transfer protocol (MTP) device to perform | |
| 20 // media device isolated file system operations. Class that implements this | |
| 21 // delegate does the actual communication with the MTP device. | |
| 22 // ScopedMTPDeviceMapEntry class manages the lifetime of the delegate via | |
| 23 // MTPDeviceMapService class. Member functions and callbacks runs on the IO | |
| 24 // thread. | |
| 25 class MTPDeviceAsyncDelegate { | |
| 26 public: | |
| 27 // A callback to be called when GetFileInfo method call succeeds. | |
| 28 typedef base::Callback< | |
| 29 void(const base::PlatformFileInfo& file_info)> GetFileInfoSuccessCallback; | |
| 30 | |
| 31 // A callback to be called when ReadDirectory method call succeeds. | |
| 32 typedef base::Callback< | |
| 33 void(const AsyncFileUtil::EntryList& file_list, | |
| 34 bool has_more)> ReadDirectorySuccessCallback; | |
| 35 | |
| 36 // A callback to be called when GetFileInfo/ReadDirectory/CreateSnapshot | |
| 37 // method call fails. | |
| 38 typedef base::Callback< | |
| 39 void(base::PlatformFileError error)> ErrorCallback; | |
| 40 | |
| 41 // A callback to be called when CreateSnapshotFile method call succeeds. | |
| 42 typedef base::Callback< | |
| 43 void(const base::PlatformFileInfo& file_info, | |
| 44 const base::FilePath& local_path)> CreateSnapshotFileSuccessCallback; | |
| 45 | |
| 46 // Gets information about the given |file_path| and invokes the appropriate | |
| 47 // callback asynchronously when complete. | |
| 48 virtual void GetFileInfo( | |
| 49 const base::FilePath& file_path, | |
| 50 const GetFileInfoSuccessCallback& success_callback, | |
| 51 const ErrorCallback& error_callback) = 0; | |
| 52 | |
| 53 // Enumerates the |root| directory contents and invokes the appropriate | |
| 54 // callback asynchronously when complete. | |
| 55 virtual void ReadDirectory( | |
| 56 const base::FilePath& root, | |
| 57 const ReadDirectorySuccessCallback& success_callback, | |
| 58 const ErrorCallback& error_callback) = 0; | |
| 59 | |
| 60 // Copy the contents of |device_file_path| to |local_path|. Invokes the | |
| 61 // appropriate callback asynchronously when complete. | |
| 62 virtual void CreateSnapshotFile( | |
| 63 const base::FilePath& device_file_path, | |
| 64 const base::FilePath& local_path, | |
| 65 const CreateSnapshotFileSuccessCallback& success_callback, | |
| 66 const ErrorCallback& error_callback) = 0; | |
| 67 | |
| 68 // Called when the | |
| 69 // (1) Browser application is in shutdown mode (or) | |
| 70 // (2) Last extension using this MTP device is destroyed (or) | |
| 71 // (3) Attached MTP device is removed (or) | |
| 72 // (4) User revoked the MTP device gallery permission. | |
| 73 // Ownership of |MTPDeviceAsyncDelegate| is handed off to the delegate | |
| 74 // implementation class by this call. This function should take care of | |
| 75 // cancelling all the pending tasks before deleting itself. | |
| 76 virtual void CancelPendingTasksAndDeleteDelegate() = 0; | |
| 77 | |
| 78 protected: | |
| 79 // Always destruct this object via CancelPendingTasksAndDeleteDelegate(). | |
| 80 virtual ~MTPDeviceAsyncDelegate() {} | |
| 81 }; | |
| 82 | |
| 83 } // namespace fileapi | |
| 84 | |
| 85 #endif // WEBKIT_FILEAPI_MEDIA_MTP_DEVICE_ASYNC_DELEGATE_H_ | |
| OLD | NEW |