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 "chromeos/dbus/media_transfer_protocol_daemon_client.h" | 5 #include "chromeos/dbus/media_transfer_protocol_daemon_client.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 writer.AppendUint32(file_id); | 197 writer.AppendUint32(file_id); |
198 proxy_->CallMethod( | 198 proxy_->CallMethod( |
199 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 199 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
200 base::Bind(&MediaTransferProtocolDaemonClientImpl::OnReadFile, | 200 base::Bind(&MediaTransferProtocolDaemonClientImpl::OnReadFile, |
201 weak_ptr_factory_.GetWeakPtr(), | 201 weak_ptr_factory_.GetWeakPtr(), |
202 callback, | 202 callback, |
203 error_callback)); | 203 error_callback)); |
204 } | 204 } |
205 | 205 |
206 // MediaTransferProtocolDaemonClient override. | 206 // MediaTransferProtocolDaemonClient override. |
| 207 virtual void GetFileInfoByPath(const std::string& handle, |
| 208 const std::string& path, |
| 209 const GetFileInfoCallback& callback, |
| 210 const ErrorCallback& error_callback) { |
| 211 dbus::MethodCall method_call(mtpd::kMtpdInterface, "GetFileInfoByPath"); |
| 212 dbus::MessageWriter writer(&method_call); |
| 213 writer.AppendString(handle); |
| 214 writer.AppendString(path); |
| 215 proxy_->CallMethod( |
| 216 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 217 base::Bind(&MediaTransferProtocolDaemonClientImpl::OnGetFileInfo, |
| 218 weak_ptr_factory_.GetWeakPtr(), |
| 219 callback, |
| 220 error_callback)); |
| 221 } |
| 222 |
| 223 // MediaTransferProtocolDaemonClient override. |
| 224 virtual void GetFileInfoById(const std::string& handle, |
| 225 uint32 file_id, |
| 226 const GetFileInfoCallback& callback, |
| 227 const ErrorCallback& error_callback) { |
| 228 dbus::MethodCall method_call(mtpd::kMtpdInterface, "GetFileInfoById"); |
| 229 dbus::MessageWriter writer(&method_call); |
| 230 writer.AppendString(handle); |
| 231 writer.AppendUint32(file_id); |
| 232 proxy_->CallMethod( |
| 233 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 234 base::Bind(&MediaTransferProtocolDaemonClientImpl::OnGetFileInfo, |
| 235 weak_ptr_factory_.GetWeakPtr(), |
| 236 callback, |
| 237 error_callback)); |
| 238 } |
| 239 |
| 240 // MediaTransferProtocolDaemonClient override. |
207 virtual void SetUpConnections( | 241 virtual void SetUpConnections( |
208 const MTPStorageEventHandler& handler) OVERRIDE { | 242 const MTPStorageEventHandler& handler) OVERRIDE { |
209 static const SignalEventTuple kSignalEventTuples[] = { | 243 static const SignalEventTuple kSignalEventTuples[] = { |
210 { mtpd::kMTPStorageAttached, true }, | 244 { mtpd::kMTPStorageAttached, true }, |
211 { mtpd::kMTPStorageDetached, false }, | 245 { mtpd::kMTPStorageDetached, false }, |
212 }; | 246 }; |
213 const size_t kNumSignalEventTuples = arraysize(kSignalEventTuples); | 247 const size_t kNumSignalEventTuples = arraysize(kSignalEventTuples); |
214 | 248 |
215 for (size_t i = 0; i < kNumSignalEventTuples; ++i) { | 249 for (size_t i = 0; i < kNumSignalEventTuples; ++i) { |
216 proxy_->ConnectToSignal( | 250 proxy_->ConnectToSignal( |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 size_t data_length = 0; | 369 size_t data_length = 0; |
336 dbus::MessageReader reader(response); | 370 dbus::MessageReader reader(response); |
337 if (!reader.PopArrayOfBytes(&data_bytes, &data_length)) { | 371 if (!reader.PopArrayOfBytes(&data_bytes, &data_length)) { |
338 error_callback.Run(); | 372 error_callback.Run(); |
339 return; | 373 return; |
340 } | 374 } |
341 std::string data(reinterpret_cast<const char*>(data_bytes), data_length); | 375 std::string data(reinterpret_cast<const char*>(data_bytes), data_length); |
342 callback.Run(data); | 376 callback.Run(data); |
343 } | 377 } |
344 | 378 |
| 379 // Handles the result of GetFileInfoByPath/Id and calls |callback| or |
| 380 // |error_callback|. |
| 381 void OnGetFileInfo(const GetFileInfoCallback& callback, |
| 382 const ErrorCallback& error_callback, |
| 383 dbus::Response* response) { |
| 384 if (!response) { |
| 385 error_callback.Run(); |
| 386 return; |
| 387 } |
| 388 |
| 389 FileEntry file_entry(response); |
| 390 callback.Run(file_entry); |
| 391 } |
| 392 |
345 // Handles MTPStorageAttached/Dettached signals and calls |handler|. | 393 // Handles MTPStorageAttached/Dettached signals and calls |handler|. |
346 void OnMTPStorageSignal(MTPStorageEventHandler handler, | 394 void OnMTPStorageSignal(MTPStorageEventHandler handler, |
347 bool is_attach, | 395 bool is_attach, |
348 dbus::Signal* signal) { | 396 dbus::Signal* signal) { |
349 dbus::MessageReader reader(signal); | 397 dbus::MessageReader reader(signal); |
350 std::string storage_name; | 398 std::string storage_name; |
351 if (!reader.PopString(&storage_name)) { | 399 if (!reader.PopString(&storage_name)) { |
352 LOG(ERROR) << "Invalid signal: " << signal->ToString(); | 400 LOG(ERROR) << "Invalid signal: " << signal->ToString(); |
353 return; | 401 return; |
354 } | 402 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 const ReadDirectoryCallback& callback, | 451 const ReadDirectoryCallback& callback, |
404 const ErrorCallback& error_callback) OVERRIDE {} | 452 const ErrorCallback& error_callback) OVERRIDE {} |
405 virtual void ReadFileByPath(const std::string& handle, | 453 virtual void ReadFileByPath(const std::string& handle, |
406 const std::string& path, | 454 const std::string& path, |
407 const ReadFileCallback& callback, | 455 const ReadFileCallback& callback, |
408 const ErrorCallback& error_callback) OVERRIDE {} | 456 const ErrorCallback& error_callback) OVERRIDE {} |
409 virtual void ReadFileById(const std::string& handle, | 457 virtual void ReadFileById(const std::string& handle, |
410 uint32 file_id, | 458 uint32 file_id, |
411 const ReadFileCallback& callback, | 459 const ReadFileCallback& callback, |
412 const ErrorCallback& error_callback) OVERRIDE {} | 460 const ErrorCallback& error_callback) OVERRIDE {} |
| 461 virtual void GetFileInfoByPath( |
| 462 const std::string& handle, |
| 463 const std::string& path, |
| 464 const GetFileInfoCallback& callback, |
| 465 const ErrorCallback& error_callback) OVERRIDE {} |
| 466 virtual void GetFileInfoById(const std::string& handle, |
| 467 uint32 file_id, |
| 468 const GetFileInfoCallback& callback, |
| 469 const ErrorCallback& error_callback) OVERRIDE {} |
413 virtual void SetUpConnections( | 470 virtual void SetUpConnections( |
414 const MTPStorageEventHandler& handler) OVERRIDE {} | 471 const MTPStorageEventHandler& handler) OVERRIDE {} |
415 | 472 |
416 private: | 473 private: |
417 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDaemonClientStubImpl); | 474 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDaemonClientStubImpl); |
418 }; | 475 }; |
419 | 476 |
420 } // namespace | 477 } // namespace |
421 | 478 |
422 //////////////////////////////////////////////////////////////////////////////// | 479 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 MediaTransferProtocolDaemonClient* | 640 MediaTransferProtocolDaemonClient* |
584 MediaTransferProtocolDaemonClient::Create(DBusClientImplementationType type, | 641 MediaTransferProtocolDaemonClient::Create(DBusClientImplementationType type, |
585 dbus::Bus* bus) { | 642 dbus::Bus* bus) { |
586 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 643 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
587 return new MediaTransferProtocolDaemonClientImpl(bus); | 644 return new MediaTransferProtocolDaemonClientImpl(bus); |
588 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 645 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
589 return new MediaTransferProtocolDaemonClientStubImpl(); | 646 return new MediaTransferProtocolDaemonClientStubImpl(); |
590 } | 647 } |
591 | 648 |
592 } // namespace chromeos | 649 } // namespace chromeos |
OLD | NEW |