Commit 71a4de04 authored by Joel Hockey's avatar Joel Hockey Committed by Commit Bot

FilesApp: utils needed for crostini sharing tast test

To be used in tast test:
https://chromium-review.googlesource.com/c/chromiumos/platform/tast-tests/+/1351973

* Added chrome.fileManagerPrivate.unsharePathWithCrostini.  This function
  complements the existing fileManagerPrivate.sharePathsWithCrostini.

* Added util.getEntries which returns a Promise with an object of
  all entries of a provided volume keyed by fullPath.  This is a
  handy wrapper over the existing util.readEntriesRecursively.

Bug: 907231
Change-Id: Ieccdc76a6457fed44d85633e9a02c658424b967d
Reviewed-on: https://chromium-review.googlesource.com/c/1354755Reviewed-by: default avatarStuart Langley <slangley@chromium.org>
Reviewed-by: default avatarBen Wells <benwells@chromium.org>
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612555}
parent 173a384b
...@@ -702,6 +702,34 @@ void FileManagerPrivateInternalSharePathsWithCrostiniFunction:: ...@@ -702,6 +702,34 @@ void FileManagerPrivateInternalSharePathsWithCrostiniFunction::
Respond(success ? NoArguments() : Error(failure_reason)); Respond(success ? NoArguments() : Error(failure_reason));
} }
ExtensionFunction::ResponseAction
FileManagerPrivateInternalUnsharePathWithCrostiniFunction::Run() {
using extensions::api::file_manager_private_internal::
UnsharePathWithCrostini::Params;
const std::unique_ptr<Params> params(Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
Profile* profile = Profile::FromBrowserContext(browser_context());
const scoped_refptr<storage::FileSystemContext> file_system_context =
file_manager::util::GetFileSystemContextForRenderFrameHost(
profile, render_frame_host());
storage::FileSystemURL cracked =
file_system_context->CrackURL(GURL(params->url));
crostini::CrostiniSharePath::GetForProfile(profile)->UnsharePath(
crostini::kCrostiniDefaultVmName, cracked.path(),
base::BindOnce(
&FileManagerPrivateInternalUnsharePathWithCrostiniFunction::
UnsharePathCallback,
this));
return RespondLater();
}
void FileManagerPrivateInternalUnsharePathWithCrostiniFunction::
UnsharePathCallback(bool success, std::string failure_reason) {
Respond(success ? NoArguments() : Error(failure_reason));
}
ExtensionFunction::ResponseAction ExtensionFunction::ResponseAction
FileManagerPrivateInternalGetCrostiniSharedPathsFunction::Run() { FileManagerPrivateInternalGetCrostiniSharedPathsFunction::Run() {
Profile* profile = Profile::FromBrowserContext(browser_context()); Profile* profile = Profile::FromBrowserContext(browser_context());
......
...@@ -324,6 +324,27 @@ class FileManagerPrivateInternalSharePathsWithCrostiniFunction ...@@ -324,6 +324,27 @@ class FileManagerPrivateInternalSharePathsWithCrostiniFunction
FileManagerPrivateInternalSharePathsWithCrostiniFunction); FileManagerPrivateInternalSharePathsWithCrostiniFunction);
}; };
// Implements the chrome.fileManagerPrivate.unsharePathWithCrostini
// method. Unshares specified path.
class FileManagerPrivateInternalUnsharePathWithCrostiniFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION(
"fileManagerPrivateInternal.unsharePathWithCrostini",
FILEMANAGERPRIVATEINTERNAL_UNSHAREPATHWITHCROSTINI)
FileManagerPrivateInternalUnsharePathWithCrostiniFunction() = default;
protected:
~FileManagerPrivateInternalUnsharePathWithCrostiniFunction() override =
default;
private:
ResponseAction Run() override;
void UnsharePathCallback(bool success, std::string failure_reason);
DISALLOW_COPY_AND_ASSIGN(
FileManagerPrivateInternalUnsharePathWithCrostiniFunction);
};
// Implements the chrome.fileManagerPrivate.getCrostiniSharedPaths // Implements the chrome.fileManagerPrivate.getCrostiniSharedPaths
// method. Returns list of file entries. // method. Returns list of file entries.
class FileManagerPrivateInternalGetCrostiniSharedPathsFunction class FileManagerPrivateInternalGetCrostiniSharedPathsFunction
......
...@@ -1150,7 +1150,7 @@ interface Functions { ...@@ -1150,7 +1150,7 @@ interface Functions {
// |callback| // |callback|
static void mountCrostini(SimpleCallback callback); static void mountCrostini(SimpleCallback callback);
// Shares directory with crostini container. // Shares paths with crostini container.
// |entries| Entries of the files or directories to share. // |entries| Entries of the files or directories to share.
// |persist| If true, shares will persist across restarts. // |persist| If true, shares will persist across restarts.
// |callback| // |callback|
...@@ -1158,6 +1158,13 @@ interface Functions { ...@@ -1158,6 +1158,13 @@ interface Functions {
static void sharePathsWithCrostini( static void sharePathsWithCrostini(
[instanceof=Entry] object[] entries, boolean persist, SimpleCallback callback); [instanceof=Entry] object[] entries, boolean persist, SimpleCallback callback);
// Unshares path with crostini container.
// |entry| Entry of the file or directory to unshare.
// |callback|
[nocompile]
static void unsharePathWithCrostini(
[instanceof=Entry] object entry, SimpleCallback callback);
// Returns list of paths shared with crostini container. // Returns list of paths shared with crostini container.
[nocompile] [nocompile]
static void getCrostiniSharedPaths(GetCrostiniSharedPathsCallback callback); static void getCrostiniSharedPaths(GetCrostiniSharedPathsCallback callback);
......
...@@ -106,6 +106,7 @@ namespace fileManagerPrivateInternal { ...@@ -106,6 +106,7 @@ namespace fileManagerPrivateInternal {
GetRecentFilesCallback callback); GetRecentFilesCallback callback);
static void sharePathsWithCrostini(DOMString[] urls, boolean persist, static void sharePathsWithCrostini(DOMString[] urls, boolean persist,
SimpleCallback callback); SimpleCallback callback);
static void unsharePathWithCrostini(DOMString url, SimpleCallback callback);
static void getCrostiniSharedPaths( static void getCrostiniSharedPaths(
GetCrostiniSharedPathsCallback callback); GetCrostiniSharedPathsCallback callback);
static void getLinuxPackageInfo(DOMString url, static void getLinuxPackageInfo(DOMString url,
......
...@@ -237,6 +237,12 @@ binding.registerCustomHook(function(bindingsAPI) { ...@@ -237,6 +237,12 @@ binding.registerCustomHook(function(bindingsAPI) {
urls, persist, callback); urls, persist, callback);
}); });
apiFunctions.setHandleRequest(
'unsharePathWithCrostini', function(entry, callback) {
fileManagerPrivateInternal.unsharePathWithCrostini(
getEntryURL(entry), callback);
});
apiFunctions.setHandleRequest( apiFunctions.setHandleRequest(
'getCrostiniSharedPaths', function(callback) { 'getCrostiniSharedPaths', function(callback) {
fileManagerPrivateInternal.getCrostiniSharedPaths( fileManagerPrivateInternal.getCrostiniSharedPaths(
......
...@@ -73,5 +73,11 @@ chrome.test.runTests([ ...@@ -73,5 +73,11 @@ chrome.test.runTests([
chrome.test.callbackPass((entries, firstForSession) => { chrome.test.callbackPass((entries, firstForSession) => {
chrome.test.assertFalse(firstForSession); chrome.test.assertFalse(firstForSession);
})); }));
} },
function testUnsharePathWithCrostiniSuccess() {
getEntry('downloads', 'share_dir').then((entry) => {
chrome.fileManagerPrivate.unsharePathWithCrostini(
entry, chrome.test.callbackPass());
});
},
]); ]);
...@@ -1357,6 +1357,7 @@ enum HistogramValue { ...@@ -1357,6 +1357,7 @@ enum HistogramValue {
CRYPTOTOKENPRIVATE_CANPROXYTOWEBAUTHN = 1294, CRYPTOTOKENPRIVATE_CANPROXYTOWEBAUTHN = 1294,
INPUTMETHODPRIVATE_GETSETTING = 1295, INPUTMETHODPRIVATE_GETSETTING = 1295,
INPUTMETHODPRIVATE_SETSETTING = 1296, INPUTMETHODPRIVATE_SETSETTING = 1296,
FILEMANAGERPRIVATEINTERNAL_UNSHAREPATHWITHCROSTINI = 1297,
// Last entry: Add new entries above, then run: // Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py // python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY ENUM_BOUNDARY
......
...@@ -961,15 +961,24 @@ chrome.fileManagerPrivate.isCrostiniEnabled = function(callback) {}; ...@@ -961,15 +961,24 @@ chrome.fileManagerPrivate.isCrostiniEnabled = function(callback) {};
chrome.fileManagerPrivate.mountCrostini = function(callback) {}; chrome.fileManagerPrivate.mountCrostini = function(callback) {};
/** /**
* Shares directory with crostini container. * Shares paths with crostini container.
* @param {!Array<!Entry>} entries Entries of the files and directories to share. * @param {!Array<!Entry>} entries Entries of the files and directories to share.
* @param {boolean} persist If true, share will persist across restarts. * @param {boolean} persist If true, share will persist across restarts.
* @param {function()} callback Callback called after the folder is shared. * @param {function()} callback Callback called after the paths are shared.
* chrome.runtime.lastError will be set if there was an error. * chrome.runtime.lastError will be set if there was an error.
*/ */
chrome.fileManagerPrivate.sharePathsWithCrostini = function( chrome.fileManagerPrivate.sharePathsWithCrostini = function(
entries, persist, callback) {}; entries, persist, callback) {};
/**
* Unshares path with crostini container.
* @param {!Entry} entry Entry of the file or directory to unshare.
* @param {function()} callback Callback called after the path is unshared.
* chrome.runtime.lastError will be set if there was an error.
*/
chrome.fileManagerPrivate.unsharePathWithCrostini = function(
entry, callback) {};
/** /**
* Returns list of paths shared with the crostini container, and whether this is * Returns list of paths shared with the crostini container, and whether this is
* the first time this function is called for this session. * the first time this function is called for this session.
......
...@@ -17393,6 +17393,7 @@ Called by update_net_error_codes.py.--> ...@@ -17393,6 +17393,7 @@ Called by update_net_error_codes.py.-->
<int value="1294" label="CRYPTOTOKENPRIVATE_CANPROXYTOWEBAUTHN"/> <int value="1294" label="CRYPTOTOKENPRIVATE_CANPROXYTOWEBAUTHN"/>
<int value="1295" label="INPUTMETHODPRIVATE_GETSETTING"/> <int value="1295" label="INPUTMETHODPRIVATE_GETSETTING"/>
<int value="1296" label="INPUTMETHODPRIVATE_SETSETTING"/> <int value="1296" label="INPUTMETHODPRIVATE_SETSETTING"/>
<int value="1297" label="FILEMANAGERPRIVATEINTERNAL_UNSHAREPATHWITHCROSTINI"/>
</enum> </enum>
<enum name="ExtensionIconState"> <enum name="ExtensionIconState">
...@@ -174,6 +174,7 @@ js_library("util") { ...@@ -174,6 +174,7 @@ js_library("util") {
"../../../externs/app_window_common.js", "../../../externs/app_window_common.js",
"../../../externs/entry_location.js", "../../../externs/entry_location.js",
"../../../externs/platform.js", "../../../externs/platform.js",
"../../../externs/volume_info.js",
] ]
} }
......
...@@ -1505,6 +1505,31 @@ util.readEntriesRecursively = function( ...@@ -1505,6 +1505,31 @@ util.readEntriesRecursively = function(
processEntry(rootEntry, 0); processEntry(rootEntry, 0);
}; };
/**
* Do not remove or modify. Used in vm.CrostiniFiles tast tests at:
* https://chromium.googlesource.com/chromiumos/platform/tast-tests
*
* Get all entries for the given volume.
* @param {!VolumeInfo} volumeInfo
* @return {!Promise<Object<Entry>>} all entries keyed by fullPath.
*/
util.getEntries = function(volumeInfo) {
const root = volumeInfo.fileSystem.root;
return new Promise((resolve, reject) => {
const allEntries = {'/': root};
function entriesCallback(someEntries) {
someEntries.forEach(entry => {
allEntries[entry.fullPath] = entry;
});
}
function successCallback() {
resolve(allEntries);
}
util.readEntriesRecursively(
root, entriesCallback, successCallback, reject, () => false);
});
};
/** /**
* Executes a functions only when the context is not the incognito one in a * Executes a functions only when the context is not the incognito one in a
* regular session. * regular session.
......
...@@ -190,6 +190,9 @@ chrome.fileManagerPrivate = { ...@@ -190,6 +190,9 @@ chrome.fileManagerPrivate = {
sharePathsWithCrostini: (entries, persist, callback) => { sharePathsWithCrostini: (entries, persist, callback) => {
setTimeout(callback, 0); setTimeout(callback, 0);
}, },
unsharePathWithCrostini: (entry, callback) => {
setTimeout(callback, 0);
},
nextCopyId_: 0, nextCopyId_: 0,
startCopy: (entry, parentEntry, newName, callback) => { startCopy: (entry, parentEntry, newName, callback) => {
// Returns copyId immediately. // Returns copyId immediately.
......
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