From d85394fce83bd0acb07b84f7328a637f7d203d33 Mon Sep 17 00:00:00 2001 From: hirono Date: Thu, 28 Aug 2014 01:11:58 -0700 Subject: [PATCH] Files.app: Remove MountedDiskMonitor. The role of MountedDiskMonitor is replaced with DeviceEventRouter. BUG=360946,396258 TEST=manually Review URL: https://codereview.chromium.org/479563007 Cr-Commit-Position: refs/heads/master@{#292347} --- .../extensions/file_manager/device_event_router.cc | 3 +- .../extensions/file_manager/device_event_router.h | 3 +- .../file_manager/device_event_router_unittest.cc | 6 +- .../extensions/file_manager/event_router.cc | 3 +- .../extensions/file_manager/event_router.h | 3 +- .../chromeos/file_manager/mounted_disk_monitor.cc | 134 -------------------- .../chromeos/file_manager/mounted_disk_monitor.h | 87 ------------- .../file_manager/mounted_disk_monitor_unittest.cc | 139 --------------------- .../chromeos/file_manager/volume_manager.cc | 69 ++++------ .../browser/chromeos/file_manager/volume_manager.h | 4 +- .../file_manager/volume_manager_observer.h | 3 +- .../file_manager/volume_manager_unittest.cc | 10 +- chrome/chrome_browser_chromeos.gypi | 2 - chrome/chrome_tests_unit.gypi | 1 - 14 files changed, 31 insertions(+), 436 deletions(-) delete mode 100644 chrome/browser/chromeos/file_manager/mounted_disk_monitor.cc delete mode 100644 chrome/browser/chromeos/file_manager/mounted_disk_monitor.h delete mode 100644 chrome/browser/chromeos/file_manager/mounted_disk_monitor_unittest.cc diff --git a/chrome/browser/chromeos/extensions/file_manager/device_event_router.cc b/chrome/browser/chromeos/extensions/file_manager/device_event_router.cc index 5c01fc02550c..6a4cb4f07a31 100644 --- a/chrome/browser/chromeos/extensions/file_manager/device_event_router.cc +++ b/chrome/browser/chromeos/extensions/file_manager/device_event_router.cc @@ -122,8 +122,7 @@ void DeviceEventRouter::OnDiskRemoved( } void DeviceEventRouter::OnVolumeMounted(chromeos::MountError error_code, - const VolumeInfo& volume_info, - bool is_remounting) { + const VolumeInfo& volume_info) { DCHECK(thread_checker_.CalledOnValidThread()); const std::string& device_path = diff --git a/chrome/browser/chromeos/extensions/file_manager/device_event_router.h b/chrome/browser/chromeos/extensions/file_manager/device_event_router.h index 9a149cdb1b5f..73f764fb757e 100644 --- a/chrome/browser/chromeos/extensions/file_manager/device_event_router.h +++ b/chrome/browser/chromeos/extensions/file_manager/device_event_router.h @@ -48,8 +48,7 @@ class DeviceEventRouter : public VolumeManagerObserver, virtual void OnDeviceAdded(const std::string& device_path) OVERRIDE; virtual void OnDeviceRemoved(const std::string& device_path) OVERRIDE; virtual void OnVolumeMounted(chromeos::MountError error_code, - const VolumeInfo& volume_info, - bool is_remounting) OVERRIDE; + const VolumeInfo& volume_info) OVERRIDE; virtual void OnVolumeUnmounted(chromeos::MountError error_code, const VolumeInfo& volume_info) OVERRIDE; virtual void OnFormatStarted(const std::string& device_path, diff --git a/chrome/browser/chromeos/extensions/file_manager/device_event_router_unittest.cc b/chrome/browser/chromeos/extensions/file_manager/device_event_router_unittest.cc index 7b1a560c14c0..3f2dcefd2328 100644 --- a/chrome/browser/chromeos/extensions/file_manager/device_event_router_unittest.cc +++ b/chrome/browser/chromeos/extensions/file_manager/device_event_router_unittest.cc @@ -113,8 +113,7 @@ TEST_F(DeviceEventRouterTest, AddAndRemoveDevice) { CreateTestVolumeInfo("/device/test", "/mount/path1"); device_event_router->OnDeviceAdded("/device/test"); device_event_router->OnDiskAdded(disk1, true); - device_event_router->OnVolumeMounted( - chromeos::MOUNT_ERROR_NONE, volumeInfo, false); + device_event_router->OnVolumeMounted(chromeos::MOUNT_ERROR_NONE, volumeInfo); device_event_router->OnVolumeUnmounted(chromeos::MOUNT_ERROR_NONE, volumeInfo); device_event_router->OnDiskRemoved(disk1_unmounted); @@ -133,8 +132,7 @@ TEST_F(DeviceEventRouterTest, DeviceScan) { device_event_router->OnDeviceAdded("/device/test"); base::RunLoop().RunUntilIdle(); device_event_router->OnDiskAdded(disk, true); - device_event_router->OnVolumeMounted( - chromeos::MOUNT_ERROR_NONE, volumeInfo, false); + device_event_router->OnVolumeMounted(chromeos::MOUNT_ERROR_NONE, volumeInfo); device_event_router->OnVolumeUnmounted(chromeos::MOUNT_ERROR_NONE, volumeInfo); device_event_router->OnDiskRemoved(disk_unmounted); diff --git a/chrome/browser/chromeos/extensions/file_manager/event_router.cc b/chrome/browser/chromeos/extensions/file_manager/event_router.cc index 83e1f144e341..c459ccbbff8b 100644 --- a/chrome/browser/chromeos/extensions/file_manager/event_router.cc +++ b/chrome/browser/chromeos/extensions/file_manager/event_router.cc @@ -887,8 +887,7 @@ void EventRouter::OnDeviceRemoved(const std::string& device_path) { } void EventRouter::OnVolumeMounted(chromeos::MountError error_code, - const VolumeInfo& volume_info, - bool is_remounting) { + const VolumeInfo& volume_info) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // profile_ is NULL if ShutdownOnUIThread() is called earlier. This can // happen at shutdown. This should be removed after removing Drive mounting diff --git a/chrome/browser/chromeos/extensions/file_manager/event_router.h b/chrome/browser/chromeos/extensions/file_manager/event_router.h index 42e65b60b5f4..7e094d6a1926 100644 --- a/chrome/browser/chromeos/extensions/file_manager/event_router.h +++ b/chrome/browser/chromeos/extensions/file_manager/event_router.h @@ -127,8 +127,7 @@ class EventRouter virtual void OnDeviceAdded(const std::string& device_path) OVERRIDE; virtual void OnDeviceRemoved(const std::string& device_path) OVERRIDE; virtual void OnVolumeMounted(chromeos::MountError error_code, - const VolumeInfo& volume_info, - bool is_remounting) OVERRIDE; + const VolumeInfo& volume_info) OVERRIDE; virtual void OnVolumeUnmounted(chromeos::MountError error_code, const VolumeInfo& volume_info) OVERRIDE; virtual void OnFormatStarted( diff --git a/chrome/browser/chromeos/file_manager/mounted_disk_monitor.cc b/chrome/browser/chromeos/file_manager/mounted_disk_monitor.cc deleted file mode 100644 index b67c2d90a858..000000000000 --- a/chrome/browser/chromeos/file_manager/mounted_disk_monitor.cc +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/chromeos/file_manager/mounted_disk_monitor.h" - -#include "base/bind.h" -#include "base/location.h" -#include "base/message_loop/message_loop_proxy.h" -#include "chromeos/dbus/power_manager_client.h" - -using chromeos::disks::DiskMountManager; - -namespace file_manager { -namespace { - -// Time span of the resuming process. All unmount events sent during this -// time are considered as being part of remounting process, since remounting -// is done just after resuming. -const base::TimeDelta kResumingTimeSpan = base::TimeDelta::FromSeconds(5); - -} // namespace - -MountedDiskMonitor::MountedDiskMonitor( - chromeos::PowerManagerClient* power_manager_client) - : power_manager_client_(power_manager_client), - is_resuming_(false), - resuming_time_span_(kResumingTimeSpan), - weak_factory_(this) { - DCHECK(power_manager_client_); - power_manager_client_->AddObserver(this); -} - -MountedDiskMonitor::~MountedDiskMonitor() { - power_manager_client_->RemoveObserver(this); -} - -void MountedDiskMonitor::SuspendImminent() { - // Flip the resuming flag while suspending, so it is possible to detect - // resuming as soon as possible after the lid is open. Note, that mount - // events may occur before the SuspendDone method is called. - is_resuming_ = true; - weak_factory_.InvalidateWeakPtrs(); -} - -void MountedDiskMonitor::SuspendDone( - const base::TimeDelta& sleep_duration) { - // Undo any previous resets. Release the resuming flag after a fixed timeout. - weak_factory_.InvalidateWeakPtrs(); - base::MessageLoopProxy::current()->PostDelayedTask( - FROM_HERE, - base::Bind(&MountedDiskMonitor::Reset, - weak_factory_.GetWeakPtr()), - resuming_time_span_); -} - -bool MountedDiskMonitor::DiskIsRemounting( - const DiskMountManager::Disk& disk) const { - return unmounted_while_resuming_.count(disk.fs_uuid()) > 0; -} - -bool MountedDiskMonitor::DeviceIsHardUnpluggedButNotReported( - const std::string& device_path) const { - const std::map::const_iterator it - = hard_unplugged_.find(device_path); - return it != hard_unplugged_.end() && it->second == HARD_UNPLUGGED; -} - -void MountedDiskMonitor::MarkAsHardUnpluggedReported( - const std::string& device_path) { - hard_unplugged_[device_path] = HARD_UNPLUGGED_AND_REPORTED; -} - -void MountedDiskMonitor::OnMountEvent( - chromeos::disks::DiskMountManager::MountEvent event, - chromeos::MountError error_code, - const chromeos::disks::DiskMountManager::MountPointInfo& mount_info, - const DiskMountManager::Disk* disk) { - if (mount_info.mount_type != chromeos::MOUNT_TYPE_DEVICE) - return; - - switch (event) { - case DiskMountManager::MOUNTING: { - if (!disk || error_code != chromeos::MOUNT_ERROR_NONE) - return; - mounted_disks_[mount_info.source_path] = disk->fs_uuid(); - break; - } - - case DiskMountManager::UNMOUNTING: { - DiskMap::iterator it = mounted_disks_.find(mount_info.source_path); - if (it == mounted_disks_.end()) - return; - const std::string& fs_uuid = it->second; - if (is_resuming_) - unmounted_while_resuming_.insert(fs_uuid); - mounted_disks_.erase(it); - break; - } - } -} - -void MountedDiskMonitor::OnDiskEvent( - chromeos::disks::DiskMountManager::DiskEvent event, - const chromeos::disks::DiskMountManager::Disk* disk) { - if (event == chromeos::disks::DiskMountManager::DISK_REMOVED) { - // If the mount path is not empty, the disk is hard unplugged. - if (!is_resuming_ && - !disk->mount_path().empty() && - hard_unplugged_.find(disk->system_path_prefix()) == - hard_unplugged_.end()) { - hard_unplugged_.insert( - std::make_pair(disk->system_path_prefix(), HARD_UNPLUGGED)); - } - } -} - -void MountedDiskMonitor::OnDeviceEvent( - chromeos::disks::DiskMountManager::DeviceEvent event, - const std::string& device_path) { - if (event == chromeos::disks::DiskMountManager::DEVICE_REMOVED) { - const std::map::iterator it - = hard_unplugged_.find(device_path); - if (it != hard_unplugged_.end()) - hard_unplugged_.erase(it); - } -} - -void MountedDiskMonitor::Reset() { - unmounted_while_resuming_.clear(); - is_resuming_ = false; -} - -} // namespace file_manager diff --git a/chrome/browser/chromeos/file_manager/mounted_disk_monitor.h b/chrome/browser/chromeos/file_manager/mounted_disk_monitor.h deleted file mode 100644 index ebaac2c36d63..000000000000 --- a/chrome/browser/chromeos/file_manager/mounted_disk_monitor.h +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CHROMEOS_FILE_MANAGER_MOUNTED_DISK_MONITOR_H_ -#define CHROME_BROWSER_CHROMEOS_FILE_MANAGER_MOUNTED_DISK_MONITOR_H_ - -#include -#include -#include - -#include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" -#include "chromeos/dbus/power_manager_client.h" -#include "chromeos/disks/disk_mount_manager.h" - -namespace file_manager { - -// Observes PowerManager and updates its state when the system suspends and -// resumes. After the system resumes it will stay in "is_resuming" state for -// couple of seconds. This is to give DiskManager time to process device -// removed/added events (events for the devices that were present before suspend -// should not trigger any new notifications or file manager windows). -class MountedDiskMonitor : public chromeos::PowerManagerClient::Observer { - public: - explicit MountedDiskMonitor( - chromeos::PowerManagerClient* power_manager_client); - virtual ~MountedDiskMonitor(); - - // PowerManagerClient::Observer overrides: - virtual void SuspendImminent() OVERRIDE; - virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE; - - // Receives forwarded notifications originates from DiskMountManager. - void OnDiskEvent( - chromeos::disks::DiskMountManager::DiskEvent event, - const chromeos::disks::DiskMountManager::Disk* disk); - void OnDeviceEvent( - chromeos::disks::DiskMountManager::DeviceEvent event, - const std::string& device_path); - void OnMountEvent( - chromeos::disks::DiskMountManager::MountEvent event, - chromeos::MountError error_code, - const chromeos::disks::DiskMountManager::MountPointInfo& mount_info, - const chromeos::disks::DiskMountManager::Disk* disk); - - // Checks if the disk is being remounted. The disk is remounting if it has - // been unmounted during the resuming time span. - bool DiskIsRemounting( - const chromeos::disks::DiskMountManager::Disk& disk) const; - bool DeviceIsHardUnpluggedButNotReported( - const std::string& device_path) const; - void MarkAsHardUnpluggedReported(const std::string& device_path); - - // In order to avoid consuming time a lot for testing, this allows to set the - // resuming time span. - void set_resuming_time_span_for_testing( - const base::TimeDelta& resuming_time_span) { - resuming_time_span_ = resuming_time_span; - } - - private: - enum HardUnpluggedState { HARD_UNPLUGGED, HARD_UNPLUGGED_AND_REPORTED }; - // Maps source paths with corresponding uuids. - typedef std::map DiskMap; - - // Set of uuids. - typedef std::set DiskSet; - - void Reset(); - - chromeos::PowerManagerClient* power_manager_client_; - - bool is_resuming_; - DiskMap mounted_disks_; - DiskSet unmounted_while_resuming_; - // Set of device path that is hard unplugged. - std::map hard_unplugged_; - base::TimeDelta resuming_time_span_; - base::WeakPtrFactory weak_factory_; - - DISALLOW_COPY_AND_ASSIGN(MountedDiskMonitor); -}; - -} // namespace file_manager - -#endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_MOUNTED_DISK_MONITOR_H_ diff --git a/chrome/browser/chromeos/file_manager/mounted_disk_monitor_unittest.cc b/chrome/browser/chromeos/file_manager/mounted_disk_monitor_unittest.cc deleted file mode 100644 index 7b2345c9a399..000000000000 --- a/chrome/browser/chromeos/file_manager/mounted_disk_monitor_unittest.cc +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/chromeos/file_manager/mounted_disk_monitor.h" - -#include "base/basictypes.h" -#include "base/message_loop/message_loop.h" -#include "base/run_loop.h" -#include "chromeos/dbus/fake_power_manager_client.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace file_manager { -namespace { - -// Creates a fake disk with |device_path| and |fs_uuid|. -scoped_ptr CreateDisk( - const std::string& device_path, - const std::string& fs_uuid) { - return make_scoped_ptr( - new chromeos::disks::DiskMountManager::Disk( - device_path, "", "", "", "", "", "", "", "", "", fs_uuid, "", - chromeos::DEVICE_TYPE_USB, 0, false, false, false, false, false, - false)); -} - -} // namespace - -class MountedDiskMonitorTest : public testing::Test { - protected: - virtual void SetUp() OVERRIDE { - power_manager_client_.reset(new chromeos::FakePowerManagerClient); - mounted_disk_monitor_.reset(new MountedDiskMonitor( - power_manager_client_.get())); - mounted_disk_monitor_->set_resuming_time_span_for_testing( - base::TimeDelta::FromSeconds(0)); - } - - base::MessageLoop message_loop_; - scoped_ptr power_manager_client_; - scoped_ptr mounted_disk_monitor_; -}; - -// Makes sure that just mounting and unmounting repeatedly doesn't affect to -// "remounting" state. -TEST_F(MountedDiskMonitorTest, WithoutSuspend) { - scoped_ptr disk( - CreateDisk("removable_device1", "uuid1")); - - const chromeos::disks::DiskMountManager::MountPointInfo kMountPoint( - "removable_device1", "/tmp/removable_device1", - chromeos::MOUNT_TYPE_DEVICE, chromeos::disks::MOUNT_CONDITION_NONE); - - // First, the disk is not remounting. - EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk)); - - // Simple mounting and unmounting doesn't affect remounting state. - mounted_disk_monitor_->OnMountEvent( - chromeos::disks::DiskMountManager::MOUNTING, - chromeos::MOUNT_ERROR_NONE, - kMountPoint, - disk.get()); - EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk)); - - mounted_disk_monitor_->OnMountEvent( - chromeos::disks::DiskMountManager::UNMOUNTING, - chromeos::MOUNT_ERROR_NONE, - kMountPoint, - disk.get()); - EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk)); - - // Mounting again also should not affect remounting state. - mounted_disk_monitor_->OnMountEvent( - chromeos::disks::DiskMountManager::MOUNTING, - chromeos::MOUNT_ERROR_NONE, - kMountPoint, - disk.get()); - EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk)); -} - -// Makes sure that the unmounting after system resuming triggers the -// "remounting" state, then after some period, the state is reset. -TEST_F(MountedDiskMonitorTest, SuspendAndResume) { - scoped_ptr disk1( - CreateDisk("removable_device1", "uuid1")); - scoped_ptr disk2( - CreateDisk("removable_device2", "uuid2")); - - const chromeos::disks::DiskMountManager::MountPointInfo kMountPoint1( - "removable_device1", "/tmp/removable_device1", - chromeos::MOUNT_TYPE_DEVICE, chromeos::disks::MOUNT_CONDITION_NONE); - const chromeos::disks::DiskMountManager::MountPointInfo kMountPoint2( - "removable_device2", "/tmp/removable_device2", - chromeos::MOUNT_TYPE_DEVICE, chromeos::disks::MOUNT_CONDITION_NONE); - - // Mount |disk1|. - mounted_disk_monitor_->OnMountEvent( - chromeos::disks::DiskMountManager::MOUNTING, - chromeos::MOUNT_ERROR_NONE, - kMountPoint1, - disk1.get()); - EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk1)); - - // Pseudo system suspend and resume. - mounted_disk_monitor_->SuspendImminent(); - mounted_disk_monitor_->SuspendDone(base::TimeDelta::FromSeconds(0)); - - // On system resume, we expect unmount and then mount immediately. - // During the phase, we expect the disk is remounting. - mounted_disk_monitor_->OnMountEvent( - chromeos::disks::DiskMountManager::UNMOUNTING, - chromeos::MOUNT_ERROR_NONE, - kMountPoint1, - disk1.get()); - EXPECT_TRUE(mounted_disk_monitor_->DiskIsRemounting(*disk1)); - - mounted_disk_monitor_->OnMountEvent( - chromeos::disks::DiskMountManager::MOUNTING, - chromeos::MOUNT_ERROR_NONE, - kMountPoint1, - disk1.get()); - EXPECT_TRUE(mounted_disk_monitor_->DiskIsRemounting(*disk1)); - - // New disk should not be "remounting." - EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk2)); - mounted_disk_monitor_->OnMountEvent( - chromeos::disks::DiskMountManager::MOUNTING, - chromeos::MOUNT_ERROR_NONE, - kMountPoint2, - disk2.get()); - EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk2)); - - // After certain period, remounting state should be cleared. - base::RunLoop().RunUntilIdle(); // Emulate time passage. - EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk1)); - EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk2)); -} - -} // namespace file_manager diff --git a/chrome/browser/chromeos/file_manager/volume_manager.cc b/chrome/browser/chromeos/file_manager/volume_manager.cc index bc05c900930a..e64f620825d7 100644 --- a/chrome/browser/chromeos/file_manager/volume_manager.cc +++ b/chrome/browser/chromeos/file_manager/volume_manager.cc @@ -16,7 +16,6 @@ #include "chrome/browser/chromeos/drive/drive_integration_service.h" #include "chrome/browser/chromeos/drive/file_system_interface.h" #include "chrome/browser/chromeos/drive/file_system_util.h" -#include "chrome/browser/chromeos/file_manager/mounted_disk_monitor.h" #include "chrome/browser/chromeos/file_manager/path_util.h" #include "chrome/browser/chromeos/file_manager/snapshot_manager.h" #include "chrome/browser/chromeos/file_manager/volume_manager_factory.h" @@ -38,9 +37,6 @@ namespace file_manager { namespace { -// A named constant to be passed to the |is_remounting| parameter. -const bool kNotRemounting = false; - const char kFileManagerMTPMountNamePrefix[] = "fileman-mtp-"; const char kMtpVolumeIdPrefix [] = "mtp:"; @@ -255,7 +251,6 @@ VolumeManager::VolumeManager( : profile_(profile), drive_integration_service_(drive_integration_service), disk_mount_manager_(disk_mount_manager), - mounted_disk_monitor_(new MountedDiskMonitor(power_manager_client)), file_system_provider_service_(file_system_provider_service), snapshot_manager_(new SnapshotManager(profile_)), weak_ptr_factory_(this) { @@ -296,16 +291,14 @@ void VolumeManager::Initialize() { DCHECK(success); DoMountEvent(chromeos::MOUNT_ERROR_NONE, - CreateDownloadsVolumeInfo(downloads), - kNotRemounting); + CreateDownloadsVolumeInfo(downloads)); // Subscribe to DriveIntegrationService. if (drive_integration_service_) { drive_integration_service_->AddObserver(this); if (drive_integration_service_->IsMounted()) { DoMountEvent(chromeos::MOUNT_ERROR_NONE, - CreateDriveVolumeInfo(profile_), - kNotRemounting); + CreateDriveVolumeInfo(profile_)); } } @@ -326,7 +319,7 @@ void VolumeManager::Initialize() { for (size_t i = 0; i < file_system_info_list.size(); ++i) { VolumeInfo volume_info = CreateProvidedFileSystemVolumeInfo(file_system_info_list[i]); - DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, kNotRemounting); + DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info); } } @@ -424,8 +417,7 @@ bool VolumeManager::RegisterDownloadsDirectoryForTesting( bool success = RegisterDownloadsMountPoint(profile_, path); DoMountEvent( success ? chromeos::MOUNT_ERROR_NONE : chromeos::MOUNT_ERROR_INVALID_PATH, - CreateDownloadsVolumeInfo(path), - kNotRemounting); + CreateDownloadsVolumeInfo(path)); return success; } @@ -434,8 +426,7 @@ void VolumeManager::AddVolumeInfoForTesting(const base::FilePath& path, chromeos::DeviceType device_type) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DoMountEvent(chromeos::MOUNT_ERROR_NONE, - CreateTestingVolumeInfo(path, volume_type, device_type), - kNotRemounting); + CreateTestingVolumeInfo(path, volume_type, device_type)); } void VolumeManager::OnFileSystemMounted() { @@ -445,7 +436,7 @@ void VolumeManager::OnFileSystemMounted() { // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed // or network is unreachable. These two errors will be handled later. VolumeInfo volume_info = CreateDriveVolumeInfo(profile_); - DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, kNotRemounting); + DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info); } void VolumeManager::OnFileSystemBeingUnmounted() { @@ -460,8 +451,6 @@ void VolumeManager::OnDiskEvent( const chromeos::disks::DiskMountManager::Disk* disk) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - mounted_disk_monitor_->OnDiskEvent(event, disk); - // Disregard hidden devices. if (disk->is_hidden()) return; @@ -506,11 +495,6 @@ void VolumeManager::OnDiskEvent( // Notify to observers. FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, OnDiskRemoved(*disk)); - const std::string& device_path = disk->system_path_prefix(); - if (mounted_disk_monitor_->DeviceIsHardUnpluggedButNotReported( - device_path)) { - mounted_disk_monitor_->MarkAsHardUnpluggedReported(device_path); - } return; } NOTREACHED(); @@ -521,8 +505,6 @@ void VolumeManager::OnDeviceEvent( const std::string& device_path) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - mounted_disk_monitor_->OnDeviceEvent(event, device_path); - DVLOG(1) << "OnDeviceEvent: " << event << ", " << device_path; switch (event) { case chromeos::disks::DiskMountManager::DEVICE_ADDED: @@ -548,10 +530,6 @@ void VolumeManager::OnMountEvent( DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_NE(chromeos::MOUNT_TYPE_INVALID, mount_info.mount_type); - const chromeos::disks::DiskMountManager::Disk* disk = - disk_mount_manager_->FindDiskBySourcePath(mount_info.source_path); - mounted_disk_monitor_->OnMountEvent(event, error_code, mount_info, disk); - if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { // If the file is not mounted now, tell it to drive file system so that // it can handle file caching correctly. @@ -561,7 +539,7 @@ void VolumeManager::OnMountEvent( error_code != chromeos::MOUNT_ERROR_NONE) || (event == chromeos::disks::DiskMountManager::UNMOUNTING && error_code == chromeos::MOUNT_ERROR_NONE)) { - drive::FileSystemInterface* file_system = + drive::FileSystemInterface* const file_system = drive::util::GetFileSystemByProfile(profile_); if (file_system) { file_system->MarkCacheFileAsUnmounted( @@ -572,13 +550,13 @@ void VolumeManager::OnMountEvent( } // Notify a mounting/unmounting event to observers. - VolumeInfo volume_info = + const chromeos::disks::DiskMountManager::Disk* const disk = + disk_mount_manager_->FindDiskBySourcePath(mount_info.source_path); + const VolumeInfo volume_info = CreateVolumeInfoFromMountPointInfo(mount_info, disk); switch (event) { case chromeos::disks::DiskMountManager::MOUNTING: { - bool is_remounting = - disk && mounted_disk_monitor_->DiskIsRemounting(*disk); - DoMountEvent(error_code, volume_info, is_remounting); + DoMountEvent(error_code, volume_info); return; } case chromeos::disks::DiskMountManager::UNMOUNTING: @@ -634,7 +612,7 @@ void VolumeManager::OnProvidedFileSystemMount( const chromeos::MountError mount_error = error == base::File::FILE_OK ? chromeos::MOUNT_ERROR_NONE : chromeos::MOUNT_ERROR_UNKNOWN; - DoMountEvent(mount_error, volume_info, kNotRemounting); + DoMountEvent(mount_error, volume_info); } void VolumeManager::OnProvidedFileSystemUnmount( @@ -674,7 +652,7 @@ void VolumeManager::OnPrivetVolumesAvailable( for (local_discovery::PrivetVolumeLister::VolumeList::const_iterator i = volumes.begin(); i != volumes.end(); i++) { VolumeInfo volume_info = CreatePrivetVolumeInfo(*i); - DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, false); + DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info); } } @@ -717,7 +695,7 @@ void VolumeManager::OnRemovableStorageAttached( volume_info.volume_label = label; volume_info.source_path = path; volume_info.device_type = chromeos::DEVICE_TYPE_MOBILE; - DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, false); + DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info); } void VolumeManager::OnRemovableStorageDetached( @@ -765,8 +743,7 @@ void VolumeManager::OnDiskMountManagerRefreshed(bool success) { chromeos::MOUNT_ERROR_NONE, CreateVolumeInfoFromMountPointInfo( it->second, - disk_mount_manager_->FindDiskBySourcePath(it->second.source_path)), - kNotRemounting); + disk_mount_manager_->FindDiskBySourcePath(it->second.source_path))); } // We mount archives only if they are opened from currently mounted volumes. @@ -792,7 +769,7 @@ void VolumeManager::OnDiskMountManagerRefreshed(bool success) { // Mount from the tail of chain. for (size_t i = chain.size(); i > 0; --i) - DoMountEvent(chromeos::MOUNT_ERROR_NONE, chain[i - 1], kNotRemounting); + DoMountEvent(chromeos::MOUNT_ERROR_NONE, chain[i - 1]); } } @@ -805,8 +782,7 @@ void VolumeManager::OnStorageMonitorInitialized() { } void VolumeManager::DoMountEvent(chromeos::MountError error_code, - const VolumeInfo& volume_info, - bool is_remounting) { + const VolumeInfo& volume_info) { // Archive files are mounted globally in system. We however don't want to show // archives from profile-specific folders (Drive/Downloads) of other users in // multi-profile session. To this end, we filter out archives not on the @@ -835,16 +811,15 @@ void VolumeManager::DoMountEvent(chromeos::MountError error_code, if (error_code == chromeos::MOUNT_ERROR_NONE || volume_info.mount_condition) { mounted_volumes_[volume_info.volume_id] = volume_info; - if (!is_remounting) { - UMA_HISTOGRAM_ENUMERATION("FileBrowser.VolumeType", - volume_info.type, - NUM_VOLUME_TYPE); - } + + UMA_HISTOGRAM_ENUMERATION("FileBrowser.VolumeType", + volume_info.type, + NUM_VOLUME_TYPE); } FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, - OnVolumeMounted(error_code, volume_info, is_remounting)); + OnVolumeMounted(error_code, volume_info)); } void VolumeManager::DoUnmountEvent(chromeos::MountError error_code, diff --git a/chrome/browser/chromeos/file_manager/volume_manager.h b/chrome/browser/chromeos/file_manager/volume_manager.h index 209c1bfc0f3a..4126073b1ba1 100644 --- a/chrome/browser/chromeos/file_manager/volume_manager.h +++ b/chrome/browser/chromeos/file_manager/volume_manager.h @@ -211,15 +211,13 @@ class VolumeManager : public KeyedService, void OnPrivetVolumesAvailable( const local_discovery::PrivetVolumeLister::VolumeList& volumes); void DoMountEvent(chromeos::MountError error_code, - const VolumeInfo& volume_info, - bool is_remounting); + const VolumeInfo& volume_info); void DoUnmountEvent(chromeos::MountError error_code, const VolumeInfo& volume_info); Profile* profile_; drive::DriveIntegrationService* drive_integration_service_; // Not owned. chromeos::disks::DiskMountManager* disk_mount_manager_; // Not owned. - scoped_ptr mounted_disk_monitor_; PrefChangeRegistrar pref_change_registrar_; ObserverList observers_; scoped_ptr privet_volume_lister_; diff --git a/chrome/browser/chromeos/file_manager/volume_manager_observer.h b/chrome/browser/chromeos/file_manager/volume_manager_observer.h index 12952f2a4809..27f2c8706cfd 100644 --- a/chrome/browser/chromeos/file_manager/volume_manager_observer.h +++ b/chrome/browser/chromeos/file_manager/volume_manager_observer.h @@ -35,8 +35,7 @@ class VolumeManagerObserver { // Fired when a volume is mounted. virtual void OnVolumeMounted(chromeos::MountError error_code, - const VolumeInfo& volume_info, - bool is_remounting) = 0; + const VolumeInfo& volume_info) = 0; // Fired when a volume is unmounted. virtual void OnVolumeUnmounted(chromeos::MountError error_code, diff --git a/chrome/browser/chromeos/file_manager/volume_manager_unittest.cc b/chrome/browser/chromeos/file_manager/volume_manager_unittest.cc index 92c308d96026..3e0748b142ce 100644 --- a/chrome/browser/chromeos/file_manager/volume_manager_unittest.cc +++ b/chrome/browser/chromeos/file_manager/volume_manager_unittest.cc @@ -50,9 +50,6 @@ class LoggingObserver : public VolumeManagerObserver { // Available on VOLUME_MOUNTED and VOLUME_UNMOUNTED. chromeos::MountError mount_error; - // Available on VOLUME_MOUNTED. - bool is_remounting; - // Available on FORMAT_STARTED and FORMAT_COMPLETED. bool success; }; @@ -95,13 +92,11 @@ class LoggingObserver : public VolumeManagerObserver { } virtual void OnVolumeMounted(chromeos::MountError error_code, - const VolumeInfo& volume_info, - bool is_remounting) OVERRIDE { + const VolumeInfo& volume_info) OVERRIDE { Event event; event.type = Event::VOLUME_MOUNTED; event.device_path = volume_info.source_path.AsUTF8Unsafe(); event.mount_error = error_code; - event.is_remounting = is_remounting; events_.push_back(event); } @@ -205,7 +200,6 @@ TEST_F(VolumeManagerTest, OnDriveFileSystemMountAndUnmount) { EXPECT_EQ(drive::util::GetDriveMountPointPath(profile()).AsUTF8Unsafe(), event.device_path); EXPECT_EQ(chromeos::MOUNT_ERROR_NONE, event.mount_error); - EXPECT_FALSE(event.is_remounting); volume_manager()->OnFileSystemBeingUnmounted(); @@ -497,7 +491,6 @@ TEST_F(VolumeManagerTest, OnMountEvent_MountingAndUnmounting) { EXPECT_EQ(LoggingObserver::Event::VOLUME_MOUNTED, event.type); EXPECT_EQ("device1", event.device_path); EXPECT_EQ(chromeos::MOUNT_ERROR_NONE, event.mount_error); - EXPECT_FALSE(event.is_remounting); volume_manager()->OnMountEvent(chromeos::disks::DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE, @@ -560,7 +553,6 @@ TEST_F(VolumeManagerTest, OnMountEvent_Remounting) { EXPECT_EQ(LoggingObserver::Event::VOLUME_MOUNTED, event.type); EXPECT_EQ("device1", event.device_path); EXPECT_EQ(chromeos::MOUNT_ERROR_NONE, event.mount_error); - EXPECT_TRUE(event.is_remounting); volume_manager()->RemoveObserver(&observer); } diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi index 3162b182c513..a8257f48fbb2 100644 --- a/chrome/chrome_browser_chromeos.gypi +++ b/chrome/chrome_browser_chromeos.gypi @@ -366,8 +366,6 @@ 'browser/chromeos/file_manager/fileapi_util.h', 'browser/chromeos/file_manager/filesystem_api_util.cc', 'browser/chromeos/file_manager/filesystem_api_util.h', - 'browser/chromeos/file_manager/mounted_disk_monitor.cc', - 'browser/chromeos/file_manager/mounted_disk_monitor.h', 'browser/chromeos/file_manager/open_util.cc', 'browser/chromeos/file_manager/open_util.h', 'browser/chromeos/file_manager/open_with_browser.cc', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 519abb0851d1..142609e201f2 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -686,7 +686,6 @@ 'browser/chromeos/file_manager/fake_disk_mount_manager.h', 'browser/chromeos/file_manager/file_tasks_unittest.cc', 'browser/chromeos/file_manager/file_watcher_unittest.cc', - 'browser/chromeos/file_manager/mounted_disk_monitor_unittest.cc', 'browser/chromeos/file_manager/path_util_unittest.cc', 'browser/chromeos/file_manager/url_util_unittest.cc', 'browser/chromeos/file_manager/volume_manager_unittest.cc', -- 2.11.4.GIT