Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: chrome/browser/media_gallery/linux/mtp_recursive_device_object_enumerator.h

Issue 11855005: [Linux, Media Gallery] Fix MTPRecursiveDeviceObjectEnumerator to recursively enumerate all the medi… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // Returns an enumerator to traverse the subdirectory objects. If there
49 // is no subdirectory, returns NULL. The caller owns the returned
50 // MTPDeviceObjectEnumerator.
51 scoped_ptr<MTPDeviceObjectEnumerator> GetSubdirectoryEnumerator();
52
43 // Stores the device handle that was used to open the device. 53 // Stores the device handle that was used to open the device.
44 const std::string device_handle_; 54 const std::string device_handle_;
45 55
46 // Stores a reference to |media_task_runner_| to construct and destruct 56 // Stores a reference to |media_task_runner_| to construct and destruct
47 // ReadMTPDirectoryWorker object on the correct thread. 57 // ReadMTPDirectoryWorker object on the correct thread.
48 scoped_refptr<base::SequencedTaskRunner> media_task_runner_; 58 scoped_refptr<base::SequencedTaskRunner> media_task_runner_;
49 59
50 // List of top-level directory file entries. 60 // Enumerator to access current directory Id/path entries.
51 const std::vector<MtpFileEntry> file_entries_; 61 scoped_ptr<MTPDeviceObjectEnumerator> current_enumerator_;
52 62
53 // Iterator to access the individual file entries. 63 scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator>
54 std::vector<MtpFileEntry>::const_iterator file_entry_iter_; 64 empty_enumerator_;
55 65
56 // Enumerator to access current directory Id/path entries. 66 // Queue of untraversed directories.
57 scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> 67 std::queue<DirectoryEntryId> untraversed_directory_entry_ids_;
58 current_enumerator_;
59 68
60 // |media_task_runner_| can wait on this event until the requested operation 69 // |media_task_runner_| can wait on this event until the requested operation
61 // is complete. 70 // is complete.
62 base::WaitableEvent* on_task_completed_event_; 71 base::WaitableEvent* on_task_completed_event_;
63 72
64 // Stores a reference to waitable event associated with the shut down message. 73 // Stores a reference to waitable event associated with the shut down message.
65 base::WaitableEvent* on_shutdown_event_; 74 base::WaitableEvent* on_shutdown_event_;
66 75
67 DISALLOW_COPY_AND_ASSIGN(MTPRecursiveDeviceObjectEnumerator); 76 DISALLOW_COPY_AND_ASSIGN(MTPRecursiveDeviceObjectEnumerator);
68 }; 77 };
69 78
70 } // namespace chrome 79 } // namespace chrome
71 80
72 #endif // CHROME_BROWSER_MEDIA_GALLERY_LINUX_MTP_RECURSIVE_DEVICE_OBJECT_ENUMER ATOR_H_ 81 #endif // CHROME_BROWSER_MEDIA_GALLERY_LINUX_MTP_RECURSIVE_DEVICE_OBJECT_ENUMER ATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698