| OLD | NEW |
| (Empty) | |
| 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. |
| 4 |
| 5 // MTPDeviceOperationsUtil provides support to media filesystem operations. |
| 6 // It has several utility functions to open a media transfer protocol (MTP) |
| 7 // device for communication, to enumerate the device contents, to read the |
| 8 // device file object, etc. All these tasks may take an arbitary long time |
| 9 // to complete. This class segregates those functionalities and runs them |
| 10 // in the blocking pool thread rather than in the UI thread. |
| 11 |
| 12 #ifndef CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_OPERATIONS_UTIL_H_ |
| 13 #define CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_OPERATIONS_UTIL_H_ |
| 14 |
| 15 #include <portabledeviceapi.h> |
| 16 |
| 17 #include <string> |
| 18 |
| 19 #include "base/platform_file.h" |
| 20 #include "base/string16.h" |
| 21 #include "base/win/scoped_comptr.h" |
| 22 #include "chrome/browser/media_gallery/win/mtp_device_object_entry.h" |
| 23 |
| 24 namespace chrome { |
| 25 |
| 26 // See the top of the file for complete class description. |
| 27 class MTPDeviceOperationsUtil { |
| 28 public: |
| 29 // Opens the device for communication. |pnp_device_id| specifies the plug and |
| 30 // play device ID string. On success, returns true and updates |device| with |
| 31 // the portable device interface. |
| 32 static bool OpenDevice(const string16& pnp_device_id, |
| 33 base::win::ScopedComPtr<IPortableDevice>* device); |
| 34 |
| 35 // Gets the details of the object specified by |object_id| from the given MTP |
| 36 // |device|. On success, fills in |file_entry_info|. On failure, returns the |
| 37 // corresponding platform file error and |file_entry_info| is not set. |
| 38 static base::PlatformFileError GetFileEntryInfo( |
| 39 IPortableDevice* device, |
| 40 const string16& object_id, |
| 41 base::PlatformFileInfo* file_entry_info); |
| 42 |
| 43 // Gets the entries of the directory specified by |directory_object_id| from |
| 44 // the given MTP |device|. On success, returns true and fills in |
| 45 // |object_entries|. On failure, returns false and |object_entries| are not |
| 46 // set. |
| 47 static bool GetDirectoryEntries(IPortableDevice* device, |
| 48 const string16& directory_object_id, |
| 49 MTPDeviceObjectEntries* object_entries); |
| 50 |
| 51 // Writes the data of the object specified by |file_object_id| from the given |
| 52 // MTP |device| to the file specified by |local_path|. On success, returns |
| 53 // true and writes the object data in |local_path|. On failure, returns false. |
| 54 static bool WriteFileObjectData(IPortableDevice* device, |
| 55 const string16& file_object_id, |
| 56 const FilePath& local_path); |
| 57 |
| 58 // Returns the identifier of the object specified by the |object_name|. |
| 59 // |parent_id| specifies the object's parent identifier. |
| 60 static string16 GetObjectIdFromName(IPortableDevice* device, |
| 61 const string16& parent_id, |
| 62 const string16& object_name); |
| 63 |
| 64 private: |
| 65 // All methods are static, this class should not be instantiated. |
| 66 MTPDeviceOperationsUtil(); |
| 67 }; |
| 68 |
| 69 } // namespace chrome |
| 70 |
| 71 #endif // CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_OPERATIONS_UTIL_H_ |
| OLD | NEW |