Commit 5992a9c1 authored by thestig@chromium.org's avatar thestig@chromium.org

Media Galleries: Access MTP devices by file ids rather than file paths.

File paths can be very slow to access because finding a file by path requires
O(N) metadata access to figure out which file id corresponds to a given name.

BUG=385307

Review URL: https://codereview.chromium.org/377383002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283732 0039d316-1c4b-4281-b951-d872f2087c98
parent 4fbf991d
...@@ -7,11 +7,10 @@ ...@@ -7,11 +7,10 @@
#include "net/base/io_buffer.h" #include "net/base/io_buffer.h"
MTPDeviceAsyncDelegate::ReadBytesRequest::ReadBytesRequest( MTPDeviceAsyncDelegate::ReadBytesRequest::ReadBytesRequest(
const std::string& device_file_relative_path, uint32 file_id, net::IOBuffer* buf, int64 offset, int buf_len,
net::IOBuffer* buf, int64 offset, int buf_len,
const ReadBytesSuccessCallback& success_callback, const ReadBytesSuccessCallback& success_callback,
const ErrorCallback& error_callback) const ErrorCallback& error_callback)
: device_file_relative_path(device_file_relative_path), : file_id(file_id),
buf(buf), buf(buf),
offset(offset), offset(offset),
buf_len(buf_len), buf_len(buf_len),
......
...@@ -49,13 +49,13 @@ class MTPDeviceAsyncDelegate { ...@@ -49,13 +49,13 @@ class MTPDeviceAsyncDelegate {
int bytes_read)> ReadBytesSuccessCallback; int bytes_read)> ReadBytesSuccessCallback;
struct ReadBytesRequest { struct ReadBytesRequest {
ReadBytesRequest(const std::string& device_file_relative_path, ReadBytesRequest(uint32 file_id,
net::IOBuffer* buf, int64 offset, int buf_len, net::IOBuffer* buf, int64 offset, int buf_len,
const ReadBytesSuccessCallback& success_callback, const ReadBytesSuccessCallback& success_callback,
const ErrorCallback& error_callback); const ErrorCallback& error_callback);
~ReadBytesRequest(); ~ReadBytesRequest();
std::string device_file_relative_path; uint32 file_id;
scoped_refptr<net::IOBuffer> buf; scoped_refptr<net::IOBuffer> buf;
int64 offset; int64 offset;
int buf_len; int buf_len;
......
...@@ -5,19 +5,20 @@ ...@@ -5,19 +5,20 @@
#ifndef CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_DELEGATE_IMPL_LINUX_H_ #ifndef CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_DELEGATE_IMPL_LINUX_H_
#define CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_DELEGATE_IMPL_LINUX_H_ #define CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_DELEGATE_IMPL_LINUX_H_
#include <queue> #include <deque>
#include <map>
#include <string>
#include "base/callback.h" #include "base/callback.h"
#include "base/containers/scoped_ptr_hash_map.h"
#include "base/files/file_path.h"
#include "base/location.h" #include "base/location.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h" #include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h"
#include "content/public/browser/browser_thread.h"
#include "webkit/browser/fileapi/async_file_util.h" #include "webkit/browser/fileapi/async_file_util.h"
namespace base {
class FilePath;
}
struct SnapshotRequestInfo; struct SnapshotRequestInfo;
// MTPDeviceDelegateImplLinux communicates with the media transfer protocol // MTPDeviceDelegateImplLinux communicates with the media transfer protocol
...@@ -40,14 +41,24 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate { ...@@ -40,14 +41,24 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate {
// Used to represent pending task details. // Used to represent pending task details.
struct PendingTaskInfo { struct PendingTaskInfo {
PendingTaskInfo(const tracked_objects::Location& location, PendingTaskInfo(const base::FilePath& path,
content::BrowserThread::ID thread_id,
const tracked_objects::Location& location,
const base::Closure& task); const base::Closure& task);
~PendingTaskInfo(); ~PendingTaskInfo();
base::FilePath path;
base::FilePath cached_path;
const content::BrowserThread::ID thread_id;
const tracked_objects::Location location; const tracked_objects::Location location;
const base::Closure task; const base::Closure task;
}; };
class MTPFileNode;
// Maps file ids to file nodes.
typedef std::map<uint32, MTPFileNode*> FileIdToMTPFileNodeMap;
// Should only be called by CreateMTPDeviceAsyncDelegate() factory call. // Should only be called by CreateMTPDeviceAsyncDelegate() factory call.
// Defer the device initializations until the first file operation request. // Defer the device initializations until the first file operation request.
// Do all the initializations in EnsureInitAndRunTask() function. // Do all the initializations in EnsureInitAndRunTask() function.
...@@ -77,17 +88,41 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate { ...@@ -77,17 +88,41 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate {
const ErrorCallback& error_callback) OVERRIDE; const ErrorCallback& error_callback) OVERRIDE;
virtual void CancelPendingTasksAndDeleteDelegate() OVERRIDE; virtual void CancelPendingTasksAndDeleteDelegate() OVERRIDE;
// Ensures the device is initialized for communication by doing a // The internal methods correspond to the similarly named methods above.
// call-and-reply to the UI thread. |task_info.task| runs on the UI thread. // The |root_node_| cache should be filled at this point.
// virtual void GetFileInfoInternal(
// If the device is already initialized, post the |task_info.task| immediately const base::FilePath& file_path,
// on the UI thread. const GetFileInfoSuccessCallback& success_callback,
const ErrorCallback& error_callback);
virtual void ReadDirectoryInternal(
const base::FilePath& root,
const ReadDirectorySuccessCallback& success_callback,
const ErrorCallback& error_callback);
virtual void CreateSnapshotFileInternal(
const base::FilePath& device_file_path,
const base::FilePath& local_path,
const CreateSnapshotFileSuccessCallback& success_callback,
const ErrorCallback& error_callback);
virtual void ReadBytesInternal(
const base::FilePath& device_file_path,
net::IOBuffer* buf, int64 offset, int buf_len,
const ReadBytesSuccessCallback& success_callback,
const ErrorCallback& error_callback);
// Ensures the device is initialized for communication.
// If the device is already initialized, call RunTask().
// //
// If the device is uninitialized, store the |task_info| in a pending task // If the device is uninitialized, store the |task_info| in a pending task
// list and runs all the pending tasks once the device is successfully // queue and runs the pending tasks in the queue once the device is
// initialized. // successfully initialized.
void EnsureInitAndRunTask(const PendingTaskInfo& task_info); void EnsureInitAndRunTask(const PendingTaskInfo& task_info);
// Runs a task. If |task_info.path| is empty, or if the path is cached, runs
// the task immediately.
// Otherwise, fills the cache first before running the task.
// |task_info.task| runs on the UI thread.
void RunTask(const PendingTaskInfo& task_info);
// Writes data from the device to the snapshot file path based on the // Writes data from the device to the snapshot file path based on the
// parameters in |current_snapshot_request_info_| by doing a call-and-reply to // parameters in |current_snapshot_request_info_| by doing a call-and-reply to
// the UI thread. // the UI thread.
...@@ -114,16 +149,16 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate { ...@@ -114,16 +149,16 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate {
const base::File::Info& file_info); const base::File::Info& file_info);
// Called when GetFileInfo() succeeds. GetFileInfo() is invoked to // Called when GetFileInfo() succeeds. GetFileInfo() is invoked to
// get the |root| directory metadata details. |file_info| specifies the |root| // get the |dir_id| directory metadata details. |file_info| specifies the
// directory details. // |dir_id| directory details.
// //
// If |root| is a directory, post a task on the UI thread to read the |root| // If |dir_id| is a directory, post a task on the UI thread to read the
// directory file entries. // |dir_id| directory file entries.
// //
// If |root| is not a directory, |error_callback| is invoked to notify the // If |dir_id| is not a directory, |error_callback| is invoked to notify the
// caller about the file error and process the next pending request. // caller about the file error and process the next pending request.
void OnDidGetFileInfoToReadDirectory( void OnDidGetFileInfoToReadDirectory(
const std::string& root, uint32 dir_id,
const ReadDirectorySuccessCallback& success_callback, const ReadDirectorySuccessCallback& success_callback,
const ErrorCallback& error_callback, const ErrorCallback& error_callback,
const base::File::Info& file_info); const base::File::Info& file_info);
...@@ -140,10 +175,12 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate { ...@@ -140,10 +175,12 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate {
// Called when ReadDirectory() succeeds. // Called when ReadDirectory() succeeds.
// //
// |file_list| contains the directory file entries. // |dir_id| is the directory read.
// |file_list| contains the directory file entries with their file ids.
// |success_callback| is invoked to notify the caller about the directory // |success_callback| is invoked to notify the caller about the directory
// file entries. // file entries.
void OnDidReadDirectory(const ReadDirectorySuccessCallback& success_callback, void OnDidReadDirectory(uint32 dir_id,
const ReadDirectorySuccessCallback& success_callback,
const fileapi::AsyncFileUtil::EntryList& file_list); const fileapi::AsyncFileUtil::EntryList& file_list);
// Called when WriteDataIntoSnapshotFile() succeeds. // Called when WriteDataIntoSnapshotFile() succeeds.
...@@ -171,11 +208,34 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate { ...@@ -171,11 +208,34 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate {
void OnDidReadBytes(const ReadBytesSuccessCallback& success_callback, void OnDidReadBytes(const ReadBytesSuccessCallback& success_callback,
const base::File::Info& file_info, int bytes_read); const base::File::Info& file_info, int bytes_read);
// Handles the device file |error|. |error_callback| is invoked to notify the // Called when FillFileCache() succeeds.
// caller about the file error. void OnDidFillFileCache(const base::FilePath& path,
const fileapi::AsyncFileUtil::EntryList& file_list,
bool has_more);
// Called when FillFileCache() fails.
void OnFillFileCacheFailed(base::File::Error error);
// Handles the device file |error| while operating on |file_id|.
// |error_callback| is invoked to notify the caller about the file error.
void HandleDeviceFileError(const ErrorCallback& error_callback, void HandleDeviceFileError(const ErrorCallback& error_callback,
uint32 file_id,
base::File::Error error); base::File::Error error);
// Given a full path, returns a non-empty sub-path that needs to be read into
// the cache if such a uncached path exists.
// |cached_path| is the portion of |path| that has had cache lookup attempts.
base::FilePath NextUncachedPathComponent(
const base::FilePath& path,
const base::FilePath& cached_path) const;
// Fills the file cache using the results from NextUncachedPathComponent().
void FillFileCache(const base::FilePath& uncached_path);
// Given a full path, if it exists in the cache, writes the file's id to |id|
// and return true.
bool CachedPathToId(const base::FilePath& path, uint32* id) const;
// MTP device initialization state. // MTP device initialization state.
InitializationState init_state_; InitializationState init_state_;
...@@ -193,7 +253,7 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate { ...@@ -193,7 +253,7 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate {
// A list of pending tasks that needs to be run when the device is // A list of pending tasks that needs to be run when the device is
// initialized or when the current task in progress is complete. // initialized or when the current task in progress is complete.
std::queue<PendingTaskInfo> pending_tasks_; std::deque<PendingTaskInfo> pending_tasks_;
// Used to track the current snapshot file request. A snapshot file is created // Used to track the current snapshot file request. A snapshot file is created
// incrementally. CreateSnapshotFile request reads the device file and writes // incrementally. CreateSnapshotFile request reads the device file and writes
...@@ -202,6 +262,15 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate { ...@@ -202,6 +262,15 @@ class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate {
// request at any time. // request at any time.
scoped_ptr<SnapshotRequestInfo> current_snapshot_request_info_; scoped_ptr<SnapshotRequestInfo> current_snapshot_request_info_;
// A mapping for quick lookups into the |root_node_| tree structure. Since
// |root_node_| contains pointers to this map, it must be declared after this
// so destruction happens in the right order.
FileIdToMTPFileNodeMap file_id_to_node_map_;
// The root node of a tree-structure that caches the directory structure of
// the MTP device.
scoped_ptr<MTPFileNode> root_node_;
// For callbacks that may run after destruction. // For callbacks that may run after destruction.
base::WeakPtrFactory<MTPDeviceDelegateImplLinux> weak_ptr_factory_; base::WeakPtrFactory<MTPDeviceDelegateImplLinux> weak_ptr_factory_;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/media_galleries/linux/mtp_device_object_enumerator.h" #include "chrome/browser/media_galleries/linux/mtp_device_object_enumerator.h"
#include "chrome/browser/media_galleries/linux/mtp_read_file_worker.h" #include "chrome/browser/media_galleries/linux/mtp_read_file_worker.h"
#include "chrome/browser/media_galleries/linux/snapshot_file_details.h" #include "chrome/browser/media_galleries/linux/snapshot_file_details.h"
...@@ -74,33 +75,33 @@ void MTPDeviceTaskHelper::OpenStorage(const std::string& storage_name, ...@@ -74,33 +75,33 @@ void MTPDeviceTaskHelper::OpenStorage(const std::string& storage_name,
callback)); callback));
} }
void MTPDeviceTaskHelper::GetFileInfoByPath( void MTPDeviceTaskHelper::GetFileInfoById(
const std::string& file_path, uint32 file_id,
const GetFileInfoSuccessCallback& success_callback, const GetFileInfoSuccessCallback& success_callback,
const ErrorCallback& error_callback) { const ErrorCallback& error_callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
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()->GetFileInfoByPath( GetMediaTransferProtocolManager()->GetFileInfoById(
device_handle_, file_path, device_handle_, file_id,
base::Bind(&MTPDeviceTaskHelper::OnGetFileInfo, base::Bind(&MTPDeviceTaskHelper::OnGetFileInfo,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),
success_callback, success_callback,
error_callback)); error_callback));
} }
void MTPDeviceTaskHelper::ReadDirectoryByPath( void MTPDeviceTaskHelper::ReadDirectoryById(
const std::string& dir_path, uint32 dir_id,
const ReadDirectorySuccessCallback& success_callback, const ReadDirectorySuccessCallback& success_callback,
const ErrorCallback& error_callback) { const ErrorCallback& error_callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
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()->ReadDirectoryByPath( GetMediaTransferProtocolManager()->ReadDirectoryById(
device_handle_, dir_path, device_handle_, dir_id,
base::Bind(&MTPDeviceTaskHelper::OnDidReadDirectoryByPath, base::Bind(&MTPDeviceTaskHelper::OnDidReadDirectoryById,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),
success_callback, success_callback,
error_callback)); error_callback));
...@@ -129,8 +130,8 @@ void MTPDeviceTaskHelper::ReadBytes( ...@@ -129,8 +130,8 @@ void MTPDeviceTaskHelper::ReadBytes(
base::File::FILE_ERROR_FAILED); base::File::FILE_ERROR_FAILED);
} }
GetMediaTransferProtocolManager()->GetFileInfoByPath( GetMediaTransferProtocolManager()->GetFileInfoById(
device_handle_, request.device_file_relative_path, device_handle_, request.file_id,
base::Bind(&MTPDeviceTaskHelper::OnGetFileInfoToReadBytes, base::Bind(&MTPDeviceTaskHelper::OnGetFileInfoToReadBytes,
weak_ptr_factory_.GetWeakPtr(), request)); weak_ptr_factory_.GetWeakPtr(), request));
} }
...@@ -171,7 +172,7 @@ void MTPDeviceTaskHelper::OnGetFileInfo( ...@@ -171,7 +172,7 @@ void MTPDeviceTaskHelper::OnGetFileInfo(
base::Bind(success_callback, FileInfoFromMTPFileEntry(file_entry))); base::Bind(success_callback, FileInfoFromMTPFileEntry(file_entry)));
} }
void MTPDeviceTaskHelper::OnDidReadDirectoryByPath( void MTPDeviceTaskHelper::OnDidReadDirectoryById(
const ReadDirectorySuccessCallback& success_callback, const ReadDirectorySuccessCallback& success_callback,
const ErrorCallback& error_callback, const ErrorCallback& error_callback,
const std::vector<MtpFileEntry>& file_entries, const std::vector<MtpFileEntry>& file_entries,
...@@ -186,6 +187,11 @@ void MTPDeviceTaskHelper::OnDidReadDirectoryByPath( ...@@ -186,6 +187,11 @@ void MTPDeviceTaskHelper::OnDidReadDirectoryByPath(
while (!(current = file_enum.Next()).empty()) { while (!(current = file_enum.Next()).empty()) {
fileapi::DirectoryEntry entry; fileapi::DirectoryEntry entry;
entry.name = fileapi::VirtualPath::BaseName(current).value(); entry.name = fileapi::VirtualPath::BaseName(current).value();
uint32 file_id = 0;
bool ret = file_enum.GetEntryId(&file_id);
DCHECK(ret);
entry.name.push_back(',');
entry.name += base::UintToString(file_id);
entry.is_directory = file_enum.IsDirectory(); entry.is_directory = file_enum.IsDirectory();
entry.size = file_enum.Size(); entry.size = file_enum.Size();
entry.last_modified_time = file_enum.LastModifiedTime(); entry.last_modified_time = file_enum.LastModifiedTime();
...@@ -202,7 +208,7 @@ void MTPDeviceTaskHelper::OnGetFileInfoToReadBytes( ...@@ -202,7 +208,7 @@ void MTPDeviceTaskHelper::OnGetFileInfoToReadBytes(
bool error) { bool error) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(request.buf); DCHECK(request.buf);
DCHECK(request.buf_len >= 0); DCHECK_GE(request.buf_len, 0);
DCHECK_GE(request.offset, 0); DCHECK_GE(request.offset, 0);
if (error) { if (error) {
return HandleDeviceError(request.error_callback, return HandleDeviceError(request.error_callback,
...@@ -229,9 +235,9 @@ void MTPDeviceTaskHelper::OnGetFileInfoToReadBytes( ...@@ -229,9 +235,9 @@ void MTPDeviceTaskHelper::OnGetFileInfoToReadBytes(
base::checked_cast<uint32>(request.buf_len), base::checked_cast<uint32>(request.buf_len),
base::saturated_cast<uint32>(file_info.size - request.offset)); base::saturated_cast<uint32>(file_info.size - request.offset));
GetMediaTransferProtocolManager()->ReadFileChunkByPath( GetMediaTransferProtocolManager()->ReadFileChunkById(
device_handle_, device_handle_,
request.device_file_relative_path, request.file_id,
base::checked_cast<uint32>(request.offset), base::checked_cast<uint32>(request.offset),
bytes_to_read, bytes_to_read,
base::Bind(&MTPDeviceTaskHelper::OnDidReadBytes, base::Bind(&MTPDeviceTaskHelper::OnDidReadBytes,
......
...@@ -31,6 +31,8 @@ class MTPDeviceTaskHelper { ...@@ -31,6 +31,8 @@ class MTPDeviceTaskHelper {
typedef MTPDeviceAsyncDelegate::GetFileInfoSuccessCallback typedef MTPDeviceAsyncDelegate::GetFileInfoSuccessCallback
GetFileInfoSuccessCallback; GetFileInfoSuccessCallback;
// NOTE: The file names in the entry list have their file id appended at the
// end. e.g. foo.jpg with file id 45 becomes foo.jpg,45.
typedef base::Callback<void(const fileapi::AsyncFileUtil::EntryList&)> typedef base::Callback<void(const fileapi::AsyncFileUtil::EntryList&)>
ReadDirectorySuccessCallback; ReadDirectorySuccessCallback;
...@@ -48,34 +50,36 @@ class MTPDeviceTaskHelper { ...@@ -48,34 +50,36 @@ class MTPDeviceTaskHelper {
void OpenStorage(const std::string& storage_name, void OpenStorage(const std::string& storage_name,
const OpenStorageCallback& callback); const OpenStorageCallback& callback);
// Dispatches the GetFileInfoByPath request to the // Dispatches the GetFileInfoById request to the
// MediaTransferProtocolManager. // MediaTransferProtocolManager.
// //
// |file_path| specifies the relative of the file whose details are requested. // |file_id| specifies the id of the file whose details are requested.
// //
// If the file details are fetched successfully, |success_callback| is invoked // If the file details are fetched successfully, |success_callback| is invoked
// on the IO thread to notify the caller about the file details. // on the IO thread to notify the caller about the file details.
// //
// If there is an error, |error_callback| is invoked on the IO thread to // If there is an error, |error_callback| is invoked on the IO thread to
// notify the caller about the file error. // notify the caller about the file error.
void GetFileInfoByPath( void GetFileInfoById(
const std::string& file_path, uint32 file_id,
const GetFileInfoSuccessCallback& success_callback, const GetFileInfoSuccessCallback& success_callback,
const ErrorCallback& error_callback); const ErrorCallback& error_callback);
// Dispatches the read directory request to the MediaTransferProtocolManager. // Dispatches the read directory request to the MediaTransferProtocolManager.
// //
// |dir_path| specifies the directory file path. // |dir_id| specifies the directory id.
// //
// If the directory file entries are enumerated successfully, // If the directory file entries are enumerated successfully,
// |success_callback| is invoked on the IO thread to notify the caller about // |success_callback| is invoked on the IO thread to notify the caller about
// the directory file entries. // the directory file entries. Please see the note in the
// ReadDirectorySuccessCallback typedef regarding the special treatment of
// file names.
// //
// If there is an error, |error_callback| is invoked on the IO thread to // If there is an error, |error_callback| is invoked on the IO thread to
// notify the caller about the file error. // notify the caller about the file error.
void ReadDirectoryByPath(const std::string& dir_path, void ReadDirectoryById(uint32 dir_id,
const ReadDirectorySuccessCallback& success_callback, const ReadDirectorySuccessCallback& success_callback,
const ErrorCallback& error_callback); const ErrorCallback& error_callback);
// Forwards the WriteDataIntoSnapshotFile request to the MTPReadFileWorker // Forwards the WriteDataIntoSnapshotFile request to the MTPReadFileWorker
// object. // object.
...@@ -122,7 +126,7 @@ class MTPDeviceTaskHelper { ...@@ -122,7 +126,7 @@ class MTPDeviceTaskHelper {
const MtpFileEntry& file_entry, const MtpFileEntry& file_entry,
bool error) const; bool error) const;
// Query callback for ReadDirectoryByPath(). // Query callback for ReadDirectoryById().
// //
// If there is no error, |error| is set to false, |file_entries| has the // If there is no error, |error| is set to false, |file_entries| has the
// directory file entries and |success_callback| is invoked on the IO thread // directory file entries and |success_callback| is invoked on the IO thread
...@@ -130,7 +134,7 @@ class MTPDeviceTaskHelper { ...@@ -130,7 +134,7 @@ class MTPDeviceTaskHelper {
// //
// If there is an error, |error| is set to true, |file_entries| is empty // If there is an error, |error| is set to true, |file_entries| is empty
// and |error_callback| is invoked on the IO thread to notify the caller. // and |error_callback| is invoked on the IO thread to notify the caller.
void OnDidReadDirectoryByPath( void OnDidReadDirectoryById(
const ReadDirectorySuccessCallback& success_callback, const ReadDirectorySuccessCallback& success_callback,
const ErrorCallback& error_callback, const ErrorCallback& error_callback,
const std::vector<MtpFileEntry>& file_entries, const std::vector<MtpFileEntry>& file_entries,
......
...@@ -66,9 +66,9 @@ void MTPReadFileWorker::ReadDataChunkFromDeviceFile( ...@@ -66,9 +66,9 @@ void MTPReadFileWorker::ReadDataChunkFromDeviceFile(
device::MediaTransferProtocolManager* mtp_device_manager = device::MediaTransferProtocolManager* mtp_device_manager =
StorageMonitor::GetInstance()->media_transfer_protocol_manager(); StorageMonitor::GetInstance()->media_transfer_protocol_manager();
mtp_device_manager->ReadFileChunkByPath( mtp_device_manager->ReadFileChunkById(
device_handle_, device_handle_,
snapshot_file_details_ptr->device_file_path(), snapshot_file_details_ptr->file_id(),
snapshot_file_details_ptr->bytes_written(), snapshot_file_details_ptr->bytes_written(),
snapshot_file_details_ptr->BytesToRead(), snapshot_file_details_ptr->BytesToRead(),
base::Bind(&MTPReadFileWorker::OnDidReadDataChunkFromDeviceFile, base::Bind(&MTPReadFileWorker::OnDidReadDataChunkFromDeviceFile,
......
...@@ -11,12 +11,12 @@ ...@@ -11,12 +11,12 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
SnapshotRequestInfo::SnapshotRequestInfo( SnapshotRequestInfo::SnapshotRequestInfo(
const std::string& device_file_path, uint32 file_id,
const base::FilePath& snapshot_file_path, const base::FilePath& snapshot_file_path,
const MTPDeviceAsyncDelegate::CreateSnapshotFileSuccessCallback& const MTPDeviceAsyncDelegate::CreateSnapshotFileSuccessCallback&
success_callback, success_callback,
const MTPDeviceAsyncDelegate::ErrorCallback& error_callback) const MTPDeviceAsyncDelegate::ErrorCallback& error_callback)
: device_file_path(device_file_path), : file_id(file_id),
snapshot_file_path(snapshot_file_path), snapshot_file_path(snapshot_file_path),
success_callback(success_callback), success_callback(success_callback),
error_callback(error_callback) { error_callback(error_callback) {
......
...@@ -16,15 +16,15 @@ ...@@ -16,15 +16,15 @@
// Used to represent snapshot file request params. // Used to represent snapshot file request params.
struct SnapshotRequestInfo { struct SnapshotRequestInfo {
SnapshotRequestInfo( SnapshotRequestInfo(
const std::string& device_file_path, uint32 file_id,
const base::FilePath& snapshot_file_path, const base::FilePath& snapshot_file_path,
const MTPDeviceAsyncDelegate::CreateSnapshotFileSuccessCallback& const MTPDeviceAsyncDelegate::CreateSnapshotFileSuccessCallback&
success_callback, success_callback,
const MTPDeviceAsyncDelegate::ErrorCallback& error_callback); const MTPDeviceAsyncDelegate::ErrorCallback& error_callback);
~SnapshotRequestInfo(); ~SnapshotRequestInfo();
// MTP device file path. // MTP device file id.
const std::string device_file_path; const uint32 file_id;
// Local platform path of the snapshot file. // Local platform path of the snapshot file.
const base::FilePath snapshot_file_path; const base::FilePath snapshot_file_path;
...@@ -47,8 +47,8 @@ class SnapshotFileDetails { ...@@ -47,8 +47,8 @@ class SnapshotFileDetails {
~SnapshotFileDetails(); ~SnapshotFileDetails();
std::string device_file_path() const { uint32 file_id() const {
return request_info_.device_file_path; return request_info_.file_id;
} }
base::FilePath snapshot_file_path() const { base::FilePath snapshot_file_path() const {
......
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