0

Convert WebContents::LastActiveTime to base::Time

TimeTicks should only be used to measure local duration (same machine,
same process) and not absolute time. TimeTicks may not increment during
process suspension (this is platform dependent) and so TimeTicks created
at different time do not share a common reference. As a consequence, it
is not possible to convert them to absolute times.

WebContents::LastActiveTime is intended to represent the date of the
last activation time, that will be persisted and sent to sync. Because
it uses TimeTicks, this field is incorrectly synced for WebContents
created on Mac or ChromeOS machines. Convert the field to a base::Time
to fix it.
Convert the field to a base::Time to fix it.


Bug: 349542284
Change-Id: Iba85b1579f8ee9ec22d60219c8f8f444eef3336d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5735384
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1338463}
This commit is contained in:
Olivier ROBIN
2024-08-07 14:32:29 +00:00
committed by Chromium LUCI CQ
parent be5d0586ca
commit da292fb29d
23 changed files with 108 additions and 67 deletions

@ -1090,16 +1090,11 @@ std::unique_ptr<SessionCommand> CreateSetActiveWindowCommand(
std::unique_ptr<SessionCommand> CreateLastActiveTimeCommand(
SessionID tab_id,
base::TimeTicks last_active_time) {
base::Time last_active_time) {
LastActiveTimePayload payload = {0};
payload.tab_id = tab_id.id();
// Convert the last_active_time from TimeTicks to Time.
base::TimeDelta delta_since_epoch =
last_active_time - base::TimeTicks::UnixEpoch();
base::Time converted_time = base::Time::UnixEpoch() + delta_since_epoch;
payload.last_active_time =
converted_time.ToDeltaSinceWindowsEpoch().InMicroseconds();
last_active_time.ToDeltaSinceWindowsEpoch().InMicroseconds();
return CreateSessionCommandForPayload(kCommandLastActiveTime, payload);
}

@ -82,7 +82,7 @@ SESSIONS_EXPORT std::unique_ptr<SessionCommand> CreateSetWindowUserTitleCommand(
const std::string& user_title);
SESSIONS_EXPORT std::unique_ptr<SessionCommand> CreateLastActiveTimeCommand(
SessionID tab_id,
base::TimeTicks last_active_time);
base::Time last_active_time);
SESSIONS_EXPORT std::unique_ptr<SessionCommand> CreateSetWindowWorkspaceCommand(
SessionID window_id,