Chromium Code Reviews| Index: chrome/browser/media_gallery/win/mtp_device_delegate_impl_win.h |
| diff --git a/chrome/browser/media_gallery/win/mtp_device_delegate_impl_win.h b/chrome/browser/media_gallery/win/mtp_device_delegate_impl_win.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..96413ff987d8490c0c7f96d18f8585c7d4273ba8 |
| --- /dev/null |
| +++ b/chrome/browser/media_gallery/win/mtp_device_delegate_impl_win.h |
| @@ -0,0 +1,108 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +// |
| +// This class supports media transfer protocol (MTP) device file system |
| +// operations. This class communicates with the portable device and completes |
| +// the requested file system operation. MTPDeviceMapService owns this object. |
| +// This object is constructed and destructed on UI thread. All the device |
| +// operations are performed on the blocking thread. A portable device can have |
| +// multiple data partitions. A user can register each partition as a media |
| +// file system. This class is instantitated per MTP device storage. |
| + |
| +#ifndef CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_ |
| +#define CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_ |
| + |
| +#include <portabledeviceapi.h> |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "base/platform_file.h" |
| +#include "base/string16.h" |
| +#include "base/win/scoped_comptr.h" |
| +#include "content/public/browser/notification_observer.h" |
| +#include "content/public/browser/notification_registrar.h" |
| +#include "webkit/fileapi/file_system_file_util.h" |
| +#include "webkit/fileapi/media/mtp_device_delegate.h" |
| + |
| +class FilePath; |
| + |
| +namespace base { |
| +class SequencedTaskRunner; |
| +} |
| + |
| +namespace chrome { |
| + |
| +// Helper class to communicate with MTP storage to complete isolated file system |
| +// operations. This class contains platform specific code to communicate with |
| +// the attached MTP storage. Instantiate this class per MTP storage. |
| +// This class is ref-counted, because MtpDeviceDelegate is ref-counted. |
| +class MTPDeviceDelegateImplWin : public fileapi::MtpDeviceDelegate, |
| + public content::NotificationObserver { |
| + public: |
| + // Constructed on UI thread. Defer the device initializations until the first |
| + // file operation request. Do all the initializations in LazyInit() function. |
| + explicit MTPDeviceDelegateImplWin(const string16& pnp_device_id); |
| + |
| + // MtpDeviceDelegate: |
| + virtual base::PlatformFileError GetFileInfo( |
| + const FilePath& file_path, |
| + base::PlatformFileInfo* file_info) OVERRIDE; |
| + virtual fileapi::FileSystemFileUtil::AbstractFileEnumerator* |
| + CreateFileEnumerator(const FilePath& root, bool recursive) OVERRIDE; |
| + virtual base::PlatformFileError CreateSnapshotFile( |
| + const FilePath& device_file_path, |
| + const FilePath& local_path, |
| + base::PlatformFileInfo* file_info) OVERRIDE; |
| + virtual base::SequencedTaskRunner* media_task_runner() OVERRIDE; |
| + virtual void DeleteOnCorrectThread() const OVERRIDE; |
| + |
| + private: |
| + friend struct fileapi::MtpDeviceDelegateDeleter; |
| + friend class base::DeleteHelper<MTPDeviceDelegateImplWin>; |
| + |
| + // Private because this class is ref-counted. |
| + virtual ~MTPDeviceDelegateImplWin(); |
| + |
| + // content::NotificationObserver: |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE; |
| + |
| + // Opens the device for communication. This function is called on the |
| + // sequenced task runner. Returns true if the device is ready for |
| + // communication, else false. |
| + bool LazyInit(); |
| + |
| + // The Pnp Device Id, used to open the device for communication, |
| + // e.g. "\\?\usb#vid_04a9&pid_3073#12#{6ac27878-a6fa-4155-ba85-f1d4f33}". |
| + string16 pnp_device_id_; |
| + |
| + // The media file system root path, which is obtained during the registration |
| + // of MTP device storage as a file system, |
| + // e.g. "\\MTP:StorageSerial:SID-{10001,E,9823}:237483". |
| + const string16 registered_device_path_; |
| + |
| + // The MTP device storage object identifier, used to enumerate the storage |
| + // contents, e.g. "s10001". |
| + string16 storage_object_id_; |
| + |
| + // The task runner used to execute tasks that may take a long time and thus |
| + // should not be performed on the UI thread. |
| + scoped_refptr<base::SequencedTaskRunner> media_task_runner_; |
| + |
| + // The portable device. |
| + base::win::ScopedComPtr<IPortableDevice> device_; |
| + |
| + // Used to listen for NOTIFICATION_APP_TERMINATING message. |
|
Lei Zhang
2012/11/01 02:34:57
indentation
kmadhusu
2012/11/01 17:59:00
Done.
|
| + content::NotificationRegistrar registrar_; |
| + |
| + // Used to notify the blocking tasks about the application termination |
| + // message. |
| + bool app_terminating_; |
|
kmadhusu
2012/11/01 02:38:00
Just realized that I should have used cancellation
kmadhusu
2012/11/01 17:59:00
Fixed.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplWin); |
| +}; |
| + |
| +} // namespace chrome |
| + |
| +#endif // CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_ |