| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/media_transfer_protocol/media_transfer_protocol_daemon_client.h
" | 5 #include "device/media_transfer_protocol/media_transfer_protocol_daemon_client.h
" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 writer.AppendString(handle); | 186 writer.AppendString(handle); |
| 187 writer.AppendFileDescriptor(file_descriptor); | 187 writer.AppendFileDescriptor(file_descriptor); |
| 188 writer.AppendUint32(parent_id); | 188 writer.AppendUint32(parent_id); |
| 189 writer.AppendString(file_name); | 189 writer.AppendString(file_name); |
| 190 proxy_->CallMethod( | 190 proxy_->CallMethod( |
| 191 &method_call, dbus::ObjectProxy::TIMEOUT_INFINITE, | 191 &method_call, dbus::ObjectProxy::TIMEOUT_INFINITE, |
| 192 base::Bind(&MediaTransferProtocolDaemonClientImpl::OnCopyFileFromLocal, | 192 base::Bind(&MediaTransferProtocolDaemonClientImpl::OnCopyFileFromLocal, |
| 193 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 193 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void DeleteObject(const std::string& handle, |
| 197 const uint32 object_id, |
| 198 const DeleteObjectCallback& callback, |
| 199 const ErrorCallback& error_callback) override { |
| 200 dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kDeleteObject); |
| 201 dbus::MessageWriter writer(&method_call); |
| 202 writer.AppendString(handle); |
| 203 writer.AppendUint32(object_id); |
| 204 proxy_->CallMethod( |
| 205 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 206 base::Bind(&MediaTransferProtocolDaemonClientImpl::OnDeleteObject, |
| 207 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 208 } |
| 209 |
| 196 // MediaTransferProtocolDaemonClient override. | 210 // MediaTransferProtocolDaemonClient override. |
| 197 void ListenForChanges(const MTPStorageEventHandler& handler) override { | 211 void ListenForChanges(const MTPStorageEventHandler& handler) override { |
| 198 DCHECK(!listen_for_changes_called_); | 212 DCHECK(!listen_for_changes_called_); |
| 199 listen_for_changes_called_ = true; | 213 listen_for_changes_called_ = true; |
| 200 | 214 |
| 201 static const SignalEventTuple kSignalEventTuples[] = { | 215 static const SignalEventTuple kSignalEventTuples[] = { |
| 202 { mtpd::kMTPStorageAttached, true }, | 216 { mtpd::kMTPStorageAttached, true }, |
| 203 { mtpd::kMTPStorageDetached, false }, | 217 { mtpd::kMTPStorageDetached, false }, |
| 204 }; | 218 }; |
| 205 const size_t kNumSignalEventTuples = arraysize(kSignalEventTuples); | 219 const size_t kNumSignalEventTuples = arraysize(kSignalEventTuples); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 const ErrorCallback& error_callback, | 389 const ErrorCallback& error_callback, |
| 376 dbus::Response* response) { | 390 dbus::Response* response) { |
| 377 if (!response) { | 391 if (!response) { |
| 378 error_callback.Run(); | 392 error_callback.Run(); |
| 379 return; | 393 return; |
| 380 } | 394 } |
| 381 | 395 |
| 382 callback.Run(); | 396 callback.Run(); |
| 383 } | 397 } |
| 384 | 398 |
| 399 void OnDeleteObject(const DeleteObjectCallback& callback, |
| 400 const ErrorCallback& error_callback, |
| 401 dbus::Response* response) { |
| 402 if (!response) { |
| 403 error_callback.Run(); |
| 404 return; |
| 405 } |
| 406 |
| 407 callback.Run(); |
| 408 } |
| 409 |
| 385 // Handles MTPStorageAttached/Dettached signals and calls |handler|. | 410 // Handles MTPStorageAttached/Dettached signals and calls |handler|. |
| 386 void OnMTPStorageSignal(MTPStorageEventHandler handler, | 411 void OnMTPStorageSignal(MTPStorageEventHandler handler, |
| 387 bool is_attach, | 412 bool is_attach, |
| 388 dbus::Signal* signal) { | 413 dbus::Signal* signal) { |
| 389 dbus::MessageReader reader(signal); | 414 dbus::MessageReader reader(signal); |
| 390 std::string storage_name; | 415 std::string storage_name; |
| 391 if (!reader.PopString(&storage_name)) { | 416 if (!reader.PopString(&storage_name)) { |
| 392 LOG(ERROR) << "Invalid signal: " << signal->ToString(); | 417 LOG(ERROR) << "Invalid signal: " << signal->ToString(); |
| 393 return; | 418 return; |
| 394 } | 419 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 425 | 450 |
| 426 MediaTransferProtocolDaemonClient::~MediaTransferProtocolDaemonClient() {} | 451 MediaTransferProtocolDaemonClient::~MediaTransferProtocolDaemonClient() {} |
| 427 | 452 |
| 428 // static | 453 // static |
| 429 MediaTransferProtocolDaemonClient* MediaTransferProtocolDaemonClient::Create( | 454 MediaTransferProtocolDaemonClient* MediaTransferProtocolDaemonClient::Create( |
| 430 dbus::Bus* bus) { | 455 dbus::Bus* bus) { |
| 431 return new MediaTransferProtocolDaemonClientImpl(bus); | 456 return new MediaTransferProtocolDaemonClientImpl(bus); |
| 432 } | 457 } |
| 433 | 458 |
| 434 } // namespace device | 459 } // namespace device |
| OLD | NEW |