Skip to content

Commit

Permalink
recent: Use modificationByMeDate in Recent root.
Browse files Browse the repository at this point in the history
This change adds MetadataModel.setUseModificationByMeTime() to ask it to
override modificationDate field in MetadataItem with
modificationByMeDate.

This function is called on changing the current directory, and set to
true when Recent root is being opened.

Bug: 758677
Test: Last modified column in Recent is replaced
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I838e7ab5b46d4a4962becea60a2225531ba67363
Reviewed-on: https://chromium-review.googlesource.com/676506
Reviewed-by: Naoki Fukino <[email protected]>
Reviewed-by: Tomasz Mikolajewski <[email protected]>
Commit-Queue: Shuhei Takahashi <[email protected]>
Cr-Commit-Position: refs/heads/master@{#504269}
  • Loading branch information
nya3jp authored and Commit Bot committed Sep 26, 2017
1 parent 84fee0e commit 6a8b4f5
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ void FillEntryPropertiesValueForDrive(const drive::ResourceEntry& entry_proto,
properties->size.reset(new double(file_info.size()));
properties->modification_time.reset(new double(
base::Time::FromInternalValue(file_info.last_modified()).ToJsTime()));
properties->modification_by_me_time.reset(new double(
base::Time::FromInternalValue(entry_proto.last_modified_by_me())
.ToJsTime()));

if (!entry_proto.has_file_specific_info())
return;
Expand Down
4 changes: 4 additions & 0 deletions chrome/common/extensions/api/file_manager_private.idl
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ enum DriveShareType {
enum EntryPropertyName {
size,
modificationTime,
modificationByMeTime,
thumbnailUrl,
croppedThumbnailUrl,
imageWidth,
Expand Down Expand Up @@ -248,6 +249,9 @@ dictionary EntryProperties {
// Timestamp of entry update time, in milliseconds past the epoch.
double? modificationTime;

// Timestamp of entry update time by me, in milliseconds past the epoch.
double? modificationByMeTime;

// URL to the Drive thumbnail image for this file.
DOMString? thumbnailUrl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var FileTask;
* @typedef {{
* size: (number|undefined),
* modificationTime: (number|undefined),
* modificationByMeTime: (number|undefined),
* thumbnailUrl: (string|undefined),
* croppedThumbnailUrl: (string|undefined),
* externalFileUrl: (string|undefined),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
'folder_shortcuts_data_model',
'gear_menu_controller',
'import_controller',
'last_modified_controller',
'launch_param',
'main_window_component',
'metadata_update_controller',
Expand Down Expand Up @@ -331,6 +332,14 @@
],
'includes': ['../../../compile_js2.gypi'],
},
{
'target_name': 'last_modified_controller',
'dependencies': [
'directory_model',
'ui/compiled_resources2.gyp:file_table',
],
'includes': ['../../../compile_js2.gypi'],
},
{
'target_name': 'launch_param',
'dependencies': [
Expand Down
1 change: 1 addition & 0 deletions ui/file_manager/file_manager/foreground/js/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ constants.LIST_CONTAINER_METADATA_PREFETCH_PROPERTY_NAMES = [
'customIconUrl',
'hosted',
'modificationTime',
'modificationByMeTime',
'shared',
'size',
];
37 changes: 33 additions & 4 deletions ui/file_manager/file_manager/foreground/js/file_list_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ function FileListModel(metadataModel) {
* @private {number}
*/
this.numImageFiles_ = 0;

/**
* Whether to use modificationByMeTime as "Last Modified" time.
* @private {boolean}
*/
this.useModificationByMeTime_ = false;
}

/**
Expand Down Expand Up @@ -263,6 +269,15 @@ FileListModel.prototype.isImageDominant = function() {
this.numImageFiles_ * 10 >= this.numFiles_ * 8;
};

/**
* Sets whether to use modificationByMeTime as "Last Modified" time.
* @param {boolean} useModificationByMeTime
*/
FileListModel.prototype.setUseModificationByMeTime = function(
useModificationByMeTime) {
this.useModificationByMeTime_ = useModificationByMeTime;
};

/**
* Updates the statistics about contents when new entry is about to be added.
* @param {Entry} entry Entry of the new item.
Expand Down Expand Up @@ -324,10 +339,10 @@ FileListModel.prototype.compareMtime_ = function(a, b) {
if (a.isDirectory !== b.isDirectory)
return a.isDirectory === this.isDescendingOrder_ ? 1 : -1;

var properties =
this.metadataModel_.getCache([a, b], ['modificationTime']);
var aTime = properties[0].modificationTime || 0;
var bTime = properties[1].modificationTime || 0;
var properties = this.metadataModel_.getCache(
[a, b], ['modificationTime', 'modificationByMeTime']);
var aTime = this.getMtime_(properties[0]);
var bTime = this.getMtime_(properties[1]);

if (aTime > bTime)
return 1;
Expand All @@ -338,6 +353,20 @@ FileListModel.prototype.compareMtime_ = function(a, b) {
return util.compareName(a, b);
};

/**
* Returns the modification time from a properties object.
* "Modification time" can be modificationTime or modificationByMeTime
* depending on this.useModificationByMeTime_.
* @param {!Object} properties Properties object.
* @return {number} Modification time.
* @private
*/
FileListModel.prototype.getMtime_ = function(properties) {
if (this.useModificationByMeTime_)
return properties.modificationByMeTime || properties.modificationTime || 0;
return properties.modificationTime || 0;
};

/**
* Compares entries by size first, then by name.
* @param {Entry} a First entry.
Expand Down
8 changes: 8 additions & 0 deletions ui/file_manager/file_manager/foreground/js/file_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ function FileManager() {
*/
this.metadataUpdateController_ = null;

/**
* Last modified controller.
* @private {LastModifiedController}
*/
this.lastModifiedController_ = null;

/**
* Component for main window and its misc UI parts.
* @type {MainWindowComponent}
Expand Down Expand Up @@ -586,6 +592,8 @@ FileManager.prototype = /** @struct */ {
assert(this.folderShortcutsModel_),
this.fileBrowserBackground_.driveSyncHandler,
this.selectionHandler_, assert(this.ui_));
this.lastModifiedController_ = new LastModifiedController(
this.ui_.listContainer.table, this.directoryModel_);

this.quickViewModel_ = new QuickViewModel();
var fileListSelectionModel = /** @type {!cr.ui.ListSelectionModel} */ (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
* Controls last modified column in the file table.
* @param {!FileTable} fileTable File table UI.
* @param {!DirectoryModel} directoryModel Directory model.
* @constructor
* @struct
*/
function LastModifiedController(fileTable, directoryModel) {
/**
* @private {!FileTable}
*/
this.fileTable_ = fileTable;

/**
* @private {!DirectoryModel}
*/
this.directoryModel_ = directoryModel;

this.directoryModel_.addEventListener(
'scan-started', this.onScanStarted_.bind(this));
}

/**
* Handles directory scan start.
* @private
*/
LastModifiedController.prototype.onScanStarted_ = function() {
// If the current directory is Recent root, request FileTable to use
// modificationByMeTime instead of modificationTime in last modified column.
var useModificationByMeTime = this.directoryModel_.getCurrentRootType() ===
VolumeManagerCommon.RootType.RECENT;
this.fileTable_.setUseModificationByMeTime(useModificationByMeTime);
this.directoryModel_.getFileList().setUseModificationByMeTime(
useModificationByMeTime);
};
1 change: 1 addition & 0 deletions ui/file_manager/file_manager/foreground/js/main_scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
// <include src="sort_menu_controller.js">
// <include src="gear_menu_controller.js">
// <include src="import_controller.js">
// <include src="last_modified_controller.js">
// <include src="launch_param.js">
// <include src="metadata/content_metadata_provider.js">
// <include src="metadata/external_metadata_provider.js">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,10 @@ function ExternalMetadataProvider() {
* @const {!Array<string>}
*/
ExternalMetadataProvider.PROPERTY_NAMES = [
'availableOffline',
'availableWhenMetered',
'contentMimeType',
'croppedThumbnailUrl',
'customIconUrl',
'dirty',
'externalFileUrl',
'hosted',
'imageHeight',
'imageRotation',
'imageWidth',
'modificationTime',
'pinned',
'present',
'shared',
'sharedWithMe',
'size',
'availableOffline', 'availableWhenMetered', 'contentMimeType',
'croppedThumbnailUrl', 'customIconUrl', 'dirty', 'externalFileUrl', 'hosted',
'imageHeight', 'imageRotation', 'imageWidth', 'modificationTime',
'modificationByMeTime', 'pinned', 'present', 'shared', 'sharedWithMe', 'size',
'thumbnailUrl'
];

Expand Down Expand Up @@ -106,6 +93,9 @@ ExternalMetadataProvider.prototype.convertResults_ =
item.imageWidth = prop.imageWidth;
if (prop.modificationTime !== undefined || nameMap['modificationTime'])
item.modificationTime = new Date(prop.modificationTime);
if (prop.modificationByMeTime !== undefined ||
nameMap['modificationByMeTime'])
item.modificationByMeTime = new Date(prop.modificationByMeTime);
if (prop.pinned !== undefined || nameMap['pinned'])
item.pinned = prop.pinned;
if (prop.present !== undefined || nameMap['present'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ function MetadataItem() {
*/
this.modificationTime;

/**
* @public {!Date|undefined}
*/
this.modificationByMeTime;

/**
* Thumbnail URL obtained from external provider.
* @public {string|undefined}
Expand Down
19 changes: 17 additions & 2 deletions ui/file_manager/file_manager/foreground/js/ui/file_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ FileTable.decorate = function(
*/
self.importStatusVisible_ = true;

/** @private {boolean} */
self.useModificationByMeTime_ = false;

var nameColumn = new cr.ui.table.TableColumn(
'name', str('NAME_COLUMN_LABEL'), fullPage ? 386 : 324);
nameColumn.renderFunction = self.renderName_.bind(self);
Expand Down Expand Up @@ -622,6 +625,15 @@ FileTable.prototype.setDateTimeFormat = function(use12hourClock) {
this.formatter_.setDateTimeFormat(use12hourClock);
};

/**
* Sets whether to use modificationByMeTime as "Last Modified" time.
* @param {boolean} useModificationByMeTime
*/
FileTable.prototype.setUseModificationByMeTime = function(
useModificationByMeTime) {
this.useModificationByMeTime_ = useModificationByMeTime;
};

/**
* Obtains if the drag selection should be start or not by referring the mouse
* event.
Expand Down Expand Up @@ -870,8 +882,11 @@ FileTable.prototype.renderDate_ = function(entry, columnId, table) {
* @private
*/
FileTable.prototype.updateDate_ = function(div, entry) {
var modTime = this.metadataModel_.getCache(
[entry], ['modificationTime'])[0].modificationTime;
var item = this.metadataModel_.getCache(
[entry], ['modificationTime', 'modificationByMeTime'])[0];
var modTime = this.useModificationByMeTime_ ?
item.modificationByMeTime || item.modificationTime :
item.modificationTime;

div.textContent = this.formatter_.formatModDate(modTime);
};
Expand Down

0 comments on commit 6a8b4f5

Please sign in to comment.