Commit 44663e8f authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Replace MtpManager's ReadDirectory() with ReadDirectoryEntryIds().

MediaTransferProtocolDaemonClient currently provides a low-level
ReadDirectoryEntryIds() method, and MtpManager does the translation to
the high-level ReadDirectory() method that MTPDeviceTaskHelper
understands.

Change MtpManager's ReadDirectory() method to ReadDirectoryEntryIds(),
so it acts more like a pass-through. Make MTPDeviceTaskHelper handle the
translation.

BUG=769630

Change-Id: I5154bd4beac0b6ab15579f166cdf8b8add6a7dac
Reviewed-on: https://chromium-review.googlesource.com/1080214
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565441}
parent 9cab92fd
...@@ -24,6 +24,13 @@ using storage_monitor::StorageMonitor; ...@@ -24,6 +24,13 @@ using storage_monitor::StorageMonitor;
namespace { namespace {
// When reading directory entries, this is the number of entries for
// GetFileInfo() to read in one operation. If set too low, efficiency goes down
// slightly due to the overhead of D-Bus calls. If set too high, then slow
// devices may trigger a D-Bus timeout.
// The value below is a good initial estimate.
const size_t kFileInfoToFetchChunkSize = 25;
// When calling GetFileInfo() with only a single file ID, the offset into the // When calling GetFileInfo() with only a single file ID, the offset into the
// file IDs vector should be 0. // file IDs vector should be 0.
constexpr size_t kSingleFileIdOffset = 0; constexpr size_t kSingleFileIdOffset = 0;
...@@ -118,11 +125,12 @@ void MTPDeviceTaskHelper::ReadDirectory( ...@@ -118,11 +125,12 @@ void MTPDeviceTaskHelper::ReadDirectory(
if (device_handle_.empty()) if (device_handle_.empty())
return HandleDeviceError(error_callback, base::File::FILE_ERROR_FAILED); return HandleDeviceError(error_callback, base::File::FILE_ERROR_FAILED);
GetMediaTransferProtocolManager()->ReadDirectory( GetMediaTransferProtocolManager()->ReadDirectoryEntryIds(
device_handle_, directory_id, max_size, device_handle_, directory_id,
base::Bind(&MTPDeviceTaskHelper::OnDidReadDirectory, base::BindOnce(
weak_ptr_factory_.GetWeakPtr(), success_callback, &MTPDeviceTaskHelper::OnReadDirectoryEntryIdsToReadDirectory,
error_callback)); weak_ptr_factory_.GetWeakPtr(), success_callback, error_callback,
max_size));
} }
void MTPDeviceTaskHelper::WriteDataIntoSnapshotFile( void MTPDeviceTaskHelper::WriteDataIntoSnapshotFile(
...@@ -253,16 +261,67 @@ void MTPDeviceTaskHelper::OnCreateDirectory( ...@@ -253,16 +261,67 @@ void MTPDeviceTaskHelper::OnCreateDirectory(
success_callback); success_callback);
} }
void MTPDeviceTaskHelper::OnDidReadDirectory( void MTPDeviceTaskHelper::OnReadDirectoryEntryIdsToReadDirectory(
const ReadDirectorySuccessCallback& success_callback, const ReadDirectorySuccessCallback& success_callback,
const ErrorCallback& error_callback, const ErrorCallback& error_callback,
size_t max_size,
const std::vector<uint32_t>& file_ids,
bool error) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (error)
return HandleDeviceError(error_callback, base::File::FILE_ERROR_FAILED);
if (file_ids.empty()) {
content::BrowserThread::PostTask(
content::BrowserThread::IO, FROM_HERE,
base::BindOnce(success_callback, MTPEntries(), /*has_more=*/false));
return;
}
std::vector<uint32_t> sorted_file_ids = file_ids;
std::sort(sorted_file_ids.begin(), sorted_file_ids.end());
const size_t chunk_size = max_size == 0
? kFileInfoToFetchChunkSize
: std::min(max_size, kFileInfoToFetchChunkSize);
// This is the first GetFileInfo() call for a read directory operation. Start
// at offset 0.
static constexpr size_t kInitialOffset = 0;
GetMediaTransferProtocolManager()->GetFileInfo(
device_handle_, file_ids, kInitialOffset, chunk_size,
base::BindOnce(&MTPDeviceTaskHelper::OnGotDirectoryEntries,
weak_ptr_factory_.GetWeakPtr(), success_callback,
error_callback, file_ids, kInitialOffset, max_size,
sorted_file_ids));
}
void MTPDeviceTaskHelper::OnGotDirectoryEntries(
const ReadDirectorySuccessCallback& success_callback,
const ErrorCallback& error_callback,
const std::vector<uint32_t>& file_ids,
size_t offset,
size_t max_size,
const std::vector<uint32_t>& sorted_file_ids,
std::vector<device::mojom::MtpFileEntryPtr> file_entries, std::vector<device::mojom::MtpFileEntryPtr> file_entries,
bool has_more, bool error) {
bool error) const {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK_EQ(file_ids.size(), sorted_file_ids.size());
if (error) if (error)
return HandleDeviceError(error_callback, base::File::FILE_ERROR_FAILED); return HandleDeviceError(error_callback, base::File::FILE_ERROR_FAILED);
// Use |sorted_file_ids| to sanity check and make sure the results are a
// subset of the requested file ids.
for (const auto& entry : file_entries) {
std::vector<uint32_t>::const_iterator it = std::lower_bound(
sorted_file_ids.begin(), sorted_file_ids.end(), entry->item_id);
if (it == sorted_file_ids.end()) {
return HandleDeviceError(error_callback, base::File::FILE_ERROR_FAILED);
}
}
MTPEntries entries; MTPEntries entries;
base::FilePath current; base::FilePath current;
MTPDeviceObjectEnumerator file_enum(std::move(file_entries)); MTPDeviceObjectEnumerator file_enum(std::move(file_entries));
...@@ -276,10 +335,29 @@ void MTPDeviceTaskHelper::OnDidReadDirectory( ...@@ -276,10 +335,29 @@ void MTPDeviceTaskHelper::OnDidReadDirectory(
entry.file_info.last_modified = file_enum.LastModifiedTime(); entry.file_info.last_modified = file_enum.LastModifiedTime();
entries.push_back(entry); entries.push_back(entry);
} }
const size_t directory_size =
max_size == 0 ? file_ids.size() : std::min(file_ids.size(), max_size);
size_t next_offset = directory_size;
if (offset < SIZE_MAX - kFileInfoToFetchChunkSize)
next_offset = std::min(next_offset, offset + kFileInfoToFetchChunkSize);
bool has_more = next_offset < directory_size;
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
content::BrowserThread::IO, content::BrowserThread::IO, FROM_HERE,
FROM_HERE, base::BindOnce(success_callback, entries, has_more));
base::Bind(success_callback, entries, has_more));
if (!has_more)
return;
const size_t chunk_size =
std::min(directory_size - next_offset, kFileInfoToFetchChunkSize);
GetMediaTransferProtocolManager()->GetFileInfo(
device_handle_, file_ids, next_offset, chunk_size,
base::BindOnce(&MTPDeviceTaskHelper::OnGotDirectoryEntries,
weak_ptr_factory_.GetWeakPtr(), success_callback,
error_callback, file_ids, next_offset, max_size,
sorted_file_ids));
} }
void MTPDeviceTaskHelper::OnGetFileInfoToReadBytes( void MTPDeviceTaskHelper::OnGetFileInfoToReadBytes(
......
...@@ -177,20 +177,44 @@ class MTPDeviceTaskHelper { ...@@ -177,20 +177,44 @@ class MTPDeviceTaskHelper {
const ErrorCallback& error_callback, const ErrorCallback& error_callback,
const bool error) const; const bool error) const;
// Query callback for ReadDirectory(). // Query callback for ReadDirectoryEntryIds().
// //
// If there is no error, |error| is set to false, |file_entries| has the // |max_size| specifies the number of entries to read. If it is zero, then
// directory file entries and |success_callback| is invoked on the IO thread // read all the entries.
// to notify the caller.
// //
// If there is an error, |error| is set to true, |file_entries| is empty // If there is no error, |error| is set to false, and |file_ids| has the IDs
// and |error_callback| is invoked on the IO thread to notify the caller. // of the directory file entries. If |file_ids| is empty, then just run
void OnDidReadDirectory( // |success_callback|. Otherwise, get the directories entries from |file_ids|
// in chunks via OnGotDirectoryEntries().
//
// If there is an error, then |error| is set to true, and |error_callback| is
// invoked on the IO thread to notify the caller.
void OnReadDirectoryEntryIdsToReadDirectory(
const ReadDirectorySuccessCallback& success_callback, const ReadDirectorySuccessCallback& success_callback,
const ErrorCallback& error_callback, const ErrorCallback& error_callback,
size_t max_size,
const std::vector<uint32_t>& file_ids,
bool error);
// Query callback for GetFileInfo() when called by
// OnReadDirectoryEntryIdsToReadDirectory().
//
// Many of the parameters are shared with
// OnReadDirectoryEntryIdsToReadDirectory() and are exactly the same.
//
// |offset| is the offset into |file_ids| to read from.
// |sorted_file_ids| is a sorted copy of |file_ids|.
// |file_entries| contains the results of the GetFileInfo() call.
// |error| indicates if the GetFileInfo() call succeeded or failed.
void OnGotDirectoryEntries(
const ReadDirectorySuccessCallback& success_callback,
const ErrorCallback& error_callback,
const std::vector<uint32_t>& file_ids,
size_t offset,
size_t max_size,
const std::vector<uint32_t>& sorted_file_ids,
std::vector<device::mojom::MtpFileEntryPtr> file_entries, std::vector<device::mojom::MtpFileEntryPtr> file_entries,
bool has_more, bool error);
bool error) const;
// Intermediate step to finish a ReadBytes request. // Intermediate step to finish a ReadBytes request.
void OnGetFileInfoToReadBytes( void OnGetFileInfoToReadBytes(
......
...@@ -71,13 +71,11 @@ void TestMediaTransferProtocolManagerChromeOS::CreateDirectory( ...@@ -71,13 +71,11 @@ void TestMediaTransferProtocolManagerChromeOS::CreateDirectory(
std::move(callback).Run(true /* error */); std::move(callback).Run(true /* error */);
} }
void TestMediaTransferProtocolManagerChromeOS::ReadDirectory( void TestMediaTransferProtocolManagerChromeOS::ReadDirectoryEntryIds(
const std::string& storage_handle, const std::string& storage_handle,
uint32_t file_id, uint32_t file_id,
uint64_t max_size, ReadDirectoryEntryIdsCallback callback) {
ReadDirectoryCallback callback) { std::move(callback).Run(std::vector<uint32_t>(), /*error=*/true);
std::move(callback).Run(std::vector<device::mojom::MtpFileEntryPtr>(),
false /* no more entries*/, true /* error */);
} }
void TestMediaTransferProtocolManagerChromeOS::ReadFileChunk( void TestMediaTransferProtocolManagerChromeOS::ReadFileChunk(
......
...@@ -45,10 +45,9 @@ class TestMediaTransferProtocolManagerChromeOS ...@@ -45,10 +45,9 @@ class TestMediaTransferProtocolManagerChromeOS
uint32_t parent_id, uint32_t parent_id,
const std::string& directory_name, const std::string& directory_name,
CreateDirectoryCallback callback) override; CreateDirectoryCallback callback) override;
void ReadDirectory(const std::string& storage_handle, void ReadDirectoryEntryIds(const std::string& storage_handle,
uint32_t file_id, uint32_t file_id,
uint64_t max_size, ReadDirectoryEntryIdsCallback callback) override;
ReadDirectoryCallback callback) override;
void ReadFileChunk(const std::string& storage_handle, void ReadFileChunk(const std::string& storage_handle,
uint32_t file_id, uint32_t file_id,
uint32_t offset, uint32_t offset,
......
...@@ -34,16 +34,6 @@ namespace { ...@@ -34,16 +34,6 @@ namespace {
MediaTransferProtocolManager* g_media_transfer_protocol_manager = nullptr; MediaTransferProtocolManager* g_media_transfer_protocol_manager = nullptr;
#endif #endif
// When reading directory entries, this is the number of entries for
// GetFileInfo() to read in one operation. If set too low, efficiency goes down
// slightly due to the overhead of D-Bus calls. If set too high, then slow
// devices may trigger a D-Bus timeout.
// The value below is a good initial estimate.
const size_t kFileInfoToFetchChunkSize = 25;
// On the first call to GetFileInfo, the offset to use is 0.
const size_t kInitialOffset = 0;
// The MediaTransferProtocolManager implementation. // The MediaTransferProtocolManager implementation.
class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager { class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager {
public: public:
...@@ -177,7 +167,7 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager { ...@@ -177,7 +167,7 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager {
} }
void CreateDirectory(const std::string& storage_handle, void CreateDirectory(const std::string& storage_handle,
const uint32_t parent_id, uint32_t parent_id,
const std::string& directory_name, const std::string& directory_name,
const CreateDirectoryCallback& callback) override { const CreateDirectoryCallback& callback) override {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
...@@ -195,23 +185,20 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager { ...@@ -195,23 +185,20 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager {
} }
// MediaTransferProtocolManager override. // MediaTransferProtocolManager override.
void ReadDirectory(const std::string& storage_handle, void ReadDirectoryEntryIds(
const uint32_t file_id, const std::string& storage_handle,
const size_t max_size, uint32_t file_id,
const ReadDirectoryCallback& callback) override { mojom::MtpManager::ReadDirectoryEntryIdsCallback callback) override {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
if (!base::ContainsKey(handles_, storage_handle) || !mtp_client_) { if (!base::ContainsKey(handles_, storage_handle) || !mtp_client_) {
callback.Run(std::vector<mojom::MtpFileEntry>(), std::move(callback).Run(std::vector<uint32_t>(), /*error=*/true);
false /* no more entries */,
true /* error */);
return; return;
} }
read_directory_callbacks_.push(callback); read_directory_callbacks_.push(std::move(callback));
mtp_client_->ReadDirectoryEntryIds( mtp_client_->ReadDirectoryEntryIds(
storage_handle, file_id, storage_handle, file_id,
base::Bind(&MediaTransferProtocolManagerImpl:: base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectoryEntryIds,
OnReadDirectoryEntryIdsToReadDirectory, weak_ptr_factory_.GetWeakPtr()),
weak_ptr_factory_.GetWeakPtr(), storage_handle, max_size),
base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectoryError, base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectoryError,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
...@@ -257,7 +244,7 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager { ...@@ -257,7 +244,7 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager {
} }
void RenameObject(const std::string& storage_handle, void RenameObject(const std::string& storage_handle,
const uint32_t object_id, uint32_t object_id,
const std::string& new_name, const std::string& new_name,
const RenameObjectCallback& callback) override { const RenameObjectCallback& callback) override {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
...@@ -276,7 +263,7 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager { ...@@ -276,7 +263,7 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager {
void CopyFileFromLocal(const std::string& storage_handle, void CopyFileFromLocal(const std::string& storage_handle,
const int source_file_descriptor, const int source_file_descriptor,
const uint32_t parent_id, uint32_t parent_id,
const std::string& file_name, const std::string& file_name,
const CopyFileFromLocalCallback& callback) override { const CopyFileFromLocalCallback& callback) override {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
...@@ -294,7 +281,7 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager { ...@@ -294,7 +281,7 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager {
} }
void DeleteObject(const std::string& storage_handle, void DeleteObject(const std::string& storage_handle,
const uint32_t object_id, uint32_t object_id,
const DeleteObjectCallback& callback) override { const DeleteObjectCallback& callback) override {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
if (!base::ContainsKey(handles_, storage_handle) || !mtp_client_) { if (!base::ContainsKey(handles_, storage_handle) || !mtp_client_) {
...@@ -321,7 +308,8 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager { ...@@ -321,7 +308,8 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager {
using CloseStorageCallbackQueue = using CloseStorageCallbackQueue =
base::queue<std::pair<CloseStorageCallback, std::string>>; base::queue<std::pair<CloseStorageCallback, std::string>>;
using CreateDirectoryCallbackQueue = base::queue<CreateDirectoryCallback>; using CreateDirectoryCallbackQueue = base::queue<CreateDirectoryCallback>;
using ReadDirectoryCallbackQueue = base::queue<ReadDirectoryCallback>; using ReadDirectoryCallbackQueue =
base::queue<mojom::MtpManager::ReadDirectoryEntryIdsCallback>;
using ReadFileCallbackQueue = base::queue<ReadFileCallback>; using ReadFileCallbackQueue = base::queue<ReadFileCallback>;
using GetFileInfoCallbackQueue = using GetFileInfoCallbackQueue =
base::queue<mojom::MtpManager::GetFileInfoCallback>; base::queue<mojom::MtpManager::GetFileInfoCallback>;
...@@ -453,86 +441,16 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager { ...@@ -453,86 +441,16 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager {
create_directory_callbacks_.pop(); create_directory_callbacks_.pop();
} }
void OnReadDirectoryEntryIdsToReadDirectory( void OnReadDirectoryEntryIds(const std::vector<uint32_t>& file_ids) {
const std::string& storage_handle,
const size_t max_size,
const std::vector<uint32_t>& file_ids) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
std::move(read_directory_callbacks_.front()).Run(file_ids, /*error=*/false);
if (file_ids.empty()) {
OnGotDirectoryEntries(storage_handle, file_ids, kInitialOffset, max_size,
file_ids, std::vector<mojom::MtpFileEntry>());
return;
}
std::vector<uint32_t> sorted_file_ids = file_ids;
std::sort(sorted_file_ids.begin(), sorted_file_ids.end());
const size_t chunk_size =
max_size == 0 ? kFileInfoToFetchChunkSize
: std::min(max_size, kFileInfoToFetchChunkSize);
mtp_client_->GetFileInfo(
storage_handle, file_ids, kInitialOffset, chunk_size,
base::Bind(&MediaTransferProtocolManagerImpl::OnGotDirectoryEntries,
weak_ptr_factory_.GetWeakPtr(), storage_handle, file_ids,
kInitialOffset, max_size, sorted_file_ids),
base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectoryError,
weak_ptr_factory_.GetWeakPtr()));
}
void OnGotDirectoryEntries(
const std::string& storage_handle,
const std::vector<uint32_t>& file_ids,
const size_t offset,
const size_t max_size,
const std::vector<uint32_t>& sorted_file_ids,
const std::vector<mojom::MtpFileEntry>& file_entries) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_EQ(file_ids.size(), sorted_file_ids.size());
// Use |sorted_file_ids| to sanity check and make sure the results are a
// subset of the requested file ids.
for (const auto& entry : file_entries) {
std::vector<uint32_t>::const_iterator it = std::lower_bound(
sorted_file_ids.begin(), sorted_file_ids.end(), entry.item_id);
if (it == sorted_file_ids.end()) {
OnReadDirectoryError();
return;
}
}
const size_t directory_size =
max_size == 0 ? file_ids.size() : std::min(file_ids.size(), max_size);
size_t next_offset = directory_size;
if (offset < SIZE_MAX - kFileInfoToFetchChunkSize)
next_offset = std::min(next_offset, offset + kFileInfoToFetchChunkSize);
bool has_more = next_offset < directory_size;
read_directory_callbacks_.front().Run(file_entries,
has_more,
false /* no error */);
if (has_more) {
const size_t chunk_size =
std::min(directory_size - next_offset, kFileInfoToFetchChunkSize);
mtp_client_->GetFileInfo(
storage_handle, file_ids, next_offset, chunk_size,
base::Bind(&MediaTransferProtocolManagerImpl::OnGotDirectoryEntries,
weak_ptr_factory_.GetWeakPtr(), storage_handle, file_ids,
next_offset, max_size, sorted_file_ids),
base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectoryError,
weak_ptr_factory_.GetWeakPtr()));
return;
}
read_directory_callbacks_.pop(); read_directory_callbacks_.pop();
} }
void OnReadDirectoryError() { void OnReadDirectoryError() {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
read_directory_callbacks_.front().Run(std::vector<mojom::MtpFileEntry>(), std::move(read_directory_callbacks_.front())
false /* no more entries */, .Run(std::vector<uint32_t>(), /*error=*/true);
true /* error */);
read_directory_callbacks_.pop(); read_directory_callbacks_.pop();
} }
......
...@@ -54,15 +54,6 @@ class MediaTransferProtocolManager { ...@@ -54,15 +54,6 @@ class MediaTransferProtocolManager {
// The first argument is true if there was an error. // The first argument is true if there was an error.
using CreateDirectoryCallback = base::Callback<void(bool error)>; using CreateDirectoryCallback = base::Callback<void(bool error)>;
// A callback to handle the result of ReadDirectory.
// The first argument is a vector of file entries.
// The second argument is true if there are more file entries.
// The third argument is true if there was an error.
using ReadDirectoryCallback =
base::Callback<void(const std::vector<mojom::MtpFileEntry>& file_entries,
bool has_more,
bool error)>;
// A callback to handle the result of ReadFileChunk. // A callback to handle the result of ReadFileChunk.
// The first argument is a string containing the file data. // The first argument is a string containing the file data.
// The second argument is true if there was an error. // The second argument is true if there was an error.
...@@ -127,16 +118,16 @@ class MediaTransferProtocolManager { ...@@ -127,16 +118,16 @@ class MediaTransferProtocolManager {
// Creates |directory_name| in |parent_id|. // Creates |directory_name| in |parent_id|.
virtual void CreateDirectory(const std::string& storage_handle, virtual void CreateDirectory(const std::string& storage_handle,
const uint32_t parent_id, uint32_t parent_id,
const std::string& directory_name, const std::string& directory_name,
const CreateDirectoryCallback& callback) = 0; const CreateDirectoryCallback& callback) = 0;
// Reads directory entries from |file_id| on |storage_handle| and runs // Reads IDs of directory entries from |file_id| on |storage_handle| and runs
// |callback|. |max_size| is a maximum number of files to be read. // |callback|.
virtual void ReadDirectory(const std::string& storage_handle, virtual void ReadDirectoryEntryIds(
const uint32_t file_id, const std::string& storage_handle,
const size_t max_size, uint32_t file_id,
const ReadDirectoryCallback& callback) = 0; mojom::MtpManager::ReadDirectoryEntryIdsCallback callback) = 0;
// Reads file data from |file_id| on |storage_handle| and runs |callback|. // Reads file data from |file_id| on |storage_handle| and runs |callback|.
// Reads |count| bytes of data starting at |offset|. // Reads |count| bytes of data starting at |offset|.
...@@ -159,7 +150,7 @@ class MediaTransferProtocolManager { ...@@ -159,7 +150,7 @@ class MediaTransferProtocolManager {
// Renames |object_id| to |new_name|. // Renames |object_id| to |new_name|.
virtual void RenameObject(const std::string& storage_handle, virtual void RenameObject(const std::string& storage_handle,
const uint32_t object_id, uint32_t object_id,
const std::string& new_name, const std::string& new_name,
const RenameObjectCallback& callback) = 0; const RenameObjectCallback& callback) = 0;
...@@ -167,13 +158,13 @@ class MediaTransferProtocolManager { ...@@ -167,13 +158,13 @@ class MediaTransferProtocolManager {
// |parent_id|. // |parent_id|.
virtual void CopyFileFromLocal(const std::string& storage_handle, virtual void CopyFileFromLocal(const std::string& storage_handle,
const int source_file_descriptor, const int source_file_descriptor,
const uint32_t parent_id, uint32_t parent_id,
const std::string& file_name, const std::string& file_name,
const CopyFileFromLocalCallback& callback) = 0; const CopyFileFromLocalCallback& callback) = 0;
// Deletes |object_id|. // Deletes |object_id|.
virtual void DeleteObject(const std::string& storage_handle, virtual void DeleteObject(const std::string& storage_handle,
const uint32_t object_id, uint32_t object_id,
const DeleteObjectCallback& callback) = 0; const DeleteObjectCallback& callback) = 0;
// Creates and returns the global MediaTransferProtocolManager instance. // Creates and returns the global MediaTransferProtocolManager instance.
......
...@@ -41,17 +41,6 @@ void EnumerateStorageCallbackWrapper( ...@@ -41,17 +41,6 @@ void EnumerateStorageCallbackWrapper(
std::move(callback).Run(std::move(storage_info_ptr_list)); std::move(callback).Run(std::move(storage_info_ptr_list));
} }
void ReadDirectoryCallbackWrapper(
mojom::MtpManager::ReadDirectoryCallback callback,
const std::vector<mojom::MtpFileEntry>& file_entries,
bool has_more,
bool error) {
std::vector<mojom::MtpFileEntryPtr> files(file_entries.size());
for (size_t i = 0; i < file_entries.size(); ++i)
files[i] = file_entries[i].Clone();
std::move(callback).Run(std::move(files), has_more, error);
}
} // namespace } // namespace
MtpDeviceManager::MtpDeviceManager() MtpDeviceManager::MtpDeviceManager()
...@@ -115,14 +104,12 @@ void MtpDeviceManager::CreateDirectory(const std::string& storage_handle, ...@@ -115,14 +104,12 @@ void MtpDeviceManager::CreateDirectory(const std::string& storage_handle,
base::AdaptCallbackForRepeating(std::move(callback))); base::AdaptCallbackForRepeating(std::move(callback)));
} }
void MtpDeviceManager::ReadDirectory(const std::string& storage_handle, void MtpDeviceManager::ReadDirectoryEntryIds(
uint32_t file_id, const std::string& storage_handle,
uint64_t max_size, uint32_t file_id,
ReadDirectoryCallback callback) { ReadDirectoryEntryIdsCallback callback) {
media_transfer_protocol_manager_->ReadDirectory( media_transfer_protocol_manager_->ReadDirectoryEntryIds(
storage_handle, file_id, max_size, storage_handle, file_id, std::move(callback));
base::Bind(ReadDirectoryCallbackWrapper,
base::AdaptCallbackForRepeating(std::move(callback))));
} }
void MtpDeviceManager::ReadFileChunk(const std::string& storage_handle, void MtpDeviceManager::ReadFileChunk(const std::string& storage_handle,
......
...@@ -46,10 +46,9 @@ class MtpDeviceManager : public mojom::MtpManager { ...@@ -46,10 +46,9 @@ class MtpDeviceManager : public mojom::MtpManager {
uint32_t parent_id, uint32_t parent_id,
const std::string& directory_name, const std::string& directory_name,
CreateDirectoryCallback callback) override; CreateDirectoryCallback callback) override;
void ReadDirectory(const std::string& storage_handle, void ReadDirectoryEntryIds(const std::string& storage_handle,
uint32_t file_id, uint32_t file_id,
uint64_t max_size, ReadDirectoryEntryIdsCallback callback) override;
ReadDirectoryCallback callback) override;
void ReadFileChunk(const std::string& storage_handle, void ReadFileChunk(const std::string& storage_handle,
uint32_t file_id, uint32_t file_id,
uint32_t offset, uint32_t offset,
......
...@@ -42,11 +42,9 @@ interface MtpManager { ...@@ -42,11 +42,9 @@ interface MtpManager {
CreateDirectory(string storage_handle, uint32 parent_id, CreateDirectory(string storage_handle, uint32 parent_id,
string directory_name) => (bool error); string directory_name) => (bool error);
// Reads directory entries from |file_id| on |storage_handle|. // Reads the directory listing for |file_id| and returns the list of file ids.
// |max_size| is a maximum number of files to be read. ReadDirectoryEntryIds(string storage_handle,
ReadDirectory(string storage_handle, uint32 file_id) => (array<uint32> file_ids, bool error);
uint32 file_id, uint64 max_size) =>
(array<MtpFileEntry> file_entries, bool has_more, bool error);
// Reads file data from |file_id| on |storage_handle|. // Reads file data from |file_id| on |storage_handle|.
// Reads |count| bytes of data starting at |offset|. // Reads |count| bytes of data starting at |offset|.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment