| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/fake_cros_disks_client.h" | 5 #include "chromeos/dbus/fake_cros_disks_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 mounted_path = GetRemovableDiskMountPoint().Append( | 97 mounted_path = GetRemovableDiskMountPoint().Append( |
| 98 base::FilePath::FromUTF8Unsafe(mount_label)); | 98 base::FilePath::FromUTF8Unsafe(mount_label)); |
| 99 break; | 99 break; |
| 100 case MOUNT_TYPE_INVALID: | 100 case MOUNT_TYPE_INVALID: |
| 101 // Unreachable | 101 // Unreachable |
| 102 return; | 102 return; |
| 103 } | 103 } |
| 104 mounted_paths_.insert(mounted_path); | 104 mounted_paths_.insert(mounted_path); |
| 105 | 105 |
| 106 base::PostTaskWithTraitsAndReplyWithResult( | 106 base::PostTaskWithTraitsAndReplyWithResult( |
| 107 FROM_HERE, base::TaskTraits() | 107 FROM_HERE, |
| 108 .WithShutdownBehavior( | 108 {base::MayBlock(), base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}, |
| 109 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | |
| 110 .MayBlock(), | |
| 111 base::Bind(&PerformFakeMount, source_path, mounted_path), | 109 base::Bind(&PerformFakeMount, source_path, mounted_path), |
| 112 base::Bind(&DidMount, mount_completed_handler_, source_path, type, | 110 base::Bind(&DidMount, mount_completed_handler_, source_path, type, |
| 113 callback, mounted_path)); | 111 callback, mounted_path)); |
| 114 } | 112 } |
| 115 | 113 |
| 116 void FakeCrosDisksClient::Unmount(const std::string& device_path, | 114 void FakeCrosDisksClient::Unmount(const std::string& device_path, |
| 117 UnmountOptions options, | 115 UnmountOptions options, |
| 118 const base::Closure& callback, | 116 const base::Closure& callback, |
| 119 const base::Closure& error_callback) { | 117 const base::Closure& error_callback) { |
| 120 DCHECK(!callback.is_null()); | 118 DCHECK(!callback.is_null()); |
| 121 DCHECK(!error_callback.is_null()); | 119 DCHECK(!error_callback.is_null()); |
| 122 | 120 |
| 123 // Remove the dummy mounted directory if it exists. | 121 // Remove the dummy mounted directory if it exists. |
| 124 if (mounted_paths_.count(base::FilePath::FromUTF8Unsafe(device_path)) > 0) { | 122 if (mounted_paths_.count(base::FilePath::FromUTF8Unsafe(device_path)) > 0) { |
| 125 mounted_paths_.erase(base::FilePath::FromUTF8Unsafe(device_path)); | 123 mounted_paths_.erase(base::FilePath::FromUTF8Unsafe(device_path)); |
| 126 base::PostTaskWithTraitsAndReply( | 124 base::PostTaskWithTraitsAndReply( |
| 127 FROM_HERE, base::TaskTraits() | 125 FROM_HERE, |
| 128 .WithShutdownBehavior( | 126 {base::MayBlock(), base::TaskPriority::BACKGROUND, |
| 129 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 127 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}, |
| 130 .WithPriority(base::TaskPriority::BACKGROUND) | |
| 131 .MayBlock(), | |
| 132 base::Bind(base::IgnoreResult(&base::DeleteFile), | 128 base::Bind(base::IgnoreResult(&base::DeleteFile), |
| 133 base::FilePath::FromUTF8Unsafe(device_path), | 129 base::FilePath::FromUTF8Unsafe(device_path), |
| 134 true /* recursive */), | 130 true /* recursive */), |
| 135 callback); | 131 callback); |
| 136 } | 132 } |
| 137 | 133 |
| 138 unmount_call_count_++; | 134 unmount_call_count_++; |
| 139 last_unmount_device_path_ = device_path; | 135 last_unmount_device_path_ = device_path; |
| 140 last_unmount_options_ = options; | 136 last_unmount_options_ = options; |
| 141 base::ThreadTaskRunnerHandle::Get()->PostTask( | 137 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 bool FakeCrosDisksClient::SendFormatCompletedEvent( | 211 bool FakeCrosDisksClient::SendFormatCompletedEvent( |
| 216 FormatError error_code, | 212 FormatError error_code, |
| 217 const std::string& device_path) { | 213 const std::string& device_path) { |
| 218 if (format_completed_handler_.is_null()) | 214 if (format_completed_handler_.is_null()) |
| 219 return false; | 215 return false; |
| 220 format_completed_handler_.Run(error_code, device_path); | 216 format_completed_handler_.Run(error_code, device_path); |
| 221 return true; | 217 return true; |
| 222 } | 218 } |
| 223 | 219 |
| 224 } // namespace chromeos | 220 } // namespace chromeos |
| OLD | NEW |