| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/core/common/autofill_clock.h" | 5 #include "components/autofill/core/common/autofill_clock.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/time/clock.h" | 9 #include "base/time/clock.h" |
| 10 #include "base/time/default_clock.h" | 10 #include "base/time/default_clock.h" |
| 11 | 11 |
| 12 namespace autofill { | 12 namespace autofill { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 static base::LazyInstance<AutofillClock> g_autofill_clock = | 16 static base::LazyInstance<AutofillClock>::DestructorAtExit g_autofill_clock = |
| 17 LAZY_INSTANCE_INITIALIZER; | 17 LAZY_INSTANCE_INITIALIZER; |
| 18 | 18 |
| 19 } // namespace | 19 } // namespace |
| 20 | 20 |
| 21 // static | 21 // static |
| 22 base::Time AutofillClock::Now() { | 22 base::Time AutofillClock::Now() { |
| 23 if (!g_autofill_clock.Get().clock_) | 23 if (!g_autofill_clock.Get().clock_) |
| 24 SetClock(); | 24 SetClock(); |
| 25 | 25 |
| 26 return g_autofill_clock.Get().clock_->Now(); | 26 return g_autofill_clock.Get().clock_->Now(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 AutofillClock::AutofillClock(){}; | 29 AutofillClock::AutofillClock(){}; |
| 30 AutofillClock::~AutofillClock(){}; | 30 AutofillClock::~AutofillClock(){}; |
| 31 | 31 |
| 32 // static | 32 // static |
| 33 void AutofillClock::SetClock() { | 33 void AutofillClock::SetClock() { |
| 34 g_autofill_clock.Get().clock_.reset(new base::DefaultClock()); | 34 g_autofill_clock.Get().clock_.reset(new base::DefaultClock()); |
| 35 } | 35 } |
| 36 | 36 |
| 37 // static | 37 // static |
| 38 void AutofillClock::SetTestClock(std::unique_ptr<base::Clock> clock) { | 38 void AutofillClock::SetTestClock(std::unique_ptr<base::Clock> clock) { |
| 39 DCHECK(clock); | 39 DCHECK(clock); |
| 40 g_autofill_clock.Get().clock_ = std::move(clock); | 40 g_autofill_clock.Get().clock_ = std::move(clock); |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // namespace autofill | 43 } // namespace autofill |
| OLD | NEW |