Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: chrome/browser/chromeos/file_manager/volume_manager.cc

Issue 2348813002: Fix a bug that unmounting devices on the policy update can be a busy loop. (Closed)
Patch Set: Format fix, use reference where copy isn't needed. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, 675 // TODO(mtomasz): Introduce own type, and avoid using MountError internally,
676 // since it is related to cros disks only. 676 // since it is related to cros disks only.
677 const chromeos::MountError mount_error = error == base::File::FILE_OK 677 const chromeos::MountError mount_error = error == base::File::FILE_OK
678 ? chromeos::MOUNT_ERROR_NONE 678 ? chromeos::MOUNT_ERROR_NONE
679 : chromeos::MOUNT_ERROR_UNKNOWN; 679 : chromeos::MOUNT_ERROR_UNKNOWN;
680 linked_ptr<Volume> volume(Volume::CreateForProvidedFileSystem( 680 linked_ptr<Volume> volume(Volume::CreateForProvidedFileSystem(
681 file_system_info, MOUNT_CONTEXT_UNKNOWN)); 681 file_system_info, MOUNT_CONTEXT_UNKNOWN));
682 DoUnmountEvent(mount_error, volume); 682 DoUnmountEvent(mount_error, volume);
683 } 683 }
684 684
685 void VolumeManager::OnExternalStorageDisabledChangedUnmountCallback(
686 chromeos::MountError error_code) {
687 if (disk_mount_manager_->mount_points().empty())
688 return;
689 // Repeat until unmount all paths
690 const std::string& mount_path =
691 disk_mount_manager_->mount_points().begin()->second.mount_path;
692 disk_mount_manager_->UnmountPath(
693 mount_path, chromeos::UNMOUNT_OPTIONS_NONE,
694 base::Bind(
695 &VolumeManager::OnExternalStorageDisabledChangedUnmountCallback,
696 weak_ptr_factory_.GetWeakPtr()));
697 }
698
685 void VolumeManager::OnExternalStorageDisabledChanged() { 699 void VolumeManager::OnExternalStorageDisabledChanged() {
686 // If the policy just got disabled we have to unmount every device currently 700 // If the policy just got disabled we have to unmount every device currently
687 // mounted. The opposite is fine - we can let the user re-plug their device to 701 // mounted. The opposite is fine - we can let the user re-plug their device to
688 // make it available. 702 // make it available.
689 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { 703 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) {
690 // We do not iterate on mount_points directly, because mount_points can 704 // We do not iterate on mount_points directly, because mount_points can
691 // be changed by UnmountPath(). 705 // be changed by UnmountPath().
692 // TODO(hidehiko): Is it necessary to unmount mounted archives, too, here? 706 // TODO(hidehiko): Is it necessary to unmount mounted archives, too, here?
693 while (!disk_mount_manager_->mount_points().empty()) { 707 if (disk_mount_manager_->mount_points().empty())
694 std::string mount_path = 708 return;
695 disk_mount_manager_->mount_points().begin()->second.mount_path; 709 const std::string& mount_path =
696 disk_mount_manager_->UnmountPath( 710 disk_mount_manager_->mount_points().begin()->second.mount_path;
697 mount_path, 711 disk_mount_manager_->UnmountPath(
698 chromeos::UNMOUNT_OPTIONS_NONE, 712 mount_path, chromeos::UNMOUNT_OPTIONS_NONE,
699 chromeos::disks::DiskMountManager::UnmountPathCallback()); 713 base::Bind(
700 } 714 &VolumeManager::OnExternalStorageDisabledChangedUnmountCallback,
715 weak_ptr_factory_.GetWeakPtr()));
701 } 716 }
702 } 717 }
703 718
704 void VolumeManager::OnRemovableStorageAttached( 719 void VolumeManager::OnRemovableStorageAttached(
705 const storage_monitor::StorageInfo& info) { 720 const storage_monitor::StorageInfo& info) {
706 if (!storage_monitor::StorageInfo::IsMTPDevice(info.device_id())) 721 if (!storage_monitor::StorageInfo::IsMTPDevice(info.device_id()))
707 return; 722 return;
708 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) 723 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled))
709 return; 724 return;
710 725
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) 902 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end())
888 return; 903 return;
889 if (error_code == chromeos::MOUNT_ERROR_NONE) 904 if (error_code == chromeos::MOUNT_ERROR_NONE)
890 mounted_volumes_.erase(volume->volume_id()); 905 mounted_volumes_.erase(volume->volume_id());
891 906
892 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, 907 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_,
893 OnVolumeUnmounted(error_code, *volume.get())); 908 OnVolumeUnmounted(error_code, *volume.get()));
894 } 909 }
895 910
896 } // namespace file_manager 911 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698