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 #include "chrome/browser/media_galleries/linux/mtp_device_object_enumerator.h" | 5 #include "chrome/browser/media_galleries/linux/mtp_device_object_enumerator.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 MTPDeviceObjectEnumerator::MTPDeviceObjectEnumerator( | 9 MTPDeviceObjectEnumerator::MTPDeviceObjectEnumerator( |
10 const std::vector<MtpFileEntry>& entries) | 10 const std::vector<MtpFileEntry>& entries) |
11 : file_entries_(entries), | 11 : file_entries_(entries), |
12 index_(0U), | 12 index_(0U), |
13 is_index_ready_(false) { | 13 is_index_ready_(false) { |
14 } | 14 } |
15 | 15 |
16 MTPDeviceObjectEnumerator::~MTPDeviceObjectEnumerator() { | 16 MTPDeviceObjectEnumerator::~MTPDeviceObjectEnumerator() { |
17 } | 17 } |
18 | 18 |
19 base::FilePath MTPDeviceObjectEnumerator::Next() { | 19 base::FilePath MTPDeviceObjectEnumerator::Next() { |
20 if (IsIndexReadyAndInRange()) | 20 if (IsIndexReadyAndInRange()) |
21 ++index_; // Normal traversal. | 21 ++index_; // Normal traversal. |
22 else if (!is_index_ready_) | 22 else if (!is_index_ready_) |
23 is_index_ready_ = true; // First time calling Next(). | 23 is_index_ready_ = true; // First time calling Next(). |
24 | 24 |
25 if (!HasMoreEntries()) | 25 if (!HasMoreEntries()) |
26 return base::FilePath(); | 26 return base::FilePath(); |
27 return base::FilePath(file_entries_[index_].file_name()); | 27 return base::FilePath(file_entries_[index_].file_name()); |
28 } | 28 } |
29 | 29 |
30 int64 MTPDeviceObjectEnumerator::Size() { | 30 int64_t MTPDeviceObjectEnumerator::Size() { |
31 if (!IsIndexReadyAndInRange()) | 31 if (!IsIndexReadyAndInRange()) |
32 return 0; | 32 return 0; |
33 return file_entries_[index_].file_size(); | 33 return file_entries_[index_].file_size(); |
34 } | 34 } |
35 | 35 |
36 bool MTPDeviceObjectEnumerator::IsDirectory() { | 36 bool MTPDeviceObjectEnumerator::IsDirectory() { |
37 if (!IsIndexReadyAndInRange()) | 37 if (!IsIndexReadyAndInRange()) |
38 return false; | 38 return false; |
39 return file_entries_[index_].file_type() == MtpFileEntry::FILE_TYPE_FOLDER; | 39 return file_entries_[index_].file_type() == MtpFileEntry::FILE_TYPE_FOLDER; |
40 } | 40 } |
41 | 41 |
42 base::Time MTPDeviceObjectEnumerator::LastModifiedTime() { | 42 base::Time MTPDeviceObjectEnumerator::LastModifiedTime() { |
43 if (!IsIndexReadyAndInRange()) | 43 if (!IsIndexReadyAndInRange()) |
44 return base::Time(); | 44 return base::Time(); |
45 return base::Time::FromTimeT(file_entries_[index_].modification_time()); | 45 return base::Time::FromTimeT(file_entries_[index_].modification_time()); |
46 } | 46 } |
47 | 47 |
48 bool MTPDeviceObjectEnumerator::GetEntryId(uint32* entry_id) const { | 48 bool MTPDeviceObjectEnumerator::GetEntryId(uint32_t* entry_id) const { |
49 DCHECK(entry_id); | 49 DCHECK(entry_id); |
50 if (!IsIndexReadyAndInRange()) | 50 if (!IsIndexReadyAndInRange()) |
51 return false; | 51 return false; |
52 | 52 |
53 *entry_id = file_entries_[index_].item_id(); | 53 *entry_id = file_entries_[index_].item_id(); |
54 return true; | 54 return true; |
55 } | 55 } |
56 | 56 |
57 bool MTPDeviceObjectEnumerator::HasMoreEntries() const { | 57 bool MTPDeviceObjectEnumerator::HasMoreEntries() const { |
58 return index_ < file_entries_.size(); | 58 return index_ < file_entries_.size(); |
59 } | 59 } |
60 | 60 |
61 bool MTPDeviceObjectEnumerator::IsIndexReadyAndInRange() const { | 61 bool MTPDeviceObjectEnumerator::IsIndexReadyAndInRange() const { |
62 return is_index_ready_ && HasMoreEntries(); | 62 return is_index_ready_ && HasMoreEntries(); |
63 } | 63 } |
OLD | NEW |