| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/chromeos/file_manager/volume_manager.h" | 5 #include "chrome/browser/chromeos/file_manager/volume_manager.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 } | 143 } |
| 144 | 144 |
| 145 // static | 145 // static |
| 146 Volume* Volume::CreateForDrive(Profile* profile) { | 146 Volume* Volume::CreateForDrive(Profile* profile) { |
| 147 const base::FilePath& drive_path = | 147 const base::FilePath& drive_path = |
| 148 drive::util::GetDriveMountPointPath(profile); | 148 drive::util::GetDriveMountPointPath(profile); |
| 149 Volume* const volume = new Volume; | 149 Volume* const volume = new Volume; |
| 150 volume->type_ = VOLUME_TYPE_GOOGLE_DRIVE; | 150 volume->type_ = VOLUME_TYPE_GOOGLE_DRIVE; |
| 151 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; | 151 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; |
| 152 volume->source_path_ = drive_path; | 152 volume->source_path_ = drive_path; |
| 153 volume->volume_source_ = VOLUME_SOURCE_NETWORK; | |
| 154 volume->mount_path_ = drive_path; | 153 volume->mount_path_ = drive_path; |
| 155 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; | 154 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; |
| 156 volume->is_parent_ = false; | 155 volume->is_parent_ = false; |
| 157 volume->is_read_only_ = false; | 156 volume->is_read_only_ = false; |
| 158 volume->has_media_ = false; | 157 volume->has_media_ = false; |
| 159 volume->volume_id_ = GenerateVolumeId(*volume); | 158 volume->volume_id_ = GenerateVolumeId(*volume); |
| 160 return volume; | 159 return volume; |
| 161 } | 160 } |
| 162 | 161 |
| 163 // static | 162 // static |
| 164 Volume* Volume::CreateForDownloads(const base::FilePath& downloads_path) { | 163 Volume* Volume::CreateForDownloads(const base::FilePath& downloads_path) { |
| 165 Volume* const volume = new Volume; | 164 Volume* const volume = new Volume; |
| 166 volume->type_ = VOLUME_TYPE_DOWNLOADS_DIRECTORY; | 165 volume->type_ = VOLUME_TYPE_DOWNLOADS_DIRECTORY; |
| 167 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; | 166 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; |
| 168 // Keep source_path empty. | 167 // Keep source_path empty. |
| 169 volume->volume_source_ = VOLUME_SOURCE_DEVICE; | |
| 170 volume->mount_path_ = downloads_path; | 168 volume->mount_path_ = downloads_path; |
| 171 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; | 169 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; |
| 172 volume->is_parent_ = false; | 170 volume->is_parent_ = false; |
| 173 volume->is_read_only_ = false; | 171 volume->is_read_only_ = false; |
| 174 volume->has_media_ = false; | 172 volume->has_media_ = false; |
| 175 volume->volume_id_ = GenerateVolumeId(*volume); | 173 volume->volume_id_ = GenerateVolumeId(*volume); |
| 176 return volume; | 174 return volume; |
| 177 } | 175 } |
| 178 | 176 |
| 179 // static | 177 // static |
| 180 Volume* Volume::CreateForRemovable( | 178 Volume* Volume::CreateForRemovable( |
| 181 const chromeos::disks::DiskMountManager::MountPointInfo& mount_point, | 179 const chromeos::disks::DiskMountManager::MountPointInfo& mount_point, |
| 182 const chromeos::disks::DiskMountManager::Disk* disk) { | 180 const chromeos::disks::DiskMountManager::Disk* disk) { |
| 183 Volume* const volume = new Volume; | 181 Volume* const volume = new Volume; |
| 184 volume->type_ = MountTypeToVolumeType(mount_point.mount_type); | 182 volume->type_ = MountTypeToVolumeType(mount_point.mount_type); |
| 185 volume->source_path_ = base::FilePath(mount_point.source_path); | 183 volume->source_path_ = base::FilePath(mount_point.source_path); |
| 186 volume->volume_source_ = | |
| 187 mount_point.mount_type == chromeos::MOUNT_TYPE_ARCHIVE | |
| 188 ? VOLUME_SOURCE_FILE | |
| 189 : VOLUME_SOURCE_DEVICE; | |
| 190 volume->mount_path_ = base::FilePath(mount_point.mount_path); | 184 volume->mount_path_ = base::FilePath(mount_point.mount_path); |
| 191 volume->mount_condition_ = mount_point.mount_condition; | 185 volume->mount_condition_ = mount_point.mount_condition; |
| 192 volume->volume_label_ = volume->mount_path().BaseName().AsUTF8Unsafe(); | 186 volume->volume_label_ = volume->mount_path().BaseName().AsUTF8Unsafe(); |
| 193 if (disk) { | 187 if (disk) { |
| 194 volume->device_type_ = disk->device_type(); | 188 volume->device_type_ = disk->device_type(); |
| 195 volume->system_path_prefix_ = base::FilePath(disk->system_path_prefix()); | 189 volume->system_path_prefix_ = base::FilePath(disk->system_path_prefix()); |
| 196 volume->is_parent_ = disk->is_parent(); | 190 volume->is_parent_ = disk->is_parent(); |
| 197 volume->is_read_only_ = disk->is_read_only(); | 191 volume->is_read_only_ = disk->is_read_only(); |
| 198 volume->has_media_ = disk->has_media(); | 192 volume->has_media_ = disk->has_media(); |
| 199 } else { | 193 } else { |
| 200 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; | 194 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; |
| 201 volume->is_parent_ = false; | 195 volume->is_parent_ = false; |
| 202 volume->is_read_only_ = | 196 volume->is_read_only_ = |
| 203 (mount_point.mount_type == chromeos::MOUNT_TYPE_ARCHIVE); | 197 (mount_point.mount_type == chromeos::MOUNT_TYPE_ARCHIVE); |
| 204 volume->has_media_ = false; | 198 volume->has_media_ = false; |
| 205 } | 199 } |
| 206 volume->volume_id_ = GenerateVolumeId(*volume); | 200 volume->volume_id_ = GenerateVolumeId(*volume); |
| 207 return volume; | 201 return volume; |
| 208 } | 202 } |
| 209 | 203 |
| 210 // static | 204 // static |
| 211 Volume* Volume::CreateForProvidedFileSystem( | 205 Volume* Volume::CreateForProvidedFileSystem( |
| 212 const chromeos::file_system_provider::ProvidedFileSystemInfo& | 206 const chromeos::file_system_provider::ProvidedFileSystemInfo& |
| 213 file_system_info, | 207 file_system_info, |
| 214 MountContext mount_context) { | 208 MountContext mount_context) { |
| 215 Volume* const volume = new Volume; | 209 Volume* const volume = new Volume; |
| 216 volume->file_system_id_ = file_system_info.file_system_id(); | 210 volume->file_system_id_ = file_system_info.file_system_id(); |
| 217 volume->extension_id_ = file_system_info.extension_id(); | 211 volume->extension_id_ = file_system_info.extension_id(); |
| 218 switch (file_system_info.source()) { | |
| 219 case chromeos::file_system_provider::SOURCE_UNKNOWN: | |
| 220 volume->volume_source_ = VOLUME_SOURCE_UNKNOWN; | |
| 221 break; | |
| 222 case chromeos::file_system_provider::SOURCE_FILE: | |
| 223 volume->volume_source_ = VOLUME_SOURCE_FILE; | |
| 224 break; | |
| 225 case chromeos::file_system_provider::SOURCE_DEVICE: | |
| 226 volume->volume_source_ = VOLUME_SOURCE_DEVICE; | |
| 227 break; | |
| 228 case chromeos::file_system_provider::SOURCE_NETWORK: | |
| 229 volume->volume_source_ = VOLUME_SOURCE_NETWORK; | |
| 230 break; | |
| 231 } | |
| 232 volume->volume_label_ = file_system_info.display_name(); | 212 volume->volume_label_ = file_system_info.display_name(); |
| 233 volume->type_ = VOLUME_TYPE_PROVIDED; | 213 volume->type_ = VOLUME_TYPE_PROVIDED; |
| 234 volume->mount_path_ = file_system_info.mount_path(); | 214 volume->mount_path_ = file_system_info.mount_path(); |
| 235 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; | 215 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; |
| 236 volume->mount_context_ = mount_context; | 216 volume->mount_context_ = mount_context; |
| 237 volume->is_parent_ = true; | 217 volume->is_parent_ = true; |
| 238 volume->is_read_only_ = !file_system_info.writable(); | 218 volume->is_read_only_ = !file_system_info.writable(); |
| 239 volume->has_media_ = false; | 219 volume->has_media_ = false; |
| 240 volume->volume_id_ = GenerateVolumeId(*volume); | 220 volume->volume_id_ = GenerateVolumeId(*volume); |
| 241 return volume; | 221 return volume; |
| 242 } | 222 } |
| 243 | 223 |
| 244 // static | 224 // static |
| 245 Volume* Volume::CreateForMTP(const base::FilePath& mount_path, | 225 Volume* Volume::CreateForMTP(const base::FilePath& mount_path, |
| 246 const std::string& label, | 226 const std::string& label, |
| 247 bool read_only) { | 227 bool read_only) { |
| 248 Volume* const volume = new Volume; | 228 Volume* const volume = new Volume; |
| 249 volume->type_ = VOLUME_TYPE_MTP; | 229 volume->type_ = VOLUME_TYPE_MTP; |
| 250 volume->mount_path_ = mount_path; | 230 volume->mount_path_ = mount_path; |
| 251 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; | 231 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; |
| 252 volume->is_parent_ = true; | 232 volume->is_parent_ = true; |
| 253 volume->is_read_only_ = read_only; | 233 volume->is_read_only_ = read_only; |
| 254 volume->volume_id_ = kMtpVolumeIdPrefix + label; | 234 volume->volume_id_ = kMtpVolumeIdPrefix + label; |
| 255 volume->volume_label_ = label; | 235 volume->volume_label_ = label; |
| 256 volume->source_path_ = mount_path; | 236 volume->source_path_ = mount_path; |
| 257 volume->volume_source_ = VOLUME_SOURCE_DEVICE; | |
| 258 volume->device_type_ = chromeos::DEVICE_TYPE_MOBILE; | 237 volume->device_type_ = chromeos::DEVICE_TYPE_MOBILE; |
| 259 return volume; | 238 return volume; |
| 260 } | 239 } |
| 261 | 240 |
| 262 // static | 241 // static |
| 263 Volume* Volume::CreateForTesting(const base::FilePath& path, | 242 Volume* Volume::CreateForTesting(const base::FilePath& path, |
| 264 VolumeType volume_type, | 243 VolumeType volume_type, |
| 265 chromeos::DeviceType device_type, | 244 chromeos::DeviceType device_type, |
| 266 bool read_only) { | 245 bool read_only) { |
| 267 Volume* const volume = new Volume; | 246 Volume* const volume = new Volume; |
| 268 volume->type_ = volume_type; | 247 volume->type_ = volume_type; |
| 269 volume->device_type_ = device_type; | 248 volume->device_type_ = device_type; |
| 270 // Keep source_path empty. | 249 // Keep source_path empty. |
| 271 volume->volume_source_ = VOLUME_SOURCE_DEVICE; | |
| 272 volume->mount_path_ = path; | 250 volume->mount_path_ = path; |
| 273 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; | 251 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; |
| 274 volume->is_parent_ = false; | 252 volume->is_parent_ = false; |
| 275 volume->is_read_only_ = read_only; | 253 volume->is_read_only_ = read_only; |
| 276 volume->has_media_ = false; | 254 volume->has_media_ = false; |
| 277 volume->volume_id_ = GenerateVolumeId(*volume); | 255 volume->volume_id_ = GenerateVolumeId(*volume); |
| 278 return volume; | 256 return volume; |
| 279 } | 257 } |
| 280 | 258 |
| 281 // static | 259 // static |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) | 825 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) |
| 848 return; | 826 return; |
| 849 if (error_code == chromeos::MOUNT_ERROR_NONE) | 827 if (error_code == chromeos::MOUNT_ERROR_NONE) |
| 850 mounted_volumes_.erase(volume->volume_id()); | 828 mounted_volumes_.erase(volume->volume_id()); |
| 851 | 829 |
| 852 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, | 830 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, |
| 853 OnVolumeUnmounted(error_code, *volume.get())); | 831 OnVolumeUnmounted(error_code, *volume.get())); |
| 854 } | 832 } |
| 855 | 833 |
| 856 } // namespace file_manager | 834 } // namespace file_manager |
| OLD | NEW |