| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/extensions/file_manager/mounted_disk_monitor.h
" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 9 #include "chromeos/dbus/power_manager_client.h" | |
| 10 #include "content/public/browser/browser_thread.h" | |
| 11 | |
| 12 using chromeos::DBusThreadManager; | |
| 13 using chromeos::disks::DiskMountManager; | |
| 14 | |
| 15 namespace file_manager { | |
| 16 namespace { | |
| 17 | |
| 18 // Time span of the resuming process. All unmount events sent during this | |
| 19 // time are considered as being part of remounting process, since remounting | |
| 20 // is done just after resuming. | |
| 21 const base::TimeDelta kResumingTimeSpan = base::TimeDelta::FromSeconds(5); | |
| 22 | |
| 23 } // namespace | |
| 24 | |
| 25 MountedDiskMonitor::MountedDiskMonitor() | |
| 26 : is_resuming_(false), | |
| 27 weak_factory_(this) { | |
| 28 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | |
| 29 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); | |
| 30 if (disk_mount_manager) { | |
| 31 disk_mount_manager->AddObserver(this); | |
| 32 disk_mount_manager->RequestMountInfoRefresh(); | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 MountedDiskMonitor::~MountedDiskMonitor() { | |
| 37 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | |
| 38 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); | |
| 39 if (disk_mount_manager) | |
| 40 disk_mount_manager->RemoveObserver(this); | |
| 41 } | |
| 42 | |
| 43 void MountedDiskMonitor::SuspendImminent() { | |
| 44 is_resuming_ = false; | |
| 45 weak_factory_.InvalidateWeakPtrs(); | |
| 46 } | |
| 47 | |
| 48 void MountedDiskMonitor::SystemResumed( | |
| 49 const base::TimeDelta& sleep_duration) { | |
| 50 is_resuming_ = true; | |
| 51 // Undo any previous resets. | |
| 52 weak_factory_.InvalidateWeakPtrs(); | |
| 53 base::MessageLoopProxy::current()->PostDelayedTask( | |
| 54 FROM_HERE, | |
| 55 base::Bind(&MountedDiskMonitor::Reset, | |
| 56 weak_factory_.GetWeakPtr()), | |
| 57 kResumingTimeSpan); | |
| 58 } | |
| 59 | |
| 60 bool MountedDiskMonitor::DiskIsRemounting( | |
| 61 const DiskMountManager::Disk& disk) const { | |
| 62 return unmounted_while_resuming_.count(disk.fs_uuid()) > 0; | |
| 63 } | |
| 64 | |
| 65 void MountedDiskMonitor::OnMountEvent( | |
| 66 chromeos::disks::DiskMountManager::MountEvent event, | |
| 67 chromeos::MountError error_code, | |
| 68 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) { | |
| 69 if (mount_info.mount_type != chromeos::MOUNT_TYPE_DEVICE) | |
| 70 return; | |
| 71 | |
| 72 switch (event) { | |
| 73 case DiskMountManager::MOUNTING: { | |
| 74 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); | |
| 75 const DiskMountManager::Disk* disk = | |
| 76 disk_mount_manager->FindDiskBySourcePath(mount_info.source_path); | |
| 77 if (!disk || error_code != chromeos::MOUNT_ERROR_NONE) | |
| 78 return; | |
| 79 mounted_disks_[mount_info.source_path] = disk->fs_uuid(); | |
| 80 break; | |
| 81 } | |
| 82 | |
| 83 case DiskMountManager::UNMOUNTING: { | |
| 84 DiskMap::iterator it = mounted_disks_.find(mount_info.source_path); | |
| 85 if (it == mounted_disks_.end()) | |
| 86 return; | |
| 87 const std::string& fs_uuid = it->second; | |
| 88 if (is_resuming_) | |
| 89 unmounted_while_resuming_.insert(fs_uuid); | |
| 90 mounted_disks_.erase(it); | |
| 91 break; | |
| 92 } | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 void MountedDiskMonitor::OnDiskEvent( | |
| 97 chromeos::disks::DiskMountManager::DiskEvent event, | |
| 98 const chromeos::disks::DiskMountManager::Disk* disk) { | |
| 99 } | |
| 100 | |
| 101 void MountedDiskMonitor::OnDeviceEvent( | |
| 102 chromeos::disks::DiskMountManager::DeviceEvent event, | |
| 103 const std::string& device_path) { | |
| 104 } | |
| 105 | |
| 106 void MountedDiskMonitor::OnFormatEvent( | |
| 107 chromeos::disks::DiskMountManager::FormatEvent event, | |
| 108 chromeos::FormatError error_code, | |
| 109 const std::string& device_path) { | |
| 110 } | |
| 111 | |
| 112 void MountedDiskMonitor::Reset() { | |
| 113 unmounted_while_resuming_.clear(); | |
| 114 is_resuming_ = false; | |
| 115 } | |
| 116 | |
| 117 } // namespace file_manager | |
| OLD | NEW |