base: Add workaround for iOS message pump timer slack bug

This patch adds a workaround for an issue in the iOS message pump in the
following scenario:

  1. The message pump timer slack is set to maximum.
  2. A delayed task is posted for far in the future (e.g., 1h).
  3. The system goes idle at least for a few seconds.
  4. Another delayed task is posted with a much smaller delay.

It appears the setting the tolerance for a CFRunLoop timer *after* setting the
next fire time, it has no effect and the previous tolerance remains active. In
the above scenario it means the task posted in step #4 actually runs in about
half the delay set in step #2.

This bug was causing a net_unittest to fail because the TaskScheduler's
periodic task to adjust the number of active threads wasn't running, causing
the system to grind to a halt because all worker pool threads were blocking on
a lock.

The workaround is to always set the timer tolerance before adjusting the timer
fire time.

Bug: 891670
Change-Id: I82e97fe993bbb8a71c417f01f4d6131cce0667ad
Reviewed-on: https://chromium-review.googlesource.com/c/1434276
Commit-Queue: Sami Kyöstilä <skyostil@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#626053}
2 files changed