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