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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 is_read_only_removable_device_(false), | 161 is_read_only_removable_device_(false), |
162 has_media_(false), | 162 has_media_(false), |
163 configurable_(false), | 163 configurable_(false), |
164 watchable_(false) { | 164 watchable_(false) { |
165 } | 165 } |
166 | 166 |
167 Volume::~Volume() { | 167 Volume::~Volume() { |
168 } | 168 } |
169 | 169 |
170 // static | 170 // static |
171 Volume* Volume::CreateForDrive(Profile* profile) { | 171 std::unique_ptr<Volume> Volume::CreateForDrive(Profile* profile) { |
172 const base::FilePath& drive_path = | 172 const base::FilePath& drive_path = |
173 drive::util::GetDriveMountPointPath(profile); | 173 drive::util::GetDriveMountPointPath(profile); |
174 Volume* const volume = new Volume; | 174 std::unique_ptr<Volume> volume(new Volume()); |
175 volume->type_ = VOLUME_TYPE_GOOGLE_DRIVE; | 175 volume->type_ = VOLUME_TYPE_GOOGLE_DRIVE; |
176 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; | 176 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; |
177 volume->source_path_ = drive_path; | 177 volume->source_path_ = drive_path; |
178 volume->source_ = SOURCE_NETWORK; | 178 volume->source_ = SOURCE_NETWORK; |
179 volume->mount_path_ = drive_path; | 179 volume->mount_path_ = drive_path; |
180 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; | 180 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; |
181 volume->volume_id_ = GenerateVolumeId(*volume); | 181 volume->volume_id_ = GenerateVolumeId(*volume); |
182 volume->watchable_ = true; | 182 volume->watchable_ = true; |
183 return volume; | 183 return volume; |
184 } | 184 } |
185 | 185 |
186 // static | 186 // static |
187 Volume* Volume::CreateForDownloads(const base::FilePath& downloads_path) { | 187 std::unique_ptr<Volume> Volume::CreateForDownloads( |
188 Volume* const volume = new Volume; | 188 const base::FilePath& downloads_path) { |
| 189 std::unique_ptr<Volume> volume(new Volume()); |
189 volume->type_ = VOLUME_TYPE_DOWNLOADS_DIRECTORY; | 190 volume->type_ = VOLUME_TYPE_DOWNLOADS_DIRECTORY; |
190 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; | 191 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; |
191 // Keep source_path empty. | 192 // Keep source_path empty. |
192 volume->source_ = SOURCE_SYSTEM; | 193 volume->source_ = SOURCE_SYSTEM; |
193 volume->mount_path_ = downloads_path; | 194 volume->mount_path_ = downloads_path; |
194 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; | 195 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; |
195 volume->volume_id_ = GenerateVolumeId(*volume); | 196 volume->volume_id_ = GenerateVolumeId(*volume); |
196 volume->watchable_ = true; | 197 volume->watchable_ = true; |
197 return volume; | 198 return volume; |
198 } | 199 } |
199 | 200 |
200 // static | 201 // static |
201 Volume* Volume::CreateForRemovable( | 202 std::unique_ptr<Volume> Volume::CreateForRemovable( |
202 const chromeos::disks::DiskMountManager::MountPointInfo& mount_point, | 203 const chromeos::disks::DiskMountManager::MountPointInfo& mount_point, |
203 const chromeos::disks::DiskMountManager::Disk* disk) { | 204 const chromeos::disks::DiskMountManager::Disk* disk) { |
204 Volume* const volume = new Volume; | 205 std::unique_ptr<Volume> volume(new Volume()); |
205 volume->type_ = MountTypeToVolumeType(mount_point.mount_type); | 206 volume->type_ = MountTypeToVolumeType(mount_point.mount_type); |
206 volume->source_path_ = base::FilePath(mount_point.source_path); | 207 volume->source_path_ = base::FilePath(mount_point.source_path); |
207 volume->source_ = mount_point.mount_type == chromeos::MOUNT_TYPE_ARCHIVE | 208 volume->source_ = mount_point.mount_type == chromeos::MOUNT_TYPE_ARCHIVE |
208 ? SOURCE_FILE | 209 ? SOURCE_FILE |
209 : SOURCE_DEVICE; | 210 : SOURCE_DEVICE; |
210 volume->mount_path_ = base::FilePath(mount_point.mount_path); | 211 volume->mount_path_ = base::FilePath(mount_point.mount_path); |
211 volume->mount_condition_ = mount_point.mount_condition; | 212 volume->mount_condition_ = mount_point.mount_condition; |
212 volume->volume_label_ = volume->mount_path().BaseName().AsUTF8Unsafe(); | 213 volume->volume_label_ = volume->mount_path().BaseName().AsUTF8Unsafe(); |
213 if (disk) { | 214 if (disk) { |
214 volume->device_type_ = disk->device_type(); | 215 volume->device_type_ = disk->device_type(); |
215 volume->system_path_prefix_ = base::FilePath(disk->system_path_prefix()); | 216 volume->system_path_prefix_ = base::FilePath(disk->system_path_prefix()); |
216 volume->is_parent_ = disk->is_parent(); | 217 volume->is_parent_ = disk->is_parent(); |
217 volume->is_read_only_ = disk->is_read_only(); | 218 volume->is_read_only_ = disk->is_read_only(); |
218 volume->is_read_only_removable_device_ = disk->is_read_only_hardware(); | 219 volume->is_read_only_removable_device_ = disk->is_read_only_hardware(); |
219 volume->has_media_ = disk->has_media(); | 220 volume->has_media_ = disk->has_media(); |
220 } else { | 221 } else { |
221 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; | 222 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; |
222 volume->is_read_only_ = | 223 volume->is_read_only_ = |
223 (mount_point.mount_type == chromeos::MOUNT_TYPE_ARCHIVE); | 224 (mount_point.mount_type == chromeos::MOUNT_TYPE_ARCHIVE); |
224 } | 225 } |
225 volume->volume_id_ = GenerateVolumeId(*volume); | 226 volume->volume_id_ = GenerateVolumeId(*volume); |
226 volume->watchable_ = true; | 227 volume->watchable_ = true; |
227 return volume; | 228 return volume; |
228 } | 229 } |
229 | 230 |
230 // static | 231 // static |
231 Volume* Volume::CreateForProvidedFileSystem( | 232 std::unique_ptr<Volume> Volume::CreateForProvidedFileSystem( |
232 const chromeos::file_system_provider::ProvidedFileSystemInfo& | 233 const chromeos::file_system_provider::ProvidedFileSystemInfo& |
233 file_system_info, | 234 file_system_info, |
234 MountContext mount_context) { | 235 MountContext mount_context) { |
235 Volume* const volume = new Volume; | 236 std::unique_ptr<Volume> volume(new Volume()); |
236 volume->file_system_id_ = file_system_info.file_system_id(); | 237 volume->file_system_id_ = file_system_info.file_system_id(); |
237 volume->extension_id_ = file_system_info.extension_id(); | 238 volume->extension_id_ = file_system_info.extension_id(); |
238 switch (file_system_info.source()) { | 239 switch (file_system_info.source()) { |
239 case extensions::SOURCE_FILE: | 240 case extensions::SOURCE_FILE: |
240 volume->source_ = SOURCE_FILE; | 241 volume->source_ = SOURCE_FILE; |
241 break; | 242 break; |
242 case extensions::SOURCE_DEVICE: | 243 case extensions::SOURCE_DEVICE: |
243 volume->source_ = SOURCE_DEVICE; | 244 volume->source_ = SOURCE_DEVICE; |
244 break; | 245 break; |
245 case extensions::SOURCE_NETWORK: | 246 case extensions::SOURCE_NETWORK: |
246 volume->source_ = SOURCE_NETWORK; | 247 volume->source_ = SOURCE_NETWORK; |
247 break; | 248 break; |
248 } | 249 } |
249 volume->volume_label_ = file_system_info.display_name(); | 250 volume->volume_label_ = file_system_info.display_name(); |
250 volume->type_ = VOLUME_TYPE_PROVIDED; | 251 volume->type_ = VOLUME_TYPE_PROVIDED; |
251 volume->mount_path_ = file_system_info.mount_path(); | 252 volume->mount_path_ = file_system_info.mount_path(); |
252 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; | 253 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; |
253 volume->mount_context_ = mount_context; | 254 volume->mount_context_ = mount_context; |
254 volume->is_parent_ = true; | 255 volume->is_parent_ = true; |
255 volume->is_read_only_ = !file_system_info.writable(); | 256 volume->is_read_only_ = !file_system_info.writable(); |
256 volume->configurable_ = file_system_info.configurable(); | 257 volume->configurable_ = file_system_info.configurable(); |
257 volume->watchable_ = file_system_info.watchable(); | 258 volume->watchable_ = file_system_info.watchable(); |
258 volume->volume_id_ = GenerateVolumeId(*volume); | 259 volume->volume_id_ = GenerateVolumeId(*volume); |
259 return volume; | 260 return volume; |
260 } | 261 } |
261 | 262 |
262 // static | 263 // static |
263 Volume* Volume::CreateForMTP(const base::FilePath& mount_path, | 264 std::unique_ptr<Volume> Volume::CreateForMTP(const base::FilePath& mount_path, |
264 const std::string& label, | 265 const std::string& label, |
265 bool read_only) { | 266 bool read_only) { |
266 Volume* const volume = new Volume; | 267 std::unique_ptr<Volume> volume(new Volume()); |
267 volume->type_ = VOLUME_TYPE_MTP; | 268 volume->type_ = VOLUME_TYPE_MTP; |
268 volume->mount_path_ = mount_path; | 269 volume->mount_path_ = mount_path; |
269 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; | 270 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; |
270 volume->is_parent_ = true; | 271 volume->is_parent_ = true; |
271 volume->is_read_only_ = read_only; | 272 volume->is_read_only_ = read_only; |
272 volume->volume_id_ = kMtpVolumeIdPrefix + label; | 273 volume->volume_id_ = kMtpVolumeIdPrefix + label; |
273 volume->volume_label_ = label; | 274 volume->volume_label_ = label; |
274 volume->source_path_ = mount_path; | 275 volume->source_path_ = mount_path; |
275 volume->source_ = SOURCE_DEVICE; | 276 volume->source_ = SOURCE_DEVICE; |
276 volume->device_type_ = chromeos::DEVICE_TYPE_MOBILE; | 277 volume->device_type_ = chromeos::DEVICE_TYPE_MOBILE; |
277 return volume; | 278 return volume; |
278 } | 279 } |
279 | 280 |
280 // static | 281 // static |
281 Volume* Volume::CreateForMediaView(const std::string& root_document_id) { | 282 std::unique_ptr<Volume> Volume::CreateForMediaView( |
282 Volume* const volume = new Volume; | 283 const std::string& root_document_id) { |
| 284 std::unique_ptr<Volume> volume(new Volume()); |
283 volume->type_ = VOLUME_TYPE_MEDIA_VIEW; | 285 volume->type_ = VOLUME_TYPE_MEDIA_VIEW; |
284 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; | 286 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; |
285 volume->source_ = SOURCE_SYSTEM; | 287 volume->source_ = SOURCE_SYSTEM; |
286 volume->mount_path_ = arc::GetDocumentsProviderMountPath( | 288 volume->mount_path_ = arc::GetDocumentsProviderMountPath( |
287 arc::kMediaDocumentsProviderAuthority, root_document_id); | 289 arc::kMediaDocumentsProviderAuthority, root_document_id); |
288 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; | 290 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; |
289 volume->volume_label_ = root_document_id; | 291 volume->volume_label_ = root_document_id; |
290 volume->is_read_only_ = true; | 292 volume->is_read_only_ = true; |
291 volume->watchable_ = false; | 293 volume->watchable_ = false; |
292 volume->volume_id_ = arc::GetMediaViewVolumeId(root_document_id); | 294 volume->volume_id_ = arc::GetMediaViewVolumeId(root_document_id); |
293 return volume; | 295 return volume; |
294 } | 296 } |
295 | 297 |
296 // static | 298 // static |
297 Volume* Volume::CreateForTesting(const base::FilePath& path, | 299 std::unique_ptr<Volume> Volume::CreateForTesting( |
298 VolumeType volume_type, | 300 const base::FilePath& path, |
299 chromeos::DeviceType device_type, | 301 VolumeType volume_type, |
300 bool read_only) { | 302 chromeos::DeviceType device_type, |
301 Volume* const volume = new Volume; | 303 bool read_only) { |
| 304 std::unique_ptr<Volume> volume(new Volume()); |
302 volume->type_ = volume_type; | 305 volume->type_ = volume_type; |
303 volume->device_type_ = device_type; | 306 volume->device_type_ = device_type; |
304 // Keep source_path empty. | 307 // Keep source_path empty. |
305 volume->source_ = SOURCE_DEVICE; | 308 volume->source_ = SOURCE_DEVICE; |
306 volume->mount_path_ = path; | 309 volume->mount_path_ = path; |
307 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; | 310 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; |
308 volume->is_read_only_ = read_only; | 311 volume->is_read_only_ = read_only; |
309 volume->volume_id_ = GenerateVolumeId(*volume); | 312 volume->volume_id_ = GenerateVolumeId(*volume); |
310 return volume; | 313 return volume; |
311 } | 314 } |
312 | 315 |
313 // static | 316 // static |
314 Volume* Volume::CreateForTesting(const base::FilePath& device_path, | 317 std::unique_ptr<Volume> Volume::CreateForTesting( |
315 const base::FilePath& mount_path) { | 318 const base::FilePath& device_path, |
316 Volume* const volume = new Volume; | 319 const base::FilePath& mount_path) { |
| 320 std::unique_ptr<Volume> volume(new Volume()); |
317 volume->system_path_prefix_ = device_path; | 321 volume->system_path_prefix_ = device_path; |
318 volume->mount_path_ = mount_path; | 322 volume->mount_path_ = mount_path; |
319 return volume; | 323 return volume; |
320 } | 324 } |
321 | 325 |
322 VolumeManager::VolumeManager( | 326 VolumeManager::VolumeManager( |
323 Profile* profile, | 327 Profile* profile, |
324 drive::DriveIntegrationService* drive_integration_service, | 328 drive::DriveIntegrationService* drive_integration_service, |
325 chromeos::PowerManagerClient* power_manager_client, | 329 chromeos::PowerManagerClient* power_manager_client, |
326 chromeos::disks::DiskMountManager* disk_mount_manager, | 330 chromeos::disks::DiskMountManager* disk_mount_manager, |
(...skipping 21 matching lines...) Expand all Loading... |
348 if (chromeos::ProfileHelper::IsSigninProfile(profile_)) | 352 if (chromeos::ProfileHelper::IsSigninProfile(profile_)) |
349 return; | 353 return; |
350 | 354 |
351 // Register 'Downloads' folder for the profile to the file system. | 355 // Register 'Downloads' folder for the profile to the file system. |
352 const base::FilePath downloads = | 356 const base::FilePath downloads = |
353 file_manager::util::GetDownloadsFolderForProfile(profile_); | 357 file_manager::util::GetDownloadsFolderForProfile(profile_); |
354 const bool success = RegisterDownloadsMountPoint(profile_, downloads); | 358 const bool success = RegisterDownloadsMountPoint(profile_, downloads); |
355 DCHECK(success); | 359 DCHECK(success); |
356 | 360 |
357 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | 361 DoMountEvent(chromeos::MOUNT_ERROR_NONE, |
358 make_linked_ptr(Volume::CreateForDownloads(downloads))); | 362 Volume::CreateForDownloads(downloads)); |
359 | 363 |
360 // Subscribe to DriveIntegrationService. | 364 // Subscribe to DriveIntegrationService. |
361 if (drive_integration_service_) { | 365 if (drive_integration_service_) { |
362 drive_integration_service_->AddObserver(this); | 366 drive_integration_service_->AddObserver(this); |
363 if (drive_integration_service_->IsMounted()) { | 367 if (drive_integration_service_->IsMounted()) { |
364 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | 368 DoMountEvent(chromeos::MOUNT_ERROR_NONE, |
365 make_linked_ptr(Volume::CreateForDrive(profile_))); | 369 Volume::CreateForDrive(profile_)); |
366 } | 370 } |
367 } | 371 } |
368 | 372 |
369 // Subscribe to DiskMountManager. | 373 // Subscribe to DiskMountManager. |
370 disk_mount_manager_->AddObserver(this); | 374 disk_mount_manager_->AddObserver(this); |
371 disk_mount_manager_->EnsureMountInfoRefreshed( | 375 disk_mount_manager_->EnsureMountInfoRefreshed( |
372 base::Bind(&VolumeManager::OnDiskMountManagerRefreshed, | 376 base::Bind(&VolumeManager::OnDiskMountManagerRefreshed, |
373 weak_ptr_factory_.GetWeakPtr()), | 377 weak_ptr_factory_.GetWeakPtr()), |
374 false /* force */); | 378 false /* force */); |
375 | 379 |
376 // Subscribe to FileSystemProviderService and register currently mounted | 380 // Subscribe to FileSystemProviderService and register currently mounted |
377 // volumes for the profile. | 381 // volumes for the profile. |
378 if (file_system_provider_service_) { | 382 if (file_system_provider_service_) { |
379 using chromeos::file_system_provider::ProvidedFileSystemInfo; | 383 using chromeos::file_system_provider::ProvidedFileSystemInfo; |
380 file_system_provider_service_->AddObserver(this); | 384 file_system_provider_service_->AddObserver(this); |
381 | 385 |
382 std::vector<ProvidedFileSystemInfo> file_system_info_list = | 386 std::vector<ProvidedFileSystemInfo> file_system_info_list = |
383 file_system_provider_service_->GetProvidedFileSystemInfoList(); | 387 file_system_provider_service_->GetProvidedFileSystemInfoList(); |
384 for (size_t i = 0; i < file_system_info_list.size(); ++i) { | 388 for (size_t i = 0; i < file_system_info_list.size(); ++i) { |
385 linked_ptr<Volume> volume(Volume::CreateForProvidedFileSystem( | 389 std::unique_ptr<Volume> volume = Volume::CreateForProvidedFileSystem( |
386 file_system_info_list[i], MOUNT_CONTEXT_AUTO)); | 390 file_system_info_list[i], MOUNT_CONTEXT_AUTO); |
387 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume); | 391 DoMountEvent(chromeos::MOUNT_ERROR_NONE, std::move(volume)); |
388 } | 392 } |
389 } | 393 } |
390 | 394 |
391 // Subscribe to Profile Preference change. | 395 // Subscribe to Profile Preference change. |
392 pref_change_registrar_.Init(profile_->GetPrefs()); | 396 pref_change_registrar_.Init(profile_->GetPrefs()); |
393 pref_change_registrar_.Add( | 397 pref_change_registrar_.Add( |
394 prefs::kExternalStorageDisabled, | 398 prefs::kExternalStorageDisabled, |
395 base::Bind(&VolumeManager::OnExternalStorageDisabledChanged, | 399 base::Bind(&VolumeManager::OnExternalStorageDisabledChanged, |
396 weak_ptr_factory_.GetWeakPtr())); | 400 weak_ptr_factory_.GetWeakPtr())); |
397 pref_change_registrar_.Add( | 401 pref_change_registrar_.Add( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) { | 454 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) { |
451 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 455 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
452 DCHECK(observer); | 456 DCHECK(observer); |
453 observers_.RemoveObserver(observer); | 457 observers_.RemoveObserver(observer); |
454 } | 458 } |
455 | 459 |
456 std::vector<base::WeakPtr<Volume>> VolumeManager::GetVolumeList() { | 460 std::vector<base::WeakPtr<Volume>> VolumeManager::GetVolumeList() { |
457 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 461 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
458 | 462 |
459 std::vector<base::WeakPtr<Volume>> result; | 463 std::vector<base::WeakPtr<Volume>> result; |
| 464 result.reserve(mounted_volumes_.size()); |
460 for (const auto& pair : mounted_volumes_) { | 465 for (const auto& pair : mounted_volumes_) { |
461 result.push_back(pair.second->AsWeakPtr()); | 466 result.push_back(pair.second->AsWeakPtr()); |
462 } | 467 } |
463 return result; | 468 return result; |
464 } | 469 } |
465 | 470 |
466 base::WeakPtr<Volume> VolumeManager::FindVolumeById( | 471 base::WeakPtr<Volume> VolumeManager::FindVolumeById( |
467 const std::string& volume_id) { | 472 const std::string& volume_id) { |
468 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 473 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
469 | 474 |
470 const auto it = mounted_volumes_.find(volume_id); | 475 const auto it = mounted_volumes_.find(volume_id); |
471 if (it != mounted_volumes_.end()) | 476 if (it != mounted_volumes_.end()) |
472 return it->second->AsWeakPtr(); | 477 return it->second->AsWeakPtr(); |
473 return base::WeakPtr<Volume>(); | 478 return base::WeakPtr<Volume>(); |
474 } | 479 } |
475 | 480 |
476 bool VolumeManager::RegisterDownloadsDirectoryForTesting( | 481 bool VolumeManager::RegisterDownloadsDirectoryForTesting( |
477 const base::FilePath& path) { | 482 const base::FilePath& path) { |
478 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 483 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
479 | 484 |
480 base::FilePath old_path; | 485 base::FilePath old_path; |
481 if (FindDownloadsMountPointPath(profile_, &old_path)) { | 486 if (FindDownloadsMountPointPath(profile_, &old_path)) { |
482 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, | 487 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, |
483 make_linked_ptr(Volume::CreateForDownloads(old_path))); | 488 *Volume::CreateForDownloads(old_path)); |
484 } | 489 } |
485 | 490 |
486 bool success = RegisterDownloadsMountPoint(profile_, path); | 491 bool success = RegisterDownloadsMountPoint(profile_, path); |
487 DoMountEvent( | 492 DoMountEvent( |
488 success ? chromeos::MOUNT_ERROR_NONE : chromeos::MOUNT_ERROR_INVALID_PATH, | 493 success ? chromeos::MOUNT_ERROR_NONE : chromeos::MOUNT_ERROR_INVALID_PATH, |
489 make_linked_ptr(Volume::CreateForDownloads(path))); | 494 Volume::CreateForDownloads(path)); |
490 return success; | 495 return success; |
491 } | 496 } |
492 | 497 |
493 void VolumeManager::AddVolumeForTesting(const base::FilePath& path, | 498 void VolumeManager::AddVolumeForTesting(const base::FilePath& path, |
494 VolumeType volume_type, | 499 VolumeType volume_type, |
495 chromeos::DeviceType device_type, | 500 chromeos::DeviceType device_type, |
496 bool read_only) { | 501 bool read_only) { |
497 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 502 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
498 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | 503 DoMountEvent( |
499 make_linked_ptr(Volume::CreateForTesting( | 504 chromeos::MOUNT_ERROR_NONE, |
500 path, volume_type, device_type, read_only))); | 505 Volume::CreateForTesting(path, volume_type, device_type, read_only)); |
501 } | 506 } |
502 | 507 |
503 void VolumeManager::AddVolumeForTesting(const linked_ptr<Volume>& volume) { | 508 void VolumeManager::AddVolumeForTesting(std::unique_ptr<Volume> volume) { |
504 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 509 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
505 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume); | 510 DoMountEvent(chromeos::MOUNT_ERROR_NONE, std::move(volume)); |
506 } | 511 } |
507 | 512 |
508 void VolumeManager::OnFileSystemMounted() { | 513 void VolumeManager::OnFileSystemMounted() { |
509 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 514 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
510 | 515 |
511 // Raise mount event. | 516 // Raise mount event. |
512 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed | 517 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed |
513 // or network is unreachable. These two errors will be handled later. | 518 // or network is unreachable. These two errors will be handled later. |
514 linked_ptr<Volume> volume(Volume::CreateForDrive(profile_)); | 519 DoMountEvent(chromeos::MOUNT_ERROR_NONE, Volume::CreateForDrive(profile_)); |
515 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume); | |
516 } | 520 } |
517 | 521 |
518 void VolumeManager::OnFileSystemBeingUnmounted() { | 522 void VolumeManager::OnFileSystemBeingUnmounted() { |
519 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 523 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
520 | 524 |
521 linked_ptr<Volume> volume(Volume::CreateForDrive(profile_)); | 525 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, *Volume::CreateForDrive(profile_)); |
522 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, volume); | |
523 } | 526 } |
524 | 527 |
525 void VolumeManager::OnDiskEvent( | 528 void VolumeManager::OnDiskEvent( |
526 chromeos::disks::DiskMountManager::DiskEvent event, | 529 chromeos::disks::DiskMountManager::DiskEvent event, |
527 const chromeos::disks::DiskMountManager::Disk* disk) { | 530 const chromeos::disks::DiskMountManager::Disk* disk) { |
528 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 531 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
529 | 532 |
530 // Disregard hidden devices. | 533 // Disregard hidden devices. |
531 if (disk->is_hidden()) | 534 if (disk->is_hidden()) |
532 return; | 535 return; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 file_system->MarkCacheFileAsUnmounted( | 625 file_system->MarkCacheFileAsUnmounted( |
623 base::FilePath(mount_info.source_path), | 626 base::FilePath(mount_info.source_path), |
624 base::Bind(&drive::util::EmptyFileOperationCallback)); | 627 base::Bind(&drive::util::EmptyFileOperationCallback)); |
625 } | 628 } |
626 } | 629 } |
627 } | 630 } |
628 | 631 |
629 // Notify a mounting/unmounting event to observers. | 632 // Notify a mounting/unmounting event to observers. |
630 const chromeos::disks::DiskMountManager::Disk* const disk = | 633 const chromeos::disks::DiskMountManager::Disk* const disk = |
631 disk_mount_manager_->FindDiskBySourcePath(mount_info.source_path); | 634 disk_mount_manager_->FindDiskBySourcePath(mount_info.source_path); |
632 linked_ptr<Volume> volume(Volume::CreateForRemovable(mount_info, disk)); | 635 std::unique_ptr<Volume> volume = Volume::CreateForRemovable(mount_info, disk); |
633 switch (event) { | 636 switch (event) { |
634 case chromeos::disks::DiskMountManager::MOUNTING: { | 637 case chromeos::disks::DiskMountManager::MOUNTING: { |
635 DoMountEvent(error_code, volume); | 638 DoMountEvent(error_code, std::move(volume)); |
636 return; | 639 return; |
637 } | 640 } |
638 case chromeos::disks::DiskMountManager::UNMOUNTING: | 641 case chromeos::disks::DiskMountManager::UNMOUNTING: |
639 DoUnmountEvent(error_code, volume); | 642 DoUnmountEvent(error_code, *volume); |
640 return; | 643 return; |
641 } | 644 } |
642 NOTREACHED(); | 645 NOTREACHED(); |
643 } | 646 } |
644 | 647 |
645 void VolumeManager::OnFormatEvent( | 648 void VolumeManager::OnFormatEvent( |
646 chromeos::disks::DiskMountManager::FormatEvent event, | 649 chromeos::disks::DiskMountManager::FormatEvent event, |
647 chromeos::FormatError error_code, | 650 chromeos::FormatError error_code, |
648 const std::string& device_path) { | 651 const std::string& device_path) { |
649 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 652 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 MountContext volume_context = MOUNT_CONTEXT_UNKNOWN; | 690 MountContext volume_context = MOUNT_CONTEXT_UNKNOWN; |
688 switch (context) { | 691 switch (context) { |
689 case chromeos::file_system_provider::MOUNT_CONTEXT_USER: | 692 case chromeos::file_system_provider::MOUNT_CONTEXT_USER: |
690 volume_context = MOUNT_CONTEXT_USER; | 693 volume_context = MOUNT_CONTEXT_USER; |
691 break; | 694 break; |
692 case chromeos::file_system_provider::MOUNT_CONTEXT_RESTORE: | 695 case chromeos::file_system_provider::MOUNT_CONTEXT_RESTORE: |
693 volume_context = MOUNT_CONTEXT_AUTO; | 696 volume_context = MOUNT_CONTEXT_AUTO; |
694 break; | 697 break; |
695 } | 698 } |
696 | 699 |
697 linked_ptr<Volume> volume( | 700 std::unique_ptr<Volume> volume = |
698 Volume::CreateForProvidedFileSystem(file_system_info, volume_context)); | 701 Volume::CreateForProvidedFileSystem(file_system_info, volume_context); |
699 | 702 |
700 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, | 703 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, |
701 // since it is related to cros disks only. | 704 // since it is related to cros disks only. |
702 chromeos::MountError mount_error; | 705 chromeos::MountError mount_error; |
703 switch (error) { | 706 switch (error) { |
704 case base::File::FILE_OK: | 707 case base::File::FILE_OK: |
705 mount_error = chromeos::MOUNT_ERROR_NONE; | 708 mount_error = chromeos::MOUNT_ERROR_NONE; |
706 break; | 709 break; |
707 case base::File::FILE_ERROR_EXISTS: | 710 case base::File::FILE_ERROR_EXISTS: |
708 mount_error = chromeos::MOUNT_ERROR_PATH_ALREADY_MOUNTED; | 711 mount_error = chromeos::MOUNT_ERROR_PATH_ALREADY_MOUNTED; |
709 break; | 712 break; |
710 default: | 713 default: |
711 mount_error = chromeos::MOUNT_ERROR_UNKNOWN; | 714 mount_error = chromeos::MOUNT_ERROR_UNKNOWN; |
712 break; | 715 break; |
713 } | 716 } |
714 | 717 |
715 DoMountEvent(mount_error, volume); | 718 DoMountEvent(mount_error, std::move(volume)); |
716 } | 719 } |
717 | 720 |
718 void VolumeManager::OnProvidedFileSystemUnmount( | 721 void VolumeManager::OnProvidedFileSystemUnmount( |
719 const chromeos::file_system_provider::ProvidedFileSystemInfo& | 722 const chromeos::file_system_provider::ProvidedFileSystemInfo& |
720 file_system_info, | 723 file_system_info, |
721 base::File::Error error) { | 724 base::File::Error error) { |
722 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, | 725 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, |
723 // since it is related to cros disks only. | 726 // since it is related to cros disks only. |
724 const chromeos::MountError mount_error = error == base::File::FILE_OK | 727 const chromeos::MountError mount_error = error == base::File::FILE_OK |
725 ? chromeos::MOUNT_ERROR_NONE | 728 ? chromeos::MOUNT_ERROR_NONE |
726 : chromeos::MOUNT_ERROR_UNKNOWN; | 729 : chromeos::MOUNT_ERROR_UNKNOWN; |
727 linked_ptr<Volume> volume(Volume::CreateForProvidedFileSystem( | 730 std::unique_ptr<Volume> volume = Volume::CreateForProvidedFileSystem( |
728 file_system_info, MOUNT_CONTEXT_UNKNOWN)); | 731 file_system_info, MOUNT_CONTEXT_UNKNOWN); |
729 DoUnmountEvent(mount_error, volume); | 732 DoUnmountEvent(mount_error, *volume); |
730 } | 733 } |
731 | 734 |
732 void VolumeManager::OnExternalStorageDisabledChangedUnmountCallback( | 735 void VolumeManager::OnExternalStorageDisabledChangedUnmountCallback( |
733 chromeos::MountError error_code) { | 736 chromeos::MountError error_code) { |
734 if (disk_mount_manager_->mount_points().empty()) | 737 if (disk_mount_manager_->mount_points().empty()) |
735 return; | 738 return; |
736 // Repeat until unmount all paths | 739 // Repeat until unmount all paths |
737 const std::string& mount_path = | 740 const std::string& mount_path = |
738 disk_mount_manager_->mount_points().begin()->second.mount_path; | 741 disk_mount_manager_->mount_points().begin()->second.mount_path; |
739 disk_mount_manager_->UnmountPath( | 742 disk_mount_manager_->UnmountPath( |
740 mount_path, chromeos::UNMOUNT_OPTIONS_NONE, | 743 mount_path, chromeos::UNMOUNT_OPTIONS_NONE, |
741 base::Bind( | 744 base::Bind( |
742 &VolumeManager::OnExternalStorageDisabledChangedUnmountCallback, | 745 &VolumeManager::OnExternalStorageDisabledChangedUnmountCallback, |
743 weak_ptr_factory_.GetWeakPtr())); | 746 weak_ptr_factory_.GetWeakPtr())); |
744 } | 747 } |
745 | 748 |
746 void VolumeManager::OnArcPlayStoreEnabledChanged(bool enabled) { | 749 void VolumeManager::OnArcPlayStoreEnabledChanged(bool enabled) { |
747 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 750 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
748 DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature)); | 751 DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature)); |
749 DCHECK(arc::IsArcAllowedForProfile(profile_)); | 752 DCHECK(arc::IsArcAllowedForProfile(profile_)); |
750 | 753 |
751 if (enabled == arc_volumes_mounted_) | 754 if (enabled == arc_volumes_mounted_) |
752 return; | 755 return; |
753 | 756 |
754 if (enabled) { | 757 if (enabled) { |
755 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | 758 DoMountEvent(chromeos::MOUNT_ERROR_NONE, |
756 linked_ptr<Volume>( | 759 Volume::CreateForMediaView(arc::kImagesRootDocumentId)); |
757 Volume::CreateForMediaView(arc::kImagesRootDocumentId))); | |
758 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | 760 DoMountEvent(chromeos::MOUNT_ERROR_NONE, |
759 linked_ptr<Volume>( | 761 Volume::CreateForMediaView(arc::kVideosRootDocumentId)); |
760 Volume::CreateForMediaView(arc::kVideosRootDocumentId))); | |
761 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | 762 DoMountEvent(chromeos::MOUNT_ERROR_NONE, |
762 linked_ptr<Volume>( | 763 Volume::CreateForMediaView(arc::kAudioRootDocumentId)); |
763 Volume::CreateForMediaView(arc::kAudioRootDocumentId))); | |
764 } else { | 764 } else { |
765 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, | 765 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, |
766 linked_ptr<Volume>( | 766 *Volume::CreateForMediaView(arc::kImagesRootDocumentId)); |
767 Volume::CreateForMediaView(arc::kImagesRootDocumentId))); | |
768 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, | 767 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, |
769 linked_ptr<Volume>( | 768 *Volume::CreateForMediaView(arc::kVideosRootDocumentId)); |
770 Volume::CreateForMediaView(arc::kVideosRootDocumentId))); | |
771 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, | 769 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, |
772 linked_ptr<Volume>( | 770 *Volume::CreateForMediaView(arc::kAudioRootDocumentId)); |
773 Volume::CreateForMediaView(arc::kAudioRootDocumentId))); | |
774 } | 771 } |
775 | 772 |
776 arc_volumes_mounted_ = enabled; | 773 arc_volumes_mounted_ = enabled; |
777 } | 774 } |
778 | 775 |
779 void VolumeManager::OnExternalStorageDisabledChanged() { | 776 void VolumeManager::OnExternalStorageDisabledChanged() { |
780 // If the policy just got disabled we have to unmount every device currently | 777 // If the policy just got disabled we have to unmount every device currently |
781 // mounted. The opposite is fine - we can let the user re-plug their device to | 778 // mounted. The opposite is fine - we can let the user re-plug their device to |
782 // make it available. | 779 // make it available. |
783 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { | 780 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 kFilesystemTypeGenericHierarchical || | 848 kFilesystemTypeGenericHierarchical || |
852 GetExternalStorageAccessMode(profile_) == | 849 GetExternalStorageAccessMode(profile_) == |
853 chromeos::MOUNT_ACCESS_MODE_READ_ONLY; | 850 chromeos::MOUNT_ACCESS_MODE_READ_ONLY; |
854 | 851 |
855 content::BrowserThread::PostTask( | 852 content::BrowserThread::PostTask( |
856 content::BrowserThread::IO, FROM_HERE, | 853 content::BrowserThread::IO, FROM_HERE, |
857 base::Bind(&MTPDeviceMapService::RegisterMTPFileSystem, | 854 base::Bind(&MTPDeviceMapService::RegisterMTPFileSystem, |
858 base::Unretained(MTPDeviceMapService::GetInstance()), | 855 base::Unretained(MTPDeviceMapService::GetInstance()), |
859 info.location(), fsid, read_only)); | 856 info.location(), fsid, read_only)); |
860 | 857 |
861 linked_ptr<Volume> volume(Volume::CreateForMTP(path, label, read_only)); | 858 std::unique_ptr<Volume> volume = Volume::CreateForMTP(path, label, read_only); |
862 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume); | 859 DoMountEvent(chromeos::MOUNT_ERROR_NONE, std::move(volume)); |
863 } | 860 } |
864 | 861 |
865 void VolumeManager::OnRemovableStorageDetached( | 862 void VolumeManager::OnRemovableStorageDetached( |
866 const storage_monitor::StorageInfo& info) { | 863 const storage_monitor::StorageInfo& info) { |
867 if (!storage_monitor::StorageInfo::IsMTPDevice(info.device_id())) | 864 if (!storage_monitor::StorageInfo::IsMTPDevice(info.device_id())) |
868 return; | 865 return; |
869 | 866 |
870 for (const auto mounted_volume : mounted_volumes_) { | 867 for (const auto& mounted_volume : mounted_volumes_) { |
871 if (mounted_volume.second->source_path().value() == info.location()) { | 868 if (mounted_volume.second->source_path().value() == info.location()) { |
872 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, mounted_volume.second); | 869 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, *mounted_volume.second.get()); |
873 | 870 |
874 const std::string fsid = GetMountPointNameForMediaStorage(info); | 871 const std::string fsid = GetMountPointNameForMediaStorage(info); |
875 storage::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(fsid); | 872 storage::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(fsid); |
876 content::BrowserThread::PostTask( | 873 content::BrowserThread::PostTask( |
877 content::BrowserThread::IO, FROM_HERE, base::Bind( | 874 content::BrowserThread::IO, FROM_HERE, base::Bind( |
878 &MTPDeviceMapService::RevokeMTPFileSystem, | 875 &MTPDeviceMapService::RevokeMTPFileSystem, |
879 base::Unretained(MTPDeviceMapService::GetInstance()), | 876 base::Unretained(MTPDeviceMapService::GetInstance()), |
880 fsid)); | 877 fsid)); |
881 return; | 878 return; |
882 } | 879 } |
883 } | 880 } |
884 } | 881 } |
885 | 882 |
886 void VolumeManager::OnDiskMountManagerRefreshed(bool success) { | 883 void VolumeManager::OnDiskMountManagerRefreshed(bool success) { |
887 if (!success) { | 884 if (!success) { |
888 LOG(ERROR) << "Failed to refresh disk mount manager"; | 885 LOG(ERROR) << "Failed to refresh disk mount manager"; |
889 return; | 886 return; |
890 } | 887 } |
891 | 888 |
892 std::vector<linked_ptr<Volume>> archives; | 889 std::vector<std::unique_ptr<Volume>> archives; |
893 | 890 |
894 const chromeos::disks::DiskMountManager::MountPointMap& mount_points = | 891 const chromeos::disks::DiskMountManager::MountPointMap& mount_points = |
895 disk_mount_manager_->mount_points(); | 892 disk_mount_manager_->mount_points(); |
896 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it = | 893 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it = |
897 mount_points.begin(); | 894 mount_points.begin(); |
898 it != mount_points.end(); | 895 it != mount_points.end(); |
899 ++it) { | 896 ++it) { |
900 if (it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { | 897 if (it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { |
901 // Archives are mounted after other types of volume. See below. | 898 // Archives are mounted after other types of volume. See below. |
902 archives.push_back( | 899 archives.push_back(Volume::CreateForRemovable(it->second, nullptr)); |
903 make_linked_ptr(Volume::CreateForRemovable(it->second, NULL))); | |
904 continue; | 900 continue; |
905 } | 901 } |
906 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | 902 DoMountEvent( |
907 make_linked_ptr(Volume::CreateForRemovable( | 903 chromeos::MOUNT_ERROR_NONE, |
908 it->second, disk_mount_manager_->FindDiskBySourcePath( | 904 Volume::CreateForRemovable( |
909 it->second.source_path)))); | 905 it->second, |
| 906 disk_mount_manager_->FindDiskBySourcePath(it->second.source_path))); |
910 } | 907 } |
911 | 908 |
912 // We mount archives only if they are opened from currently mounted volumes. | 909 // We mount archives only if they are opened from currently mounted volumes. |
913 // To check the condition correctly in DoMountEvent, we care about the order. | 910 // To check the condition correctly in DoMountEvent, we care about the order. |
914 std::vector<bool> done(archives.size(), false); | 911 std::vector<bool> done(archives.size(), false); |
915 for (size_t i = 0; i < archives.size(); ++i) { | 912 for (size_t i = 0; i < archives.size(); ++i) { |
916 if (done[i]) | 913 if (done[i]) |
917 continue; | 914 continue; |
918 | 915 |
919 std::vector<linked_ptr<Volume>> chain; | 916 std::vector<std::unique_ptr<Volume>> chain; |
| 917 // done[x] = true means archives[x] is null and that volume is in |chain|. |
920 done[i] = true; | 918 done[i] = true; |
921 chain.push_back(archives[i]); | 919 chain.push_back(std::move(archives[i])); |
922 | 920 |
923 // If archives[i]'s source_path is in another archive, mount it first. | 921 // If archives[i]'s source_path is in another archive, mount it first. |
924 for (size_t parent = i + 1; parent < archives.size(); ++parent) { | 922 for (size_t parent = i + 1; parent < archives.size(); ++parent) { |
925 if (!done[parent] && | 923 if (!done[parent] && |
926 archives[parent]->mount_path().IsParent( | 924 archives[parent]->mount_path().IsParent( |
927 chain.back()->source_path())) { | 925 chain.back()->source_path())) { |
| 926 // done[parent] started false, so archives[parent] is non-null. |
928 done[parent] = true; | 927 done[parent] = true; |
929 chain.push_back(archives[parent]); | 928 chain.push_back(std::move(archives[parent])); |
930 parent = i + 1; // Search archives[parent]'s parent from the beginning. | 929 parent = i + 1; // Search archives[parent]'s parent from the beginning. |
931 } | 930 } |
932 } | 931 } |
933 | 932 |
934 // Mount from the tail of chain. | 933 // Mount from the tail of chain. |
935 for (size_t i = chain.size(); i > 0; --i) { | 934 for (size_t i = chain.size(); i > 0; --i) { |
936 DoMountEvent(chromeos::MOUNT_ERROR_NONE, chain[i - 1]); | 935 DoMountEvent(chromeos::MOUNT_ERROR_NONE, std::move(chain[i - 1])); |
937 } | 936 } |
938 } | 937 } |
939 } | 938 } |
940 | 939 |
941 void VolumeManager::OnStorageMonitorInitialized() { | 940 void VolumeManager::OnStorageMonitorInitialized() { |
942 std::vector<storage_monitor::StorageInfo> storages = | 941 std::vector<storage_monitor::StorageInfo> storages = |
943 storage_monitor::StorageMonitor::GetInstance()->GetAllAvailableStorages(); | 942 storage_monitor::StorageMonitor::GetInstance()->GetAllAvailableStorages(); |
944 for (size_t i = 0; i < storages.size(); ++i) | 943 for (size_t i = 0; i < storages.size(); ++i) |
945 OnRemovableStorageAttached(storages[i]); | 944 OnRemovableStorageAttached(storages[i]); |
946 storage_monitor::StorageMonitor::GetInstance()->AddObserver(this); | 945 storage_monitor::StorageMonitor::GetInstance()->AddObserver(this); |
947 } | 946 } |
948 | 947 |
949 void VolumeManager::DoMountEvent(chromeos::MountError error_code, | 948 void VolumeManager::DoMountEvent(chromeos::MountError error_code, |
950 const linked_ptr<Volume>& volume) { | 949 std::unique_ptr<Volume> volume) { |
951 // Archive files are mounted globally in system. We however don't want to show | 950 // Archive files are mounted globally in system. We however don't want to show |
952 // archives from profile-specific folders (Drive/Downloads) of other users in | 951 // archives from profile-specific folders (Drive/Downloads) of other users in |
953 // multi-profile session. To this end, we filter out archives not on the | 952 // multi-profile session. To this end, we filter out archives not on the |
954 // volumes already mounted on this VolumeManager instance. | 953 // volumes already mounted on this VolumeManager instance. |
955 if (volume->type() == VOLUME_TYPE_MOUNTED_ARCHIVE_FILE) { | 954 if (volume->type() == VOLUME_TYPE_MOUNTED_ARCHIVE_FILE) { |
956 // Source may be in Drive cache folder under the current profile directory. | 955 // Source may be in Drive cache folder under the current profile directory. |
957 bool from_current_profile = | 956 bool from_current_profile = |
958 profile_->GetPath().IsParent(volume->source_path()); | 957 profile_->GetPath().IsParent(volume->source_path()); |
959 for (const auto& mounted_volume : mounted_volumes_) { | 958 for (const auto& mounted_volume : mounted_volumes_) { |
960 if (mounted_volume.second->mount_path().IsParent(volume->source_path())) { | 959 if (mounted_volume.second->mount_path().IsParent(volume->source_path())) { |
961 from_current_profile = true; | 960 from_current_profile = true; |
962 break; | 961 break; |
963 } | 962 } |
964 } | 963 } |
965 if (!from_current_profile) | 964 if (!from_current_profile) |
966 return; | 965 return; |
967 } | 966 } |
968 | 967 |
969 // Filter out removable disks if forbidden by policy for this profile. | 968 // Filter out removable disks if forbidden by policy for this profile. |
970 if (volume->type() == VOLUME_TYPE_REMOVABLE_DISK_PARTITION && | 969 if (volume->type() == VOLUME_TYPE_REMOVABLE_DISK_PARTITION && |
971 profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { | 970 profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { |
972 return; | 971 return; |
973 } | 972 } |
974 | 973 |
| 974 Volume* raw_volume = volume.get(); |
975 if (error_code == chromeos::MOUNT_ERROR_NONE || volume->mount_condition()) { | 975 if (error_code == chromeos::MOUNT_ERROR_NONE || volume->mount_condition()) { |
976 mounted_volumes_[volume->volume_id()] = volume; | 976 mounted_volumes_[volume->volume_id()] = std::move(volume); |
977 UMA_HISTOGRAM_ENUMERATION("FileBrowser.VolumeType", volume->type(), | 977 UMA_HISTOGRAM_ENUMERATION("FileBrowser.VolumeType", raw_volume->type(), |
978 NUM_VOLUME_TYPE); | 978 NUM_VOLUME_TYPE); |
979 } | 979 } |
980 | 980 |
981 for (auto& observer : observers_) | 981 for (auto& observer : observers_) |
982 observer.OnVolumeMounted(error_code, *volume); | 982 observer.OnVolumeMounted(error_code, *raw_volume); |
983 } | 983 } |
984 | 984 |
985 void VolumeManager::DoUnmountEvent(chromeos::MountError error_code, | 985 void VolumeManager::DoUnmountEvent(chromeos::MountError error_code, |
986 const linked_ptr<Volume>& volume) { | 986 const Volume& volume) { |
987 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) | 987 auto iter = mounted_volumes_.find(volume.volume_id()); |
| 988 if (iter == mounted_volumes_.end()) |
988 return; | 989 return; |
989 if (error_code == chromeos::MOUNT_ERROR_NONE) | 990 if (error_code == chromeos::MOUNT_ERROR_NONE) |
990 mounted_volumes_.erase(volume->volume_id()); | 991 mounted_volumes_.erase(iter); |
991 | 992 |
992 for (auto& observer : observers_) | 993 for (auto& observer : observers_) |
993 observer.OnVolumeUnmounted(error_code, *volume.get()); | 994 observer.OnVolumeUnmounted(error_code, volume); |
994 } | 995 } |
995 | 996 |
996 } // namespace file_manager | 997 } // namespace file_manager |
OLD | NEW |