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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 namespace chromeos { | 31 namespace chromeos { |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 const char* kDefaultMountOptions[] = { | 35 const char* kDefaultMountOptions[] = { |
36 "nodev", "noexec", "nosuid", | 36 "nodev", "noexec", "nosuid", |
37 }; | 37 }; |
38 const char kReadOnlyOption[] = "ro"; | 38 const char kReadOnlyOption[] = "ro"; |
39 const char kReadWriteOption[] = "rw"; | 39 const char kReadWriteOption[] = "rw"; |
| 40 const char kRemountOption[] = "remount"; |
40 const char kMountLabelOption[] = "mountlabel"; | 41 const char kMountLabelOption[] = "mountlabel"; |
41 | 42 |
42 const char* kDefaultUnmountOptions[] = { | 43 const char* kDefaultUnmountOptions[] = { |
43 "force", | 44 "force", |
44 }; | 45 }; |
45 | 46 |
46 const char kLazyUnmountOption[] = "lazy"; | 47 const char kLazyUnmountOption[] = "lazy"; |
47 | 48 |
48 // Checks if retrieved media type is in boundaries of DeviceMediaType. | 49 // Checks if retrieved media type is in boundaries of DeviceMediaType. |
49 bool IsValidMediaType(uint32_t type) { | 50 bool IsValidMediaType(uint32_t type) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // The CrosDisksClient implementation. | 98 // The CrosDisksClient implementation. |
98 class CrosDisksClientImpl : public CrosDisksClient { | 99 class CrosDisksClientImpl : public CrosDisksClient { |
99 public: | 100 public: |
100 CrosDisksClientImpl() : proxy_(NULL), weak_ptr_factory_(this) {} | 101 CrosDisksClientImpl() : proxy_(NULL), weak_ptr_factory_(this) {} |
101 | 102 |
102 // CrosDisksClient override. | 103 // CrosDisksClient override. |
103 void Mount(const std::string& source_path, | 104 void Mount(const std::string& source_path, |
104 const std::string& source_format, | 105 const std::string& source_format, |
105 const std::string& mount_label, | 106 const std::string& mount_label, |
106 MountAccessMode access_mode, | 107 MountAccessMode access_mode, |
| 108 RemountOption remount, |
107 const base::Closure& callback, | 109 const base::Closure& callback, |
108 const base::Closure& error_callback) override { | 110 const base::Closure& error_callback) override { |
109 dbus::MethodCall method_call(cros_disks::kCrosDisksInterface, | 111 dbus::MethodCall method_call(cros_disks::kCrosDisksInterface, |
110 cros_disks::kMount); | 112 cros_disks::kMount); |
111 dbus::MessageWriter writer(&method_call); | 113 dbus::MessageWriter writer(&method_call); |
112 writer.AppendString(source_path); | 114 writer.AppendString(source_path); |
113 writer.AppendString(source_format); | 115 writer.AppendString(source_format); |
114 std::vector<std::string> mount_options = | 116 std::vector<std::string> mount_options = |
115 ComposeMountOptions(mount_label, access_mode); | 117 ComposeMountOptions(mount_label, access_mode, remount); |
116 writer.AppendArrayOfStrings(mount_options); | 118 writer.AppendArrayOfStrings(mount_options); |
117 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 119 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
118 base::Bind(&CrosDisksClientImpl::OnMount, | 120 base::Bind(&CrosDisksClientImpl::OnMount, |
119 weak_ptr_factory_.GetWeakPtr(), | 121 weak_ptr_factory_.GetWeakPtr(), |
120 callback, | 122 callback, |
121 error_callback)); | 123 error_callback)); |
122 } | 124 } |
123 | 125 |
124 // CrosDisksClient override. | 126 // CrosDisksClient override. |
125 void Unmount(const std::string& device_path, | 127 void Unmount(const std::string& device_path, |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 // static | 650 // static |
649 base::FilePath CrosDisksClient::GetRemovableDiskMountPoint() { | 651 base::FilePath CrosDisksClient::GetRemovableDiskMountPoint() { |
650 return base::FilePath(base::SysInfo::IsRunningOnChromeOS() ? | 652 return base::FilePath(base::SysInfo::IsRunningOnChromeOS() ? |
651 FILE_PATH_LITERAL("/media/removable") : | 653 FILE_PATH_LITERAL("/media/removable") : |
652 FILE_PATH_LITERAL("/tmp/chromeos/media/removable")); | 654 FILE_PATH_LITERAL("/tmp/chromeos/media/removable")); |
653 } | 655 } |
654 | 656 |
655 // static | 657 // static |
656 std::vector<std::string> CrosDisksClient::ComposeMountOptions( | 658 std::vector<std::string> CrosDisksClient::ComposeMountOptions( |
657 const std::string& mount_label, | 659 const std::string& mount_label, |
658 MountAccessMode access_mode) { | 660 MountAccessMode access_mode, |
| 661 RemountOption remount) { |
659 std::vector<std::string> mount_options( | 662 std::vector<std::string> mount_options( |
660 kDefaultMountOptions, | 663 kDefaultMountOptions, |
661 kDefaultMountOptions + arraysize(kDefaultMountOptions)); | 664 kDefaultMountOptions + arraysize(kDefaultMountOptions)); |
662 switch (access_mode) { | 665 switch (access_mode) { |
663 case MOUNT_ACCESS_MODE_READ_ONLY: | 666 case MOUNT_ACCESS_MODE_READ_ONLY: |
664 mount_options.push_back(kReadOnlyOption); | 667 mount_options.push_back(kReadOnlyOption); |
665 break; | 668 break; |
666 case MOUNT_ACCESS_MODE_READ_WRITE: | 669 case MOUNT_ACCESS_MODE_READ_WRITE: |
667 mount_options.push_back(kReadWriteOption); | 670 mount_options.push_back(kReadWriteOption); |
668 break; | 671 break; |
669 } | 672 } |
| 673 if (remount == REMOUNT_OPTION_REMOUNT_EXISTING_DEVICE) { |
| 674 mount_options.push_back(kRemountOption); |
| 675 } |
670 | 676 |
671 if (!mount_label.empty()) { | 677 if (!mount_label.empty()) { |
672 std::string mount_label_option = | 678 std::string mount_label_option = |
673 base::StringPrintf("%s=%s", kMountLabelOption, mount_label.c_str()); | 679 base::StringPrintf("%s=%s", kMountLabelOption, mount_label.c_str()); |
674 mount_options.push_back(mount_label_option); | 680 mount_options.push_back(mount_label_option); |
675 } | 681 } |
676 return mount_options; | 682 return mount_options; |
677 } | 683 } |
678 | 684 |
679 } // namespace chromeos | 685 } // namespace chromeos |
OLD | NEW |