Commit 717169f8 authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

[directory-tree] Improve Drive rootType lookup speed

location.rootType is evaluated every time it is referenced. Store root
type in a local variable for speed. Update routine comments.

No change in behavior, no new tests.

Bug: 992819
Change-Id: I3bedd5bbe8bdd0098ded33b081ae65e26c0525b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1859794Reviewed-by: default avatarStuart Langley <slangley@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Noel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705842}
parent 65d25bba
...@@ -208,68 +208,64 @@ class DirectoryItem extends cr.ui.TreeItem { ...@@ -208,68 +208,64 @@ class DirectoryItem extends cr.ui.TreeItem {
} }
/** /**
* Returns true if this item is inside any part of My Drive. * Returns true if this.entry is inside any part of Drive 'My Drive'.
* @type {!boolean} * @type {!boolean}
*/ */
get insideMyDrive() { get insideMyDrive() {
if (!this.entry) { let rootType;
return false;
if (this.entry) {
const root = this.parentTree_.volumeManager.getLocationInfo(this.entry);
rootType = root ? root.rootType : null;
} }
const locationInfo = return rootType && (rootType === VolumeManagerCommon.RootType.DRIVE);
this.parentTree_.volumeManager.getLocationInfo(this.entry);
return locationInfo &&
locationInfo.rootType === VolumeManagerCommon.RootType.DRIVE;
} }
/** /**
* Returns true if this item is inside any part of Computers. * Returns true if this.entry is inside any part of Drive 'Computers'.
* @type {!boolean} * @type {!boolean}
*/ */
get insideComputers() { get insideComputers() {
if (!this.entry) { let rootType;
return false;
if (this.entry) {
const root = this.parentTree_.volumeManager.getLocationInfo(this.entry);
rootType = root ? root.rootType : null;
} }
const locationInfo = return rootType &&
this.parentTree_.volumeManager.getLocationInfo(this.entry); (rootType === VolumeManagerCommon.RootType.COMPUTERS_GRAND_ROOT ||
return locationInfo && rootType === VolumeManagerCommon.RootType.COMPUTER);
(locationInfo.rootType ===
VolumeManagerCommon.RootType.COMPUTERS_GRAND_ROOT ||
locationInfo.rootType === VolumeManagerCommon.RootType.COMPUTER);
} }
/** /**
* Returns true if this item is inside any part of Drive, including Team * Returns true if this.entry is inside any part of Drive.
* Drive.
* @type {!boolean} * @type {!boolean}
*/ */
get insideDrive() { get insideDrive() {
if (!this.entry) { let rootType;
return false;
if (this.entry) {
const root = this.parentTree_.volumeManager.getLocationInfo(this.entry);
rootType = root ? root.rootType : null;
} }
const locationInfo = return rootType &&
this.parentTree_.volumeManager.getLocationInfo(this.entry); (rootType === VolumeManagerCommon.RootType.DRIVE ||
return locationInfo && rootType === VolumeManagerCommon.RootType.SHARED_DRIVES_GRAND_ROOT ||
(locationInfo.rootType === VolumeManagerCommon.RootType.DRIVE || rootType === VolumeManagerCommon.RootType.SHARED_DRIVE ||
locationInfo.rootType === rootType === VolumeManagerCommon.RootType.COMPUTERS_GRAND_ROOT ||
VolumeManagerCommon.RootType.SHARED_DRIVES_GRAND_ROOT || rootType === VolumeManagerCommon.RootType.COMPUTER ||
locationInfo.rootType === VolumeManagerCommon.RootType.SHARED_DRIVE || rootType === VolumeManagerCommon.RootType.DRIVE_OFFLINE ||
locationInfo.rootType === rootType === VolumeManagerCommon.RootType.DRIVE_SHARED_WITH_ME ||
VolumeManagerCommon.RootType.COMPUTERS_GRAND_ROOT || rootType === VolumeManagerCommon.RootType.DRIVE_FAKE_ROOT);
locationInfo.rootType === VolumeManagerCommon.RootType.COMPUTER || }
locationInfo.rootType === VolumeManagerCommon.RootType.DRIVE_OFFLINE ||
locationInfo.rootType === /**
VolumeManagerCommon.RootType.DRIVE_SHARED_WITH_ME || * Returns true if this.entry supports the 'shared' feature, as in, displays
locationInfo.rootType === * a shared icon. It's only supported inside 'My Drive' or 'Computers', even
VolumeManagerCommon.RootType.DRIVE_FAKE_ROOT); * Shared Drive does not support it.
}
/**
* If the this directory supports 'shared' feature, as in displays shared
* icon. It's only supported inside 'My Drive', even Shared Drive doesn't
* support it.
* @type {!boolean} * @type {!boolean}
*/ */
get supportDriveSpecificIcons() { get supportDriveSpecificIcons() {
......
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