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