mtp_device_object_enumerator.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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// This class enumerates the media transfer protocol (MTP) device objects from 6// a given object entry list. 7 8#ifndef CHROME_BROWSER_MEDIA_GALLERIES_WIN_MTP_DEVICE_OBJECT_ENUMERATOR_H_ 9#define CHROME_BROWSER_MEDIA_GALLERIES_WIN_MTP_DEVICE_OBJECT_ENUMERATOR_H_ 10 11#include "base/files/file_path.h" 12#include "base/threading/thread_checker.h" 13#include "base/time/time.h" 14#include "chrome/browser/media_galleries/win/mtp_device_object_entry.h" 15#include "webkit/browser/fileapi/file_system_file_util.h" 16 17namespace chrome { 18 19// MTPDeviceObjectEnumerator is used to enumerate the media transfer protocol 20// (MTP) device objects from a given object entry list. 21// MTPDeviceObjectEnumerator supports MTP device file operations. 22// MTPDeviceObjectEnumerator may only be used on a single thread. 23class MTPDeviceObjectEnumerator 24 : public fileapi::FileSystemFileUtil::AbstractFileEnumerator { 25 public: 26 explicit MTPDeviceObjectEnumerator(const MTPDeviceObjectEntries& entries); 27 virtual ~MTPDeviceObjectEnumerator(); 28 29 // AbstractFileEnumerator: 30 virtual base::FilePath Next() OVERRIDE; 31 virtual int64 Size() OVERRIDE; 32 virtual bool IsDirectory() OVERRIDE; 33 virtual base::Time LastModifiedTime() OVERRIDE; 34 35 // If the current file object entry is valid, returns an non-empty object id. 36 // Returns an empty string otherwise. 37 string16 GetObjectId() const; 38 39 private: 40 // Returns true if the enumerator has more entries to traverse, false 41 // otherwise. 42 bool HasMoreEntries() const; 43 44 // Returns true if Next() has been called at least once, and the enumerator 45 // has more entries to traverse. 46 bool IsIndexReadyAndInRange() const; 47 48 // List of directory file object entries. 49 MTPDeviceObjectEntries object_entries_; 50 51 // Index into |object_entries_|. 52 // Should only be used when |is_index_ready_| is true. 53 size_t index_; 54 55 // Initially false. Set to true after Next() has been called. 56 bool is_index_ready_; 57 58 base::ThreadChecker thread_checker_; 59 60 DISALLOW_COPY_AND_ASSIGN(MTPDeviceObjectEnumerator); 61}; 62 63} // namespace chrome 64 65#endif // CHROME_BROWSER_MEDIA_GALLERIES_WIN_MTP_DEVICE_OBJECT_ENUMERATOR_H_ 66