Commit 37d8ea29 authored by kinaba@chromium.org's avatar kinaba@chromium.org

Files.app: filter out zip archives mounted in other profiles.

BUG=336124

Review URL: https://codereview.chromium.org/164183004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251319 0039d316-1c4b-4281-b951-d872f2087c98
parent 484b9923
......@@ -173,7 +173,9 @@ class FileBrowserPrivateApiTest : public ExtensionApiTest {
2
},
{
"archive_path",
// Set source path inside another mounted volume.
chromeos::CrosDisksClient::GetRemovableDiskMountPoint().AppendASCII(
"mount_path3/archive.zip").AsUTF8Unsafe(),
chromeos::CrosDisksClient::GetArchiveMountPoint().AppendASCII(
"archive_mount_path").AsUTF8Unsafe(),
chromeos::MOUNT_TYPE_ARCHIVE,
......
......@@ -212,6 +212,8 @@ VolumeManager* VolumeManager::Get(content::BrowserContext* context) {
}
void VolumeManager::Initialize() {
const bool kNotRemounting = false;
// Path to mount user folders have changed several times. We need to migrate
// the old preferences on paths to the new format when needed. For the detail,
// see the comments in file_manager::util::MigratePathFromOldFormat,
......@@ -236,33 +238,66 @@ void VolumeManager::Initialize() {
DoMountEvent(chromeos::MOUNT_ERROR_NONE,
CreateDownloadsVolumeInfo(downloads),
false /* is_remounting */);
kNotRemounting);
}
// Subscribe to DriveIntegrationService.
if (drive_integration_service_) {
drive_integration_service_->AddObserver(this);
if (drive_integration_service_->IsMounted()) {
DoMountEvent(
chromeos::MOUNT_ERROR_NONE, CreateDriveVolumeInfo(profile_), false);
DoMountEvent(chromeos::MOUNT_ERROR_NONE,
CreateDriveVolumeInfo(profile_),
kNotRemounting);
}
}
// Subscribe to DiskMountManager.
disk_mount_manager_->AddObserver(this);
std::vector<VolumeInfo> archives;
const chromeos::disks::DiskMountManager::MountPointMap& mount_points =
disk_mount_manager_->mount_points();
for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it =
mount_points.begin();
it != mount_points.end();
++it) {
if (it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) {
// Archives are mounted after other type of volumes. See below.
archives.push_back(CreateVolumeInfoFromMountPointInfo(it->second, NULL));
continue;
}
DoMountEvent(
chromeos::MOUNT_ERROR_NONE,
CreateVolumeInfoFromMountPointInfo(
it->second,
disk_mount_manager_->FindDiskBySourcePath(it->second.source_path)),
false /* is_remounting */);
kNotRemounting);
}
// We mount archives only if they are opened from currently mounted volumes.
// To check the condition correctly in DoMountEvent, we care the order.
std::vector<bool> done(archives.size(), false);
for (size_t i = 0; i < archives.size(); ++i) {
if (!done[i]) {
std::vector<VolumeInfo> chain;
done[i] = true;
chain.push_back(archives[i]);
// If archives[i]'s source_path is in another archive, mount it first.
for (size_t parent = 0; parent < archives.size(); ++parent) {
if (!done[parent] &&
archives[parent].mount_path.IsParent(chain.back().source_path)) {
done[parent] = true;
chain.push_back(archives[parent]);
parent = 0; // Search archives[parent]'s parent from the beginning.
}
}
// Mount from the tail of chain.
for (size_t i = chain.size(); i > 0; --i)
DoMountEvent(chromeos::MOUNT_ERROR_NONE, chain[i - 1], kNotRemounting);
}
}
disk_mount_manager_->RequestMountInfoRefresh();
......@@ -556,7 +591,24 @@ void VolumeManager::OnPrivetVolumesAvailable(
void VolumeManager::DoMountEvent(chromeos::MountError error_code,
const VolumeInfo& volume_info,
bool is_remounting) {
// TODO(kinaba): filter zip.
// 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
// volumes already mounted on this VolumeManager instance.
if (volume_info.type == VOLUME_TYPE_MOUNTED_ARCHIVE_FILE) {
// Source may be in Drive cache folder under the current profile directory.
bool from_current_profile =
profile_->GetPath().IsParent(volume_info.source_path);
for (std::map<std::string, VolumeInfo>::const_iterator iter =
mounted_volumes_.begin();
!from_current_profile && iter != mounted_volumes_.end();
++iter) {
if (iter->second.mount_path.IsParent(volume_info.source_path))
from_current_profile = true;
}
if (!from_current_profile)
return;
}
if (error_code == chromeos::MOUNT_ERROR_NONE || volume_info.mount_condition)
mounted_volumes_[volume_info.volume_id] = volume_info;
......
......@@ -681,4 +681,59 @@ TEST_F(VolumeManagerTest, FindVolumeInfoById) {
EXPECT_EQ(VOLUME_TYPE_DOWNLOADS_DIRECTORY, volume_info.type);
}
TEST_F(VolumeManagerTest, ArchiveSourceFiltering) {
LoggingObserver observer;
volume_manager_->AddObserver(&observer);
// Mount a USB stick.
volume_manager_->OnMountEvent(
chromeos::disks::DiskMountManager::MOUNTING,
chromeos::MOUNT_ERROR_NONE,
chromeos::disks::DiskMountManager::MountPointInfo(
"/removable/usb",
"/removable/usb",
chromeos::MOUNT_TYPE_DEVICE,
chromeos::disks::MOUNT_CONDITION_NONE));
// Mount a zip archive in the stick.
volume_manager_->OnMountEvent(
chromeos::disks::DiskMountManager::MOUNTING,
chromeos::MOUNT_ERROR_NONE,
chromeos::disks::DiskMountManager::MountPointInfo(
"/removable/usb/1.zip",
"/archive/1",
chromeos::MOUNT_TYPE_ARCHIVE,
chromeos::disks::MOUNT_CONDITION_NONE));
VolumeInfo volume_info;
ASSERT_TRUE(volume_manager_->FindVolumeInfoById("archive:1", &volume_info));
EXPECT_EQ("/archive/1", volume_info.mount_path.AsUTF8Unsafe());
EXPECT_EQ(2u, observer.events().size());
// Mount a zip archive in the previous zip archive.
volume_manager_->OnMountEvent(
chromeos::disks::DiskMountManager::MOUNTING,
chromeos::MOUNT_ERROR_NONE,
chromeos::disks::DiskMountManager::MountPointInfo(
"/archive/1/2.zip",
"/archive/2",
chromeos::MOUNT_TYPE_ARCHIVE,
chromeos::disks::MOUNT_CONDITION_NONE));
ASSERT_TRUE(volume_manager_->FindVolumeInfoById("archive:2", &volume_info));
EXPECT_EQ("/archive/2", volume_info.mount_path.AsUTF8Unsafe());
EXPECT_EQ(3u, observer.events().size());
// A zip file is mounted from other profile. It must be ignored in the current
// VolumeManager.
volume_manager_->OnMountEvent(
chromeos::disks::DiskMountManager::MOUNTING,
chromeos::MOUNT_ERROR_NONE,
chromeos::disks::DiskMountManager::MountPointInfo(
"/other/profile/drive/folder/3.zip",
"/archive/3",
chromeos::MOUNT_TYPE_ARCHIVE,
chromeos::disks::MOUNT_CONDITION_NONE));
EXPECT_FALSE(volume_manager_->FindVolumeInfoById("archive:3", &volume_info));
EXPECT_EQ(3u, observer.events().size());
}
} // namespace file_manager
......@@ -62,7 +62,7 @@ var expectedDriveVolume = {
var expectedArchiveVolume = {
volumeId: 'archive:archive_mount_path',
mountPath: '/archive/archive_mount_path',
sourcePath: 'archive_path',
sourcePath: /removable\/mount_path3\/archive.zip$/,
volumeType: 'archive',
isReadOnly: true,
profile: {profileId: "", displayName: "", isCurrentProfile: 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