Chromium Code Reviews| 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_MEDIA_GALLERY_LINUX_MTP_RECURSIVE_DEVICE_OBJECT_ENUMERATO R_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_GALLERY_LINUX_MTP_RECURSIVE_DEVICE_OBJECT_ENUMERATO R_H_ |
| 6 #define CHROME_BROWSER_MEDIA_GALLERY_LINUX_MTP_RECURSIVE_DEVICE_OBJECT_ENUMERATO R_H_ | 6 #define CHROME_BROWSER_MEDIA_GALLERY_LINUX_MTP_RECURSIVE_DEVICE_OBJECT_ENUMERATO R_H_ |
| 7 | 7 |
| 8 #include <queue> | |
| 8 #include <string> | 9 #include <string> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/time.h" | 14 #include "base/time.h" |
| 14 #include "device/media_transfer_protocol/mtp_file_entry.pb.h" | 15 #include "device/media_transfer_protocol/mtp_file_entry.pb.h" |
| 15 #include "webkit/fileapi/file_system_file_util.h" | 16 #include "webkit/fileapi/file_system_file_util.h" |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 class SequencedTaskRunner; | 19 class SequencedTaskRunner; |
| 19 class WaitableEvent; | 20 class WaitableEvent; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace chrome { | 23 namespace chrome { |
| 23 | 24 |
| 25 class MTPDeviceObjectEnumerator; | |
| 26 | |
| 24 // Recursively enumerate each file entry from a given media file entry set. | 27 // Recursively enumerate each file entry from a given media file entry set. |
| 25 class MTPRecursiveDeviceObjectEnumerator | 28 class MTPRecursiveDeviceObjectEnumerator |
| 26 : public fileapi::FileSystemFileUtil::AbstractFileEnumerator { | 29 : public fileapi::FileSystemFileUtil::AbstractFileEnumerator { |
| 27 public: | 30 public: |
| 28 MTPRecursiveDeviceObjectEnumerator(const std::string& handle, | 31 MTPRecursiveDeviceObjectEnumerator(const std::string& handle, |
| 29 base::SequencedTaskRunner* task_runner, | 32 base::SequencedTaskRunner* task_runner, |
| 30 const std::vector<MtpFileEntry>& entries, | 33 const std::vector<MtpFileEntry>& entries, |
| 31 base::WaitableEvent* task_completed_event, | 34 base::WaitableEvent* task_completed_event, |
| 32 base::WaitableEvent* shutdown_event); | 35 base::WaitableEvent* shutdown_event); |
| 33 | 36 |
| 34 virtual ~MTPRecursiveDeviceObjectEnumerator(); | 37 virtual ~MTPRecursiveDeviceObjectEnumerator(); |
| 35 | 38 |
| 36 // AbstractFileEnumerator: | 39 // AbstractFileEnumerator: |
| 37 virtual FilePath Next() OVERRIDE; | 40 virtual FilePath Next() OVERRIDE; |
| 38 virtual int64 Size() OVERRIDE; | 41 virtual int64 Size() OVERRIDE; |
| 39 virtual bool IsDirectory() OVERRIDE; | 42 virtual bool IsDirectory() OVERRIDE; |
| 40 virtual base::Time LastModifiedTime() OVERRIDE; | 43 virtual base::Time LastModifiedTime() OVERRIDE; |
| 41 | 44 |
| 42 private: | 45 private: |
| 46 typedef uint32_t DirectoryEntryId; | |
| 47 | |
| 48 void UpdateEnumeratorToTraverseSubdirectory(); | |
|
Lei Zhang
2013/01/12 01:48:01
Comment.
Lei Zhang
2013/01/12 01:48:01
Alternatively, return a scoped_ptr<MTPDeviceObject
kmadhusu
2013/01/14 18:47:32
Done.
kmadhusu
2013/01/14 18:47:32
Done.
| |
| 49 | |
| 43 // Stores the device handle that was used to open the device. | 50 // Stores the device handle that was used to open the device. |
| 44 const std::string device_handle_; | 51 const std::string device_handle_; |
| 45 | 52 |
| 46 // Stores a reference to |media_task_runner_| to construct and destruct | 53 // Stores a reference to |media_task_runner_| to construct and destruct |
| 47 // ReadMTPDirectoryWorker object on the correct thread. | 54 // ReadMTPDirectoryWorker object on the correct thread. |
| 48 scoped_refptr<base::SequencedTaskRunner> media_task_runner_; | 55 scoped_refptr<base::SequencedTaskRunner> media_task_runner_; |
| 49 | 56 |
| 50 // List of top-level directory file entries. | 57 // Enumerator to access current directory Id/path entries. |
| 51 const std::vector<MtpFileEntry> file_entries_; | 58 scoped_ptr<MTPDeviceObjectEnumerator> current_enumerator_; |
| 52 | 59 |
| 53 // Iterator to access the individual file entries. | 60 scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> |
| 54 std::vector<MtpFileEntry>::const_iterator file_entry_iter_; | 61 empty_enumerator_; |
| 55 | 62 |
| 56 // Enumerator to access current directory Id/path entries. | 63 // Queue of untraversed directories. |
| 57 scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> | 64 std::queue<DirectoryEntryId> untraversed_directory_entry_ids_; |
| 58 current_enumerator_; | |
| 59 | 65 |
| 60 // |media_task_runner_| can wait on this event until the requested operation | 66 // |media_task_runner_| can wait on this event until the requested operation |
| 61 // is complete. | 67 // is complete. |
| 62 base::WaitableEvent* on_task_completed_event_; | 68 base::WaitableEvent* on_task_completed_event_; |
| 63 | 69 |
| 64 // Stores a reference to waitable event associated with the shut down message. | 70 // Stores a reference to waitable event associated with the shut down message. |
| 65 base::WaitableEvent* on_shutdown_event_; | 71 base::WaitableEvent* on_shutdown_event_; |
| 66 | 72 |
| 67 DISALLOW_COPY_AND_ASSIGN(MTPRecursiveDeviceObjectEnumerator); | 73 DISALLOW_COPY_AND_ASSIGN(MTPRecursiveDeviceObjectEnumerator); |
| 68 }; | 74 }; |
| 69 | 75 |
| 70 } // namespace chrome | 76 } // namespace chrome |
| 71 | 77 |
| 72 #endif // CHROME_BROWSER_MEDIA_GALLERY_LINUX_MTP_RECURSIVE_DEVICE_OBJECT_ENUMER ATOR_H_ | 78 #endif // CHROME_BROWSER_MEDIA_GALLERY_LINUX_MTP_RECURSIVE_DEVICE_OBJECT_ENUMER ATOR_H_ |
| OLD | NEW |