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

Unified Diff: chrome/utility/local_discovery/service_discovery_client_impl.cc

Issue 137343005: Send multiple queries when DiscoverNewServices is called on a service watcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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: chrome/utility/local_discovery/service_discovery_client_impl.cc
diff --git a/chrome/utility/local_discovery/service_discovery_client_impl.cc b/chrome/utility/local_discovery/service_discovery_client_impl.cc
index c17c0e15f8efd3b95e9f9b96c3c9f9863e61ac5c..ebb541d932faf6f63cadfd5784c266d0aff35071 100644
--- a/chrome/utility/local_discovery/service_discovery_client_impl.cc
+++ b/chrome/utility/local_discovery/service_discovery_client_impl.cc
@@ -18,6 +18,9 @@ namespace {
// TODO(noamsml): Make this configurable through the LocalDomainResolver
// interface.
const int kLocalDomainSecondAddressTimeoutMs = 100;
+
+const int kInitialRequeryTimeSeconds = 1;
+const int kMaxRequeryTimeSeconds = 2; // Time for last requery
}
ServiceDiscoveryClientImpl::ServiceDiscoveryClientImpl(
@@ -74,8 +77,7 @@ void ServiceWatcherImpl::DiscoverNewServices(bool force_update) {
DCHECK(started_);
if (force_update)
services_.clear();
- CreateTransaction(true /*network*/, false /*cache*/, force_update,
- &transaction_network_);
+ SendQuery(kInitialRequeryTimeSeconds, force_update);
}
void ServiceWatcherImpl::ReadCachedServices() {
@@ -234,6 +236,25 @@ void ServiceWatcherImpl::OnNsecRecord(const std::string& name,
// on any name.
}
+void ServiceWatcherImpl::ScheduleQuery(int timeout_seconds) {
+ if (timeout_seconds <= kMaxRequeryTimeSeconds) {
+ base::MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&ServiceWatcherImpl::SendQuery,
+ AsWeakPtr(),
+ timeout_seconds * 2 /*next_timeout_seconds*/,
+ false /*force_update*/),
+ base::TimeDelta::FromSeconds(timeout_seconds));
+ }
+}
+
+void ServiceWatcherImpl::SendQuery(int next_timeout_seconds,
+ bool force_update) {
+ CreateTransaction(true /*network*/, false /*cache*/, force_update,
+ &transaction_network_);
+ ScheduleQuery(next_timeout_seconds);
+}
+
ServiceResolverImpl::ServiceResolverImpl(
const std::string& service_name,
const ResolveCompleteCallback& callback,

Powered by Google App Engine
This is Rietveld 408576698