Renamed ServiceDiscoveryClientMdns to ServiceDiscoveryClientUtility.

BUG=349645

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266697 0039d316-1c4b-4281-b951-d872f2087c98
parent ae41683d
// Copyright 2013 The Chromium Authors. All rights reserved. // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/local_discovery/service_discovery_client_mdns.h" #include "chrome/browser/local_discovery/service_discovery_client_utility.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "chrome/browser/local_discovery/service_discovery_host_client.h" #include "chrome/browser/local_discovery/service_discovery_host_client.h"
...@@ -18,14 +18,15 @@ const int kRestartDelayOnNetworkChangeSeconds = 3; ...@@ -18,14 +18,15 @@ const int kRestartDelayOnNetworkChangeSeconds = 3;
const int kReportSuccessAfterSeconds = 10; const int kReportSuccessAfterSeconds = 10;
} }
scoped_ptr<ServiceWatcher> ServiceDiscoveryClientMdns::CreateServiceWatcher( scoped_ptr<ServiceWatcher> ServiceDiscoveryClientUtility::CreateServiceWatcher(
const std::string& service_type, const std::string& service_type,
const ServiceWatcher::UpdatedCallback& callback) { const ServiceWatcher::UpdatedCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
return host_client_->CreateServiceWatcher(service_type, callback); return host_client_->CreateServiceWatcher(service_type, callback);
} }
scoped_ptr<ServiceResolver> ServiceDiscoveryClientMdns::CreateServiceResolver( scoped_ptr<ServiceResolver>
ServiceDiscoveryClientUtility::CreateServiceResolver(
const std::string& service_name, const std::string& service_name,
const ServiceResolver::ResolveCompleteCallback& callback) { const ServiceResolver::ResolveCompleteCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
...@@ -33,7 +34,7 @@ scoped_ptr<ServiceResolver> ServiceDiscoveryClientMdns::CreateServiceResolver( ...@@ -33,7 +34,7 @@ scoped_ptr<ServiceResolver> ServiceDiscoveryClientMdns::CreateServiceResolver(
} }
scoped_ptr<LocalDomainResolver> scoped_ptr<LocalDomainResolver>
ServiceDiscoveryClientMdns::CreateLocalDomainResolver( ServiceDiscoveryClientUtility::CreateLocalDomainResolver(
const std::string& domain, const std::string& domain,
net::AddressFamily address_family, net::AddressFamily address_family,
const LocalDomainResolver::IPAddressCallback& callback) { const LocalDomainResolver::IPAddressCallback& callback) {
...@@ -42,7 +43,7 @@ ServiceDiscoveryClientMdns::CreateLocalDomainResolver( ...@@ -42,7 +43,7 @@ ServiceDiscoveryClientMdns::CreateLocalDomainResolver(
callback); callback);
} }
ServiceDiscoveryClientMdns::ServiceDiscoveryClientMdns() ServiceDiscoveryClientUtility::ServiceDiscoveryClientUtility()
: restart_attempts_(kMaxRestartAttempts), : restart_attempts_(kMaxRestartAttempts),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
...@@ -50,13 +51,13 @@ ServiceDiscoveryClientMdns::ServiceDiscoveryClientMdns() ...@@ -50,13 +51,13 @@ ServiceDiscoveryClientMdns::ServiceDiscoveryClientMdns()
StartNewClient(); StartNewClient();
} }
ServiceDiscoveryClientMdns::~ServiceDiscoveryClientMdns() { ServiceDiscoveryClientUtility::~ServiceDiscoveryClientUtility() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
host_client_->Shutdown(); host_client_->Shutdown();
} }
void ServiceDiscoveryClientMdns::OnNetworkChanged( void ServiceDiscoveryClientUtility::OnNetworkChanged(
net::NetworkChangeNotifier::ConnectionType type) { net::NetworkChangeNotifier::ConnectionType type) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Only network changes resets kMaxRestartAttempts. // Only network changes resets kMaxRestartAttempts.
...@@ -64,29 +65,29 @@ void ServiceDiscoveryClientMdns::OnNetworkChanged( ...@@ -64,29 +65,29 @@ void ServiceDiscoveryClientMdns::OnNetworkChanged(
ScheduleStartNewClient(); ScheduleStartNewClient();
} }
void ServiceDiscoveryClientMdns::ScheduleStartNewClient() { void ServiceDiscoveryClientUtility::ScheduleStartNewClient() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
host_client_->Shutdown(); host_client_->Shutdown();
weak_ptr_factory_.InvalidateWeakPtrs(); weak_ptr_factory_.InvalidateWeakPtrs();
base::MessageLoop::current()->PostDelayedTask( base::MessageLoop::current()->PostDelayedTask(
FROM_HERE, FROM_HERE,
base::Bind(&ServiceDiscoveryClientMdns::StartNewClient, base::Bind(&ServiceDiscoveryClientUtility::StartNewClient,
weak_ptr_factory_.GetWeakPtr()), weak_ptr_factory_.GetWeakPtr()),
base::TimeDelta::FromSeconds(kRestartDelayOnNetworkChangeSeconds)); base::TimeDelta::FromSeconds(kRestartDelayOnNetworkChangeSeconds));
} }
void ServiceDiscoveryClientMdns::StartNewClient() { void ServiceDiscoveryClientUtility::StartNewClient() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
scoped_refptr<ServiceDiscoveryHostClient> old_client = host_client_; scoped_refptr<ServiceDiscoveryHostClient> old_client = host_client_;
if ((restart_attempts_--) > 0) { if ((restart_attempts_--) > 0) {
host_client_ = new ServiceDiscoveryHostClient(); host_client_ = new ServiceDiscoveryHostClient();
host_client_->Start( host_client_->Start(
base::Bind(&ServiceDiscoveryClientMdns::ScheduleStartNewClient, base::Bind(&ServiceDiscoveryClientUtility::ScheduleStartNewClient,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
base::MessageLoop::current()->PostDelayedTask( base::MessageLoop::current()->PostDelayedTask(
FROM_HERE, FROM_HERE,
base::Bind(&ServiceDiscoveryClientMdns::ReportSuccess, base::Bind(&ServiceDiscoveryClientUtility::ReportSuccess,
weak_ptr_factory_.GetWeakPtr()), weak_ptr_factory_.GetWeakPtr()),
base::TimeDelta::FromSeconds(kReportSuccessAfterSeconds)); base::TimeDelta::FromSeconds(kReportSuccessAfterSeconds));
} else { } else {
...@@ -99,7 +100,7 @@ void ServiceDiscoveryClientMdns::StartNewClient() { ...@@ -99,7 +100,7 @@ void ServiceDiscoveryClientMdns::StartNewClient() {
old_client->InvalidateWatchers(); old_client->InvalidateWatchers();
} }
void ServiceDiscoveryClientMdns::ReportSuccess() { void ServiceDiscoveryClientUtility::ReportSuccess() {
UMA_HISTOGRAM_COUNTS_100("LocalDiscovery.ClientRestartAttempts", UMA_HISTOGRAM_COUNTS_100("LocalDiscovery.ClientRestartAttempts",
kMaxRestartAttempts - restart_attempts_); kMaxRestartAttempts - restart_attempts_);
} }
......
// Copyright 2013 The Chromium Authors. All rights reserved. // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_MDNS_H_ #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_UTILITY_H_
#define CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_MDNS_H_ #define CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_UTILITY_H_
#include <string> #include <string>
...@@ -16,11 +16,13 @@ namespace local_discovery { ...@@ -16,11 +16,13 @@ namespace local_discovery {
class ServiceDiscoveryHostClient; class ServiceDiscoveryHostClient;
class ServiceDiscoveryClientMdns // Wrapper for ServiceDiscoveryHostClient to hide restarting of utility process
// from mdns users.
class ServiceDiscoveryClientUtility
: public ServiceDiscoverySharedClient, : public ServiceDiscoverySharedClient,
public net::NetworkChangeNotifier::NetworkChangeObserver { public net::NetworkChangeNotifier::NetworkChangeObserver {
public: public:
ServiceDiscoveryClientMdns(); ServiceDiscoveryClientUtility();
// ServiceDiscoveryClient implementation. // ServiceDiscoveryClient implementation.
virtual scoped_ptr<ServiceWatcher> CreateServiceWatcher( virtual scoped_ptr<ServiceWatcher> CreateServiceWatcher(
...@@ -39,20 +41,20 @@ class ServiceDiscoveryClientMdns ...@@ -39,20 +41,20 @@ class ServiceDiscoveryClientMdns
net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
private: private:
friend class base::RefCounted<ServiceDiscoveryClientMdns>; friend class base::RefCounted<ServiceDiscoveryClientUtility>;
virtual ~ServiceDiscoveryClientMdns(); virtual ~ServiceDiscoveryClientUtility();
void ScheduleStartNewClient(); void ScheduleStartNewClient();
void StartNewClient(); void StartNewClient();
void ReportSuccess(); void ReportSuccess();
scoped_refptr<ServiceDiscoveryHostClient> host_client_; scoped_refptr<ServiceDiscoveryHostClient> host_client_;
int restart_attempts_; int restart_attempts_;
base::WeakPtrFactory<ServiceDiscoveryClientMdns> weak_ptr_factory_; base::WeakPtrFactory<ServiceDiscoveryClientUtility> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ServiceDiscoveryClientMdns); DISALLOW_COPY_AND_ASSIGN(ServiceDiscoveryClientUtility);
}; };
} // namespace local_discovery } // namespace local_discovery
#endif // CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_MDNS_H_ #endif // CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_UTILITY_H_
...@@ -68,7 +68,7 @@ class ServiceDiscoveryHostClient ...@@ -68,7 +68,7 @@ class ServiceDiscoveryHostClient
class ServiceWatcherProxy; class ServiceWatcherProxy;
class ServiceResolverProxy; class ServiceResolverProxy;
class LocalDomainResolverProxy; class LocalDomainResolverProxy;
friend class ServiceDiscoveryClientMdns; friend class ServiceDiscoveryClientUtility;
typedef std::map<uint64, ServiceWatcher::UpdatedCallback> WatcherCallbacks; typedef std::map<uint64, ServiceWatcher::UpdatedCallback> WatcherCallbacks;
typedef std::map<uint64, ServiceResolver::ResolveCompleteCallback> typedef std::map<uint64, ServiceResolver::ResolveCompleteCallback>
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#endif #endif
#if defined(ENABLE_MDNS) #if defined(ENABLE_MDNS)
#include "chrome/browser/local_discovery/service_discovery_client_mdns.h" #include "chrome/browser/local_discovery/service_discovery_client_utility.h"
#endif // ENABLE_MDNS #endif // ENABLE_MDNS
namespace local_discovery { namespace local_discovery {
...@@ -44,7 +44,7 @@ scoped_refptr<ServiceDiscoverySharedClient> ...@@ -44,7 +44,7 @@ scoped_refptr<ServiceDiscoverySharedClient>
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
return ServiceDiscoveryClientMacFactory::CreateInstance(); return ServiceDiscoveryClientMacFactory::CreateInstance();
#else #else
return new ServiceDiscoveryClientMdns(); return new ServiceDiscoveryClientUtility();
#endif #endif
} }
......
...@@ -3457,8 +3457,8 @@ ...@@ -3457,8 +3457,8 @@
'sources' : [ 'sources' : [
'browser/local_discovery/privet_traffic_detector.cc', 'browser/local_discovery/privet_traffic_detector.cc',
'browser/local_discovery/privet_traffic_detector.h', 'browser/local_discovery/privet_traffic_detector.h',
'browser/local_discovery/service_discovery_client_mdns.cc', 'browser/local_discovery/service_discovery_client_utility.cc',
'browser/local_discovery/service_discovery_client_mdns.h', 'browser/local_discovery/service_discovery_client_utility.h',
'browser/local_discovery/service_discovery_host_client.cc', 'browser/local_discovery/service_discovery_host_client.cc',
'browser/local_discovery/service_discovery_host_client.h', 'browser/local_discovery/service_discovery_host_client.h',
'browser/local_discovery/privet_http_asynchronous_factory_impl.cc', 'browser/local_discovery/privet_http_asynchronous_factory_impl.cc',
......
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