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/cros_disks_client.h" | 5 #include "chromeos/dbus/cros_disks_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/chromeos/chromeos_version.h" | 10 #include "base/chromeos/chromeos_version.h" |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 | 408 |
409 virtual ~CrosDisksClientStubImpl() {} | 409 virtual ~CrosDisksClientStubImpl() {} |
410 | 410 |
411 // CrosDisksClient overrides: | 411 // CrosDisksClient overrides: |
412 virtual void Mount(const std::string& source_path, | 412 virtual void Mount(const std::string& source_path, |
413 const std::string& source_format, | 413 const std::string& source_format, |
414 const std::string& mount_label, | 414 const std::string& mount_label, |
415 MountType type, | 415 MountType type, |
416 const MountCallback& callback, | 416 const MountCallback& callback, |
417 const ErrorCallback& error_callback) OVERRIDE { | 417 const ErrorCallback& error_callback) OVERRIDE { |
418 // Already mounted path. | |
419 if (mounted_paths_.count(source_path) != 0) { | |
420 FinishMount(MOUNT_ERROR_PATH_ALREADY_MOUNTED, source_path, type, | |
421 std::string(), callback); | |
422 return; | |
423 } | |
424 | |
425 // This stub implementation only accepts archive mount requests. | 418 // This stub implementation only accepts archive mount requests. |
426 if (type != MOUNT_TYPE_ARCHIVE) { | 419 if (type != MOUNT_TYPE_ARCHIVE) { |
427 FinishMount(MOUNT_ERROR_INTERNAL, source_path, type, std::string(), | 420 FinishMount(MOUNT_ERROR_INTERNAL, source_path, type, std::string(), |
428 callback); | 421 callback); |
429 return; | 422 return; |
430 } | 423 } |
431 | 424 |
432 const base::FilePath mounted_path = GetArchiveMountPoint().Append( | 425 const base::FilePath mounted_path = GetArchiveMountPoint().Append( |
433 base::FilePath::FromUTF8Unsafe(mount_label)); | 426 base::FilePath::FromUTF8Unsafe(mount_label)); |
434 | 427 |
428 // Already mounted path. | |
429 if (source_paths_.count(mounted_path.value()) != 0) { | |
430 FinishMount(MOUNT_ERROR_PATH_ALREADY_MOUNTED, source_path, type, | |
431 std::string(), callback); | |
432 return; | |
433 } | |
434 | |
435 // Perform fake mount. | 435 // Perform fake mount. |
436 base::PostTaskAndReplyWithResult( | 436 base::PostTaskAndReplyWithResult( |
437 base::WorkerPool::GetTaskRunner(true /* task_is_slow */), | 437 base::WorkerPool::GetTaskRunner(true /* task_is_slow */), |
438 FROM_HERE, | 438 FROM_HERE, |
439 base::Bind(&PerformFakeMount, | 439 base::Bind(&PerformFakeMount, |
440 source_path, | 440 source_path, |
441 mounted_path), | 441 mounted_path), |
442 base::Bind(&CrosDisksClientStubImpl::ContinueMount, | 442 base::Bind(&CrosDisksClientStubImpl::ContinueMount, |
443 weak_ptr_factory_.GetWeakPtr(), | 443 weak_ptr_factory_.GetWeakPtr(), |
444 source_path, | 444 source_path, |
445 type, | 445 type, |
446 callback, | 446 callback, |
447 mounted_path)); | 447 mounted_path)); |
448 } | 448 } |
449 | 449 |
450 virtual void Unmount(const std::string& device_path, | 450 virtual void Unmount(const std::string& device_path, |
451 UnmountOptions options, | 451 UnmountOptions options, |
452 const UnmountCallback& callback, | 452 const UnmountCallback& callback, |
453 const UnmountCallback& error_callback) OVERRIDE { | 453 const UnmountCallback& error_callback) OVERRIDE { |
454 // Not mounted. | 454 // Not mounted. |
455 if (mounted_paths_.count(device_path) == 0) { | 455 if (source_paths_.count(device_path) == 0) { |
456 base::MessageLoopProxy::current()->PostTask( | 456 base::MessageLoopProxy::current()->PostTask( |
457 FROM_HERE, base::Bind(error_callback, device_path)); | 457 FROM_HERE, base::Bind(error_callback, device_path)); |
458 return; | 458 return; |
459 } | 459 } |
460 | 460 |
461 const base::FilePath mounted_path = mounted_paths_[device_path]; | 461 source_paths_.erase(device_path); |
462 mounted_paths_.erase(device_path); | |
463 | 462 |
464 // Remove the directory created in Mount(). | 463 // Remove the directory created in Mount(). |
465 base::WorkerPool::PostTask( | 464 base::WorkerPool::PostTaskAndReply( |
466 FROM_HERE, | 465 FROM_HERE, |
467 base::Bind(base::IgnoreResult(&file_util::Delete), | 466 base::Bind(base::IgnoreResult(&file_util::Delete), |
468 mounted_path, | 467 base::FilePath::FromUTF8Unsafe(device_path), |
469 true /* recursive */), | 468 true /* recursive */), |
469 base::Bind(callback, device_path), | |
470 true /* task_is_slow */); | 470 true /* task_is_slow */); |
471 | |
472 base::MessageLoopProxy::current()->PostTask( | |
473 FROM_HERE, base::Bind(callback, device_path)); | |
474 } | 471 } |
475 | 472 |
476 virtual void EnumerateAutoMountableDevices( | 473 virtual void EnumerateAutoMountableDevices( |
477 const EnumerateAutoMountableDevicesCallback& callback, | 474 const EnumerateAutoMountableDevicesCallback& callback, |
478 const ErrorCallback& error_callback) OVERRIDE { | 475 const ErrorCallback& error_callback) OVERRIDE { |
479 std::vector<std::string> device_paths; | 476 std::vector<std::string> device_paths; |
480 base::MessageLoopProxy::current()->PostTask( | 477 base::MessageLoopProxy::current()->PostTask( |
481 FROM_HERE, base::Bind(callback, device_paths)); | 478 FROM_HERE, base::Bind(callback, device_paths)); |
482 } | 479 } |
483 | 480 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 // Part of Mount() implementation. | 533 // Part of Mount() implementation. |
537 void ContinueMount(const std::string& source_path, | 534 void ContinueMount(const std::string& source_path, |
538 MountType type, | 535 MountType type, |
539 const MountCallback& callback, | 536 const MountCallback& callback, |
540 const base::FilePath& mounted_path, | 537 const base::FilePath& mounted_path, |
541 MountError mount_error) { | 538 MountError mount_error) { |
542 if (mount_error != MOUNT_ERROR_NONE) { | 539 if (mount_error != MOUNT_ERROR_NONE) { |
543 FinishMount(mount_error, source_path, type, std::string(), callback); | 540 FinishMount(mount_error, source_path, type, std::string(), callback); |
544 return; | 541 return; |
545 } | 542 } |
546 mounted_paths_[source_path] = mounted_path; | 543 source_paths_[mounted_path.value()] = source_path; |
547 FinishMount(MOUNT_ERROR_NONE, source_path, type, | 544 FinishMount(MOUNT_ERROR_NONE, source_path, type, |
548 mounted_path.AsUTF8Unsafe(), callback); | 545 mounted_path.AsUTF8Unsafe(), callback); |
549 } | 546 } |
550 | 547 |
551 // Runs |callback| and sends MountCompleted signal. | 548 // Runs |callback| and sends MountCompleted signal. |
552 // Part of Mount() implementation. | 549 // Part of Mount() implementation. |
553 void FinishMount(MountError error, | 550 void FinishMount(MountError error, |
554 const std::string& source_path, | 551 const std::string& source_path, |
555 MountType type, | 552 MountType type, |
556 const std::string& mounted_path, | 553 const std::string& mounted_path, |
557 const MountCallback& callback) { | 554 const MountCallback& callback) { |
558 base::MessageLoopProxy::current()->PostTask(FROM_HERE, callback); | 555 base::MessageLoopProxy::current()->PostTask(FROM_HERE, callback); |
559 if (!mount_completed_handler_.is_null()) { | 556 if (!mount_completed_handler_.is_null()) { |
560 base::MessageLoopProxy::current()->PostTask( | 557 base::MessageLoopProxy::current()->PostTask( |
561 FROM_HERE, | 558 FROM_HERE, |
562 base::Bind(mount_completed_handler_, | 559 base::Bind(mount_completed_handler_, |
563 error, source_path, type, mounted_path)); | 560 error, source_path, type, mounted_path)); |
564 } | 561 } |
565 } | 562 } |
566 | 563 |
567 // Source path to mounted path map. | 564 // Mounted path to source path map. |
568 std::map<std::string, base::FilePath> mounted_paths_; | 565 std::map<std::string, std::string> source_paths_; |
satorux1
2013/03/07 03:18:30
mount_to_source_path_map_ ?
hashimoto
2013/03/07 03:31:50
Done.
| |
569 | 566 |
570 MountEventHandler mount_event_handler_; | 567 MountEventHandler mount_event_handler_; |
571 MountCompletedHandler mount_completed_handler_; | 568 MountCompletedHandler mount_completed_handler_; |
572 | 569 |
573 base::WeakPtrFactory<CrosDisksClientStubImpl> weak_ptr_factory_; | 570 base::WeakPtrFactory<CrosDisksClientStubImpl> weak_ptr_factory_; |
574 | 571 |
575 DISALLOW_COPY_AND_ASSIGN(CrosDisksClientStubImpl); | 572 DISALLOW_COPY_AND_ASSIGN(CrosDisksClientStubImpl); |
576 }; | 573 }; |
577 | 574 |
578 } // namespace | 575 } // namespace |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
765 } | 762 } |
766 | 763 |
767 // static | 764 // static |
768 base::FilePath CrosDisksClient::GetRemovableDiskMountPoint() { | 765 base::FilePath CrosDisksClient::GetRemovableDiskMountPoint() { |
769 return base::FilePath(base::chromeos::IsRunningOnChromeOS() ? | 766 return base::FilePath(base::chromeos::IsRunningOnChromeOS() ? |
770 FILE_PATH_LITERAL("/media/removable") : | 767 FILE_PATH_LITERAL("/media/removable") : |
771 FILE_PATH_LITERAL("/tmp/chromeos/media/removable")); | 768 FILE_PATH_LITERAL("/tmp/chromeos/media/removable")); |
772 } | 769 } |
773 | 770 |
774 } // namespace chromeos | 771 } // namespace chromeos |
OLD | NEW |