diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-12 02:12:44 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-12 02:12:44 +0000 |
commit | 45afb77f6cf901a879477878f6887d6969551cc8 (patch) | |
tree | de19a60bb041a4a2b82b5a51b3f098c992c8b866 /chrome | |
parent | 63bfb40b91c13a4011efee1e81edf639aa9a8a2d (diff) | |
download | chromium_src-45afb77f6cf901a879477878f6887d6969551cc8.zip chromium_src-45afb77f6cf901a879477878f6887d6969551cc8.tar.gz chromium_src-45afb77f6cf901a879477878f6887d6969551cc8.tar.bz2 |
file_manager: Generate volume IDs in VolumeManager
Along the way, add FindVolumeInfoById() which will be used in
upcomig patches.
BUG=316077
TEST=none
R=kinaba@chromium.org
Review URL: https://codereview.chromium.org/68463002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@234375 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
5 files changed, 77 insertions, 10 deletions
diff --git a/chrome/browser/chromeos/extensions/file_manager/private_api_util.cc b/chrome/browser/chromeos/extensions/file_manager/private_api_util.cc index 6426d09..0198c9e 100644 --- a/chrome/browser/chromeos/extensions/file_manager/private_api_util.cc +++ b/chrome/browser/chromeos/extensions/file_manager/private_api_util.cc @@ -138,10 +138,7 @@ void VolumeInfoToVolumeMetadata( volume_metadata->mount_path = "/" + relative_mount_path.AsUTF8Unsafe(); } - // TODO(satorux): Find a better way to generate unique IDs. IDs should - // probably be assigned when VolumeInfo list is created. For now, IDs are - // generated from the mount path here. crbug.com/316077 - volume_metadata->volume_id = "id:" + volume_metadata->mount_path; + volume_metadata->volume_id = volume_info.volume_id; if (!volume_info.source_path.empty()) { volume_metadata->source_path.reset( diff --git a/chrome/browser/chromeos/file_manager/volume_manager.cc b/chrome/browser/chromeos/file_manager/volume_manager.cc index e3fb8cc..3b190ac 100644 --- a/chrome/browser/chromeos/file_manager/volume_manager.cc +++ b/chrome/browser/chromeos/file_manager/volume_manager.cc @@ -52,6 +52,30 @@ VolumeType MountTypeToVolumeType( return VOLUME_TYPE_DOWNLOADS_DIRECTORY; } +// Returns a string representation of the given volume type. +std::string VolumeTypeToString(VolumeType type) { + switch (type) { + case VOLUME_TYPE_GOOGLE_DRIVE: + return "drive"; + case VOLUME_TYPE_DOWNLOADS_DIRECTORY: + return "downloads"; + case VOLUME_TYPE_REMOVABLE_DISK_PARTITION: + return "removable"; + case VOLUME_TYPE_MOUNTED_ARCHIVE_FILE: + return "archive"; + } + NOTREACHED(); + return ""; +} + +// Generates a unique volume ID for the given volume info. +std::string GenerateVolumeId(const VolumeInfo& volume_info) { + // For the same volume type, base names are unique, as mount points are + // flat for the same volume type. + return (VolumeTypeToString(volume_info.type) + ":" + + volume_info.mount_path.BaseName().AsUTF8Unsafe()); +} + // Returns the VolumeInfo for Drive file system. VolumeInfo CreateDriveVolumeInfo() { const base::FilePath& drive_path = drive::util::GetDriveMountPointPath(); @@ -64,6 +88,7 @@ VolumeInfo CreateDriveVolumeInfo() { volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE; volume_info.is_parent = false; volume_info.is_read_only = false; + volume_info.volume_id = GenerateVolumeId(volume_info); return volume_info; } @@ -77,6 +102,7 @@ VolumeInfo CreateDownloadsVolumeInfo( volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE; volume_info.is_parent = false; volume_info.is_read_only = false; + volume_info.volume_id = GenerateVolumeId(volume_info); return volume_info; } @@ -100,6 +126,7 @@ VolumeInfo CreateVolumeInfoFromMountPointInfo( volume_info.is_parent = false; volume_info.is_read_only = false; } + volume_info.volume_id = GenerateVolumeId(volume_info); return volume_info; } @@ -236,6 +263,22 @@ std::vector<VolumeInfo> VolumeManager::GetVolumeInfoList() const { return result; } +bool VolumeManager::FindVolumeInfoById(const std::string& volume_id, + VolumeInfo* result) const { + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + DCHECK(result); + + std::vector<VolumeInfo> info_list = GetVolumeInfoList(); + for (size_t i = 0; i < info_list.size(); ++i) { + if (info_list[i].volume_id == volume_id) { + *result = info_list[i]; + return true; + } + } + + return false; +} + void VolumeManager::OnFileSystemMounted() { DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); diff --git a/chrome/browser/chromeos/file_manager/volume_manager.h b/chrome/browser/chromeos/file_manager/volume_manager.h index 73e9093..2d3ccbc 100644 --- a/chrome/browser/chromeos/file_manager/volume_manager.h +++ b/chrome/browser/chromeos/file_manager/volume_manager.h @@ -47,6 +47,9 @@ struct VolumeInfo { VolumeInfo(); ~VolumeInfo(); + // The ID of the volume. + std::string volume_id; + // The type of mounted volume. VolumeType type; @@ -117,6 +120,11 @@ class VolumeManager : public BrowserContextKeyedService, // Returns the information about all volumes currently mounted. std::vector<VolumeInfo> GetVolumeInfoList() const; + // Finds VolumeInfo for the given volume ID. If found, returns true and the + // result is written into |result|. Returns false otherwise. + bool FindVolumeInfoById(const std::string& volume_id, + VolumeInfo* result) const; + // drive::DriveIntegrationServiceObserver overrides. virtual void OnFileSystemMounted() OVERRIDE; virtual void OnFileSystemBeingUnmounted() OVERRIDE; diff --git a/chrome/browser/chromeos/file_manager/volume_manager_unittest.cc b/chrome/browser/chromeos/file_manager/volume_manager_unittest.cc index 2333e06..9fea5ea 100644 --- a/chrome/browser/chromeos/file_manager/volume_manager_unittest.cc +++ b/chrome/browser/chromeos/file_manager/volume_manager_unittest.cc @@ -652,4 +652,23 @@ TEST_F(VolumeManagerTest, OnExternalStorageDisabledChanged) { EXPECT_EQ("mount2", unmount_request2.mount_path); } +TEST_F(VolumeManagerTest, GetVolumeInfoList) { + volume_manager_->Initialize(); // Adds "Downloads" + std::vector<VolumeInfo> info_list = volume_manager_->GetVolumeInfoList(); + ASSERT_EQ(1u, info_list.size()); + EXPECT_EQ("downloads:Downloads", info_list[0].volume_id); + EXPECT_EQ(VOLUME_TYPE_DOWNLOADS_DIRECTORY, info_list[0].type); +} + +TEST_F(VolumeManagerTest, FindVolumeInfoById) { + volume_manager_->Initialize(); // Adds "Downloads" + VolumeInfo volume_info; + ASSERT_FALSE(volume_manager_->FindVolumeInfoById( + "nonexistent", &volume_info)); + ASSERT_TRUE(volume_manager_->FindVolumeInfoById( + "downloads:Downloads", &volume_info)); + EXPECT_EQ("downloads:Downloads", volume_info.volume_id); + EXPECT_EQ(VOLUME_TYPE_DOWNLOADS_DIRECTORY, volume_info.type); +} + } // namespace file_manager diff --git a/chrome/test/data/extensions/api_test/file_browser/mount_test/test.js b/chrome/test/data/extensions/api_test/file_browser/mount_test/test.js index 79db066..741853b 100644 --- a/chrome/test/data/extensions/api_test/file_browser/mount_test/test.js +++ b/chrome/test/data/extensions/api_test/file_browser/mount_test/test.js @@ -4,7 +4,7 @@ // These have to be sync'd with file_browser_private_apitest.cc var expectedVolume1 = { - volumeId: 'id:/removable/mount_path1', + volumeId: 'removable:mount_path1', mountPath: '/removable/mount_path1', sourcePath: 'device_path1', volumeType: 'removable', @@ -13,7 +13,7 @@ var expectedVolume1 = { }; var expectedVolume2 = { - volumeId: 'id:/removable/mount_path2', + volumeId: 'removable:mount_path2', mountPath: '/removable/mount_path2', sourcePath: 'device_path2', volumeType: 'removable', @@ -22,7 +22,7 @@ var expectedVolume2 = { }; var expectedVolume3 = { - volumeId: 'id:/removable/mount_path3', + volumeId: 'removable:mount_path3', mountPath: '/removable/mount_path3', sourcePath: 'device_path3', volumeType: 'removable', @@ -31,14 +31,14 @@ var expectedVolume3 = { }; var expectedDownloadsVolume = { - volumeId: 'id:/Downloads', + volumeId: 'downloads:Downloads', mountPath: '/Downloads', volumeType: 'downloads', isReadOnly: false }; var expectedDriveVolume = { - volumeId: 'id:/drive', + volumeId: 'drive:drive', mountPath: '/drive', sourcePath: '/special/drive', volumeType: 'drive', @@ -46,7 +46,7 @@ var expectedDriveVolume = { }; var expectedArchiveVolume = { - volumeId: 'id:/archive/archive_mount_path', + volumeId: 'archive:archive_mount_path', mountPath: '/archive/archive_mount_path', sourcePath: 'archive_path', volumeType: 'archive', |