mtp_device_object_enumerator.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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#ifndef CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_OBJECT_ENUMERATOR_H_
6#define CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_OBJECT_ENUMERATOR_H_
7
8#include <vector>
9
10#include "base/files/file_path.h"
11#include "base/time.h"
12#include "device/media_transfer_protocol/mtp_file_entry.pb.h"
13#include "webkit/browser/fileapi/file_system_file_util.h"
14
15namespace chrome {
16
17// Used to enumerate top-level files of an media file system.
18class MTPDeviceObjectEnumerator
19    : public fileapi::FileSystemFileUtil::AbstractFileEnumerator {
20 public:
21  explicit MTPDeviceObjectEnumerator(const std::vector<MtpFileEntry>& entries);
22
23  virtual ~MTPDeviceObjectEnumerator();
24
25  // AbstractFileEnumerator:
26  virtual base::FilePath Next() OVERRIDE;
27  virtual int64 Size() OVERRIDE;
28  virtual bool IsDirectory() OVERRIDE;
29  virtual base::Time LastModifiedTime() OVERRIDE;
30
31  // If the current file entry is valid, returns true and fills in |entry_id|
32  // with the entry identifier else returns false and |entry_id| is not set.
33  bool GetEntryId(uint32_t* entry_id) const;
34
35 private:
36  // Returns true if the enumerator has more entries to traverse, false
37  // otherwise.
38  bool HasMoreEntries() const;
39
40  // Returns true if Next() has been called at least once, and the enumerator
41  // has more entries to traverse.
42  bool IsIndexReadyAndInRange() const;
43
44  // List of directory file entries information.
45  const std::vector<MtpFileEntry> file_entries_;
46
47  // Index into |file_entries_|.
48  // Should only be used when |is_index_ready_| is true.
49  size_t index_;
50
51  // Initially false. Set to true after Next() has been called.
52  bool is_index_ready_;
53
54  DISALLOW_COPY_AND_ASSIGN(MTPDeviceObjectEnumerator);
55};
56
57}  // namespace chrome
58
59#endif  // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_OBJECT_ENUMERATOR_H_
60