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

Unified Diff: components/autofill/core/browser/autofill_clock.cc

Issue 2639403002: [Autofill] Remove direct use of base::Time::Now() in Autofill (Closed)
Patch Set: Rebase 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
Index: components/autofill/core/browser/autofill_clock.cc
diff --git a/components/autofill/core/browser/autofill_clock.cc b/components/autofill/core/browser/autofill_clock.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0601822178232b7dae1c33dd49be3f1c3906e62f
--- /dev/null
+++ b/components/autofill/core/browser/autofill_clock.cc
@@ -0,0 +1,30 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
Mathieu 2017/01/25 19:57:24 +4
sebsg 2017/01/25 21:35:27 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/autofill/core/browser/autofill_clock.h"
Mathieu 2017/01/25 19:57:24 does it make sense to have this in core/common?
sebsg 2017/01/25 21:35:27 Done.
+
+#include "base/time/clock.h"
+#include "base/time/default_clock.h"
+
+namespace autofill {
+
+static base::LazyInstance<AutofillClock> instance_ = LAZY_INSTANCE_INITIALIZER;
Mathieu 2017/01/25 19:57:24 can this be in the anonymous namespace?
Mathieu 2017/01/25 19:57:24 naming style is probably to have g_autofill_clock
sebsg 2017/01/25 21:35:26 Done.
sebsg 2017/01/25 21:35:27 Done.
+
+// static
+base::Time AutofillClock::Now() {
+ return instance_.Get().clock_->Now();
+}
+
+AutofillClock::AutofillClock() {
+ clock_ = base::MakeUnique<base::DefaultClock>();
Mathieu 2017/01/25 19:57:24 I prefer the style clock_.reset(new base::Defaul
sebsg 2017/01/25 21:35:27 Done.
+}
+
+AutofillClock::~AutofillClock() {}
+
+// static
+void AutofillClock::SetClockForTests(base::Clock* clock) {
Mathieu 2017/01/25 19:57:24 probably better to pass a std::unique_ptr? makes o
sebsg 2017/01/25 21:35:27 True, thanks for the suggestion.
+ instance_.Get().clock_.reset(clock);
+}
+
+} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698