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 #ifndef COMPONENTS_AUTOFILL_CORE_COMMON_AUTOFILL_CLOCK_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CORE_COMMON_AUTOFILL_CLOCK_H_ |
6 #define COMPONENTS_AUTOFILL_CORE_COMMON_AUTOFILL_CLOCK_H_ | 6 #define COMPONENTS_AUTOFILL_CORE_COMMON_AUTOFILL_CLOCK_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 class Clock; | 14 class Clock; |
15 class Time; | 15 class Time; |
16 } // namespace base | 16 } // namespace base |
17 | 17 |
18 namespace autofill { | 18 namespace autofill { |
19 | 19 |
20 // Handles getting the current time for the Autofill feature. Can be injected | 20 // Handles getting the current time for the Autofill feature. Can be injected |
21 // with a customizable clock to facilitate testing. | 21 // with a customizable clock to facilitate testing. |
22 class AutofillClock { | 22 class AutofillClock { |
23 public: | 23 public: |
24 // Returns the current time based on |clock_|. | 24 // Returns the current time based on |clock_|. |
25 static base::Time Now(); | 25 static base::Time Now(); |
26 | 26 |
27 private: | 27 private: |
28 friend class TestAutofillClock; | 28 friend class TestAutofillClock; |
29 friend struct base::DefaultLazyInstanceTraits<AutofillClock>; | 29 friend struct base::LazyInstanceTraitsBase<AutofillClock>; |
30 | 30 |
31 // Resets a normal clock. | 31 // Resets a normal clock. |
32 static void SetClock(); | 32 static void SetClock(); |
33 | 33 |
34 // Sets the clock to be used for tests. | 34 // Sets the clock to be used for tests. |
35 static void SetTestClock(std::unique_ptr<base::Clock> clock); | 35 static void SetTestClock(std::unique_ptr<base::Clock> clock); |
36 | 36 |
37 AutofillClock(); | 37 AutofillClock(); |
38 ~AutofillClock(); | 38 ~AutofillClock(); |
39 | 39 |
40 // The clock used to return the current time. | 40 // The clock used to return the current time. |
41 std::unique_ptr<base::Clock> clock_; | 41 std::unique_ptr<base::Clock> clock_; |
42 | 42 |
43 DISALLOW_COPY_AND_ASSIGN(AutofillClock); | 43 DISALLOW_COPY_AND_ASSIGN(AutofillClock); |
44 }; | 44 }; |
45 | 45 |
46 } // namespace autofill | 46 } // namespace autofill |
47 | 47 |
48 #endif // COMPONENTS_AUTOFILL_CORE_COMMON_AUTOFILL_CLOCK_H_ | 48 #endif // COMPONENTS_AUTOFILL_CORE_COMMON_AUTOFILL_CLOCK_H_ |
OLD | NEW |