Howdy Folks,We have some chromium code which attempts to timeout after 30 seconds of idle. We use TimeTicks to measure elapsed time, as per the advice in base/time.h. However, we've noticed that on Android, at least, TimeTicks may "stand still" between suspend and resume (again, as per the comments in base/time.h). This means that comparing base::TimeTicks::Now() to base::TimeTicks start_ does not do the right thing in this case. We could plausibly hook into OnSuspend/OnRestore to get a base::Time values which would let us understand how much time has elapsed during the suspend, but I'm wondering if there is a better solution for this? (Or if I'm doing something obviously wrong).
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
--
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+unsubscribe@chromium.org.
On Fri, Nov 4, 2016 at 2:09 PM, Ryan Hamilton <r...@chromium.org> wrote:Howdy Folks,We have some chromium code which attempts to timeout after 30 seconds of idle. We use TimeTicks to measure elapsed time, as per the advice in base/time.h. However, we've noticed that on Android, at least, TimeTicks may "stand still" between suspend and resume (again, as per the comments in base/time.h). This means that comparing base::TimeTicks::Now() to base::TimeTicks start_ does not do the right thing in this case. We could plausibly hook into OnSuspend/OnRestore to get a base::Time values which would let us understand how much time has elapsed during the suspend, but I'm wondering if there is a better solution for this? (Or if I'm doing something obviously wrong).Does Time track the wall clock time change?
A crude solution might be to use the max delta(Time::Now() - old_time, TimeTicks::Now() - old_time_ticks), but in cases like DST or manual user clock adjustments that could return large values when not much "real world time" had passed.
IIRC brettw originally wrote the Time classes, maybe he has advice.
OnSuspend/OnResume should no longer fire on Android since they don't mean the same thing as other platforms. https://codereview.chromium.org/2324923002/ Which suspend/resume mechanism are you referring to?
+mui, charlieaThis came up recently in a different Chrome bug regarding cookie expiration after suspend. It happens on desktop platforms as well.Time should track the wall clock time change, but suffers from all sorts of weirdness like non-slewed clock adjustments.
Sorry I should have been clearer, it seems surprising that time ever stops moving on Android; that would mean there does exist a real suspend/resume mode.
On desktop it's understandable that time will stop and suddenly jump in that case; the typical solution is to invalidate on suspend / resume. I agree a wrapper could be helpful for this behavior, we have a few monitors that need this.
When I wrote that CL we couldn't find any real cases of suspend resume on Android; just an abuse of an idle signal. If there's a actually a real suspend/resume signal on Android we can (and should) hook that back up.
The original post said, "some chromium code which attempts to timeout after 30 seconds of idle." So, why is it a problem that TimeTicks clock freezes during system suspend? If the system is asleep after 30 "real-world" seconds have elapsed, your timeout handler could not run anyway.If it's important to run the timeout handler the instant the system resumes, then I'd suggest you actually monitor system suspend/resume events; and call your timeout handler on resume to check whether 30 seconds have actually passed. Because you know TimeTicks clock has frozen, the only other clock available to check this is base::Time clock. However, I'd imagine OS authors would very likely make discontinuous adjustments to that clock right at system resume time. So, this may be very error-prone.BTW--Do our APIs for system resume events include information on how long the system was suspended? Maybe that's all you need?
The original post said, "some chromium code which attempts to timeout after 30 seconds of idle." So, why is it a problem that TimeTicks clock freezes during system suspend? If the system is asleep after 30 "real-world" seconds have elapsed, your timeout handler could not run anyway.
If it's important to run the timeout handler the instant the system resumes, then I'd suggest you actually monitor system suspend/resume events; and call your timeout handler on resume to check whether 30 seconds have actually passed. Because you know TimeTicks clock has frozen, the only other clock available to check this is base::Time clock. However, I'd imagine OS authors would very likely make discontinuous adjustments to that clock right at system resume time. So, this may be very error-prone.BTW--Do our APIs for system resume events include information on how long the system was suspended? Maybe that's all you need?
Note: The need for a TimeTicks clock that doesn't freeze has come up on a few occasions for other Chromium features. None that I'm aware of solved this problem directly (i.e., usually a design change or trade-off was made to resolve an issue). However, on Linux, CLOCK_BOOTTIME was introduced to solve this exact problem (http://man7.org/linux/man-pages/man2/clock_gettime.2.html). I'm not sure about other platforms (I'd have to research that). So, perhaps it makes sense to introduce another type of monotonic tick clock in base/time? Comments?