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 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/file_manager_private.h"
#include "chromeos/disks/disk_mount_manager.h"
#include "components/drive/chromeos/file_system_interface.h"
#include "components/drive/event_logger.h"
#include "content/public/browser/browser_thread.h"
#include "google_apis/drive/task_util.h"
......@@ -73,21 +72,6 @@ ExtensionFunction::ResponseAction FileManagerPrivateAddMountFunction::Run() {
if (path.empty())
return RespondNow(Error("Invalid path"));
// Check if the source path is under Drive cache directory.
if (drive::util::IsUnderDriveMountPoint(path)) {
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(
&FileManagerPrivateAddMountFunction::RunAfterGetDriveFile, this,
drive_path));
} else {
file_manager::VolumeManager* volume_manager =
file_manager::VolumeManager::Get(chrome_details_.GetProfile());
DCHECK(volume_manager);
......@@ -113,73 +97,16 @@ ExtensionFunction::ResponseAction FileManagerPrivateAddMountFunction::Run() {
base::BindOnce(&EnsureReadableFilePermissionAsync, path,
google_apis::CreateRelayCallback(base::BindOnce(
&FileManagerPrivateAddMountFunction::
RunAfterMarkCacheFileAsMounted,
RunAfterEnsureReadableFilePermission,
this, path.BaseName()))));
} else {
RunAfterMarkCacheFileAsMounted(
path.BaseName(), drive::FILE_ERROR_OK, path);
}
RunAfterEnsureReadableFilePermission(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(
const base::FilePath& drive_path,
const base::FilePath& cache_path,
drive::FileError error,
bool is_marked_as_mounted) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (error != drive::FILE_ERROR_OK) {
Respond(Error(FileErrorToString(error)));
return;
}
if (is_marked_as_mounted) {
// When the file is already mounted, we call the mount function as usual,
// so that it can issue events containing the VolumeInfo, which is
// necessary to make the app navigate to the mounted volume.
RunAfterMarkCacheFileAsMounted(drive_path.BaseName(), drive::FILE_ERROR_OK,
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(
drive_path,
base::BindOnce(
&FileManagerPrivateAddMountFunction::RunAfterMarkCacheFileAsMounted,
this, drive_path.BaseName()));
}
void FileManagerPrivateAddMountFunction::RunAfterMarkCacheFileAsMounted(
void FileManagerPrivateAddMountFunction::RunAfterEnsureReadableFilePermission(
const base::FilePath& display_name,
drive::FileError error,
const base::FilePath& file_path) {
......@@ -266,110 +193,6 @@ ExtensionFunction::ResponseAction FileManagerPrivateRemoveMountFunction::Run() {
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
FileManagerPrivateGetVolumeMetadataListFunction::Run() {
if (args_->GetSize())
......
......@@ -33,22 +33,9 @@ class FileManagerPrivateAddMountFunction : public LoggedExtensionFunction {
ResponseAction Run() override;
private:
// Part of Run(). Called after GetFile for Drive File System.
void RunAfterGetDriveFile(const base::FilePath& drive_path,
drive::FileError error,
const base::FilePath& cache_path,
std::unique_ptr<drive::ResourceEntry> entry);
// 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,
// Part of Run(). Called after EnsureReadableFilePermissionAsync or when the
// file is on an external drive.
void RunAfterEnsureReadableFilePermission(const base::FilePath& display_name,
drive::FileError error,
const base::FilePath& file_path);
......@@ -69,40 +56,6 @@ class FileManagerPrivateRemoveMountFunction : public LoggedExtensionFunction {
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.
class FileManagerPrivateGetVolumeMetadataListFunction
: public LoggedExtensionFunction {
......
......@@ -486,20 +486,6 @@ unpacker.app = {
* rejects with ProviderError in case of any errors.
*/
unmountVolume: function(fileSystemId, opt_forceUnmount) {
return new Promise(function(fulfill, reject) {
chrome.fileManagerPrivate.markCacheAsMounted(
fileSystemId, false /* isMounted */, function() {
if (chrome.runtime.lastError) {
console.error(
'Unmount error: ' + chrome.runtime.lastError.message +
'.');
reject('FAILED');
return;
}
fulfill();
});
})
.then(function() {
return new Promise(function(fulfill, reject) {
var volume = unpacker.app.volumes[fileSystemId];
console.assert(
......@@ -534,7 +520,6 @@ unpacker.app = {
fulfill();
});
});
});
},
/**
......@@ -882,18 +867,6 @@ unpacker.app = {
loadPromise
.then(function() {
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(
{
fileSystemId: fileSystemId,
......
......@@ -726,8 +726,6 @@ callback GetEntryPropertiesCallback =
// |sourcePath| Source path of the mount.
callback AddMountCallback = void(DOMString sourcePath);
callback MarkCacheAsMountedCallback = void();
// |volumeMetadataList| The list of VolumeMetadata representing mounted volumes.
callback GetVolumeMetadataListCallback =
void(VolumeMetadata[] volumeMetadataList);
......@@ -956,16 +954,6 @@ interface Functions {
// |volumeId| An ID of the volume.
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.
// |callback|
static void getVolumeMetadataList(GetVolumeMetadataListCallback callback);
......
......@@ -667,19 +667,6 @@ chrome.fileManagerPrivate.addMount = function(source, callback) {};
*/
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|
* @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