Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / media_galleries / win / mtp_device_object_enumerator.cc
blob3fcff89ea9f9b261e1d8d2856b26477570a2f0e3
1 // Copyright (c) 2013 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 // MTPDeviceObjectEnumerator implementation.
7 #include "chrome/browser/media_galleries/win/mtp_device_object_enumerator.h"
9 #include "base/threading/thread_restrictions.h"
10 #include "content/public/browser/browser_thread.h"
12 MTPDeviceObjectEnumerator::MTPDeviceObjectEnumerator(
13 const MTPDeviceObjectEntries& entries)
14 : object_entries_(entries),
15 index_(0U),
16 is_index_ready_(false) {
17 base::ThreadRestrictions::AssertIOAllowed();
20 MTPDeviceObjectEnumerator::~MTPDeviceObjectEnumerator() {
21 DCHECK(thread_checker_.CalledOnValidThread());
24 base::FilePath MTPDeviceObjectEnumerator::Next() {
25 DCHECK(thread_checker_.CalledOnValidThread());
26 if (IsIndexReadyAndInRange())
27 ++index_; // Normal traversal.
28 else if (!is_index_ready_)
29 is_index_ready_ = true; // First time calling Next().
31 if (!HasMoreEntries())
32 return base::FilePath();
33 return base::FilePath(object_entries_[index_].name);
36 int64 MTPDeviceObjectEnumerator::Size() {
37 DCHECK(thread_checker_.CalledOnValidThread());
38 if (!IsIndexReadyAndInRange())
39 return 0;
40 return object_entries_[index_].size;
43 bool MTPDeviceObjectEnumerator::IsDirectory() {
44 DCHECK(thread_checker_.CalledOnValidThread());
45 if (!IsIndexReadyAndInRange())
46 return false;
47 return object_entries_[index_].is_directory;
50 base::Time MTPDeviceObjectEnumerator::LastModifiedTime() {
51 DCHECK(thread_checker_.CalledOnValidThread());
52 if (!IsIndexReadyAndInRange())
53 return base::Time();
54 return object_entries_[index_].last_modified_time;
57 base::string16 MTPDeviceObjectEnumerator::GetObjectId() const {
58 DCHECK(thread_checker_.CalledOnValidThread());
59 if (!IsIndexReadyAndInRange())
60 return base::string16();
61 return object_entries_[index_].object_id;
64 bool MTPDeviceObjectEnumerator::HasMoreEntries() const {
65 return index_ < object_entries_.size();
68 bool MTPDeviceObjectEnumerator::IsIndexReadyAndInRange() const {
69 return is_index_ready_ && HasMoreEntries();