| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "dbus/bus.h" | 9 #include "dbus/bus.h" |
| 10 #include "dbus/message.h" | 10 #include "dbus/message.h" |
| 11 #include "dbus/object_path.h" | 11 #include "dbus/object_path.h" |
| 12 #include "dbus/object_proxy.h" | 12 #include "dbus/object_proxy.h" |
| 13 #include "device/media_transfer_protocol/mtp_file_entry.pb.h" | 13 #include "device/media_transfer_protocol/mtp_file_entry.pb.h" |
| 14 #include "device/media_transfer_protocol/mtp_storage_info.pb.h" | 14 #include "device/media_transfer_protocol/mtp_storage_info.pb.h" |
| 15 #include "third_party/cros_system_api/dbus/service_constants.h" | 15 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 16 | 16 |
| 17 namespace device { | 17 namespace device { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 const char kInvalidResponseMsg[] = "Invalid Response: "; | 21 const char kInvalidResponseMsg[] = "Invalid Response: "; |
| 22 uint32 kMaxChunkSize = 1024*1024; // D-Bus has message size limits. |
| 22 | 23 |
| 23 // The MediaTransferProtocolDaemonClient implementation. | 24 // The MediaTransferProtocolDaemonClient implementation. |
| 24 class MediaTransferProtocolDaemonClientImpl | 25 class MediaTransferProtocolDaemonClientImpl |
| 25 : public MediaTransferProtocolDaemonClient { | 26 : public MediaTransferProtocolDaemonClient { |
| 26 public: | 27 public: |
| 27 explicit MediaTransferProtocolDaemonClientImpl(dbus::Bus* bus) | 28 explicit MediaTransferProtocolDaemonClientImpl(dbus::Bus* bus) |
| 28 : proxy_(bus->GetObjectProxy( | 29 : proxy_(bus->GetObjectProxy( |
| 29 mtpd::kMtpdServiceName, | 30 mtpd::kMtpdServiceName, |
| 30 dbus::ObjectPath(mtpd::kMtpdServicePath))), | 31 dbus::ObjectPath(mtpd::kMtpdServicePath))), |
| 31 listen_for_changes_called_(false), | 32 listen_for_changes_called_(false), |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } | 134 } |
| 134 | 135 |
| 135 // MediaTransferProtocolDaemonClient override. | 136 // MediaTransferProtocolDaemonClient override. |
| 136 virtual void ReadFileChunkByPath( | 137 virtual void ReadFileChunkByPath( |
| 137 const std::string& handle, | 138 const std::string& handle, |
| 138 const std::string& path, | 139 const std::string& path, |
| 139 uint32 offset, | 140 uint32 offset, |
| 140 uint32 bytes_to_read, | 141 uint32 bytes_to_read, |
| 141 const ReadFileCallback& callback, | 142 const ReadFileCallback& callback, |
| 142 const ErrorCallback& error_callback) OVERRIDE { | 143 const ErrorCallback& error_callback) OVERRIDE { |
| 144 DCHECK_LE(bytes_to_read, kMaxChunkSize); |
| 143 dbus::MethodCall method_call(mtpd::kMtpdInterface, | 145 dbus::MethodCall method_call(mtpd::kMtpdInterface, |
| 144 mtpd::kReadFileChunkByPath); | 146 mtpd::kReadFileChunkByPath); |
| 145 dbus::MessageWriter writer(&method_call); | 147 dbus::MessageWriter writer(&method_call); |
| 146 writer.AppendString(handle); | 148 writer.AppendString(handle); |
| 147 writer.AppendString(path); | 149 writer.AppendString(path); |
| 148 writer.AppendUint32(offset); | 150 writer.AppendUint32(offset); |
| 149 writer.AppendUint32(bytes_to_read); | 151 writer.AppendUint32(bytes_to_read); |
| 150 proxy_->CallMethod( | 152 proxy_->CallMethod( |
| 151 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 153 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 152 base::Bind(&MediaTransferProtocolDaemonClientImpl::OnReadFile, | 154 base::Bind(&MediaTransferProtocolDaemonClientImpl::OnReadFile, |
| 153 weak_ptr_factory_.GetWeakPtr(), | 155 weak_ptr_factory_.GetWeakPtr(), |
| 154 callback, | 156 callback, |
| 155 error_callback)); | 157 error_callback)); |
| 156 } | 158 } |
| 157 | 159 |
| 158 // MediaTransferProtocolDaemonClient override. | 160 // MediaTransferProtocolDaemonClient override. |
| 159 virtual void ReadFileChunkById(const std::string& handle, | 161 virtual void ReadFileChunkById(const std::string& handle, |
| 160 uint32 file_id, | 162 uint32 file_id, |
| 161 uint32 offset, | 163 uint32 offset, |
| 162 uint32 bytes_to_read, | 164 uint32 bytes_to_read, |
| 163 const ReadFileCallback& callback, | 165 const ReadFileCallback& callback, |
| 164 const ErrorCallback& error_callback) OVERRIDE { | 166 const ErrorCallback& error_callback) OVERRIDE { |
| 167 DCHECK_LE(bytes_to_read, kMaxChunkSize); |
| 165 dbus::MethodCall method_call(mtpd::kMtpdInterface, | 168 dbus::MethodCall method_call(mtpd::kMtpdInterface, |
| 166 mtpd::kReadFileChunkById); | 169 mtpd::kReadFileChunkById); |
| 167 dbus::MessageWriter writer(&method_call); | 170 dbus::MessageWriter writer(&method_call); |
| 168 writer.AppendString(handle); | 171 writer.AppendString(handle); |
| 169 writer.AppendUint32(file_id); | 172 writer.AppendUint32(file_id); |
| 170 writer.AppendUint32(offset); | 173 writer.AppendUint32(offset); |
| 171 writer.AppendUint32(bytes_to_read); | 174 writer.AppendUint32(bytes_to_read); |
| 172 proxy_->CallMethod( | 175 proxy_->CallMethod( |
| 173 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 176 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 174 base::Bind(&MediaTransferProtocolDaemonClientImpl::OnReadFile, | 177 base::Bind(&MediaTransferProtocolDaemonClientImpl::OnReadFile, |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 | 426 |
| 424 MediaTransferProtocolDaemonClient::~MediaTransferProtocolDaemonClient() {} | 427 MediaTransferProtocolDaemonClient::~MediaTransferProtocolDaemonClient() {} |
| 425 | 428 |
| 426 // static | 429 // static |
| 427 MediaTransferProtocolDaemonClient* MediaTransferProtocolDaemonClient::Create( | 430 MediaTransferProtocolDaemonClient* MediaTransferProtocolDaemonClient::Create( |
| 428 dbus::Bus* bus) { | 431 dbus::Bus* bus) { |
| 429 return new MediaTransferProtocolDaemonClientImpl(bus); | 432 return new MediaTransferProtocolDaemonClientImpl(bus); |
| 430 } | 433 } |
| 431 | 434 |
| 432 } // namespace device | 435 } // namespace device |
| OLD | NEW |