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.
5 #include "chrome/browser/media_galleries/linux/mtp_device_object_enumerator.h"
7 #include "base/logging.h"
9 MTPDeviceObjectEnumerator::MTPDeviceObjectEnumerator(
10 const std::vector
<MtpFileEntry
>& entries
)
11 : file_entries_(entries
),
13 is_index_ready_(false) {
16 MTPDeviceObjectEnumerator::~MTPDeviceObjectEnumerator() {
19 base::FilePath
MTPDeviceObjectEnumerator::Next() {
20 if (IsIndexReadyAndInRange())
21 ++index_
; // Normal traversal.
22 else if (!is_index_ready_
)
23 is_index_ready_
= true; // First time calling Next().
25 if (!HasMoreEntries())
26 return base::FilePath();
27 return base::FilePath(file_entries_
[index_
].file_name());
30 int64
MTPDeviceObjectEnumerator::Size() {
31 if (!IsIndexReadyAndInRange())
33 return file_entries_
[index_
].file_size();
36 bool MTPDeviceObjectEnumerator::IsDirectory() {
37 if (!IsIndexReadyAndInRange())
39 return file_entries_
[index_
].file_type() == MtpFileEntry::FILE_TYPE_FOLDER
;
42 base::Time
MTPDeviceObjectEnumerator::LastModifiedTime() {
43 if (!IsIndexReadyAndInRange())
45 return base::Time::FromTimeT(file_entries_
[index_
].modification_time());
48 bool MTPDeviceObjectEnumerator::GetEntryId(uint32
* entry_id
) const {
50 if (!IsIndexReadyAndInRange())
53 *entry_id
= file_entries_
[index_
].item_id();
57 bool MTPDeviceObjectEnumerator::HasMoreEntries() const {
58 return index_
< file_entries_
.size();
61 bool MTPDeviceObjectEnumerator::IsIndexReadyAndInRange() const {
62 return is_index_ready_
&& HasMoreEntries();