Commit 49c3b5dd authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

Make Crostini externs file an @interface

 - change the Crostini externs file to be an @interface class
   - add missing methods from the current implementation
   - add background BUILD rules to Closure compile {Crostini}
 - rename the background page Crostini to CrostiniImpl and
   make it @implements the {Crostini} class interface
 - use CrostiniImpl as the implementation for Files App: it is
   only instantiated on the Files app background page.
 - use CrostiniImpl for foreground unittests for now, until a
   mock (test-only) implementation is available.

No change in test behavior, no new tests.

Tbr: lucmult@
Bug: 911024
Change-Id: I580c9701374d6d8c1842a96040625c6be719ed64
Reviewed-on: https://chromium-review.googlesource.com/c/1358319
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613341}
parent f6c9c797
......@@ -4,10 +4,22 @@
/**
* Crostini shared path state handler.
* @constructor
*
* @interface
*/
function Crostini() {}
/**
* Initialize Volume Manager.
* @param {!VolumeManager} volumeManager
*/
Crostini.prototype.init = function(volumeManager) {};
/**
* Register for any shared path changes.
*/
Crostini.prototype.listen = function() {};
/**
* Set from feature 'crostini-files'.
* @param {boolean} enabled
......@@ -15,7 +27,8 @@ function Crostini() {}
Crostini.prototype.setEnabled = function(enabled) {};
/**
* @return {boolean} Whether crostini is enabled.
* Returns true if crostini is enabled.
* @return {boolean}
*/
Crostini.prototype.isEnabled = function() {};
......
......@@ -79,6 +79,7 @@ js_library("closure_compile_externs") {
sources = []
externs_list = [
"$externs_path/metrics_private.js",
"../../../externs/background/crostini.js",
"../../../externs/background/drive_sync_handler.js",
"../../../externs/background/file_browser_background.js",
"../../../externs/background/file_browser_background_full.js",
......@@ -146,6 +147,7 @@ js_library("crostini") {
"//ui/file_manager/base/js:volume_manager_types",
"//ui/file_manager/externs:volume_manager",
]
externs_list = [ "//ui/file_manager/externs/background/crostini.js" ]
}
js_unittest("crostini_unittest") {
......
......@@ -80,7 +80,7 @@ function FileBrowserBackgroundImpl() {
this.driveSyncHandler);
/** @type {!Crostini} */
this.crostini = new Crostini();
this.crostini = new CrostiniImpl();
/**
* String assets.
......
......@@ -3,11 +3,16 @@
// found in the LICENSE file.
/**
* Crostini shared path state handler.
* Implementation of Crostini shared path state handler.
*
* @constructor
* @implements {Crostini}
*/
function Crostini() {
/** @private {boolean} */
function CrostiniImpl() {
/**
* True if crostini is enabled.
* @private {boolean}
*/
this.enabled_ = false;
/**
......@@ -25,7 +30,7 @@ function Crostini() {
* @type {!Map<VolumeManagerCommon.RootType, string>}
* @const
*/
Crostini.VALID_ROOT_TYPES_FOR_SHARE = new Map([
CrostiniImpl.VALID_ROOT_TYPES_FOR_SHARE = new Map([
[VolumeManagerCommon.RootType.DOWNLOADS, 'Downloads'],
[VolumeManagerCommon.RootType.REMOVABLE, 'Removable'],
]);
......@@ -38,7 +43,7 @@ Crostini.VALID_ROOT_TYPES_FOR_SHARE = new Map([
* @type {!Map<VolumeManagerCommon.RootType, string>}
* @const
*/
Crostini.VALID_DRIVE_FS_ROOT_TYPES_FOR_SHARE = new Map([
CrostiniImpl.VALID_DRIVE_FS_ROOT_TYPES_FOR_SHARE = new Map([
[VolumeManagerCommon.RootType.COMPUTERS_GRAND_ROOT, 'DriveComputers'],
[VolumeManagerCommon.RootType.COMPUTER, 'DriveComputers'],
[VolumeManagerCommon.RootType.DRIVE, 'MyDrive'],
......@@ -46,21 +51,24 @@ Crostini.VALID_DRIVE_FS_ROOT_TYPES_FOR_SHARE = new Map([
[VolumeManagerCommon.RootType.TEAM_DRIVE, 'TeamDrive'],
]);
/** @private {string} */
Crostini.UMA_ROOT_TYPE_OTHER = 'Other';
/**
* @private {string}
* @const
*/
CrostiniImpl.UMA_ROOT_TYPE_OTHER = 'Other';
/**
* Initialize Volume Manager.
* @param {!VolumeManager} volumeManager
*/
Crostini.prototype.init = function(volumeManager) {
CrostiniImpl.prototype.init = function(volumeManager) {
this.volumeManager_ = volumeManager;
};
/**
* Register for any shared path changes.
*/
Crostini.prototype.listen = function() {
CrostiniImpl.prototype.listen = function() {
chrome.fileManagerPrivate.onCrostiniSharedPathsChanged.addListener(
this.onChange_.bind(this));
};
......@@ -69,14 +77,15 @@ Crostini.prototype.listen = function() {
* Set from feature 'crostini-files'.
* @param {boolean} enabled
*/
Crostini.prototype.setEnabled = function(enabled) {
CrostiniImpl.prototype.setEnabled = function(enabled) {
this.enabled_ = enabled;
};
/**
* @return {boolean} Whether crostini is enabled.
* Returns true if crostini is enabled.
* @return {boolean}
*/
Crostini.prototype.isEnabled = function() {
CrostiniImpl.prototype.isEnabled = function() {
return this.enabled_;
};
......@@ -84,7 +93,7 @@ Crostini.prototype.isEnabled = function() {
* Registers an entry as a shared path.
* @param {!Entry} entry
*/
Crostini.prototype.registerSharedPath = function(entry) {
CrostiniImpl.prototype.registerSharedPath = function(entry) {
const info = this.volumeManager_.getLocationInfo(entry);
if (!info)
return;
......@@ -101,9 +110,9 @@ Crostini.prototype.registerSharedPath = function(entry) {
paths[entry.fullPath] = true;
// Record UMA.
let suffix = Crostini.VALID_ROOT_TYPES_FOR_SHARE.get(info.rootType) ||
Crostini.VALID_DRIVE_FS_ROOT_TYPES_FOR_SHARE.get(info.rootType) ||
Crostini.UMA_ROOT_TYPE_OTHER;
let suffix = CrostiniImpl.VALID_ROOT_TYPES_FOR_SHARE.get(info.rootType) ||
CrostiniImpl.VALID_DRIVE_FS_ROOT_TYPES_FOR_SHARE.get(info.rootType) ||
CrostiniImpl.UMA_ROOT_TYPE_OTHER;
metrics.recordSmallCount(
'CrostiniSharedPaths.Depth.' + suffix,
entry.fullPath.split('/').length - 1);
......@@ -113,7 +122,7 @@ Crostini.prototype.registerSharedPath = function(entry) {
* Unregisters entry as a shared path.
* @param {!Entry} entry
*/
Crostini.prototype.unregisterSharedPath = function(entry) {
CrostiniImpl.prototype.unregisterSharedPath = function(entry) {
const info = this.volumeManager_.getLocationInfo(entry);
if (!info)
return;
......@@ -128,7 +137,7 @@ Crostini.prototype.unregisterSharedPath = function(entry) {
* @param {chrome.fileManagerPrivate.CrostiniSharedPathsChangedEvent} event
* @private
*/
Crostini.prototype.onChange_ = function(event) {
CrostiniImpl.prototype.onChange_ = function(event) {
if (event.eventType === 'share') {
for (const entry of event.entries) {
this.registerSharedPath(entry);
......@@ -146,7 +155,7 @@ Crostini.prototype.onChange_ = function(event) {
* @return {boolean} True if path is shared either by a direct
* share or from one of its ancestor directories.
*/
Crostini.prototype.isPathShared = function(entry) {
CrostiniImpl.prototype.isPathShared = function(entry) {
const root = this.volumeManager_.getLocationInfo(entry).rootType;
const paths = this.shared_paths_[root];
if (!paths)
......@@ -166,7 +175,7 @@ Crostini.prototype.isPathShared = function(entry) {
* @param {!Entry} entry
* @param {boolean} persist If path is to be persisted.
*/
Crostini.prototype.canSharePath = function(entry, persist) {
CrostiniImpl.prototype.canSharePath = function(entry, persist) {
if (!this.enabled_)
return false;
......@@ -176,7 +185,7 @@ Crostini.prototype.canSharePath = function(entry, persist) {
// Allow Downloads, and Drive if DriveFS is enabled.
const rootType = this.volumeManager_.getLocationInfo(entry).rootType;
return Crostini.VALID_ROOT_TYPES_FOR_SHARE.has(rootType) ||
return CrostiniImpl.VALID_ROOT_TYPES_FOR_SHARE.has(rootType) ||
(loadTimeData.getBoolean('DRIVE_FS_ENABLED') &&
Crostini.VALID_DRIVE_FS_ROOT_TYPES_FOR_SHARE.has(rootType));
CrostiniImpl.VALID_DRIVE_FS_ROOT_TYPES_FOR_SHARE.has(rootType));
};
......@@ -48,7 +48,7 @@ function setUp() {
/** @type {!VolumeManagerCommon.RootType<string>} */ ('testroot');
// Create and initialize Crostini.
crostini = new Crostini();
crostini = new CrostiniImpl();
crostini.init(volumeManager);
}
......@@ -136,7 +136,7 @@ function testCanSharePath() {
// Test with DriveFs disabled.
setDriveFsEnabled(false);
const disallowed = new Map(Crostini.VALID_DRIVE_FS_ROOT_TYPES_FOR_SHARE);
const disallowed = new Map(CrostiniImpl.VALID_DRIVE_FS_ROOT_TYPES_FOR_SHARE);
disallowed.set('test', 'test');
for (let type of disallowed.keys()) {
volumeManagerRootType =
......@@ -156,8 +156,8 @@ function testCanSharePath() {
// Test with DriveFs enabled.
setDriveFsEnabled(true);
const allowed = new Map([
...Crostini.VALID_ROOT_TYPES_FOR_SHARE,
...Crostini.VALID_DRIVE_FS_ROOT_TYPES_FOR_SHARE
...CrostiniImpl.VALID_ROOT_TYPES_FOR_SHARE,
...CrostiniImpl.VALID_DRIVE_FS_ROOT_TYPES_FOR_SHARE
]);
for (let type of allowed.keys()) {
volumeManagerRootType = type;
......
......@@ -77,7 +77,7 @@ function getMockFileManager() {
}
},
namingController: {},
crostini: new Crostini(),
crostini: new CrostiniImpl(),
};
result.crostini.init(result.volumeManager);
return result;
......@@ -484,7 +484,7 @@ function testMaybeShareCrostiniOrShowDialog() {
const sharedDir = new MockDirectoryEntry(mockFsDownloads, '/shared');
const shared = new MockFileEntry(mockFsDownloads, '/shared/file');
const crostini = new Crostini();
const crostini = new CrostiniImpl();
crostini.init(volumeManagerDownloads);
crostini.setEnabled(true);
crostini.registerSharedPath(sharedDir, volumeManagerDownloads);
......
......@@ -34,13 +34,17 @@ function setUp() {
cr.ui.decorate('command', cr.ui.Command);
}
/**
* Returns a Crostini implementation.
* @return {!Crostini}
*/
function createCrostini() {
const crostini = new Crostini();
crostini.init({
getLocationInfo: () => {
return 'test';
}
});
const crostini = new CrostiniImpl();
crostini.init(/** @type {!VolumeManager} */ ({
getLocationInfo: (entry) => {
return /** @type {!EntryLocation} */ ('test');
},
}));
return crostini;
}
......
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