Chromium Code Reviews| Index: components/autofill/core/common/autofill_clock.cc |
| diff --git a/components/autofill/core/common/autofill_clock.cc b/components/autofill/core/common/autofill_clock.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4befd4c06e635bf21a9f53ba5550bc3afefa0d65 |
| --- /dev/null |
| +++ b/components/autofill/core/common/autofill_clock.cc |
| @@ -0,0 +1,42 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/autofill/core/common/autofill_clock.h" |
| + |
| +#include <utility> |
| + |
| +#include "base/time/clock.h" |
| +#include "base/time/default_clock.h" |
| + |
| +namespace autofill { |
| + |
| +namespace { |
| + |
| +static base::LazyInstance<AutofillClock> g_autofill_clock = |
| + LAZY_INSTANCE_INITIALIZER; |
| + |
| +} // namespace |
| + |
| +// static |
| +base::Time AutofillClock::Now() { |
| + if (!g_autofill_clock.Get().clock_) |
| + SetClock(); |
| + |
| + return g_autofill_clock.Get().clock_->Now(); |
| +} |
| + |
| +AutofillClock::AutofillClock(){}; |
| +AutofillClock::~AutofillClock(){}; |
| + |
| +// static |
| +void AutofillClock::SetClock() { |
| + g_autofill_clock.Get().clock_.reset(new base::DefaultClock()); |
| +} |
| + |
| +// static |
| +void AutofillClock::SetTestClock(std::unique_ptr<base::Clock> clock) { |
|
Roger McFarlane (Chromium)
2017/02/01 15:34:26
DCHECK(clock != nullptr)
?
sebsg
2017/02/01 18:25:57
Done.
|
| + g_autofill_clock.Get().clock_ = std::move(clock); |
| +} |
| + |
| +} // namespace autofill |