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