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

Remove legacy drive code in private_api_mount

This code was used to deal with mounting rar files located in the legacy
drive file system. Now that DriveFS is default, this is no longer
needed.

Bug: 1003238
Test: manually mounted/unmounted zip and rar files on DUT
Change-Id: I75ab0da2ba26f8f004f1b48ac5bb9f2d2158c6b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1826752
Commit-Queue: Austin Tankiang <austinct@chromium.org>
Reviewed-by: default avatarAnand Mistry <amistry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701482}
parent 1a7e06e5
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/file_manager_private.h" #include "chrome/common/extensions/api/file_manager_private.h"
#include "chromeos/disks/disk_mount_manager.h" #include "chromeos/disks/disk_mount_manager.h"
#include "components/drive/chromeos/file_system_interface.h"
#include "components/drive/event_logger.h" #include "components/drive/event_logger.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "google_apis/drive/task_util.h" #include "google_apis/drive/task_util.h"
...@@ -73,113 +72,41 @@ ExtensionFunction::ResponseAction FileManagerPrivateAddMountFunction::Run() { ...@@ -73,113 +72,41 @@ ExtensionFunction::ResponseAction FileManagerPrivateAddMountFunction::Run() {
if (path.empty()) if (path.empty())
return RespondNow(Error("Invalid path")); return RespondNow(Error("Invalid path"));
// Check if the source path is under Drive cache directory. file_manager::VolumeManager* volume_manager =
if (drive::util::IsUnderDriveMountPoint(path)) { file_manager::VolumeManager::Get(chrome_details_.GetProfile());
drive::FileSystemInterface* file_system = DCHECK(volume_manager);
drive::util::GetFileSystemByProfile(chrome_details_.GetProfile());
if (!file_system)
return RespondNow(Error("Drive not available"));
// Ensure that the cache file exists.
const base::FilePath drive_path = drive::util::ExtractDrivePath(path);
file_system->GetFile(
drive_path,
base::BindOnce(
&FileManagerPrivateAddMountFunction::RunAfterGetDriveFile, this,
drive_path));
} else {
file_manager::VolumeManager* volume_manager =
file_manager::VolumeManager::Get(chrome_details_.GetProfile());
DCHECK(volume_manager);
bool is_under_downloads = false;
const std::vector<base::WeakPtr<file_manager::Volume>> volumes =
volume_manager->GetVolumeList();
for (const auto& volume : volumes) {
if (volume->type() == file_manager::VOLUME_TYPE_DOWNLOADS_DIRECTORY &&
volume->mount_path().IsParent(path)) {
is_under_downloads = true;
break;
}
}
if (is_under_downloads) { bool is_under_downloads = false;
// For files under downloads, change the file permission and make it const std::vector<base::WeakPtr<file_manager::Volume>> volumes =
// readable from avfs/fuse if needed. volume_manager->GetVolumeList();
base::PostTask( for (const auto& volume : volumes) {
FROM_HERE, if (volume->type() == file_manager::VOLUME_TYPE_DOWNLOADS_DIRECTORY &&
{base::ThreadPool(), base::MayBlock(), volume->mount_path().IsParent(path)) {
base::TaskPriority::USER_BLOCKING}, is_under_downloads = true;
base::BindOnce(&EnsureReadableFilePermissionAsync, path, break;
google_apis::CreateRelayCallback(base::BindOnce(
&FileManagerPrivateAddMountFunction::
RunAfterMarkCacheFileAsMounted,
this, path.BaseName()))));
} else {
RunAfterMarkCacheFileAsMounted(
path.BaseName(), drive::FILE_ERROR_OK, path);
} }
} }
return RespondLater();
}
void FileManagerPrivateAddMountFunction::RunAfterGetDriveFile(
const base::FilePath& drive_path,
drive::FileError error,
const base::FilePath& cache_path,
std::unique_ptr<drive::ResourceEntry> entry) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (error != drive::FILE_ERROR_OK) {
Respond(Error(FileErrorToString(error)));
return;
}
drive::FileSystemInterface* const file_system =
drive::util::GetFileSystemByProfile(chrome_details_.GetProfile());
if (!file_system) {
Respond(Error("Drive not available"));
return;
}
file_system->IsCacheFileMarkedAsMounted(
drive_path, base::BindOnce(&FileManagerPrivateAddMountFunction::
RunAfterIsCacheFileMarkedAsMounted,
this, drive_path, cache_path));
}
void FileManagerPrivateAddMountFunction::RunAfterIsCacheFileMarkedAsMounted( if (is_under_downloads) {
const base::FilePath& drive_path, // For files under downloads, change the file permission and make it
const base::FilePath& cache_path, // readable from avfs/fuse if needed.
drive::FileError error, base::PostTask(
bool is_marked_as_mounted) { FROM_HERE,
DCHECK_CURRENTLY_ON(BrowserThread::UI); {base::ThreadPool(), base::MayBlock(),
if (error != drive::FILE_ERROR_OK) { base::TaskPriority::USER_BLOCKING},
Respond(Error(FileErrorToString(error))); base::BindOnce(&EnsureReadableFilePermissionAsync, path,
return; google_apis::CreateRelayCallback(base::BindOnce(
} &FileManagerPrivateAddMountFunction::
if (is_marked_as_mounted) { RunAfterEnsureReadableFilePermission,
// When the file is already mounted, we call the mount function as usual, this, path.BaseName()))));
// so that it can issue events containing the VolumeInfo, which is } else {
// necessary to make the app navigate to the mounted volume. RunAfterEnsureReadableFilePermission(path.BaseName(), drive::FILE_ERROR_OK,
RunAfterMarkCacheFileAsMounted(drive_path.BaseName(), drive::FILE_ERROR_OK, path);
cache_path);
return;
}
drive::FileSystemInterface* const file_system =
drive::util::GetFileSystemByProfile(chrome_details_.GetProfile());
if (!file_system) {
Respond(Error("Drive not available"));
return;
} }
file_system->MarkCacheFileAsMounted( return RespondLater();
drive_path,
base::BindOnce(
&FileManagerPrivateAddMountFunction::RunAfterMarkCacheFileAsMounted,
this, drive_path.BaseName()));
} }
void FileManagerPrivateAddMountFunction::RunAfterMarkCacheFileAsMounted( void FileManagerPrivateAddMountFunction::RunAfterEnsureReadableFilePermission(
const base::FilePath& display_name, const base::FilePath& display_name,
drive::FileError error, drive::FileError error,
const base::FilePath& file_path) { const base::FilePath& file_path) {
...@@ -266,110 +193,6 @@ ExtensionFunction::ResponseAction FileManagerPrivateRemoveMountFunction::Run() { ...@@ -266,110 +193,6 @@ ExtensionFunction::ResponseAction FileManagerPrivateRemoveMountFunction::Run() {
return RespondNow(NoArguments()); return RespondNow(NoArguments());
} }
FileManagerPrivateMarkCacheAsMountedFunction::
FileManagerPrivateMarkCacheAsMountedFunction()
: chrome_details_(this) {}
ExtensionFunction::ResponseAction
FileManagerPrivateMarkCacheAsMountedFunction::Run() {
using file_manager_private::MarkCacheAsMounted::Params;
const std::unique_ptr<Params> params(Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
const base::FilePath path(params->source_path);
bool is_mounted = params->is_mounted;
if (path.empty())
return RespondNow(Error("Invalid path"));
if (!drive::util::IsUnderDriveMountPoint(path)) {
// Ignore non-drive files. Treated as success.
return RespondNow(NoArguments());
}
drive::FileSystemInterface* file_system =
drive::util::GetFileSystemByProfile(chrome_details_.GetProfile());
if (!file_system)
return RespondNow(Error("Drive not available"));
// Ensure that the cache file exists.
const base::FilePath drive_path = drive::util::ExtractDrivePath(path);
file_system->GetFile(
drive_path,
base::BindOnce(
&FileManagerPrivateMarkCacheAsMountedFunction::RunAfterGetDriveFile,
this, drive_path, is_mounted));
return RespondLater();
}
void FileManagerPrivateMarkCacheAsMountedFunction::RunAfterGetDriveFile(
const base::FilePath& drive_path,
bool is_mounted,
drive::FileError error,
const base::FilePath& cache_path,
std::unique_ptr<drive::ResourceEntry> entry) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (error != drive::FILE_ERROR_OK) {
Respond(Error(FileErrorToString(error)));
return;
}
drive::FileSystemInterface* const file_system =
drive::util::GetFileSystemByProfile(chrome_details_.GetProfile());
if (!file_system) {
Respond(Error("Drive not available"));
return;
}
// TODO(yamaguchi): Check the current status of the file.
// Currently calling this method twice will result in error, although it
// doesn't give bad side effect.
if (is_mounted) {
file_system->MarkCacheFileAsMounted(
drive_path,
base::BindOnce(&FileManagerPrivateMarkCacheAsMountedFunction::
RunAfterMarkCacheFileAsMounted,
this));
} else {
file_system->MarkCacheFileAsUnmounted(
cache_path, base::Bind(&FileManagerPrivateMarkCacheAsMountedFunction::
RunAfterMarkCacheFileAsUnmounted,
this));
}
}
void FileManagerPrivateMarkCacheAsMountedFunction::
RunAfterMarkCacheFileAsMounted(drive::FileError error,
const base::FilePath& file_path) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
switch (error) {
case drive::FILE_ERROR_INVALID_OPERATION:
// The file was already marked as mounted. Ignore and treat as success.
case drive::FILE_ERROR_OK:
Respond(NoArguments());
break;
default:
Respond(Error(FileErrorToString(error)));
}
}
void FileManagerPrivateMarkCacheAsMountedFunction::
RunAfterMarkCacheFileAsUnmounted(drive::FileError error) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
switch (error) {
case drive::FILE_ERROR_INVALID_OPERATION:
// The file was already marked as unmounted. Ignore and treat as success.
case drive::FILE_ERROR_OK:
Respond(NoArguments());
break;
default:
Respond(Error(FileErrorToString(error)));
}
}
ExtensionFunction::ResponseAction ExtensionFunction::ResponseAction
FileManagerPrivateGetVolumeMetadataListFunction::Run() { FileManagerPrivateGetVolumeMetadataListFunction::Run() {
if (args_->GetSize()) if (args_->GetSize())
......
...@@ -33,24 +33,11 @@ class FileManagerPrivateAddMountFunction : public LoggedExtensionFunction { ...@@ -33,24 +33,11 @@ class FileManagerPrivateAddMountFunction : public LoggedExtensionFunction {
ResponseAction Run() override; ResponseAction Run() override;
private: private:
// Part of Run(). Called after GetFile for Drive File System. // Part of Run(). Called after EnsureReadableFilePermissionAsync or when the
void RunAfterGetDriveFile(const base::FilePath& drive_path, // file is on an external drive.
drive::FileError error, void RunAfterEnsureReadableFilePermission(const base::FilePath& display_name,
const base::FilePath& cache_path, drive::FileError error,
std::unique_ptr<drive::ResourceEntry> entry); const base::FilePath& file_path);
// Part of Run(). Called after IsCacheMarkedAsMounted for Drive File System.
void RunAfterIsCacheFileMarkedAsMounted(const base::FilePath& display_name,
const base::FilePath& cache_path,
drive::FileError error,
bool is_marked_as_mounted);
// Part of Run(). Called after MarkCacheFielAsMounted for Drive File System.
// (or directly called from RunAsync() for other file system, or when the
// file is already marked as mounted).
void RunAfterMarkCacheFileAsMounted(const base::FilePath& display_name,
drive::FileError error,
const base::FilePath& file_path);
const ChromeExtensionFunctionDetails chrome_details_; const ChromeExtensionFunctionDetails chrome_details_;
}; };
...@@ -69,40 +56,6 @@ class FileManagerPrivateRemoveMountFunction : public LoggedExtensionFunction { ...@@ -69,40 +56,6 @@ class FileManagerPrivateRemoveMountFunction : public LoggedExtensionFunction {
ResponseAction Run() override; ResponseAction Run() override;
}; };
// Implements chrome.fileManagerPrivate.markCacheAsMounted method.
// Marks a cached file as mounted or unmounted.
class FileManagerPrivateMarkCacheAsMountedFunction
: public LoggedExtensionFunction {
public:
FileManagerPrivateMarkCacheAsMountedFunction();
DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.markCacheAsMounted",
FILEMANAGERPRIVATE_MARKCACHEASMOUNTED)
protected:
~FileManagerPrivateMarkCacheAsMountedFunction() override = default;
// ExtensionFunction overrides.
ResponseAction Run() override;
private:
// Part of Run(). Called after GetFile for Drive File System.
void RunAfterGetDriveFile(const base::FilePath& drive_path,
bool is_mounted,
drive::FileError error,
const base::FilePath& cache_path,
std::unique_ptr<drive::ResourceEntry> entry);
// Part of Run(). Called after MarkCacheFielAsMounted for Drive File System.
void RunAfterMarkCacheFileAsMounted(drive::FileError error,
const base::FilePath& file_path);
// Part of Run(). Called after MarkCacheFielAsUnmounted for Drive File System.
void RunAfterMarkCacheFileAsUnmounted(drive::FileError error);
const ChromeExtensionFunctionDetails chrome_details_;
};
// Implements chrome.fileManagerPrivate.getVolumeMetadataList method. // Implements chrome.fileManagerPrivate.getVolumeMetadataList method.
class FileManagerPrivateGetVolumeMetadataListFunction class FileManagerPrivateGetVolumeMetadataListFunction
: public LoggedExtensionFunction { : public LoggedExtensionFunction {
......
...@@ -487,54 +487,39 @@ unpacker.app = { ...@@ -487,54 +487,39 @@ unpacker.app = {
*/ */
unmountVolume: function(fileSystemId, opt_forceUnmount) { unmountVolume: function(fileSystemId, opt_forceUnmount) {
return new Promise(function(fulfill, reject) { return new Promise(function(fulfill, reject) {
chrome.fileManagerPrivate.markCacheAsMounted( var volume = unpacker.app.volumes[fileSystemId];
fileSystemId, false /* isMounted */, function() { console.assert(
if (chrome.runtime.lastError) { volume || opt_forceUnmount,
console.error( 'Unmount that is not forced must not be called for ',
'Unmount error: ' + chrome.runtime.lastError.message + 'volumes that are not restored.');
'.');
reject('FAILED'); if (!opt_forceUnmount && volume.inUse()) {
return; reject('IN_USE');
} return;
fulfill(); }
});
})
.then(function() {
return new Promise(function(fulfill, reject) {
var volume = unpacker.app.volumes[fileSystemId];
console.assert(
volume || opt_forceUnmount,
'Unmount that is not forced must not be called for ',
'volumes that are not restored.');
if (!opt_forceUnmount && volume.inUse()) { var options = {fileSystemId: fileSystemId};
reject('IN_USE'); chrome.fileSystemProvider.unmount(options, function() {
return; if (chrome.runtime.lastError) {
} console.error(
'Unmount error: ' + chrome.runtime.lastError.message + '.');
reject('FAILED');
return;
}
var options = {fileSystemId: fileSystemId}; // In case of forced unmount volume can be undefined due to not
chrome.fileSystemProvider.unmount(options, function() { // being restored. An unmount that is not forced will be called
if (chrome.runtime.lastError) { // only after restoring state. In the case of forced unmount when
console.error( // volume is not restored, we will not do a normal cleanup, but
'Unmount error: ' + chrome.runtime.lastError.message + '.'); // just remove the load volume promise to allow further mounts.
reject('FAILED'); if (opt_forceUnmount)
return; delete unpacker.app.volumeLoadedPromises[fileSystemId];
} else
unpacker.app.cleanupVolume(fileSystemId);
// In case of forced unmount volume can be undefined due to not fulfill();
// being restored. An unmount that is not forced will be called });
// only after restoring state. In the case of forced unmount when });
// volume is not restored, we will not do a normal cleanup, but
// just remove the load volume promise to allow further mounts.
if (opt_forceUnmount)
delete unpacker.app.volumeLoadedPromises[fileSystemId];
else
unpacker.app.cleanupVolume(fileSystemId);
fulfill();
});
});
});
}, },
/** /**
...@@ -882,18 +867,6 @@ unpacker.app = { ...@@ -882,18 +867,6 @@ unpacker.app = {
loadPromise loadPromise
.then(function() { .then(function() {
unpacker.app.volumeLoadFinished[fileSystemId] = true; unpacker.app.volumeLoadFinished[fileSystemId] = true;
return new Promise(function(fulfill, reject) {
chrome.fileManagerPrivate.markCacheAsMounted(
displayPath, true /* isMounted */, function() {
if (chrome.runtime.lastError) {
reject(chrome.runtime.lastError);
return;
}
fulfill();
});
});
})
.then(function() {
chrome.fileSystemProvider.mount( chrome.fileSystemProvider.mount(
{ {
fileSystemId: fileSystemId, fileSystemId: fileSystemId,
......
...@@ -726,8 +726,6 @@ callback GetEntryPropertiesCallback = ...@@ -726,8 +726,6 @@ callback GetEntryPropertiesCallback =
// |sourcePath| Source path of the mount. // |sourcePath| Source path of the mount.
callback AddMountCallback = void(DOMString sourcePath); callback AddMountCallback = void(DOMString sourcePath);
callback MarkCacheAsMountedCallback = void();
// |volumeMetadataList| The list of VolumeMetadata representing mounted volumes. // |volumeMetadataList| The list of VolumeMetadata representing mounted volumes.
callback GetVolumeMetadataListCallback = callback GetVolumeMetadataListCallback =
void(VolumeMetadata[] volumeMetadataList); void(VolumeMetadata[] volumeMetadataList);
...@@ -956,16 +954,6 @@ interface Functions { ...@@ -956,16 +954,6 @@ interface Functions {
// |volumeId| An ID of the volume. // |volumeId| An ID of the volume.
static void removeMount(DOMString volumeId); static void removeMount(DOMString volumeId);
// Marks a cache file of Drive as mounted or unmounted.
// Does nothing if the file is not under Drive directory.
// |sourcePath| Mounted source file. Relative file path within external file
// system.
// |isMounted| Mark as mounted if true. Mark as unmounted otherwise.
// |callback| Completion callback. $(ref:runtime.lastError) will be set if
// there was an error.
static void markCacheAsMounted(DOMString sourcePath, boolean isMounted,
MarkCacheAsMountedCallback callback);
// Get the list of mounted volumes. // Get the list of mounted volumes.
// |callback| // |callback|
static void getVolumeMetadataList(GetVolumeMetadataListCallback callback); static void getVolumeMetadataList(GetVolumeMetadataListCallback callback);
......
...@@ -667,19 +667,6 @@ chrome.fileManagerPrivate.addMount = function(source, callback) {}; ...@@ -667,19 +667,6 @@ chrome.fileManagerPrivate.addMount = function(source, callback) {};
*/ */
chrome.fileManagerPrivate.removeMount = function(volumeId) {}; chrome.fileManagerPrivate.removeMount = function(volumeId) {};
/**
* Marks a cache file of Drive as mounted or unmounted.
* Does nothing if the file is not under Drive directory.
* @param {string} sourcePath Mounted source file. Relative file path within
* external file system.
* @param {boolean} isMounted Mark as mounted if true. Mark as unmounted
* otherwise.
* @param {function()} callback Completion callback. runtime.lastError will be
* set if there was an error.
*/
chrome.fileManagerPrivate.markCacheAsMounted = function(
sourcePath, isMounted, callback) {};
/** /**
* Get the list of mounted volumes. |callback| * Get the list of mounted volumes. |callback|
* @param {function((!Array<!chrome.fileManagerPrivate.VolumeMetadata>|undefined))} * @param {function((!Array<!chrome.fileManagerPrivate.VolumeMetadata>|undefined))}
......
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