Refactor AlarmTimer to report error to the caller.

This is to address the comment

Instead of just upstreaming it, which exposes a method unused in Chromium,
this CL introduces Create() factory method and drops the code to
fallback in case of timerfd_create failure.

Now, a caller should check whether Create() returns null or not.
In case of null, to keep the previous behavior, the caller can
create an instance of the parent class.

Along with the change, in order to run unittest for the class
without capability CAP_WAKE_ALARM, this CL also introduces CreateForTesting().
We used to test just fall-back code paths.

In addition, this CL fixes the FD leak on destruction.

TEST=Build and run components_unittests --gtest_filter=AlarmTimerTest*. Run try.

Change-Id: Ieb9660335120565ccff7f192d7a8192ca1e59ebc
Reviewed-by: Ryo Hashimoto <>
Reviewed-by: Dmitry Titov <>
Reviewed-by: Dan Erat <>
Commit-Queue: Hidehiko Abe <>
Cr-Original-Commit-Position: refs/heads/master@{#626151}
Cr-Mirrored-Commit: ef771c73c30e55550b1adb8685eba3075b398786
3 files changed