| Commit-Queue | +1 |
function mojoTimeToDate(mojoTime: Time): Date {Helmut JanuschkaThere's a mojo_base.mojom.JSTime that will do this conversion automatically.
thx!
mojo_base.mojom.Time state_change_time;Helmut JanuschkaNit: prefer JSTime here.
Done
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
1 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:
```
The name of the file: chrome/test/data/webui/discards/discards_test.ts
Insertions: 2, Deletions: 2.
@@ -30,7 +30,7 @@
discardReason: LifecycleUnitDiscardReason.EXTERNAL,
id: 0,
siteEngagementScore: 0,
- stateChangeTime: {internalValue: 0n},
+ stateChangeTime: new Date(0),
};
const dummy2: TabDiscardsInfo = {
title: 'title 2',
@@ -51,7 +51,7 @@
discardReason: LifecycleUnitDiscardReason.EXTERNAL,
id: 0,
siteEngagementScore: 0,
- stateChangeTime: {internalValue: 0n},
+ stateChangeTime: new Date(0),
};
['title', 'tabUrl', 'visibility', 'state', 'isAutoDiscardable',
```
```
The name of the file: chrome/browser/ui/webui/discards/discards.mojom
Insertions: 1, Deletions: 1.
@@ -71,7 +71,7 @@
// Whether or not the tab has input focus.
bool has_focus;
// Wall-clock time at which the lifecycle state last changed.
- mojo_base.mojom.Time state_change_time;
+ mojo_base.mojom.JSTime state_change_time;
};
// Interface for providing information about discards. Lives in the browser
```
```
The name of the file: chrome/browser/resources/discards/discards_tab.ts
Insertions: 2, Deletions: 14.
@@ -9,7 +9,6 @@
import {getFaviconForPageURL} from 'chrome://resources/js/icon.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.js';
import {CrLitElement} from 'chrome://resources/lit/v3_0/lit.rollup.js';
-import type {Time} from 'chrome://resources/mojo/mojo/public/mojom/base/time.mojom-webui.js';
import {boolToString, durationToString, getOrCreateDetailsProvider} from './discards.js';
import type {DetailsProviderRemote, TabDiscardsInfo} from './discards.mojom-webui.js';
@@ -19,17 +18,6 @@
import {LifecycleUnitDiscardReason, LifecycleUnitLoadingState, LifecycleUnitState} from './lifecycle_unit_state.mojom-webui.js';
import {SortedTableMixinLit} from './sorted_table_mixin_lit.js';
-// Converts a `mojo_base.mojom.Time` to a JS `Date`. `internalValue` is
-// microseconds since the Windows FILETIME epoch (1601-01-01 UTC); `Date`
-// expects milliseconds since the Unix epoch.
-function mojoTimeToDate(mojoTime: Time): Date {
- const windowsEpoch = Date.UTC(1601, 0, 1, 0, 0, 0, 0);
- const unixEpoch = Date.UTC(1970, 0, 1, 0, 0, 0, 0);
- const epochDeltaInMs = unixEpoch - windowsEpoch;
- const timeInMs = Number(mojoTime.internalValue) / 1000;
- return new Date(timeInMs - epochDeltaInMs);
-}
-
function compareByTitle(a: TabDiscardsInfo, b: TabDiscardsInfo): number {
const val1 = a.title.toLowerCase();
const val2 = b.title.toLowerCase();
@@ -292,7 +280,7 @@
private lifecycleStateToString_(
state: LifecycleUnitState, reason: LifecycleUnitDiscardReason,
visibility: LifecycleUnitVisibility, hasFocus: boolean,
- stateChangeTime: Time): string {
+ stateChangeTime: Date): string {
function pageLifecycleStateFromVisibilityAndFocus(): string {
switch (visibility) {
case LifecycleUnitVisibility.HIDDEN:
@@ -314,7 +302,7 @@
case LifecycleUnitState.DISCARDED:
return 'discarded (' + this.discardReasonToString_(reason) + ')' +
((reason === LifecycleUnitDiscardReason.URGENT) ?
- ' at ' + mojoTimeToDate(stateChangeTime).toLocaleString() :
+ ' at ' + stateChangeTime.toLocaleString() :
'');
default:
assertNotReached();
```
Use mojo JSTime for chrome://discards state_change_time
Stamp a wall-clock alongside TimeTicks in LifecycleUnitBase::SetState
and ship it via the mojom JSTime field so the display is an actual wall
clock instead of a TimeTicks::UnixEpoch-relative TimeDelta.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |