diff options
author | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-07 01:08:57 +0000 |
---|---|---|
committer | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-07 01:08:57 +0000 |
commit | bcfa007f7f77709443d15f41307c9d3f8a6d6173 (patch) | |
tree | 6eb3f2f8255d7f667e4eddd629830e01a61a8eaf /chrome | |
parent | d5b6684366b6c3e3f0af682126b4828c71bbc16a (diff) | |
download | chromium_src-bcfa007f7f77709443d15f41307c9d3f8a6d6173.zip chromium_src-bcfa007f7f77709443d15f41307c9d3f8a6d6173.tar.gz chromium_src-bcfa007f7f77709443d15f41307c9d3f8a6d6173.tar.bz2 |
Created a helper function "FindDiskBySourcePath" in DiskMountManager.
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10829160
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150205 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
9 files changed, 56 insertions, 24 deletions
diff --git a/chrome/browser/chromeos/disks/disk_mount_manager.cc b/chrome/browser/chromeos/disks/disk_mount_manager.cc index 98e24ac..388259c 100644 --- a/chrome/browser/chromeos/disks/disk_mount_manager.cc +++ b/chrome/browser/chromeos/disks/disk_mount_manager.cc @@ -230,6 +230,12 @@ class DiskMountManagerImpl : public DiskMountManager { // DiskMountManager override. const DiskMap& disks() const OVERRIDE { return disks_; } + // DiskMountManager override. + virtual const Disk* FindDiskBySourcePath(const std::string& source_path) + const OVERRIDE { + DiskMap::const_iterator disk_it = disks_.find(source_path); + return disk_it == disks_.end() ? NULL : disk_it->second; + } // DiskMountManager override. const MountPointMap& mount_points() const OVERRIDE { return mount_points_; } diff --git a/chrome/browser/chromeos/disks/disk_mount_manager.h b/chrome/browser/chromeos/disks/disk_mount_manager.h index df6dd18..546c4b7 100644 --- a/chrome/browser/chromeos/disks/disk_mount_manager.h +++ b/chrome/browser/chromeos/disks/disk_mount_manager.h @@ -198,6 +198,10 @@ class DiskMountManager { // Gets the list of disks found. virtual const DiskMap& disks() const = 0; + // Returns Disk object corresponding to |source_path| or NULL on failure. + virtual const Disk* FindDiskBySourcePath( + const std::string& source_path) const = 0; + // Gets the list of mount points. virtual const MountPointMap& mount_points() const = 0; diff --git a/chrome/browser/chromeos/disks/mock_disk_mount_manager.cc b/chrome/browser/chromeos/disks/mock_disk_mount_manager.cc index 3890965..de08ebe 100644 --- a/chrome/browser/chromeos/disks/mock_disk_mount_manager.cc +++ b/chrome/browser/chromeos/disks/mock_disk_mount_manager.cc @@ -53,6 +53,9 @@ MockDiskMountManager::MockDiskMountManager() { .WillByDefault(Invoke(this, &MockDiskMountManager::disksInternal)); ON_CALL(*this, mount_points()) .WillByDefault(Invoke(this, &MockDiskMountManager::mountPointsInternal)); + ON_CALL(*this, FindDiskBySourcePath(_)) + .WillByDefault(Invoke( + this, &MockDiskMountManager::FindDiskBySourcePathInternal)); } MockDiskMountManager::~MockDiskMountManager() { @@ -147,6 +150,8 @@ void MockDiskMountManager::SetupDefaultReplies() { .WillRepeatedly(ReturnRef(disks_)); EXPECT_CALL(*this, mount_points()) .WillRepeatedly(ReturnRef(mount_points_)); + EXPECT_CALL(*this, FindDiskBySourcePath(_)) + .Times(AnyNumber()); EXPECT_CALL(*this, RequestMountInfoRefresh()) .Times(AnyNumber()); EXPECT_CALL(*this, MountPath(_, _, _, _)) @@ -202,6 +207,13 @@ MockDiskMountManager::mountPointsInternal() const { return mount_points_; } +const DiskMountManager::Disk* +MockDiskMountManager::FindDiskBySourcePathInternal( + const std::string& source_path) const { + DiskMap::const_iterator disk_it = disks_.find(source_path); + return disk_it == disks_.end() ? NULL : disk_it->second; +} + void MockDiskMountManager::NotifyDiskChanged( DiskMountManagerEventType event, const DiskMountManager::Disk* disk) { diff --git a/chrome/browser/chromeos/disks/mock_disk_mount_manager.h b/chrome/browser/chromeos/disks/mock_disk_mount_manager.h index 78d787b..aec2894 100644 --- a/chrome/browser/chromeos/disks/mock_disk_mount_manager.h +++ b/chrome/browser/chromeos/disks/mock_disk_mount_manager.h @@ -26,6 +26,8 @@ class MockDiskMountManager : public DiskMountManager { MOCK_METHOD1(AddObserver, void(DiskMountManager::Observer*)); MOCK_METHOD1(RemoveObserver, void(DiskMountManager::Observer*)); MOCK_CONST_METHOD0(disks, const DiskMountManager::DiskMap&(void)); + MOCK_CONST_METHOD1(FindDiskBySourcePath, + const DiskMountManager::Disk*(const std::string&)); MOCK_CONST_METHOD0(mount_points, const DiskMountManager::MountPointMap&(void)); MOCK_METHOD0(RequestMountInfoRefresh, void(void)); @@ -69,9 +71,12 @@ class MockDiskMountManager : public DiskMountManager { // Is used to implement disks. const DiskMountManager::DiskMap& disksInternal() const { return disks_; } - // This function is primarily for MediaDeviceNotificationsTest. const DiskMountManager::MountPointMap& mountPointsInternal() const; + // Returns Disk object associated with the |source_path| or NULL on failure. + const DiskMountManager::Disk* FindDiskBySourcePathInternal( + const std::string& source_path) const; + // Notifies observers about device status update. void NotifyDeviceChanged(DiskMountManagerEventType event, const std::string& path); diff --git a/chrome/browser/chromeos/extensions/file_browser_event_router.cc b/chrome/browser/chromeos/extensions/file_browser_event_router.cc index 5858978..01dd0dd 100644 --- a/chrome/browser/chromeos/extensions/file_browser_event_router.cc +++ b/chrome/browser/chromeos/extensions/file_browser_event_router.cc @@ -340,12 +340,10 @@ void FileBrowserEventRouter::MountCompleted( if (mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && event_type == DiskMountManager::MOUNTING) { DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); - DiskMountManager::DiskMap::const_iterator disk_it = - disk_mount_manager->disks().find(mount_info.source_path); - if (disk_it == disk_mount_manager->disks().end()) { + const DiskMountManager::Disk* disk = + disk_mount_manager->FindDiskBySourcePath(mount_info.source_path); + if (!disk) return; - } - DiskMountManager::Disk* disk = disk_it->second; notifications_->ManageNotificationsOnMountCompleted( disk->system_path_prefix(), disk->drive_label(), disk->is_parent(), diff --git a/chrome/browser/chromeos/extensions/file_browser_private_api.cc b/chrome/browser/chromeos/extensions/file_browser_private_api.cc index 48fa84f..1f4c8b4 100644 --- a/chrome/browser/chromeos/extensions/file_browser_private_api.cc +++ b/chrome/browser/chromeos/extensions/file_browser_private_api.cc @@ -108,15 +108,10 @@ const DiskMountManager::Disk* GetVolumeAsDisk(const std::string& mount_path) { if (mount_point_it == disk_mount_manager->mount_points().end()) return NULL; - DiskMountManager::DiskMap::const_iterator disk_it = - disk_mount_manager->disks().find(mount_point_it->second.source_path); + const DiskMountManager::Disk* disk = disk_mount_manager->FindDiskBySourcePath( + mount_point_it->second.source_path); - if (disk_it == disk_mount_manager->disks().end() || - disk_it->second->is_hidden()) { - return NULL; - } - - return disk_it->second; + return (disk && disk->is_hidden()) ? NULL : disk; } base::DictionaryValue* CreateValueFromDisk( diff --git a/chrome/browser/chromeos/extensions/file_browser_private_apitest.cc b/chrome/browser/chromeos/extensions/file_browser_private_apitest.cc index 303dbcd..a70d348 100644 --- a/chrome/browser/chromeos/extensions/file_browser_private_apitest.cc +++ b/chrome/browser/chromeos/extensions/file_browser_private_apitest.cc @@ -15,6 +15,7 @@ #include "webkit/fileapi/file_system_mount_point_provider.h" using ::testing::_; +using ::testing::AnyNumber; using ::testing::ReturnRef; using ::testing::StrEq; using content::BrowserContext; @@ -152,6 +153,11 @@ class ExtensionFileBrowserPrivateApiTest : public ExtensionApiTest { chromeos::disks::DiskMountManager::InitializeForTesting( disk_mount_manager_mock_); disk_mount_manager_mock_->SetupDefaultReplies(); + + // OVERRIDE FindDiskBySourcePath mock function. + ON_CALL(*disk_mount_manager_mock_, FindDiskBySourcePath(_)). + WillByDefault(Invoke( + this, &ExtensionFileBrowserPrivateApiTest::FindVolumeBySourcePath)); } // ExtensionApiTest override @@ -210,6 +216,13 @@ class ExtensionFileBrowserPrivateApiTest : public ExtensionApiTest { } } + const DiskMountManager::Disk* FindVolumeBySourcePath( + const std::string& source_path) { + DiskMountManager::DiskMap::const_iterator volume_it = + volumes_.find(source_path); + return (volume_it == volumes_.end()) ? NULL : volume_it->second; + } + protected: chromeos::disks::MockDiskMountManager* disk_mount_manager_mock_; DiskMountManager::DiskMap volumes_; diff --git a/chrome/browser/chromeos/imageburner/burn_controller.cc b/chrome/browser/chromeos/imageburner/burn_controller.cc index f83f23a..33991e3 100644 --- a/chrome/browser/chromeos/imageburner/burn_controller.cc +++ b/chrome/browser/chromeos/imageburner/burn_controller.cc @@ -334,8 +334,9 @@ class BurnControllerImpl int64 GetDeviceSize(const std::string& device_path) { disks::DiskMountManager* disk_mount_manager = disks::DiskMountManager::GetInstance(); - const disks::DiskMountManager::DiskMap& disks = disk_mount_manager->disks(); - return disks.find(device_path)->second->total_size_in_bytes(); + const disks::DiskMountManager::Disk* disk = + disk_mount_manager->FindDiskBySourcePath(device_path); + return disk ? disk->total_size_in_bytes() : 0; } bool CheckNetwork() { diff --git a/chrome/browser/media_gallery/media_device_notifications_chromeos.cc b/chrome/browser/media_gallery/media_device_notifications_chromeos.cc index 9d29a73..7a9b4d8 100644 --- a/chrome/browser/media_gallery/media_device_notifications_chromeos.cc +++ b/chrome/browser/media_gallery/media_device_notifications_chromeos.cc @@ -22,20 +22,18 @@ namespace { bool GetDeviceInfo(const std::string& source_path, std::string* device_id, string16* device_label) { // Get the media device uuid and label if exists. - const disks::DiskMountManager::DiskMap& disks = - disks::DiskMountManager::GetInstance()->disks(); - disks::DiskMountManager::DiskMap::const_iterator it = disks.find(source_path); - if (it == disks.end()) + const disks::DiskMountManager::Disk* disk = + disks::DiskMountManager::GetInstance()->FindDiskBySourcePath(source_path); + if (!disk) return false; - const disks::DiskMountManager::Disk& disk = *(it->second); - *device_id = disk.fs_uuid(); + *device_id = disk->fs_uuid(); // TODO(kmadhusu): If device label is empty, extract vendor and model details // and use them as device_label. - *device_label = UTF8ToUTF16(disk.device_label().empty() ? + *device_label = UTF8ToUTF16(disk->device_label().empty() ? FilePath(source_path).BaseName().value() : - disk.device_label()); + disk->device_label()); return true; } |