Commit bcfa007f authored by kmadhusu@chromium.org's avatar kmadhusu@chromium.org

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
parent d5b66843
...@@ -230,6 +230,12 @@ class DiskMountManagerImpl : public DiskMountManager { ...@@ -230,6 +230,12 @@ class DiskMountManagerImpl : public DiskMountManager {
// DiskMountManager override. // DiskMountManager override.
const DiskMap& disks() const OVERRIDE { return disks_; } 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. // DiskMountManager override.
const MountPointMap& mount_points() const OVERRIDE { return mount_points_; } const MountPointMap& mount_points() const OVERRIDE { return mount_points_; }
......
...@@ -198,6 +198,10 @@ class DiskMountManager { ...@@ -198,6 +198,10 @@ class DiskMountManager {
// Gets the list of disks found. // Gets the list of disks found.
virtual const DiskMap& disks() const = 0; 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. // Gets the list of mount points.
virtual const MountPointMap& mount_points() const = 0; virtual const MountPointMap& mount_points() const = 0;
......
...@@ -53,6 +53,9 @@ MockDiskMountManager::MockDiskMountManager() { ...@@ -53,6 +53,9 @@ MockDiskMountManager::MockDiskMountManager() {
.WillByDefault(Invoke(this, &MockDiskMountManager::disksInternal)); .WillByDefault(Invoke(this, &MockDiskMountManager::disksInternal));
ON_CALL(*this, mount_points()) ON_CALL(*this, mount_points())
.WillByDefault(Invoke(this, &MockDiskMountManager::mountPointsInternal)); .WillByDefault(Invoke(this, &MockDiskMountManager::mountPointsInternal));
ON_CALL(*this, FindDiskBySourcePath(_))
.WillByDefault(Invoke(
this, &MockDiskMountManager::FindDiskBySourcePathInternal));
} }
MockDiskMountManager::~MockDiskMountManager() { MockDiskMountManager::~MockDiskMountManager() {
...@@ -147,6 +150,8 @@ void MockDiskMountManager::SetupDefaultReplies() { ...@@ -147,6 +150,8 @@ void MockDiskMountManager::SetupDefaultReplies() {
.WillRepeatedly(ReturnRef(disks_)); .WillRepeatedly(ReturnRef(disks_));
EXPECT_CALL(*this, mount_points()) EXPECT_CALL(*this, mount_points())
.WillRepeatedly(ReturnRef(mount_points_)); .WillRepeatedly(ReturnRef(mount_points_));
EXPECT_CALL(*this, FindDiskBySourcePath(_))
.Times(AnyNumber());
EXPECT_CALL(*this, RequestMountInfoRefresh()) EXPECT_CALL(*this, RequestMountInfoRefresh())
.Times(AnyNumber()); .Times(AnyNumber());
EXPECT_CALL(*this, MountPath(_, _, _, _)) EXPECT_CALL(*this, MountPath(_, _, _, _))
...@@ -202,6 +207,13 @@ MockDiskMountManager::mountPointsInternal() const { ...@@ -202,6 +207,13 @@ MockDiskMountManager::mountPointsInternal() const {
return mount_points_; 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( void MockDiskMountManager::NotifyDiskChanged(
DiskMountManagerEventType event, DiskMountManagerEventType event,
const DiskMountManager::Disk* disk) { const DiskMountManager::Disk* disk) {
......
...@@ -26,6 +26,8 @@ class MockDiskMountManager : public DiskMountManager { ...@@ -26,6 +26,8 @@ class MockDiskMountManager : public DiskMountManager {
MOCK_METHOD1(AddObserver, void(DiskMountManager::Observer*)); MOCK_METHOD1(AddObserver, void(DiskMountManager::Observer*));
MOCK_METHOD1(RemoveObserver, void(DiskMountManager::Observer*)); MOCK_METHOD1(RemoveObserver, void(DiskMountManager::Observer*));
MOCK_CONST_METHOD0(disks, const DiskMountManager::DiskMap&(void)); MOCK_CONST_METHOD0(disks, const DiskMountManager::DiskMap&(void));
MOCK_CONST_METHOD1(FindDiskBySourcePath,
const DiskMountManager::Disk*(const std::string&));
MOCK_CONST_METHOD0(mount_points, MOCK_CONST_METHOD0(mount_points,
const DiskMountManager::MountPointMap&(void)); const DiskMountManager::MountPointMap&(void));
MOCK_METHOD0(RequestMountInfoRefresh, void(void)); MOCK_METHOD0(RequestMountInfoRefresh, void(void));
...@@ -69,9 +71,12 @@ class MockDiskMountManager : public DiskMountManager { ...@@ -69,9 +71,12 @@ class MockDiskMountManager : public DiskMountManager {
// Is used to implement disks. // Is used to implement disks.
const DiskMountManager::DiskMap& disksInternal() const { return disks_; } const DiskMountManager::DiskMap& disksInternal() const { return disks_; }
// This function is primarily for MediaDeviceNotificationsTest.
const DiskMountManager::MountPointMap& mountPointsInternal() const; 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. // Notifies observers about device status update.
void NotifyDeviceChanged(DiskMountManagerEventType event, void NotifyDeviceChanged(DiskMountManagerEventType event,
const std::string& path); const std::string& path);
......
...@@ -340,12 +340,10 @@ void FileBrowserEventRouter::MountCompleted( ...@@ -340,12 +340,10 @@ void FileBrowserEventRouter::MountCompleted(
if (mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && if (mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE &&
event_type == DiskMountManager::MOUNTING) { event_type == DiskMountManager::MOUNTING) {
DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance();
DiskMountManager::DiskMap::const_iterator disk_it = const DiskMountManager::Disk* disk =
disk_mount_manager->disks().find(mount_info.source_path); disk_mount_manager->FindDiskBySourcePath(mount_info.source_path);
if (disk_it == disk_mount_manager->disks().end()) { if (!disk)
return; return;
}
DiskMountManager::Disk* disk = disk_it->second;
notifications_->ManageNotificationsOnMountCompleted( notifications_->ManageNotificationsOnMountCompleted(
disk->system_path_prefix(), disk->drive_label(), disk->is_parent(), disk->system_path_prefix(), disk->drive_label(), disk->is_parent(),
......
...@@ -108,15 +108,10 @@ const DiskMountManager::Disk* GetVolumeAsDisk(const std::string& mount_path) { ...@@ -108,15 +108,10 @@ const DiskMountManager::Disk* GetVolumeAsDisk(const std::string& mount_path) {
if (mount_point_it == disk_mount_manager->mount_points().end()) if (mount_point_it == disk_mount_manager->mount_points().end())
return NULL; return NULL;
DiskMountManager::DiskMap::const_iterator disk_it = const DiskMountManager::Disk* disk = disk_mount_manager->FindDiskBySourcePath(
disk_mount_manager->disks().find(mount_point_it->second.source_path); mount_point_it->second.source_path);
if (disk_it == disk_mount_manager->disks().end() || return (disk && disk->is_hidden()) ? NULL : disk;
disk_it->second->is_hidden()) {
return NULL;
}
return disk_it->second;
} }
base::DictionaryValue* CreateValueFromDisk( base::DictionaryValue* CreateValueFromDisk(
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "webkit/fileapi/file_system_mount_point_provider.h" #include "webkit/fileapi/file_system_mount_point_provider.h"
using ::testing::_; using ::testing::_;
using ::testing::AnyNumber;
using ::testing::ReturnRef; using ::testing::ReturnRef;
using ::testing::StrEq; using ::testing::StrEq;
using content::BrowserContext; using content::BrowserContext;
...@@ -152,6 +153,11 @@ class ExtensionFileBrowserPrivateApiTest : public ExtensionApiTest { ...@@ -152,6 +153,11 @@ class ExtensionFileBrowserPrivateApiTest : public ExtensionApiTest {
chromeos::disks::DiskMountManager::InitializeForTesting( chromeos::disks::DiskMountManager::InitializeForTesting(
disk_mount_manager_mock_); disk_mount_manager_mock_);
disk_mount_manager_mock_->SetupDefaultReplies(); disk_mount_manager_mock_->SetupDefaultReplies();
// OVERRIDE FindDiskBySourcePath mock function.
ON_CALL(*disk_mount_manager_mock_, FindDiskBySourcePath(_)).
WillByDefault(Invoke(
this, &ExtensionFileBrowserPrivateApiTest::FindVolumeBySourcePath));
} }
// ExtensionApiTest override // ExtensionApiTest override
...@@ -210,6 +216,13 @@ class ExtensionFileBrowserPrivateApiTest : public ExtensionApiTest { ...@@ -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: protected:
chromeos::disks::MockDiskMountManager* disk_mount_manager_mock_; chromeos::disks::MockDiskMountManager* disk_mount_manager_mock_;
DiskMountManager::DiskMap volumes_; DiskMountManager::DiskMap volumes_;
......
...@@ -334,8 +334,9 @@ class BurnControllerImpl ...@@ -334,8 +334,9 @@ class BurnControllerImpl
int64 GetDeviceSize(const std::string& device_path) { int64 GetDeviceSize(const std::string& device_path) {
disks::DiskMountManager* disk_mount_manager = disks::DiskMountManager* disk_mount_manager =
disks::DiskMountManager::GetInstance(); disks::DiskMountManager::GetInstance();
const disks::DiskMountManager::DiskMap& disks = disk_mount_manager->disks(); const disks::DiskMountManager::Disk* disk =
return disks.find(device_path)->second->total_size_in_bytes(); disk_mount_manager->FindDiskBySourcePath(device_path);
return disk ? disk->total_size_in_bytes() : 0;
} }
bool CheckNetwork() { bool CheckNetwork() {
......
...@@ -22,20 +22,18 @@ namespace { ...@@ -22,20 +22,18 @@ namespace {
bool GetDeviceInfo(const std::string& source_path, std::string* device_id, bool GetDeviceInfo(const std::string& source_path, std::string* device_id,
string16* device_label) { string16* device_label) {
// Get the media device uuid and label if exists. // Get the media device uuid and label if exists.
const disks::DiskMountManager::DiskMap& disks = const disks::DiskMountManager::Disk* disk =
disks::DiskMountManager::GetInstance()->disks(); disks::DiskMountManager::GetInstance()->FindDiskBySourcePath(source_path);
disks::DiskMountManager::DiskMap::const_iterator it = disks.find(source_path); if (!disk)
if (it == disks.end())
return false; 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 // TODO(kmadhusu): If device label is empty, extract vendor and model details
// and use them as device_label. // 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() : FilePath(source_path).BaseName().value() :
disk.device_label()); disk->device_label());
return true; return true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment