| 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 writer.AppendUint32(offset); | 164 writer.AppendUint32(offset); |
| 165 writer.AppendUint32(bytes_to_read); | 165 writer.AppendUint32(bytes_to_read); |
| 166 proxy_->CallMethod( | 166 proxy_->CallMethod( |
| 167 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 167 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 168 base::Bind(&MediaTransferProtocolDaemonClientImpl::OnReadFile, | 168 base::Bind(&MediaTransferProtocolDaemonClientImpl::OnReadFile, |
| 169 weak_ptr_factory_.GetWeakPtr(), | 169 weak_ptr_factory_.GetWeakPtr(), |
| 170 callback, | 170 callback, |
| 171 error_callback)); | 171 error_callback)); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void CopyFileFromLocal(const std::string& handle, |
| 175 const uint32 source_file_descriptor, |
| 176 const uint32 parent_id, |
| 177 const std::string& file_name, |
| 178 const CopyFileFromLocalCallback& callback, |
| 179 const ErrorCallback& error_callback) override { |
| 180 dbus::FileDescriptor file_descriptor(source_file_descriptor); |
| 181 file_descriptor.CheckValidity(); |
| 182 |
| 183 dbus::MethodCall method_call(mtpd::kMtpdInterface, |
| 184 mtpd::kCopyFileFromLocal); |
| 185 dbus::MessageWriter writer(&method_call); |
| 186 writer.AppendString(handle); |
| 187 writer.AppendFileDescriptor(file_descriptor); |
| 188 writer.AppendUint32(parent_id); |
| 189 writer.AppendString(file_name); |
| 190 proxy_->CallMethod( |
| 191 &method_call, dbus::ObjectProxy::TIMEOUT_INFINITE, |
| 192 base::Bind(&MediaTransferProtocolDaemonClientImpl::OnCopyFileFromLocal, |
| 193 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 194 } |
| 195 |
| 174 // MediaTransferProtocolDaemonClient override. | 196 // MediaTransferProtocolDaemonClient override. |
| 175 void ListenForChanges(const MTPStorageEventHandler& handler) override { | 197 void ListenForChanges(const MTPStorageEventHandler& handler) override { |
| 176 DCHECK(!listen_for_changes_called_); | 198 DCHECK(!listen_for_changes_called_); |
| 177 listen_for_changes_called_ = true; | 199 listen_for_changes_called_ = true; |
| 178 | 200 |
| 179 static const SignalEventTuple kSignalEventTuples[] = { | 201 static const SignalEventTuple kSignalEventTuples[] = { |
| 180 { mtpd::kMTPStorageAttached, true }, | 202 { mtpd::kMTPStorageAttached, true }, |
| 181 { mtpd::kMTPStorageDetached, false }, | 203 { mtpd::kMTPStorageDetached, false }, |
| 182 }; | 204 }; |
| 183 const size_t kNumSignalEventTuples = arraysize(kSignalEventTuples); | 205 const size_t kNumSignalEventTuples = arraysize(kSignalEventTuples); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 size_t data_length = 0; | 364 size_t data_length = 0; |
| 343 dbus::MessageReader reader(response); | 365 dbus::MessageReader reader(response); |
| 344 if (!reader.PopArrayOfBytes(&data_bytes, &data_length)) { | 366 if (!reader.PopArrayOfBytes(&data_bytes, &data_length)) { |
| 345 error_callback.Run(); | 367 error_callback.Run(); |
| 346 return; | 368 return; |
| 347 } | 369 } |
| 348 std::string data(reinterpret_cast<const char*>(data_bytes), data_length); | 370 std::string data(reinterpret_cast<const char*>(data_bytes), data_length); |
| 349 callback.Run(data); | 371 callback.Run(data); |
| 350 } | 372 } |
| 351 | 373 |
| 374 void OnCopyFileFromLocal(const CopyFileFromLocalCallback& callback, |
| 375 const ErrorCallback& error_callback, |
| 376 dbus::Response* response) { |
| 377 if (!response) { |
| 378 error_callback.Run(); |
| 379 return; |
| 380 } |
| 381 |
| 382 callback.Run(); |
| 383 } |
| 384 |
| 352 // Handles MTPStorageAttached/Dettached signals and calls |handler|. | 385 // Handles MTPStorageAttached/Dettached signals and calls |handler|. |
| 353 void OnMTPStorageSignal(MTPStorageEventHandler handler, | 386 void OnMTPStorageSignal(MTPStorageEventHandler handler, |
| 354 bool is_attach, | 387 bool is_attach, |
| 355 dbus::Signal* signal) { | 388 dbus::Signal* signal) { |
| 356 dbus::MessageReader reader(signal); | 389 dbus::MessageReader reader(signal); |
| 357 std::string storage_name; | 390 std::string storage_name; |
| 358 if (!reader.PopString(&storage_name)) { | 391 if (!reader.PopString(&storage_name)) { |
| 359 LOG(ERROR) << "Invalid signal: " << signal->ToString(); | 392 LOG(ERROR) << "Invalid signal: " << signal->ToString(); |
| 360 return; | 393 return; |
| 361 } | 394 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 392 | 425 |
| 393 MediaTransferProtocolDaemonClient::~MediaTransferProtocolDaemonClient() {} | 426 MediaTransferProtocolDaemonClient::~MediaTransferProtocolDaemonClient() {} |
| 394 | 427 |
| 395 // static | 428 // static |
| 396 MediaTransferProtocolDaemonClient* MediaTransferProtocolDaemonClient::Create( | 429 MediaTransferProtocolDaemonClient* MediaTransferProtocolDaemonClient::Create( |
| 397 dbus::Bus* bus) { | 430 dbus::Bus* bus) { |
| 398 return new MediaTransferProtocolDaemonClientImpl(bus); | 431 return new MediaTransferProtocolDaemonClientImpl(bus); |
| 399 } | 432 } |
| 400 | 433 |
| 401 } // namespace device | 434 } // namespace device |
| OLD | NEW |