Commit 963756a3 authored by Donna Wu's avatar Donna Wu Committed by Commit Bot

Migrate MtpDeviceManager to OnceCallback.

This CL migrated to as many OnceCallback(s) as possible in
services/device/media_transfer_protocol directory. Due to some
unchanged DBus interfaces, there are still several base::Bind()
left in the implementation.

BUG=714018

Change-Id: Iceb2558f45a54e43503fc67fe40380cc9baef248
Reviewed-on: https://chromium-review.googlesource.com/1111693Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Donna Wu <donna.wu@intel.com>
Cr-Commit-Position: refs/heads/master@{#570676}
parent 033617cc
...@@ -67,53 +67,51 @@ class MediaTransferProtocolDaemonClientImpl ...@@ -67,53 +67,51 @@ class MediaTransferProtocolDaemonClientImpl
} }
// MediaTransferProtocolDaemonClient override. // MediaTransferProtocolDaemonClient override.
void EnumerateStorages(const EnumerateStoragesCallback& callback, void EnumerateStorages(EnumerateStoragesCallback callback,
const ErrorCallback& error_callback) override { ErrorCallback error_callback) override {
dbus::MethodCall method_call(mtpd::kMtpdInterface, dbus::MethodCall method_call(mtpd::kMtpdInterface,
mtpd::kEnumerateStorages); mtpd::kEnumerateStorages);
proxy_->CallMethod( proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&MediaTransferProtocolDaemonClientImpl::OnEnumerateStorages, base::BindOnce(
weak_ptr_factory_.GetWeakPtr(), &MediaTransferProtocolDaemonClientImpl::OnEnumerateStorages,
callback, weak_ptr_factory_.GetWeakPtr(), std::move(callback),
error_callback)); std::move(error_callback)));
} }
// MediaTransferProtocolDaemonClient override. // MediaTransferProtocolDaemonClient override.
void GetStorageInfo(const std::string& storage_name, void GetStorageInfo(const std::string& storage_name,
const GetStorageInfoCallback& callback, GetStorageInfoCallback callback,
const ErrorCallback& error_callback) override { ErrorCallback error_callback) override {
dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kGetStorageInfo); dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kGetStorageInfo);
dbus::MessageWriter writer(&method_call); dbus::MessageWriter writer(&method_call);
writer.AppendString(storage_name); writer.AppendString(storage_name);
proxy_->CallMethod( proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&MediaTransferProtocolDaemonClientImpl::OnGetStorageInfo, base::BindOnce(&MediaTransferProtocolDaemonClientImpl::OnGetStorageInfo,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(), storage_name,
storage_name, std::move(callback), std::move(error_callback)));
callback,
error_callback));
} }
void GetStorageInfoFromDevice(const std::string& storage_name, void GetStorageInfoFromDevice(const std::string& storage_name,
const GetStorageInfoCallback& callback, GetStorageInfoCallback callback,
const ErrorCallback& error_callback) override { ErrorCallback error_callback) override {
dbus::MethodCall method_call(mtpd::kMtpdInterface, dbus::MethodCall method_call(mtpd::kMtpdInterface,
mtpd::kGetStorageInfoFromDevice); mtpd::kGetStorageInfoFromDevice);
dbus::MessageWriter writer(&method_call); dbus::MessageWriter writer(&method_call);
writer.AppendString(storage_name); writer.AppendString(storage_name);
proxy_->CallMethod( proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&MediaTransferProtocolDaemonClientImpl::OnGetStorageInfo, base::BindOnce(&MediaTransferProtocolDaemonClientImpl::OnGetStorageInfo,
weak_ptr_factory_.GetWeakPtr(), storage_name, callback, weak_ptr_factory_.GetWeakPtr(), storage_name,
error_callback)); std::move(callback), std::move(error_callback)));
} }
// MediaTransferProtocolDaemonClient override. // MediaTransferProtocolDaemonClient override.
void OpenStorage(const std::string& storage_name, void OpenStorage(const std::string& storage_name,
const std::string& mode, const std::string& mode,
const OpenStorageCallback& callback, OpenStorageCallback callback,
const ErrorCallback& error_callback) override { ErrorCallback error_callback) override {
dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kOpenStorage); dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kOpenStorage);
dbus::MessageWriter writer(&method_call); dbus::MessageWriter writer(&method_call);
writer.AppendString(storage_name); writer.AppendString(storage_name);
...@@ -121,32 +119,30 @@ class MediaTransferProtocolDaemonClientImpl ...@@ -121,32 +119,30 @@ class MediaTransferProtocolDaemonClientImpl
writer.AppendString(mode); writer.AppendString(mode);
proxy_->CallMethod( proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&MediaTransferProtocolDaemonClientImpl::OnOpenStorage, base::BindOnce(&MediaTransferProtocolDaemonClientImpl::OnOpenStorage,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(), std::move(callback),
callback, std::move(error_callback)));
error_callback));
} }
// MediaTransferProtocolDaemonClient override. // MediaTransferProtocolDaemonClient override.
void CloseStorage(const std::string& handle, void CloseStorage(const std::string& handle,
const CloseStorageCallback& callback, CloseStorageCallback callback,
const ErrorCallback& error_callback) override { ErrorCallback error_callback) override {
dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kCloseStorage); dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kCloseStorage);
dbus::MessageWriter writer(&method_call); dbus::MessageWriter writer(&method_call);
writer.AppendString(handle); writer.AppendString(handle);
proxy_->CallMethod( proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&MediaTransferProtocolDaemonClientImpl::OnCloseStorage, base::BindOnce(&MediaTransferProtocolDaemonClientImpl::OnCloseStorage,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(), std::move(callback),
callback, std::move(error_callback)));
error_callback));
} }
void CreateDirectory(const std::string& handle, void CreateDirectory(const std::string& handle,
const uint32_t parent_id, const uint32_t parent_id,
const std::string& directory_name, const std::string& directory_name,
const CreateDirectoryCallback& callback, CreateDirectoryCallback callback,
const ErrorCallback& error_callback) override { ErrorCallback error_callback) override {
dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kCreateDirectory); dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kCreateDirectory);
dbus::MessageWriter writer(&method_call); dbus::MessageWriter writer(&method_call);
writer.AppendString(handle); writer.AppendString(handle);
...@@ -154,15 +150,17 @@ class MediaTransferProtocolDaemonClientImpl ...@@ -154,15 +150,17 @@ class MediaTransferProtocolDaemonClientImpl
writer.AppendString(directory_name); writer.AppendString(directory_name);
proxy_->CallMethod( proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&MediaTransferProtocolDaemonClientImpl::OnCreateDirectory, base::BindOnce(
weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); &MediaTransferProtocolDaemonClientImpl::OnCreateDirectory,
weak_ptr_factory_.GetWeakPtr(), std::move(callback),
std::move(error_callback)));
} }
// MediaTransferProtocolDaemonClient override. // MediaTransferProtocolDaemonClient override.
void ReadDirectoryEntryIds(const std::string& handle, void ReadDirectoryEntryIds(const std::string& handle,
uint32_t file_id, uint32_t file_id,
const ReadDirectoryEntryIdsCallback& callback, ReadDirectoryEntryIdsCallback callback,
const ErrorCallback& error_callback) override { ErrorCallback error_callback) override {
dbus::MethodCall method_call(mtpd::kMtpdInterface, dbus::MethodCall method_call(mtpd::kMtpdInterface,
mtpd::kReadDirectoryEntryIds); mtpd::kReadDirectoryEntryIds);
dbus::MessageWriter writer(&method_call); dbus::MessageWriter writer(&method_call);
...@@ -170,16 +168,16 @@ class MediaTransferProtocolDaemonClientImpl ...@@ -170,16 +168,16 @@ class MediaTransferProtocolDaemonClientImpl
writer.AppendUint32(file_id); writer.AppendUint32(file_id);
proxy_->CallMethod( proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&MediaTransferProtocolDaemonClientImpl::OnReadDirectoryIds, base::BindOnce(
weak_ptr_factory_.GetWeakPtr(), &MediaTransferProtocolDaemonClientImpl::OnReadDirectoryIds,
callback, weak_ptr_factory_.GetWeakPtr(), std::move(callback),
error_callback)); std::move(error_callback)));
} }
void GetFileInfo(const std::string& handle, void GetFileInfo(const std::string& handle,
const std::vector<uint32_t>& file_ids, const std::vector<uint32_t>& file_ids,
const GetFileInfoCallback& callback, GetFileInfoCallback callback,
const ErrorCallback& error_callback) override { ErrorCallback error_callback) override {
dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kGetFileInfo); dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kGetFileInfo);
dbus::MessageWriter writer(&method_call); dbus::MessageWriter writer(&method_call);
writer.AppendString(handle); writer.AppendString(handle);
...@@ -194,10 +192,9 @@ class MediaTransferProtocolDaemonClientImpl ...@@ -194,10 +192,9 @@ class MediaTransferProtocolDaemonClientImpl
} }
proxy_->CallMethod( proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&MediaTransferProtocolDaemonClientImpl::OnGetFileInfo, base::BindOnce(&MediaTransferProtocolDaemonClientImpl::OnGetFileInfo,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(), std::move(callback),
callback, std::move(error_callback)));
error_callback));
} }
// MediaTransferProtocolDaemonClient override. // MediaTransferProtocolDaemonClient override.
...@@ -205,8 +202,8 @@ class MediaTransferProtocolDaemonClientImpl ...@@ -205,8 +202,8 @@ class MediaTransferProtocolDaemonClientImpl
uint32_t file_id, uint32_t file_id,
uint32_t offset, uint32_t offset,
uint32_t bytes_to_read, uint32_t bytes_to_read,
const ReadFileCallback& callback, ReadFileCallback callback,
const ErrorCallback& error_callback) override { ErrorCallback error_callback) override {
DCHECK_LE(bytes_to_read, kMaxChunkSize); DCHECK_LE(bytes_to_read, kMaxChunkSize);
dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kReadFileChunk); dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kReadFileChunk);
dbus::MessageWriter writer(&method_call); dbus::MessageWriter writer(&method_call);
...@@ -216,17 +213,16 @@ class MediaTransferProtocolDaemonClientImpl ...@@ -216,17 +213,16 @@ class MediaTransferProtocolDaemonClientImpl
writer.AppendUint32(bytes_to_read); writer.AppendUint32(bytes_to_read);
proxy_->CallMethod( proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&MediaTransferProtocolDaemonClientImpl::OnReadFile, base::BindOnce(&MediaTransferProtocolDaemonClientImpl::OnReadFile,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(), std::move(callback),
callback, std::move(error_callback)));
error_callback));
} }
void RenameObject(const std::string& handle, void RenameObject(const std::string& handle,
const uint32_t object_id, const uint32_t object_id,
const std::string& new_name, const std::string& new_name,
const RenameObjectCallback& callback, RenameObjectCallback callback,
const ErrorCallback& error_callback) override { ErrorCallback error_callback) override {
dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kRenameObject); dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kRenameObject);
dbus::MessageWriter writer(&method_call); dbus::MessageWriter writer(&method_call);
writer.AppendString(handle); writer.AppendString(handle);
...@@ -234,16 +230,17 @@ class MediaTransferProtocolDaemonClientImpl ...@@ -234,16 +230,17 @@ class MediaTransferProtocolDaemonClientImpl
writer.AppendString(new_name); writer.AppendString(new_name);
proxy_->CallMethod( proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&MediaTransferProtocolDaemonClientImpl::OnRenameObject, base::BindOnce(&MediaTransferProtocolDaemonClientImpl::OnRenameObject,
weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); weak_ptr_factory_.GetWeakPtr(), std::move(callback),
std::move(error_callback)));
} }
void CopyFileFromLocal(const std::string& handle, void CopyFileFromLocal(const std::string& handle,
const int source_file_descriptor, const int source_file_descriptor,
const uint32_t parent_id, const uint32_t parent_id,
const std::string& file_name, const std::string& file_name,
const CopyFileFromLocalCallback& callback, CopyFileFromLocalCallback callback,
const ErrorCallback& error_callback) override { ErrorCallback error_callback) override {
dbus::MethodCall method_call(mtpd::kMtpdInterface, dbus::MethodCall method_call(mtpd::kMtpdInterface,
mtpd::kCopyFileFromLocal); mtpd::kCopyFileFromLocal);
dbus::MessageWriter writer(&method_call); dbus::MessageWriter writer(&method_call);
...@@ -253,22 +250,25 @@ class MediaTransferProtocolDaemonClientImpl ...@@ -253,22 +250,25 @@ class MediaTransferProtocolDaemonClientImpl
writer.AppendString(file_name); writer.AppendString(file_name);
proxy_->CallMethod( proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_INFINITE, &method_call, dbus::ObjectProxy::TIMEOUT_INFINITE,
base::Bind(&MediaTransferProtocolDaemonClientImpl::OnCopyFileFromLocal, base::BindOnce(
weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); &MediaTransferProtocolDaemonClientImpl::OnCopyFileFromLocal,
weak_ptr_factory_.GetWeakPtr(), std::move(callback),
std::move(error_callback)));
} }
void DeleteObject(const std::string& handle, void DeleteObject(const std::string& handle,
const uint32_t object_id, const uint32_t object_id,
const DeleteObjectCallback& callback, DeleteObjectCallback callback,
const ErrorCallback& error_callback) override { ErrorCallback error_callback) override {
dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kDeleteObject); dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kDeleteObject);
dbus::MessageWriter writer(&method_call); dbus::MessageWriter writer(&method_call);
writer.AppendString(handle); writer.AppendString(handle);
writer.AppendUint32(object_id); writer.AppendUint32(object_id);
proxy_->CallMethod( proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&MediaTransferProtocolDaemonClientImpl::OnDeleteObject, base::BindOnce(&MediaTransferProtocolDaemonClientImpl::OnDeleteObject,
weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); weak_ptr_factory_.GetWeakPtr(), std::move(callback),
std::move(error_callback)));
} }
// MediaTransferProtocolDaemonClient override. // MediaTransferProtocolDaemonClient override.
...@@ -300,31 +300,31 @@ class MediaTransferProtocolDaemonClientImpl ...@@ -300,31 +300,31 @@ class MediaTransferProtocolDaemonClientImpl
// Handles the result of EnumerateStorages and calls |callback| or // Handles the result of EnumerateStorages and calls |callback| or
// |error_callback|. // |error_callback|.
void OnEnumerateStorages(const EnumerateStoragesCallback& callback, void OnEnumerateStorages(EnumerateStoragesCallback callback,
const ErrorCallback& error_callback, ErrorCallback error_callback,
dbus::Response* response) { dbus::Response* response) {
if (!response) { if (!response) {
error_callback.Run(); std::move(error_callback).Run();
return; return;
} }
dbus::MessageReader reader(response); dbus::MessageReader reader(response);
std::vector<std::string> storage_names; std::vector<std::string> storage_names;
if (!reader.PopArrayOfStrings(&storage_names)) { if (!reader.PopArrayOfStrings(&storage_names)) {
LOG(ERROR) << kInvalidResponseMsg << response->ToString(); LOG(ERROR) << kInvalidResponseMsg << response->ToString();
error_callback.Run(); std::move(error_callback).Run();
return; return;
} }
callback.Run(storage_names); std::move(callback).Run(storage_names);
} }
// Handles the result of GetStorageInfo and calls |callback| or // Handles the result of GetStorageInfo and calls |callback| or
// |error_callback|. // |error_callback|.
void OnGetStorageInfo(const std::string& storage_name, void OnGetStorageInfo(const std::string& storage_name,
const GetStorageInfoCallback& callback, GetStorageInfoCallback callback,
const ErrorCallback& error_callback, ErrorCallback error_callback,
dbus::Response* response) { dbus::Response* response) {
if (!response) { if (!response) {
error_callback.Run(); std::move(error_callback).Run();
return; return;
} }
...@@ -332,59 +332,59 @@ class MediaTransferProtocolDaemonClientImpl ...@@ -332,59 +332,59 @@ class MediaTransferProtocolDaemonClientImpl
MtpStorageInfo protobuf; MtpStorageInfo protobuf;
if (!reader.PopArrayOfBytesAsProto(&protobuf)) { if (!reader.PopArrayOfBytesAsProto(&protobuf)) {
LOG(ERROR) << kInvalidResponseMsg << response->ToString(); LOG(ERROR) << kInvalidResponseMsg << response->ToString();
error_callback.Run(); std::move(error_callback).Run();
return; return;
} }
callback.Run(GetMojoMtpStorageInfoFromProtobuf(protobuf)); std::move(callback).Run(GetMojoMtpStorageInfoFromProtobuf(protobuf));
} }
// Handles the result of OpenStorage and calls |callback| or |error_callback|. // Handles the result of OpenStorage and calls |callback| or |error_callback|.
void OnOpenStorage(const OpenStorageCallback& callback, void OnOpenStorage(OpenStorageCallback callback,
const ErrorCallback& error_callback, ErrorCallback error_callback,
dbus::Response* response) { dbus::Response* response) {
if (!response) { if (!response) {
error_callback.Run(); std::move(error_callback).Run();
return; return;
} }
dbus::MessageReader reader(response); dbus::MessageReader reader(response);
std::string handle; std::string handle;
if (!reader.PopString(&handle)) { if (!reader.PopString(&handle)) {
LOG(ERROR) << kInvalidResponseMsg << response->ToString(); LOG(ERROR) << kInvalidResponseMsg << response->ToString();
error_callback.Run(); std::move(error_callback).Run();
return; return;
} }
callback.Run(handle); std::move(callback).Run(handle);
} }
// Handles the result of CloseStorage and calls |callback| or // Handles the result of CloseStorage and calls |callback| or
// |error_callback|. // |error_callback|.
void OnCloseStorage(const CloseStorageCallback& callback, void OnCloseStorage(CloseStorageCallback callback,
const ErrorCallback& error_callback, ErrorCallback error_callback,
dbus::Response* response) { dbus::Response* response) {
if (!response) { if (!response) {
error_callback.Run(); std::move(error_callback).Run();
return; return;
} }
callback.Run(); std::move(callback).Run();
} }
void OnCreateDirectory(const CreateDirectoryCallback& callback, void OnCreateDirectory(CreateDirectoryCallback callback,
const ErrorCallback& error_callback, ErrorCallback error_callback,
dbus::Response* response) { dbus::Response* response) {
if (!response) { if (!response) {
error_callback.Run(); std::move(error_callback).Run();
return; return;
} }
callback.Run(); std::move(callback).Run();
} }
// Handles the result of ReadDirectoryEntryIds and calls |callback| or // Handles the result of ReadDirectoryEntryIds and calls |callback| or
// |error_callback|. // |error_callback|.
void OnReadDirectoryIds(const ReadDirectoryEntryIdsCallback& callback, void OnReadDirectoryIds(ReadDirectoryEntryIdsCallback callback,
const ErrorCallback& error_callback, ErrorCallback error_callback,
dbus::Response* response) { dbus::Response* response) {
if (!response) { if (!response) {
error_callback.Run(); std::move(error_callback).Run();
return; return;
} }
...@@ -392,7 +392,7 @@ class MediaTransferProtocolDaemonClientImpl ...@@ -392,7 +392,7 @@ class MediaTransferProtocolDaemonClientImpl
dbus::MessageReader array_reader(nullptr); dbus::MessageReader array_reader(nullptr);
if (!reader.PopArray(&array_reader) || reader.HasMoreData()) { if (!reader.PopArray(&array_reader) || reader.HasMoreData()) {
LOG(ERROR) << kInvalidResponseMsg << response->ToString(); LOG(ERROR) << kInvalidResponseMsg << response->ToString();
error_callback.Run(); std::move(error_callback).Run();
return; return;
} }
...@@ -401,20 +401,20 @@ class MediaTransferProtocolDaemonClientImpl ...@@ -401,20 +401,20 @@ class MediaTransferProtocolDaemonClientImpl
uint32_t file_id; uint32_t file_id;
if (!array_reader.PopUint32(&file_id)) { if (!array_reader.PopUint32(&file_id)) {
LOG(ERROR) << kInvalidResponseMsg << response->ToString(); LOG(ERROR) << kInvalidResponseMsg << response->ToString();
error_callback.Run(); std::move(error_callback).Run();
return; return;
} }
file_ids.push_back(file_id); file_ids.push_back(file_id);
} }
callback.Run(file_ids); std::move(callback).Run(file_ids);
} }
// Handles the result of GetFileInfo and calls |callback| or |error_callback|. // Handles the result of GetFileInfo and calls |callback| or |error_callback|.
void OnGetFileInfo(const GetFileInfoCallback& callback, void OnGetFileInfo(GetFileInfoCallback callback,
const ErrorCallback& error_callback, ErrorCallback error_callback,
dbus::Response* response) { dbus::Response* response) {
if (!response) { if (!response) {
error_callback.Run(); std::move(error_callback).Run();
return; return;
} }
...@@ -422,7 +422,7 @@ class MediaTransferProtocolDaemonClientImpl ...@@ -422,7 +422,7 @@ class MediaTransferProtocolDaemonClientImpl
MtpFileEntries entries_protobuf; MtpFileEntries entries_protobuf;
if (!reader.PopArrayOfBytesAsProto(&entries_protobuf)) { if (!reader.PopArrayOfBytesAsProto(&entries_protobuf)) {
LOG(ERROR) << kInvalidResponseMsg << response->ToString(); LOG(ERROR) << kInvalidResponseMsg << response->ToString();
error_callback.Run(); std::move(error_callback).Run();
return; return;
} }
...@@ -433,16 +433,16 @@ class MediaTransferProtocolDaemonClientImpl ...@@ -433,16 +433,16 @@ class MediaTransferProtocolDaemonClientImpl
file_entries.push_back( file_entries.push_back(
GetMojoMtpFileEntryFromProtobuf(entry)); GetMojoMtpFileEntryFromProtobuf(entry));
} }
callback.Run(file_entries); std::move(callback).Run(file_entries);
} }
// Handles the result of ReadFileChunk and calls |callback| or // Handles the result of ReadFileChunk and calls |callback| or
// |error_callback|. // |error_callback|.
void OnReadFile(const ReadFileCallback& callback, void OnReadFile(ReadFileCallback callback,
const ErrorCallback& error_callback, ErrorCallback error_callback,
dbus::Response* response) { dbus::Response* response) {
if (!response) { if (!response) {
error_callback.Run(); std::move(error_callback).Run();
return; return;
} }
...@@ -450,44 +450,44 @@ class MediaTransferProtocolDaemonClientImpl ...@@ -450,44 +450,44 @@ class MediaTransferProtocolDaemonClientImpl
size_t data_length = 0; size_t data_length = 0;
dbus::MessageReader reader(response); dbus::MessageReader reader(response);
if (!reader.PopArrayOfBytes(&data_bytes, &data_length)) { if (!reader.PopArrayOfBytes(&data_bytes, &data_length)) {
error_callback.Run(); std::move(error_callback).Run();
return; return;
} }
std::string data(reinterpret_cast<const char*>(data_bytes), data_length); std::string data(reinterpret_cast<const char*>(data_bytes), data_length);
callback.Run(data); std::move(callback).Run(data);
} }
void OnRenameObject(const RenameObjectCallback& callback, void OnRenameObject(RenameObjectCallback callback,
const ErrorCallback& error_callback, ErrorCallback error_callback,
dbus::Response* response) { dbus::Response* response) {
if (!response) { if (!response) {
error_callback.Run(); std::move(error_callback).Run();
return; return;
} }
callback.Run(); std::move(callback).Run();
} }
void OnCopyFileFromLocal(const CopyFileFromLocalCallback& callback, void OnCopyFileFromLocal(CopyFileFromLocalCallback callback,
const ErrorCallback& error_callback, ErrorCallback error_callback,
dbus::Response* response) { dbus::Response* response) {
if (!response) { if (!response) {
error_callback.Run(); std::move(error_callback).Run();
return; return;
} }
callback.Run(); std::move(callback).Run();
} }
void OnDeleteObject(const DeleteObjectCallback& callback, void OnDeleteObject(DeleteObjectCallback callback,
const ErrorCallback& error_callback, ErrorCallback error_callback,
dbus::Response* response) { dbus::Response* response) {
if (!response) { if (!response) {
error_callback.Run(); std::move(error_callback).Run();
return; return;
} }
callback.Run(); std::move(callback).Run();
} }
// Handles MTPStorageAttached/Dettached signals and calls |handler|. // Handles MTPStorageAttached/Dettached signals and calls |handler|.
......
...@@ -38,50 +38,51 @@ namespace device { ...@@ -38,50 +38,51 @@ namespace device {
class MediaTransferProtocolDaemonClient { class MediaTransferProtocolDaemonClient {
public: public:
// A callback to be called when DBus method call fails. // A callback to be called when DBus method call fails.
using ErrorCallback = base::Closure; using ErrorCallback = base::OnceClosure;
// A callback to handle the result of EnumerateAutoMountableDevices. // A callback to handle the result of EnumerateAutoMountableDevices.
// The argument is the enumerated storage names. // The argument is the enumerated storage names.
using EnumerateStoragesCallback = using EnumerateStoragesCallback =
base::Callback<void(const std::vector<std::string>& storage_names)>; base::OnceCallback<void(const std::vector<std::string>& storage_names)>;
// A callback to handle the result of GetStorageInfo. // A callback to handle the result of GetStorageInfo.
// The argument is the information about the specified storage. // The argument is the information about the specified storage.
using GetStorageInfoCallback = using GetStorageInfoCallback =
base::Callback<void(const mojom::MtpStorageInfo& storage_info)>; base::OnceCallback<void(const mojom::MtpStorageInfo& storage_info)>;
// A callback to handle the result of OpenStorage. // A callback to handle the result of OpenStorage.
// The argument is the returned handle. // The argument is the returned handle.
using OpenStorageCallback = base::Callback<void(const std::string& handle)>; using OpenStorageCallback =
base::OnceCallback<void(const std::string& handle)>;
// A callback to handle the result of CloseStorage. // A callback to handle the result of CloseStorage.
using CloseStorageCallback = base::Closure; using CloseStorageCallback = base::OnceClosure;
// A callback to handle the result of CreateDirectory. // A callback to handle the result of CreateDirectory.
using CreateDirectoryCallback = base::Closure; using CreateDirectoryCallback = base::OnceClosure;
// A callback to handle the result of ReadDirectoryEntryIds. // A callback to handle the result of ReadDirectoryEntryIds.
// The argument is a vector of file ids. // The argument is a vector of file ids.
using ReadDirectoryEntryIdsCallback = using ReadDirectoryEntryIdsCallback =
base::Callback<void(const std::vector<uint32_t>& file_ids)>; base::OnceCallback<void(const std::vector<uint32_t>& file_ids)>;
// A callback to handle the result of GetFileInfo. // A callback to handle the result of GetFileInfo.
// The argument is a vector of file entries. // The argument is a vector of file entries.
using GetFileInfoCallback = base::Callback<void( using GetFileInfoCallback = base::OnceCallback<void(
const std::vector<mojom::MtpFileEntry>& file_entries)>; const std::vector<mojom::MtpFileEntry>& file_entries)>;
// A callback to handle the result of ReadFileChunkById. // A callback to handle the result of ReadFileChunkById.
// The argument is a string containing the file data. // The argument is a string containing the file data.
using ReadFileCallback = base::Callback<void(const std::string& data)>; using ReadFileCallback = base::OnceCallback<void(const std::string& data)>;
// A callback to handle the result of RenameObject. // A callback to handle the result of RenameObject.
using RenameObjectCallback = base::Closure; using RenameObjectCallback = base::OnceClosure;
// A callback to handle the result of CopyFileFromLocal. // A callback to handle the result of CopyFileFromLocal.
using CopyFileFromLocalCallback = base::Closure; using CopyFileFromLocalCallback = base::OnceClosure;
// A callback to handle the result of DeleteObject. // A callback to handle the result of DeleteObject.
using DeleteObjectCallback = base::Closure; using DeleteObjectCallback = base::OnceClosure;
// A callback to handle storage attach/detach events. // A callback to handle storage attach/detach events.
// The first argument is true for attach, false for detach. // The first argument is true for attach, false for detach.
...@@ -93,37 +94,35 @@ class MediaTransferProtocolDaemonClient { ...@@ -93,37 +94,35 @@ class MediaTransferProtocolDaemonClient {
// Calls EnumerateStorages method. |callback| is called after the // Calls EnumerateStorages method. |callback| is called after the
// method call succeeds, otherwise, |error_callback| is called. // method call succeeds, otherwise, |error_callback| is called.
virtual void EnumerateStorages( virtual void EnumerateStorages(EnumerateStoragesCallback callback,
const EnumerateStoragesCallback& callback, ErrorCallback error_callback) = 0;
const ErrorCallback& error_callback) = 0;
// Calls GetStorageInfo method. |callback| is called after the method call // Calls GetStorageInfo method. |callback| is called after the method call
// succeeds, otherwise, |error_callback| is called. // succeeds, otherwise, |error_callback| is called.
virtual void GetStorageInfo(const std::string& storage_name, virtual void GetStorageInfo(const std::string& storage_name,
const GetStorageInfoCallback& callback, GetStorageInfoCallback callback,
const ErrorCallback& error_callback) = 0; ErrorCallback error_callback) = 0;
// Calls GetStorageInfoFromDevice method. |callback| is called after the // Calls GetStorageInfoFromDevice method. |callback| is called after the
// method call succeeds, otherwise, |error_callback| is called. // method call succeeds, otherwise, |error_callback| is called.
virtual void GetStorageInfoFromDevice( virtual void GetStorageInfoFromDevice(const std::string& storage_name,
const std::string& storage_name, GetStorageInfoCallback callback,
const GetStorageInfoCallback& callback, ErrorCallback error_callback) = 0;
const ErrorCallback& error_callback) = 0;
// Calls OpenStorage method. |callback| is called after the method call // Calls OpenStorage method. |callback| is called after the method call
// succeeds, otherwise, |error_callback| is called. // succeeds, otherwise, |error_callback| is called.
// OpenStorage returns a handle in |callback|. // OpenStorage returns a handle in |callback|.
virtual void OpenStorage(const std::string& storage_name, virtual void OpenStorage(const std::string& storage_name,
const std::string& mode, const std::string& mode,
const OpenStorageCallback& callback, OpenStorageCallback callback,
const ErrorCallback& error_callback) = 0; ErrorCallback error_callback) = 0;
// Calls CloseStorage method. |callback| is called after the method call // Calls CloseStorage method. |callback| is called after the method call
// succeeds, otherwise, |error_callback| is called. // succeeds, otherwise, |error_callback| is called.
// |handle| comes from a OpenStorageCallback. // |handle| comes from a OpenStorageCallback.
virtual void CloseStorage(const std::string& handle, virtual void CloseStorage(const std::string& handle,
const CloseStorageCallback& callback, CloseStorageCallback callback,
const ErrorCallback& error_callback) = 0; ErrorCallback error_callback) = 0;
// Calls CreateDirectory method. |callback| is called after the method call // Calls CreateDirectory method. |callback| is called after the method call
// succeeds, otherwise, |error_callback| is called. // succeeds, otherwise, |error_callback| is called.
...@@ -132,25 +131,24 @@ class MediaTransferProtocolDaemonClient { ...@@ -132,25 +131,24 @@ class MediaTransferProtocolDaemonClient {
virtual void CreateDirectory(const std::string& handle, virtual void CreateDirectory(const std::string& handle,
const uint32_t parent_id, const uint32_t parent_id,
const std::string& directory_name, const std::string& directory_name,
const CreateDirectoryCallback& callback, CreateDirectoryCallback callback,
const ErrorCallback& error_callback) = 0; ErrorCallback error_callback) = 0;
// Calls ReadDirectoryEntryIds method. |callback| is called after the method // Calls ReadDirectoryEntryIds method. |callback| is called after the method
// call succeeds, otherwise, |error_callback| is called. // call succeeds, otherwise, |error_callback| is called.
// |file_id| is a MTP-device specific id for a file. // |file_id| is a MTP-device specific id for a file.
virtual void ReadDirectoryEntryIds( virtual void ReadDirectoryEntryIds(const std::string& handle,
const std::string& handle, uint32_t file_id,
uint32_t file_id, ReadDirectoryEntryIdsCallback callback,
const ReadDirectoryEntryIdsCallback& callback, ErrorCallback error_callback) = 0;
const ErrorCallback& error_callback) = 0;
// Calls GetFileInfo method. |callback| is called after the method // Calls GetFileInfo method. |callback| is called after the method
// call succeeds, otherwise, |error_callback| is called. // call succeeds, otherwise, |error_callback| is called.
// |file_ids| is a list of MTP-device specific file ids. // |file_ids| is a list of MTP-device specific file ids.
virtual void GetFileInfo(const std::string& handle, virtual void GetFileInfo(const std::string& handle,
const std::vector<uint32_t>& file_ids, const std::vector<uint32_t>& file_ids,
const GetFileInfoCallback& callback, GetFileInfoCallback callback,
const ErrorCallback& error_callback) = 0; ErrorCallback error_callback) = 0;
// Calls ReadFileChunk method. |callback| is called after the method call // Calls ReadFileChunk method. |callback| is called after the method call
// succeeds, otherwise, |error_callback| is called. // succeeds, otherwise, |error_callback| is called.
...@@ -161,8 +159,8 @@ class MediaTransferProtocolDaemonClient { ...@@ -161,8 +159,8 @@ class MediaTransferProtocolDaemonClient {
uint32_t file_id, uint32_t file_id,
uint32_t offset, uint32_t offset,
uint32_t bytes_to_read, uint32_t bytes_to_read,
const ReadFileCallback& callback, ReadFileCallback callback,
const ErrorCallback& error_callback) = 0; ErrorCallback error_callback) = 0;
// Calls RenameObject method. |callback| is called after the method call // Calls RenameObject method. |callback| is called after the method call
// succeeds, otherwise, |error_callback| is called. // succeeds, otherwise, |error_callback| is called.
...@@ -171,8 +169,8 @@ class MediaTransferProtocolDaemonClient { ...@@ -171,8 +169,8 @@ class MediaTransferProtocolDaemonClient {
virtual void RenameObject(const std::string& handle, virtual void RenameObject(const std::string& handle,
const uint32_t object_id, const uint32_t object_id,
const std::string& new_name, const std::string& new_name,
const RenameObjectCallback& callback, RenameObjectCallback callback,
const ErrorCallback& error_callback) = 0; ErrorCallback error_callback) = 0;
// Calls CopyFileFromLocal method. |callback| is called after the method call // Calls CopyFileFromLocal method. |callback| is called after the method call
// succeeds, otherwise, |error_callback| is called. // succeeds, otherwise, |error_callback| is called.
...@@ -183,16 +181,16 @@ class MediaTransferProtocolDaemonClient { ...@@ -183,16 +181,16 @@ class MediaTransferProtocolDaemonClient {
const int source_file_descriptor, const int source_file_descriptor,
const uint32_t parent_id, const uint32_t parent_id,
const std::string& file_name, const std::string& file_name,
const CopyFileFromLocalCallback& callback, CopyFileFromLocalCallback callback,
const ErrorCallback& error_callback) = 0; ErrorCallback error_callback) = 0;
// Calls DeleteObject method. |callback| is called after the method call // Calls DeleteObject method. |callback| is called after the method call
// succeeds, otherwise, |error_callback| is called. // succeeds, otherwise, |error_callback| is called.
// |object_id| is an object id of a file or directory which is deleted. // |object_id| is an object id of a file or directory which is deleted.
virtual void DeleteObject(const std::string& handle, virtual void DeleteObject(const std::string& handle,
const uint32_t object_id, const uint32_t object_id,
const DeleteObjectCallback& callback, DeleteObjectCallback callback,
const ErrorCallback& error_callback) = 0; ErrorCallback error_callback) = 0;
// Registers given callback for events. Should only be called once. // Registers given callback for events. Should only be called once.
// |storage_event_handler| is called when a mtp storage attach or detach // |storage_event_handler| is called when a mtp storage attach or detach
......
...@@ -92,10 +92,10 @@ void MtpDeviceManager::GetStorageInfoFromDevice( ...@@ -92,10 +92,10 @@ void MtpDeviceManager::GetStorageInfoFromDevice(
get_storage_info_from_device_callbacks_.push(std::move(callback)); get_storage_info_from_device_callbacks_.push(std::move(callback));
mtp_client_->GetStorageInfoFromDevice( mtp_client_->GetStorageInfoFromDevice(
storage_name, storage_name,
base::Bind(&MtpDeviceManager::OnGetStorageInfoFromDevice, base::BindOnce(&MtpDeviceManager::OnGetStorageInfoFromDevice,
weak_ptr_factory_.GetWeakPtr()), weak_ptr_factory_.GetWeakPtr()),
base::Bind(&MtpDeviceManager::OnGetStorageInfoFromDeviceError, base::BindOnce(&MtpDeviceManager::OnGetStorageInfoFromDeviceError,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
void MtpDeviceManager::OpenStorage(const std::string& storage_name, void MtpDeviceManager::OpenStorage(const std::string& storage_name,
...@@ -108,10 +108,10 @@ void MtpDeviceManager::OpenStorage(const std::string& storage_name, ...@@ -108,10 +108,10 @@ void MtpDeviceManager::OpenStorage(const std::string& storage_name,
} }
open_storage_callbacks_.push(std::move(callback)); open_storage_callbacks_.push(std::move(callback));
mtp_client_->OpenStorage(storage_name, mode, mtp_client_->OpenStorage(storage_name, mode,
base::Bind(&MtpDeviceManager::OnOpenStorage, base::BindOnce(&MtpDeviceManager::OnOpenStorage,
weak_ptr_factory_.GetWeakPtr()), weak_ptr_factory_.GetWeakPtr()),
base::Bind(&MtpDeviceManager::OnOpenStorageError, base::BindOnce(&MtpDeviceManager::OnOpenStorageError,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
void MtpDeviceManager::CloseStorage(const std::string& storage_handle, void MtpDeviceManager::CloseStorage(const std::string& storage_handle,
...@@ -123,11 +123,12 @@ void MtpDeviceManager::CloseStorage(const std::string& storage_handle, ...@@ -123,11 +123,12 @@ void MtpDeviceManager::CloseStorage(const std::string& storage_handle,
} }
close_storage_callbacks_.push( close_storage_callbacks_.push(
std::make_pair(std::move(callback), storage_handle)); std::make_pair(std::move(callback), storage_handle));
mtp_client_->CloseStorage(storage_handle, mtp_client_->CloseStorage(
base::Bind(&MtpDeviceManager::OnCloseStorage, storage_handle,
weak_ptr_factory_.GetWeakPtr()), base::BindOnce(&MtpDeviceManager::OnCloseStorage,
base::Bind(&MtpDeviceManager::OnCloseStorageError, weak_ptr_factory_.GetWeakPtr()),
weak_ptr_factory_.GetWeakPtr())); base::BindOnce(&MtpDeviceManager::OnCloseStorageError,
weak_ptr_factory_.GetWeakPtr()));
} }
void MtpDeviceManager::CreateDirectory(const std::string& storage_handle, void MtpDeviceManager::CreateDirectory(const std::string& storage_handle,
...@@ -142,10 +143,10 @@ void MtpDeviceManager::CreateDirectory(const std::string& storage_handle, ...@@ -142,10 +143,10 @@ void MtpDeviceManager::CreateDirectory(const std::string& storage_handle,
create_directory_callbacks_.push(std::move(callback)); create_directory_callbacks_.push(std::move(callback));
mtp_client_->CreateDirectory( mtp_client_->CreateDirectory(
storage_handle, parent_id, directory_name, storage_handle, parent_id, directory_name,
base::Bind(&MtpDeviceManager::OnCreateDirectory, base::BindOnce(&MtpDeviceManager::OnCreateDirectory,
weak_ptr_factory_.GetWeakPtr()), weak_ptr_factory_.GetWeakPtr()),
base::Bind(&MtpDeviceManager::OnCreateDirectoryError, base::BindOnce(&MtpDeviceManager::OnCreateDirectoryError,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
void MtpDeviceManager::ReadDirectoryEntryIds( void MtpDeviceManager::ReadDirectoryEntryIds(
...@@ -160,10 +161,10 @@ void MtpDeviceManager::ReadDirectoryEntryIds( ...@@ -160,10 +161,10 @@ void MtpDeviceManager::ReadDirectoryEntryIds(
read_directory_callbacks_.push(std::move(callback)); read_directory_callbacks_.push(std::move(callback));
mtp_client_->ReadDirectoryEntryIds( mtp_client_->ReadDirectoryEntryIds(
storage_handle, file_id, storage_handle, file_id,
base::Bind(&MtpDeviceManager::OnReadDirectoryEntryIds, base::BindOnce(&MtpDeviceManager::OnReadDirectoryEntryIds,
weak_ptr_factory_.GetWeakPtr()), weak_ptr_factory_.GetWeakPtr()),
base::Bind(&MtpDeviceManager::OnReadDirectoryError, base::BindOnce(&MtpDeviceManager::OnReadDirectoryError,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
void MtpDeviceManager::ReadFileChunk(const std::string& storage_handle, void MtpDeviceManager::ReadFileChunk(const std::string& storage_handle,
...@@ -177,11 +178,11 @@ void MtpDeviceManager::ReadFileChunk(const std::string& storage_handle, ...@@ -177,11 +178,11 @@ void MtpDeviceManager::ReadFileChunk(const std::string& storage_handle,
return; return;
} }
read_file_callbacks_.push(std::move(callback)); read_file_callbacks_.push(std::move(callback));
mtp_client_->ReadFileChunk( mtp_client_->ReadFileChunk(storage_handle, file_id, offset, count,
storage_handle, file_id, offset, count, base::BindOnce(&MtpDeviceManager::OnReadFile,
base::Bind(&MtpDeviceManager::OnReadFile, weak_ptr_factory_.GetWeakPtr()), weak_ptr_factory_.GetWeakPtr()),
base::Bind(&MtpDeviceManager::OnReadFileError, base::BindOnce(&MtpDeviceManager::OnReadFileError,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
void MtpDeviceManager::GetFileInfo(const std::string& storage_handle, void MtpDeviceManager::GetFileInfo(const std::string& storage_handle,
...@@ -195,10 +196,10 @@ void MtpDeviceManager::GetFileInfo(const std::string& storage_handle, ...@@ -195,10 +196,10 @@ void MtpDeviceManager::GetFileInfo(const std::string& storage_handle,
} }
get_file_info_callbacks_.push(std::move(callback)); get_file_info_callbacks_.push(std::move(callback));
mtp_client_->GetFileInfo(storage_handle, file_ids, mtp_client_->GetFileInfo(storage_handle, file_ids,
base::Bind(&MtpDeviceManager::OnGetFileInfo, base::BindOnce(&MtpDeviceManager::OnGetFileInfo,
weak_ptr_factory_.GetWeakPtr()), weak_ptr_factory_.GetWeakPtr()),
base::Bind(&MtpDeviceManager::OnGetFileInfoError, base::BindOnce(&MtpDeviceManager::OnGetFileInfoError,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
void MtpDeviceManager::RenameObject(const std::string& storage_handle, void MtpDeviceManager::RenameObject(const std::string& storage_handle,
...@@ -211,11 +212,12 @@ void MtpDeviceManager::RenameObject(const std::string& storage_handle, ...@@ -211,11 +212,12 @@ void MtpDeviceManager::RenameObject(const std::string& storage_handle,
return; return;
} }
rename_object_callbacks_.push(std::move(callback)); rename_object_callbacks_.push(std::move(callback));
mtp_client_->RenameObject(storage_handle, object_id, new_name, mtp_client_->RenameObject(
base::Bind(&MtpDeviceManager::OnRenameObject, storage_handle, object_id, new_name,
weak_ptr_factory_.GetWeakPtr()), base::BindOnce(&MtpDeviceManager::OnRenameObject,
base::Bind(&MtpDeviceManager::OnRenameObjectError, weak_ptr_factory_.GetWeakPtr()),
weak_ptr_factory_.GetWeakPtr())); base::BindOnce(&MtpDeviceManager::OnRenameObjectError,
weak_ptr_factory_.GetWeakPtr()));
} }
void MtpDeviceManager::CopyFileFromLocal(const std::string& storage_handle, void MtpDeviceManager::CopyFileFromLocal(const std::string& storage_handle,
...@@ -231,10 +233,10 @@ void MtpDeviceManager::CopyFileFromLocal(const std::string& storage_handle, ...@@ -231,10 +233,10 @@ void MtpDeviceManager::CopyFileFromLocal(const std::string& storage_handle,
copy_file_from_local_callbacks_.push(std::move(callback)); copy_file_from_local_callbacks_.push(std::move(callback));
mtp_client_->CopyFileFromLocal( mtp_client_->CopyFileFromLocal(
storage_handle, source_file_descriptor, parent_id, file_name, storage_handle, source_file_descriptor, parent_id, file_name,
base::Bind(&MtpDeviceManager::OnCopyFileFromLocal, base::BindOnce(&MtpDeviceManager::OnCopyFileFromLocal,
weak_ptr_factory_.GetWeakPtr()), weak_ptr_factory_.GetWeakPtr()),
base::Bind(&MtpDeviceManager::OnCopyFileFromLocalError, base::BindOnce(&MtpDeviceManager::OnCopyFileFromLocalError,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
void MtpDeviceManager::DeleteObject(const std::string& storage_handle, void MtpDeviceManager::DeleteObject(const std::string& storage_handle,
...@@ -246,20 +248,22 @@ void MtpDeviceManager::DeleteObject(const std::string& storage_handle, ...@@ -246,20 +248,22 @@ void MtpDeviceManager::DeleteObject(const std::string& storage_handle,
return; return;
} }
delete_object_callbacks_.push(std::move(callback)); delete_object_callbacks_.push(std::move(callback));
mtp_client_->DeleteObject(storage_handle, object_id, mtp_client_->DeleteObject(
base::Bind(&MtpDeviceManager::OnDeleteObject, storage_handle, object_id,
weak_ptr_factory_.GetWeakPtr()), base::BindOnce(&MtpDeviceManager::OnDeleteObject,
base::Bind(&MtpDeviceManager::OnDeleteObjectError, weak_ptr_factory_.GetWeakPtr()),
weak_ptr_factory_.GetWeakPtr())); base::BindOnce(&MtpDeviceManager::OnDeleteObjectError,
weak_ptr_factory_.GetWeakPtr()));
} }
// private methods // private methods
void MtpDeviceManager::OnStorageAttached(const std::string& storage_name) { void MtpDeviceManager::OnStorageAttached(const std::string& storage_name) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
mtp_client_->GetStorageInfo(storage_name, mtp_client_->GetStorageInfo(
base::Bind(&MtpDeviceManager::OnGetStorageInfo, storage_name,
weak_ptr_factory_.GetWeakPtr()), base::BindOnce(&MtpDeviceManager::OnGetStorageInfo,
base::DoNothing()); weak_ptr_factory_.GetWeakPtr()),
base::DoNothing::Once());
} }
void MtpDeviceManager::OnStorageDetached(const std::string& storage_name) { void MtpDeviceManager::OnStorageDetached(const std::string& storage_name) {
...@@ -504,9 +508,9 @@ void MtpDeviceManager::FinishSetupOnOriginThread( ...@@ -504,9 +508,9 @@ void MtpDeviceManager::FinishSetupOnOriginThread(
mtp_client_->ListenForChanges(base::Bind(&MtpDeviceManager::OnStorageChanged, mtp_client_->ListenForChanges(base::Bind(&MtpDeviceManager::OnStorageChanged,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
mtp_client_->EnumerateStorages( mtp_client_->EnumerateStorages(
base::Bind(&MtpDeviceManager::OnEnumerateStorages, base::BindOnce(&MtpDeviceManager::OnEnumerateStorages,
weak_ptr_factory_.GetWeakPtr()), weak_ptr_factory_.GetWeakPtr()),
base::DoNothing()); base::DoNothing::Once());
} }
// static // static
......
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