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

Unified Diff: chrome/browser/media/router/discovery/dial/dial_registry.cc

Issue 2843653002: [DIAL tests] Slightly improve DialRegistry tests. (Closed)
Patch Set: Addressed mark's comments Created 3 years, 8 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: chrome/browser/media/router/discovery/dial/dial_registry.cc
diff --git a/chrome/browser/media/router/discovery/dial/dial_registry.cc b/chrome/browser/media/router/discovery/dial/dial_registry.cc
index f394945b5a37ca659178c64addb7078e9ce2c2cb..7d800eb49a9c9f8c669cbc5544fe6a593e0655ed 100644
--- a/chrome/browser/media/router/discovery/dial/dial_registry.cc
+++ b/chrome/browser/media/router/discovery/dial/dial_registry.cc
@@ -10,6 +10,7 @@
#include "base/memory/ptr_util.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
+#include "base/time/default_clock.h"
#include "base/time/time.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
@@ -43,10 +44,10 @@ DialRegistry::DialRegistry()
registry_generation_(0),
last_event_registry_generation_(0),
label_count_(0),
- refresh_interval_delta_(
- base::TimeDelta::FromSeconds(kDialRefreshIntervalSecs)),
- expiration_delta_(base::TimeDelta::FromSeconds(kDialExpirationSecs)),
- max_devices_(kDialMaxDevices) {
+ refresh_interval_delta_(TimeDelta::FromSeconds(kDialRefreshIntervalSecs)),
+ expiration_delta_(TimeDelta::FromSeconds(kDialExpirationSecs)),
+ max_devices_(kDialMaxDevices),
+ clock_(new base::DefaultClock()) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_GT(max_devices_, 0U);
// This is a leaky singleton, so there's no code to remove |this| as an
@@ -73,10 +74,6 @@ void DialRegistry::ClearDialService() {
dial_.reset();
}
-base::Time DialRegistry::Now() const {
- return Time::Now();
-}
-
void DialRegistry::OnListenerAdded() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (++num_listeners_ == 1) {
@@ -125,6 +122,10 @@ void DialRegistry::AddDeviceForTest(const DialDeviceData& device_data) {
std::make_pair(device_data.device_id(), std::move(test_data)));
}
+void DialRegistry::SetClockForTest(std::unique_ptr<base::Clock> clock) {
+ clock_ = std::move(clock);
+}
+
bool DialRegistry::ReadyToDiscover() {
if (num_listeners_ == 0) {
OnDialError(DIAL_NO_LISTENERS);
@@ -219,7 +220,7 @@ bool DialRegistry::PruneExpiredDevices() {
}
bool DialRegistry::IsDeviceExpired(const DialDeviceData& device) const {
- Time now = Now();
+ Time now = clock_->Now();
// Check against our default expiration timeout.
Time default_expiration_time = device.response_time() + expiration_delta_;

Powered by Google App Engine
This is Rietveld 408576698