Commit af5540d2 authored by Austin Tankiang's avatar Austin Tankiang Committed by Commit Bot

Remove legacy drive code from chrome/browser/chromeos/file_manager

Bug: 1003238
Change-Id: I829684e1b9959948c3deb70649ce590aac6347c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1877500
Commit-Queue: Austin Tankiang <austinct@chromium.org>
Reviewed-by: default avatarSergei Datsenko <dats@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710203}
parent 50ab1e95
......@@ -17,7 +17,6 @@
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/file_manager/app_id.h"
#include "chrome/browser/chromeos/file_manager/fileapi_util.h"
#include "chrome/browser/chromeos/file_manager/open_with_browser.h"
......@@ -227,9 +226,6 @@ FileBrowserHandlerExecutor::SetupFileAccessPermissions(
base::FilePath local_path = url.path();
base::FilePath virtual_path = url.virtual_path();
const bool is_drive_file = url.type() == storage::kFileSystemTypeDrive;
DCHECK(!is_drive_file || drive::util::IsUnderDriveMountPoint(local_path));
const bool is_native_file =
url.type() == storage::kFileSystemTypeNativeLocal ||
url.type() == storage::kFileSystemTypeRestrictedNativeLocal;
......
......@@ -531,9 +531,9 @@ TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTasks) {
// Find apps for a "text/plain" file. Foo.app and Bar.app should be found.
std::vector<extensions::EntryInfo> entries;
entries.emplace_back(drive::util::GetDriveMountPointPath(&test_profile_)
.AppendASCII("foo.txt"),
"text/plain", false);
entries.emplace_back(
util::GetMyFilesFolderForProfile(&test_profile_).AppendASCII("foo.txt"),
"text/plain", false);
std::vector<FullTaskDescriptor> tasks;
FindFileHandlerTasks(&test_profile_, entries, &tasks);
......@@ -550,12 +550,12 @@ TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTasks) {
// Find apps for "text/plain" and "text/html" files. Only Foo.app should be
// found.
entries.clear();
entries.emplace_back(drive::util::GetDriveMountPointPath(&test_profile_)
.AppendASCII("foo.txt"),
"text/plain", false);
entries.emplace_back(drive::util::GetDriveMountPointPath(&test_profile_)
.AppendASCII("foo.html"),
"text/html", false);
entries.emplace_back(
util::GetMyFilesFolderForProfile(&test_profile_).AppendASCII("foo.txt"),
"text/plain", false);
entries.emplace_back(
util::GetMyFilesFolderForProfile(&test_profile_).AppendASCII("foo.html"),
"text/html", false);
tasks.clear();
FindFileHandlerTasks(&test_profile_, entries, &tasks);
ASSERT_EQ(1U, tasks.size());
......@@ -615,9 +615,9 @@ TEST_F(FileManagerFileTasksComplexTest,
std::vector<FullTaskDescriptor> tasks;
std::vector<extensions::EntryInfo> entries;
entries.emplace_back(drive::util::GetDriveMountPointPath(&test_profile_)
.AppendASCII("foo.csv"),
"text/csv", false);
entries.emplace_back(
util::GetMyFilesFolderForProfile(&test_profile_).AppendASCII("foo.csv"),
"text/csv", false);
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitWithFeatures({blink::features::kNativeFileSystemAPI,
......@@ -781,9 +781,9 @@ TEST_F(FileManagerFileTasksComplexTest, FindAllTypesOfTasks) {
// Find apps for "foo.txt". All apps should be found.
std::vector<extensions::EntryInfo> entries;
std::vector<GURL> file_urls;
entries.emplace_back(drive::util::GetDriveMountPointPath(&test_profile_)
.AppendASCII("foo.txt"),
"text/plain", false);
entries.emplace_back(
util::GetMyFilesFolderForProfile(&test_profile_).AppendASCII("foo.txt"),
"text/plain", false);
file_urls.emplace_back("filesystem:chrome-extension://id/dir/foo.txt");
std::vector<FullTaskDescriptor> tasks;
......@@ -860,9 +860,9 @@ TEST_F(FileManagerFileTasksComplexTest, FindAllTypesOfTasks_GoogleDocument) {
// should be found.
std::vector<extensions::EntryInfo> entries;
std::vector<GURL> file_urls;
entries.emplace_back(drive::util::GetDriveMountPointPath(&test_profile_)
.AppendASCII("foo.gdoc"),
"application/vnd.google-apps.document", false);
entries.emplace_back(
util::GetMyFilesFolderForProfile(&test_profile_).AppendASCII("foo.gdoc"),
"application/vnd.google-apps.document", false);
file_urls.emplace_back("filesystem:chrome-extension://id/dir/foo.gdoc");
std::vector<FullTaskDescriptor> tasks;
......@@ -1005,9 +1005,9 @@ TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTask_Generic) {
// Test case with .txt file
std::vector<extensions::EntryInfo> txt_entries;
txt_entries.emplace_back(drive::util::GetDriveMountPointPath(&test_profile_)
.AppendASCII("foo.txt"),
"text/plain", false);
txt_entries.emplace_back(
util::GetMyFilesFolderForProfile(&test_profile_).AppendASCII("foo.txt"),
"text/plain", false);
std::vector<FullTaskDescriptor> txt_result;
FindFileHandlerTasks(&test_profile_, txt_entries, &txt_result);
EXPECT_EQ(4U, txt_result.size());
......@@ -1026,9 +1026,9 @@ TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTask_Generic) {
// Test case with .jpg file
std::vector<extensions::EntryInfo> jpg_entries;
jpg_entries.emplace_back(drive::util::GetDriveMountPointPath(&test_profile_)
.AppendASCII("foo.jpg"),
"image/jpeg", false);
jpg_entries.emplace_back(
util::GetMyFilesFolderForProfile(&test_profile_).AppendASCII("foo.jpg"),
"image/jpeg", false);
std::vector<FullTaskDescriptor> jpg_result;
FindFileHandlerTasks(&test_profile_, jpg_entries, &jpg_result);
EXPECT_EQ(3U, jpg_result.size());
......@@ -1046,8 +1046,8 @@ TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTask_Generic) {
// Test case with directories.
std::vector<extensions::EntryInfo> dir_entries;
dir_entries.emplace_back(
drive::util::GetDriveMountPointPath(&test_profile_).AppendASCII("dir"),
"", true);
util::GetMyFilesFolderForProfile(&test_profile_).AppendASCII("dir"), "",
true);
std::vector<FullTaskDescriptor> dir_result;
FindFileHandlerTasks(&test_profile_, dir_entries, &dir_result);
ASSERT_EQ(1U, dir_result.size());
......@@ -1133,9 +1133,9 @@ TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTask_Verbs) {
// but only one ADD_TO that is not a generic handler will be taken into
// account, even though there are 2 ADD_TO matches for "text/plain".
std::vector<extensions::EntryInfo> entries;
entries.emplace_back(drive::util::GetDriveMountPointPath(&test_profile_)
.AppendASCII("foo.txt"),
"text/plain", false);
entries.emplace_back(
util::GetMyFilesFolderForProfile(&test_profile_).AppendASCII("foo.txt"),
"text/plain", false);
std::vector<FullTaskDescriptor> tasks;
FindFileHandlerTasks(&test_profile_, entries, &tasks);
......@@ -1159,9 +1159,9 @@ TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTask_Verbs) {
// ADD_TO that is a good match will be taken into account, even though there
// are 3 ADD_TO matches for "text/html".
entries.clear();
entries.emplace_back(drive::util::GetDriveMountPointPath(&test_profile_)
.AppendASCII("foo.html"),
"text/html", false);
entries.emplace_back(
util::GetMyFilesFolderForProfile(&test_profile_).AppendASCII("foo.html"),
"text/html", false);
tasks.clear();
FindFileHandlerTasks(&test_profile_, entries, &tasks);
......@@ -1177,8 +1177,8 @@ TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTask_Verbs) {
// Foo.app with only PACK_WITH should be found.
entries.clear();
entries.emplace_back(
drive::util::GetDriveMountPointPath(&test_profile_).AppendASCII("dir"),
"", true);
util::GetMyFilesFolderForProfile(&test_profile_).AppendASCII("dir"), "",
true);
tasks.clear();
FindFileHandlerTasks(&test_profile_, entries, &tasks);
......
......@@ -13,11 +13,9 @@
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/file_manager/app_id.h"
#include "chrome/browser/chromeos/file_manager/filesystem_api_util.h"
#include "chrome/browser/profiles/profile.h"
#include "components/drive/file_system_core_util.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
......@@ -471,34 +469,6 @@ storage::FileSystemContext* GetFileSystemContextForRenderFrameHost(
GetFileSystemContext();
}
base::FilePath ConvertDrivePathToRelativeFileSystemPath(
Profile* profile,
const std::string& extension_id,
const base::FilePath& drive_path) {
// "/special/drive-xxx"
base::FilePath path = drive::util::GetDriveMountPointPath(profile);
// appended with (|drive_path| - "drive").
drive::util::GetDriveGrandRootPath().AppendRelativePath(drive_path, &path);
base::FilePath relative_path;
ConvertAbsoluteFilePathToRelativeFileSystemPath(profile,
extension_id,
path,
&relative_path);
return relative_path;
}
GURL ConvertDrivePathToFileSystemUrl(Profile* profile,
const base::FilePath& drive_path,
const std::string& extension_id) {
const base::FilePath relative_path =
ConvertDrivePathToRelativeFileSystemPath(profile, extension_id,
drive_path);
if (relative_path.empty())
return GURL();
return ConvertRelativeFilePathToFileSystemUrl(relative_path, extension_id);
}
bool ConvertAbsoluteFilePathToFileSystemUrl(Profile* profile,
const base::FilePath& absolute_path,
const std::string& extension_id,
......
......@@ -99,22 +99,7 @@ storage::FileSystemContext* GetFileSystemContextForRenderFrameHost(
Profile* profile,
content::RenderFrameHost* render_frame_host);
// Converts DrivePath (e.g., "drive/root", which always starts with the fixed
// "drive" directory) to a RelativeFileSystemPathrelative (e.g.,
// "drive-xxx/root/foo". which starts from the "mount point" in the FileSystem
// API that may be distinguished for each profile by the appended "xxx" part.)
base::FilePath ConvertDrivePathToRelativeFileSystemPath(
Profile* profile,
const std::string& extension_id,
const base::FilePath& drive_path);
// Converts DrivePath to FileSystem URL.
// E.g., "drive/root" to filesystem://id/external/drive-xxx/root.
GURL ConvertDrivePathToFileSystemUrl(Profile* profile,
const base::FilePath& drive_path,
const std::string& extension_id);
// Converts AbsolutePath (e.g., "/special/drive-xxx/root" or
// Converts AbsolutePath (e.g., "/media/removable/foo" or
// "/home/chronos/u-xxx/Downloads") into filesystem URL. Returns false
// if |absolute_path| is not managed by the external filesystem provider.
bool ConvertAbsoluteFilePathToFileSystemUrl(Profile* profile,
......@@ -123,7 +108,7 @@ bool ConvertAbsoluteFilePathToFileSystemUrl(Profile* profile,
GURL* url);
// Converts AbsolutePath into RelativeFileSystemPath (e.g.,
// "/special/drive-xxx/root/foo" => "drive-xxx/root/foo".) Returns false if
// "/media/removable/foo/bar" => "removable/foo/bar".) Returns false if
// |absolute_path| is not managed by the external filesystem provider.
bool ConvertAbsoluteFilePathToRelativeFileSystemPath(
Profile* profile,
......
......@@ -24,7 +24,6 @@
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "components/arc/arc_service_manager.h"
#include "components/drive/chromeos/file_system_interface.h"
#include "components/drive/file_errors.h"
#include "components/drive/file_system_core_util.h"
#include "content/public/browser/browser_task_traits.h"
......@@ -38,22 +37,6 @@ namespace file_manager {
namespace util {
namespace {
// Helper function used to implement GetNonNativeLocalPathMimeType. It extracts
// the mime type from the passed Drive resource entry.
void GetMimeTypeAfterGetResourceEntryForDrive(
base::OnceCallback<void(const base::Optional<std::string>&)> callback,
drive::FileError error,
std::unique_ptr<drive::ResourceEntry> entry) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (error != drive::FILE_ERROR_OK || !entry->has_file_specific_info() ||
entry->file_specific_info().content_mime_type().empty()) {
std::move(callback).Run(base::nullopt);
return;
}
std::move(callback).Run(entry->file_specific_info().content_mime_type());
}
void GetMimeTypeAfterGetMetadata(
base::OnceCallback<void(const base::Optional<std::string>&)> callback,
drive::FileError error,
......@@ -196,14 +179,6 @@ void GetNonNativeLocalPathMimeType(
if (drive_integration_service &&
drive_integration_service->GetRelativeDrivePath(path,
&drive_relative_path)) {
if (drive::FileSystemInterface* file_system =
drive_integration_service->file_system()) {
file_system->GetResourceEntry(
drive::util::ExtractDrivePath(path),
base::BindOnce(&GetMimeTypeAfterGetResourceEntryForDrive,
std::move(callback)));
return;
}
if (auto* drivefs = drive_integration_service->GetDriveFsInterface()) {
drivefs->GetMetadata(
drive_relative_path,
......
......@@ -375,7 +375,7 @@ bool ConvertPathToArcUrl(const base::FilePath& path, GURL* arc_url_out) {
bool force_external = false;
// Force external URL for DriveFS and Crostini.
drive::DriveIntegrationService* integration_service =
drive::util::GetIntegrationServiceByProfile(primary_profile);
drive::DriveIntegrationServiceFactory::FindForProfile(primary_profile);
if ((integration_service &&
integration_service->GetMountPointPath().AppendRelativePath(
path, &relative_path)) ||
......
......@@ -114,9 +114,9 @@ void ConvertToContentUrls(
// Replacements:
// * /home/chronos/user/Downloads => Downloads
// * /home/chronos/u-<hash>/Downloads => Downloads
// * /special/drive-<hash>/root => Google Drive
// * /special/drive-<hash>/team_drives => Team Drives
// * /special/drive-<hash>/Computers => Computers
// * /media/fuse/drivefs-<hash>/root => Google Drive
// * /media/fuse/drivefs-<hash>/team_drives => Team Drives
// * /media/fuse/drivefs-<hash>/Computers => Computers
// * /run/arc/sdcard/write/emulated/0 => Play files
// * /media/fuse/crostini_<hash>_termina_penguin => Linux files
// * '/' with ' \u203a ' (angled quote sign) for display purposes.
......
......@@ -533,6 +533,8 @@ class FileManagerPathUtilConvertUrlTest : public testing::Test {
profile_manager_->CreateTestingProfile("user@gmail.com");
ASSERT_TRUE(primary_profile);
ASSERT_TRUE(profile_manager_->CreateTestingProfile("user2@gmail.com"));
primary_profile->GetPrefs()->SetString(drive::prefs::kDriveFsProfileSalt,
"a");
// Set up an Arc service manager with a fake file system.
arc_service_manager_ = std::make_unique<arc::ArcServiceManager>();
......@@ -549,10 +551,12 @@ class FileManagerPathUtilConvertUrlTest : public testing::Test {
// Add a drive mount point for the primary profile.
storage::ExternalMountPoints* mount_points =
storage::ExternalMountPoints::GetSystemInstance();
drive_mount_point_ = drive::util::GetDriveMountPointPath(primary_profile);
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(primary_profile);
drive_mount_point_ = integration_service->GetMountPointPath();
mount_points->RegisterFileSystem(
drive_mount_point_.BaseName().AsUTF8Unsafe(),
storage::kFileSystemTypeDrive, storage::FileSystemMountOption(),
storage::kFileSystemTypeNativeLocal, storage::FileSystemMountOption(),
drive_mount_point_);
// Add a crostini mount point for the primary profile.
......@@ -651,7 +655,8 @@ TEST_F(FileManagerPathUtilConvertUrlTest, ConvertPathToArcUrl_Special) {
// - creating externalfile: URL from the path
// - encoding the URL to Chrome content provider URL
EXPECT_EQ(GURL("content://org.chromium.arc.chromecontentprovider/"
"externalfile%3Adrive-user%252540gmail.com-hash%2Fa%2Fb%2Fc"),
"externalfile%3Adrivefs-b1f44746e7144c3caafeacaa8bb5c569%2Fa"
"%2Fb%2Fc"),
url);
}
......@@ -777,8 +782,8 @@ TEST_F(FileManagerPathUtilConvertUrlTest, ConvertToContentUrls_Special) {
run_loop->Quit();
ASSERT_EQ(1U, urls.size());
EXPECT_EQ(GURL("content://org.chromium.arc.chromecontentprovider/"
"externalfile%3Adrive-user%252540gmail.com-hash%2Fa%"
"2Fb%2Fc"),
"externalfile%3Adrivefs-b1f44746e7144c3caafeacaa8bb5"
"c569%2Fa%2Fb%2Fc"),
urls[0]);
},
&run_loop));
......@@ -891,8 +896,8 @@ TEST_F(FileManagerPathUtilConvertUrlTest, ConvertToContentUrls_MultipleUrls) {
"removable/a/b/c"),
urls[1]);
EXPECT_EQ(GURL("content://org.chromium.arc.chromecontentprovider/"
"externalfile%3Adrive-user%252540gmail.com-hash%2Fa%"
"2Fb%2Fc"),
"externalfile%3Adrivefs-b1f44746e7144c3caafeacaa8bb5"
"c569%2Fa%2Fb%2Fc"),
urls[2]);
EXPECT_EQ(
GURL("content://org.chromium.arc.file_system.fileprovider/"
......
......@@ -46,7 +46,6 @@
#include "chromeos/constants/chromeos_switches.h"
#include "chromeos/disks/disk.h"
#include "chromeos/disks/disk_mount_manager.h"
#include "components/drive/chromeos/file_system_interface.h"
#include "components/prefs/pref_service.h"
#include "components/storage_monitor/storage_monitor.h"
#include "content/public/browser/browser_context.h"
......@@ -890,24 +889,7 @@ void VolumeManager::OnMountEvent(
const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
switch (mount_info.mount_type) {
case 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.
// Note that drive file system knows if the file is managed by drive file
// system or not, so here we report all paths.
if ((event == chromeos::disks::DiskMountManager::MOUNTING &&
error_code != chromeos::MOUNT_ERROR_NONE) ||
(event == chromeos::disks::DiskMountManager::UNMOUNTING &&
error_code == chromeos::MOUNT_ERROR_NONE)) {
drive::FileSystemInterface* const file_system =
drive::util::GetFileSystemByProfile(profile_);
if (file_system) {
file_system->MarkCacheFileAsUnmounted(
base::FilePath(mount_info.source_path), base::DoNothing());
}
}
FALLTHROUGH;
}
case chromeos::MOUNT_TYPE_ARCHIVE:
case chromeos::MOUNT_TYPE_DEVICE: {
// Notify a mounting/unmounting event to observers.
const chromeos::disks::Disk* const disk =
......
......@@ -9,8 +9,8 @@
#include <vector>
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/file_manager/file_tasks.h"
#include "chrome/browser/chromeos/file_manager/path_util.h"
#include "chrome/browser/web_applications/components/app_registrar.h"
#include "chrome/browser/web_applications/components/web_app_helpers.h"
#include "chrome/browser/web_applications/test/test_app_registrar.h"
......@@ -69,7 +69,7 @@ TEST_F(WebFileTasksTest, WebAppFileHandlingCanBeDisabled) {
std::vector<extensions::EntryInfo> entries;
entries.emplace_back(
drive::util::GetDriveMountPointPath(profile()).AppendASCII("foo.csv"),
util::GetMyFilesFolderForProfile(profile()).AppendASCII("foo.csv"),
"text/csv", false);
std::vector<FullTaskDescriptor> tasks;
......@@ -123,7 +123,7 @@ TEST_F(WebFileTasksTest, FindWebFileHandlerTasks) {
// Find apps for a "text/plain" file. Both Foo and Bar should be found.
std::vector<extensions::EntryInfo> entries;
entries.emplace_back(
drive::util::GetDriveMountPointPath(profile()).AppendASCII("foo.txt"),
util::GetMyFilesFolderForProfile(profile()).AppendASCII("foo.txt"),
"text/plain", false);
std::vector<FullTaskDescriptor> tasks;
......@@ -137,7 +137,7 @@ TEST_F(WebFileTasksTest, FindWebFileHandlerTasks) {
// Add a "text/html" file. Only Foo should be found.
entries.emplace_back(
drive::util::GetDriveMountPointPath(profile()).AppendASCII("foo.html"),
util::GetMyFilesFolderForProfile(profile()).AppendASCII("foo.html"),
"text/html", false);
tasks.clear();
FindWebTasks(profile(), entries, &tasks);
......@@ -147,7 +147,7 @@ TEST_F(WebFileTasksTest, FindWebFileHandlerTasks) {
// Add an "image/png" file. No tasks should be found.
entries.emplace_back(
drive::util::GetDriveMountPointPath(profile()).AppendASCII("foo.png"),
util::GetMyFilesFolderForProfile(profile()).AppendASCII("foo.png"),
"image/png", false);
tasks.clear();
FindWebTasks(profile(), entries, &tasks);
......@@ -196,7 +196,7 @@ TEST_F(WebFileTasksTest, FindWebFileHandlerTask_Generic) {
// All apps should be able to handle ".txt" files.
entries.emplace_back(
drive::util::GetDriveMountPointPath(profile()).AppendASCII("foo.txt"),
util::GetMyFilesFolderForProfile(profile()).AppendASCII("foo.txt"),
"text/plain", false);
FindWebTasks(profile(), entries, &tasks);
// Ensure stable order.
......@@ -221,7 +221,7 @@ TEST_F(WebFileTasksTest, FindWebFileHandlerTask_Generic) {
// Every app but Bar should be able to handle jpegs.
entries.emplace_back(
drive::util::GetDriveMountPointPath(profile()).AppendASCII("foo.jpg"),
util::GetMyFilesFolderForProfile(profile()).AppendASCII("foo.jpg"),
"image/jpeg", false);
FindWebTasks(profile(), entries, &tasks);
// Ensure stable order.,
......
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