Commit 7a11a32c authored by noamsml@chromium.org's avatar noamsml@chromium.org

Add "actively refresh services" method to ServiceDiscoveryClient

Add method to ServiceDiscoveryClient that will allow it to actively refresh
stale services when their TTL runs out.

BUG=336883

Review URL: https://codereview.chromium.org/141583010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@247857 0039d316-1c4b-4281-b951-d872f2087c98
parent 3bdbf7fe
...@@ -45,6 +45,9 @@ class MockServiceWatcher : public ServiceWatcher { ...@@ -45,6 +45,9 @@ class MockServiceWatcher : public ServiceWatcher {
MOCK_METHOD1(DiscoverNewServices, void(bool force_update)); MOCK_METHOD1(DiscoverNewServices, void(bool force_update));
MOCK_METHOD1(SetActivelyRefreshServices, void(
bool actively_refresh_services));
virtual std::string GetServiceType() const { virtual std::string GetServiceType() const {
return service_type_; return service_type_;
} }
......
...@@ -50,6 +50,8 @@ class ServiceWatcherImplMac : public ServiceWatcher { ...@@ -50,6 +50,8 @@ class ServiceWatcherImplMac : public ServiceWatcher {
virtual void Start() OVERRIDE; virtual void Start() OVERRIDE;
virtual void DiscoverNewServices(bool force_update) OVERRIDE; virtual void DiscoverNewServices(bool force_update) OVERRIDE;
virtual void SetActivelyRefreshServices(
bool actively_refresh_services) OVERRIDE;
virtual std::string GetServiceType() const OVERRIDE; virtual std::string GetServiceType() const OVERRIDE;
std::string service_type_; std::string service_type_;
......
...@@ -164,6 +164,12 @@ void ServiceWatcherImplMac::DiscoverNewServices(bool force_update) { ...@@ -164,6 +164,12 @@ void ServiceWatcherImplMac::DiscoverNewServices(bool force_update) {
inDomain:[NSString stringWithUTF8String:domain.c_str()]]; inDomain:[NSString stringWithUTF8String:domain.c_str()]];
} }
void ServiceWatcherImplMac::SetActivelyRefreshServices(
bool actively_refresh_services) {
DCHECK(started_);
// TODO(noamsml): Implement this method.
}
std::string ServiceWatcherImplMac::GetServiceType() const { std::string ServiceWatcherImplMac::GetServiceType() const {
return service_type_; return service_type_;
} }
......
...@@ -82,6 +82,14 @@ class ServiceDiscoveryHostClient::ServiceWatcherProxy : public ServiceWatcher { ...@@ -82,6 +82,14 @@ class ServiceDiscoveryHostClient::ServiceWatcherProxy : public ServiceWatcher {
host_->Send(new LocalDiscoveryMsg_DiscoverServices(id_, force_update)); host_->Send(new LocalDiscoveryMsg_DiscoverServices(id_, force_update));
} }
virtual void SetActivelyRefreshServices(
bool actively_refresh_services) OVERRIDE {
DVLOG(1) << "ServiceWatcher::SetActivelyRefreshServices with id " << id_;
DCHECK(started_);
host_->Send(new LocalDiscoveryMsg_SetActivelyRefreshServices(
id_, actively_refresh_services));
}
virtual std::string GetServiceType() const OVERRIDE { virtual std::string GetServiceType() const OVERRIDE {
return service_type_; return service_type_;
} }
......
...@@ -68,6 +68,11 @@ IPC_MESSAGE_CONTROL2(LocalDiscoveryMsg_DiscoverServices, ...@@ -68,6 +68,11 @@ IPC_MESSAGE_CONTROL2(LocalDiscoveryMsg_DiscoverServices,
uint64 /* id */, uint64 /* id */,
bool /* force_update */) bool /* force_update */)
// Discovers new services.
IPC_MESSAGE_CONTROL2(LocalDiscoveryMsg_SetActivelyRefreshServices,
uint64 /* id */,
bool /* actively_refresh_services */)
// Destroys watcher in utility process. // Destroys watcher in utility process.
IPC_MESSAGE_CONTROL1(LocalDiscoveryMsg_DestroyWatcher, IPC_MESSAGE_CONTROL1(LocalDiscoveryMsg_DestroyWatcher,
uint64 /* id */) uint64 /* id */)
......
...@@ -67,6 +67,8 @@ class ServiceWatcher { ...@@ -67,6 +67,8 @@ class ServiceWatcher {
// Probe for services of this type. // Probe for services of this type.
virtual void DiscoverNewServices(bool force_update) = 0; virtual void DiscoverNewServices(bool force_update) = 0;
virtual void SetActivelyRefreshServices(bool actively_refresh_services) = 0;
virtual std::string GetServiceType() const = 0; virtual std::string GetServiceType() const = 0;
}; };
......
...@@ -80,6 +80,12 @@ void ServiceWatcherImpl::DiscoverNewServices(bool force_update) { ...@@ -80,6 +80,12 @@ void ServiceWatcherImpl::DiscoverNewServices(bool force_update) {
SendQuery(kInitialRequeryTimeSeconds, force_update); SendQuery(kInitialRequeryTimeSeconds, force_update);
} }
void ServiceWatcherImpl::SetActivelyRefreshServices(
bool actively_refresh_services) {
DCHECK(started_);
NOTIMPLEMENTED();
}
void ServiceWatcherImpl::ReadCachedServices() { void ServiceWatcherImpl::ReadCachedServices() {
DCHECK(started_); DCHECK(started_);
CreateTransaction(false /*network*/, true /*cache*/, false /*force refresh*/, CreateTransaction(false /*network*/, true /*cache*/, false /*force refresh*/,
......
...@@ -60,6 +60,9 @@ class ServiceWatcherImpl : public ServiceWatcher, ...@@ -60,6 +60,9 @@ class ServiceWatcherImpl : public ServiceWatcher,
virtual void DiscoverNewServices(bool force_update) OVERRIDE; virtual void DiscoverNewServices(bool force_update) OVERRIDE;
virtual void SetActivelyRefreshServices(
bool actively_refresh_services) OVERRIDE;
virtual std::string GetServiceType() const OVERRIDE; virtual std::string GetServiceType() const OVERRIDE;
virtual void OnRecordUpdate(net::MDnsListener::UpdateType update, virtual void OnRecordUpdate(net::MDnsListener::UpdateType update,
......
...@@ -224,6 +224,8 @@ bool ServiceDiscoveryMessageHandler::OnMessageReceived( ...@@ -224,6 +224,8 @@ bool ServiceDiscoveryMessageHandler::OnMessageReceived(
#endif // OS_POSIX #endif // OS_POSIX
IPC_MESSAGE_HANDLER(LocalDiscoveryMsg_StartWatcher, OnStartWatcher) IPC_MESSAGE_HANDLER(LocalDiscoveryMsg_StartWatcher, OnStartWatcher)
IPC_MESSAGE_HANDLER(LocalDiscoveryMsg_DiscoverServices, OnDiscoverServices) IPC_MESSAGE_HANDLER(LocalDiscoveryMsg_DiscoverServices, OnDiscoverServices)
IPC_MESSAGE_HANDLER(LocalDiscoveryMsg_SetActivelyRefreshServices,
OnSetActivelyRefreshServices)
IPC_MESSAGE_HANDLER(LocalDiscoveryMsg_DestroyWatcher, OnDestroyWatcher) IPC_MESSAGE_HANDLER(LocalDiscoveryMsg_DestroyWatcher, OnDestroyWatcher)
IPC_MESSAGE_HANDLER(LocalDiscoveryMsg_ResolveService, OnResolveService) IPC_MESSAGE_HANDLER(LocalDiscoveryMsg_ResolveService, OnResolveService)
IPC_MESSAGE_HANDLER(LocalDiscoveryMsg_DestroyResolver, OnDestroyResolver) IPC_MESSAGE_HANDLER(LocalDiscoveryMsg_DestroyResolver, OnDestroyResolver)
...@@ -272,6 +274,14 @@ void ServiceDiscoveryMessageHandler::OnDiscoverServices(uint64 id, ...@@ -272,6 +274,14 @@ void ServiceDiscoveryMessageHandler::OnDiscoverServices(uint64 id,
base::Unretained(this), id, force_update)); base::Unretained(this), id, force_update));
} }
void ServiceDiscoveryMessageHandler::OnSetActivelyRefreshServices(
uint64 id, bool actively_refresh_services) {
PostTask(FROM_HERE,
base::Bind(
&ServiceDiscoveryMessageHandler::SetActivelyRefreshServices,
base::Unretained(this), id, actively_refresh_services));
}
void ServiceDiscoveryMessageHandler::OnDestroyWatcher(uint64 id) { void ServiceDiscoveryMessageHandler::OnDestroyWatcher(uint64 id) {
PostTask(FROM_HERE, PostTask(FROM_HERE,
base::Bind(&ServiceDiscoveryMessageHandler::DestroyWatcher, base::Bind(&ServiceDiscoveryMessageHandler::DestroyWatcher,
...@@ -332,6 +342,16 @@ void ServiceDiscoveryMessageHandler::DiscoverServices(uint64 id, ...@@ -332,6 +342,16 @@ void ServiceDiscoveryMessageHandler::DiscoverServices(uint64 id,
service_watchers_[id]->DiscoverNewServices(force_update); service_watchers_[id]->DiscoverNewServices(force_update);
} }
void ServiceDiscoveryMessageHandler::SetActivelyRefreshServices(
uint64 id,
bool actively_refresh_services) {
VLOG(1) << "ActivelyRefreshServices, id=" << id;
if (!service_discovery_client_)
return;
DCHECK(ContainsKey(service_watchers_, id));
service_watchers_[id]->SetActivelyRefreshServices(actively_refresh_services);
}
void ServiceDiscoveryMessageHandler::DestroyWatcher(uint64 id) { void ServiceDiscoveryMessageHandler::DestroyWatcher(uint64 id) {
VLOG(1) << "DestoryWatcher, id=" << id; VLOG(1) << "DestoryWatcher, id=" << id;
if (!service_discovery_client_) if (!service_discovery_client_)
......
...@@ -60,6 +60,7 @@ class ServiceDiscoveryMessageHandler : public chrome::UtilityMessageHandler { ...@@ -60,6 +60,7 @@ class ServiceDiscoveryMessageHandler : public chrome::UtilityMessageHandler {
#endif // OS_POSIX #endif // OS_POSIX
void OnStartWatcher(uint64 id, const std::string& service_type); void OnStartWatcher(uint64 id, const std::string& service_type);
void OnDiscoverServices(uint64 id, bool force_update); void OnDiscoverServices(uint64 id, bool force_update);
void OnSetActivelyRefreshServices(uint64 id, bool actively_refresh_services);
void OnDestroyWatcher(uint64 id); void OnDestroyWatcher(uint64 id);
void OnResolveService(uint64 id, const std::string& service_name); void OnResolveService(uint64 id, const std::string& service_name);
void OnDestroyResolver(uint64 id); void OnDestroyResolver(uint64 id);
...@@ -70,6 +71,7 @@ class ServiceDiscoveryMessageHandler : public chrome::UtilityMessageHandler { ...@@ -70,6 +71,7 @@ class ServiceDiscoveryMessageHandler : public chrome::UtilityMessageHandler {
void InitializeMdns(); void InitializeMdns();
void StartWatcher(uint64 id, const std::string& service_type); void StartWatcher(uint64 id, const std::string& service_type);
void DiscoverServices(uint64 id, bool force_update); void DiscoverServices(uint64 id, bool force_update);
void SetActivelyRefreshServices(uint64 id, bool actively_refresh_services);
void DestroyWatcher(uint64 id); void DestroyWatcher(uint64 id);
void ResolveService(uint64 id, const std::string& service_name); void ResolveService(uint64 id, const std::string& service_name);
void DestroyResolver(uint64 id); void DestroyResolver(uint64 id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment