Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Unified Diff: components/autofill/core/common/autofill_clock.h

Issue 2639403002: [Autofill] Remove direct use of base::Time::Now() in Autofill (Closed)
Patch Set: Added DCHECK Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/autofill/core/common/BUILD.gn ('k') | components/autofill/core/common/autofill_clock.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/core/common/autofill_clock.h
diff --git a/components/autofill/core/common/autofill_clock.h b/components/autofill/core/common/autofill_clock.h
new file mode 100644
index 0000000000000000000000000000000000000000..45a991211baef0caa2e6207d251a878e97850d95
--- /dev/null
+++ b/components/autofill/core/common/autofill_clock.h
@@ -0,0 +1,48 @@
+// 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.
+
+#ifndef COMPONENTS_AUTOFILL_CORE_COMMON_AUTOFILL_CLOCK_H_
+#define COMPONENTS_AUTOFILL_CORE_COMMON_AUTOFILL_CLOCK_H_
+
+#include <memory>
+
+#include "base/lazy_instance.h"
+#include "base/macros.h"
+
+namespace base {
+class Clock;
+class Time;
+} // namespace base
+
+namespace autofill {
+
+// Handles getting the current time for the Autofill feature. Can be injected
+// with a customizable clock to facilitate testing.
+class AutofillClock {
+ public:
+ // Returns the current time based on |clock_|.
+ static base::Time Now();
+
+ private:
+ friend class TestAutofillClock;
+ friend struct base::DefaultLazyInstanceTraits<AutofillClock>;
+
+ // Resets a normal clock.
+ static void SetClock();
+
+ // Sets the clock to be used for tests.
+ static void SetTestClock(std::unique_ptr<base::Clock> clock);
+
+ AutofillClock();
+ ~AutofillClock();
+
+ // The clock used to return the current time.
+ std::unique_ptr<base::Clock> clock_;
+
+ DISALLOW_COPY_AND_ASSIGN(AutofillClock);
+};
+
+} // namespace autofill
+
+#endif // COMPONENTS_AUTOFILL_CORE_COMMON_AUTOFILL_CLOCK_H_
« no previous file with comments | « components/autofill/core/common/BUILD.gn ('k') | components/autofill/core/common/autofill_clock.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698