diff options
author | noamsml@chromium.org <noamsml@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-26 16:58:46 +0000 |
---|---|---|
committer | noamsml@chromium.org <noamsml@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-26 16:58:46 +0000 |
commit | 9442f1cb570962e319460107f2d42194b29525b6 (patch) | |
tree | 63ea91aec71dbbfab47bc2211b29f90532eb531f | |
parent | 171a9203a7f906f6ceccc23f1aed304682dbf163 (diff) | |
download | chromium_src-9442f1cb570962e319460107f2d42194b29525b6.zip chromium_src-9442f1cb570962e319460107f2d42194b29525b6.tar.gz chromium_src-9442f1cb570962e319460107f2d42194b29525b6.tar.bz2 |
Merge 225148 "Notify browser process if binding failed or proces..."
> Notify browser process if binding failed or process crash.
> Try rebind several time. Rebinding usually fails some time after network change event.
>
> BUG=297212
> NOTRY=true
>
> Review URL: https://chromiumcodereview.appspot.com/23830011
TBR=vitalybuka@chromium.org
Review URL: https://codereview.chromium.org/24725004
git-svn-id: svn://svn.chromium.org/chrome/branches/1650/src@225466 0039d316-1c4b-4281-b951-d872f2087c98
7 files changed, 73 insertions, 48 deletions
diff --git a/chrome/browser/local_discovery/service_discovery_client_mdns.cc b/chrome/browser/local_discovery/service_discovery_client_mdns.cc index c4943cf..bb81b55 100644 --- a/chrome/browser/local_discovery/service_discovery_client_mdns.cc +++ b/chrome/browser/local_discovery/service_discovery_client_mdns.cc @@ -12,6 +12,7 @@ namespace local_discovery { using content::BrowserThread; namespace { +const int kMaxRestartAttempts = 10; const int kRestartDelayOnNetworkChangeSeconds = 3; } @@ -39,13 +40,16 @@ ServiceDiscoveryClientMdns::CreateLocalDomainResolver( callback); } -ServiceDiscoveryClientMdns::ServiceDiscoveryClientMdns() { +ServiceDiscoveryClientMdns::ServiceDiscoveryClientMdns() + : restart_attempts_(kMaxRestartAttempts), + weak_ptr_factory_(this) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); net::NetworkChangeNotifier::AddNetworkChangeObserver(this); - host_client_ = new ServiceDiscoveryHostClient(); - host_client_->Start(); + StartNewClient(); } ServiceDiscoveryClientMdns::~ServiceDiscoveryClientMdns() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); host_client_->Shutdown(); } @@ -53,24 +57,37 @@ ServiceDiscoveryClientMdns::~ServiceDiscoveryClientMdns() { void ServiceDiscoveryClientMdns::OnNetworkChanged( net::NetworkChangeNotifier::ConnectionType type) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + // Only network changes resets kMaxRestartAttempts. + restart_attempts_ = kMaxRestartAttempts; + ScheduleStartNewClient(); +} + +void ServiceDiscoveryClientMdns::ScheduleStartNewClient() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); host_client_->Shutdown(); - network_change_callback_.Reset( - base::Bind(&ServiceDiscoveryClientMdns::StartNewClient, - base::Unretained(this))); // Unretained to avoid ref cycle. + weak_ptr_factory_.InvalidateWeakPtrs(); base::MessageLoop::current()->PostDelayedTask( FROM_HERE, - network_change_callback_.callback(), + base::Bind(&ServiceDiscoveryClientMdns::StartNewClient, + weak_ptr_factory_.GetWeakPtr()), base::TimeDelta::FromSeconds(kRestartDelayOnNetworkChangeSeconds)); } void ServiceDiscoveryClientMdns::StartNewClient() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); scoped_refptr<ServiceDiscoveryHostClient> old_client = host_client_; - host_client_ = new ServiceDiscoveryHostClient(); - host_client_->Start(); + if ((restart_attempts_--) > 0) { + host_client_ = new ServiceDiscoveryHostClient(); + host_client_->Start( + base::Bind(&ServiceDiscoveryClientMdns::ScheduleStartNewClient, + weak_ptr_factory_.GetWeakPtr())); + } else { + host_client_ = NULL; + } // Run when host_client_ is created. Callbacks created by InvalidateWatchers // may create new watchers. - old_client->InvalidateWatchers(); + if (old_client) + old_client->InvalidateWatchers(); } } // namespace local_discovery diff --git a/chrome/browser/local_discovery/service_discovery_client_mdns.h b/chrome/browser/local_discovery/service_discovery_client_mdns.h index c4b1bdf5..308cbf3 100644 --- a/chrome/browser/local_discovery/service_discovery_client_mdns.h +++ b/chrome/browser/local_discovery/service_discovery_client_mdns.h @@ -42,10 +42,12 @@ class ServiceDiscoveryClientMdns friend class base::RefCounted<ServiceDiscoveryClientMdns>; virtual ~ServiceDiscoveryClientMdns(); + void ScheduleStartNewClient(); void StartNewClient(); - base::CancelableClosure network_change_callback_; scoped_refptr<ServiceDiscoveryHostClient> host_client_; + int restart_attempts_; + base::WeakPtrFactory<ServiceDiscoveryClientMdns> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(ServiceDiscoveryClientMdns); }; diff --git a/chrome/browser/local_discovery/service_discovery_host_client.cc b/chrome/browser/local_discovery/service_discovery_host_client.cc index bdfd2dc..9d3d971 100644 --- a/chrome/browser/local_discovery/service_discovery_host_client.cc +++ b/chrome/browser/local_discovery/service_discovery_host_client.cc @@ -211,8 +211,10 @@ void ServiceDiscoveryHostClient::UnregisterLocalDomainResolverCallback( domain_resolver_callbacks_.erase(id); } -void ServiceDiscoveryHostClient::Start() { +void ServiceDiscoveryHostClient::Start( + const base::Closure& error_callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + error_callback_ = error_callback; io_runner_->PostTask( FROM_HERE, base::Bind(&ServiceDiscoveryHostClient::StartOnIOThread, this)); @@ -258,6 +260,7 @@ void ServiceDiscoveryHostClient::ShutdownOnIOThread() { utility_host_->Send(new LocalDiscoveryMsg_ShutdownLocalDiscovery); utility_host_->EndBatchMode(); } + error_callback_ = base::Closure(); } void ServiceDiscoveryHostClient::Send(IPC::Message* msg) { @@ -273,10 +276,16 @@ void ServiceDiscoveryHostClient::SendOnIOThread(IPC::Message* msg) { utility_host_->Send(msg); } +void ServiceDiscoveryHostClient::OnProcessCrashed(int exit_code) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + OnError(); +} + bool ServiceDiscoveryHostClient::OnMessageReceived( const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(ServiceDiscoveryHostClient, message) + IPC_MESSAGE_HANDLER(LocalDiscoveryHostMsg_Error, OnError) IPC_MESSAGE_HANDLER(LocalDiscoveryHostMsg_WatcherCallback, OnWatcherCallback) IPC_MESSAGE_HANDLER(LocalDiscoveryHostMsg_ResolverCallback, @@ -302,6 +311,12 @@ void ServiceDiscoveryHostClient::InvalidateWatchers() { } } +void ServiceDiscoveryHostClient::OnError() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + if (!error_callback_.is_null()) + callback_runner_->PostTask(FROM_HERE, error_callback_); +} + void ServiceDiscoveryHostClient::OnWatcherCallback( uint64 id, ServiceWatcher::UpdateType update, diff --git a/chrome/browser/local_discovery/service_discovery_host_client.h b/chrome/browser/local_discovery/service_discovery_host_client.h index 008bd8c..7b335b1 100644 --- a/chrome/browser/local_discovery/service_discovery_host_client.h +++ b/chrome/browser/local_discovery/service_discovery_host_client.h @@ -30,7 +30,7 @@ class ServiceDiscoveryHostClient ServiceDiscoveryHostClient(); // Starts utility process with ServiceDiscoveryClient. - void Start(); + void Start(const base::Closure& error_callback); // Shutdowns utility process. void Shutdown(); @@ -48,6 +48,7 @@ class ServiceDiscoveryHostClient const LocalDomainResolver::IPAddressCallback& callback) OVERRIDE; // UtilityProcessHostClient implementation. + virtual void OnProcessCrashed(int exit_code) OVERRIDE; virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; protected: @@ -85,6 +86,7 @@ class ServiceDiscoveryHostClient void UnregisterLocalDomainResolverCallback(uint64 id); // IPC Message handlers. + void OnError(); void OnWatcherCallback(uint64 id, ServiceWatcher::UpdateType update, const std::string& service_name); @@ -116,6 +118,7 @@ class ServiceDiscoveryHostClient // Incrementing counter to assign ID to watchers and resolvers. uint64 current_id_; + base::Closure error_callback_; WatcherCallbacks service_watcher_callbacks_; ResolverCallbacks service_resolver_callbacks_; DomainResolverCallbacks domain_resolver_callbacks_; diff --git a/chrome/common/local_discovery/local_discovery_messages.h b/chrome/common/local_discovery/local_discovery_messages.h index a5ebccc..1add9a2 100644 --- a/chrome/common/local_discovery/local_discovery_messages.h +++ b/chrome/common/local_discovery/local_discovery_messages.h @@ -73,6 +73,9 @@ IPC_MESSAGE_CONTROL0(LocalDiscoveryMsg_ShutdownLocalDiscovery) // Utility process host messages: // These are messages from the utility process to the browser. +// Notifies browser process if process failed. +IPC_MESSAGE_CONTROL0(LocalDiscoveryHostMsg_Error) + // Notifies browser process about new services. IPC_MESSAGE_CONTROL3(LocalDiscoveryHostMsg_WatcherCallback, uint64 /* id */, diff --git a/chrome/utility/local_discovery/service_discovery_message_handler.cc b/chrome/utility/local_discovery/service_discovery_message_handler.cc index 5b0ab95..d559547 100644 --- a/chrome/utility/local_discovery/service_discovery_message_handler.cc +++ b/chrome/utility/local_discovery/service_discovery_message_handler.cc @@ -110,27 +110,10 @@ void StaticInitializeSocketFactory() { #endif // OS_WIN -void SendServiceResolved(uint64 id, ServiceResolver::RequestStatus status, - const ServiceDescription& description) { - content::UtilityThread::Get()->Send( - new LocalDiscoveryHostMsg_ResolverCallback(id, status, description)); +void SendHostMessageOnUtilityThread(IPC::Message* msg) { + content::UtilityThread::Get()->Send(msg); } -void SendServiceUpdated(uint64 id, ServiceWatcher::UpdateType update, - const std::string& name) { - content::UtilityThread::Get()->Send( - new LocalDiscoveryHostMsg_WatcherCallback(id, update, name)); -} - -void SendLocalDomainResolved(uint64 id, bool success, - const net::IPAddressNumber& address_ipv4, - const net::IPAddressNumber& address_ipv6) { - content::UtilityThread::Get()->Send( - new LocalDiscoveryHostMsg_LocalDomainResolverCallback( - id, success, address_ipv4, address_ipv6)); -} - - std::string WatcherUpdateToString(ServiceWatcher::UpdateType update) { switch (update) { case ServiceWatcher::UPDATE_ADDED: @@ -178,8 +161,10 @@ void ServiceDiscoveryMessageHandler::InitializeMdns() { { // Temporarily redirect network code to use pre-created sockets. ScopedSocketFactorySetter socket_factory_setter; - if (!mdns_client_->StartListening()) + if (!mdns_client_->StartListening()) { + Send(new LocalDiscoveryHostMsg_Error()); return; + } } service_discovery_client_.reset( @@ -387,7 +372,6 @@ void ServiceDiscoveryMessageHandler::ShutdownOnIOThread() { service_watchers_.clear(); service_resolvers_.clear(); local_domain_resolvers_.clear(); - service_discovery_client_.reset(); mdns_client_.reset(); } @@ -398,8 +382,8 @@ void ServiceDiscoveryMessageHandler::OnServiceUpdated( const std::string& name) { VLOG(1) << "OnServiceUpdated with id " << id << WatcherUpdateToString(update); DCHECK(service_discovery_client_); - utility_task_runner_->PostTask(FROM_HERE, - base::Bind(&SendServiceUpdated, id, update, name)); + + Send(new LocalDiscoveryHostMsg_WatcherCallback(id, update, name)); } void ServiceDiscoveryMessageHandler::OnServiceResolved( @@ -410,8 +394,7 @@ void ServiceDiscoveryMessageHandler::OnServiceResolved( << ResolverStatusToString(status); DCHECK(service_discovery_client_); - utility_task_runner_->PostTask(FROM_HERE, - base::Bind(&SendServiceResolved, id, status, description)); + Send(new LocalDiscoveryHostMsg_ResolverCallback(id, status, description)); } void ServiceDiscoveryMessageHandler::OnLocalDomainResolved( @@ -419,19 +402,19 @@ void ServiceDiscoveryMessageHandler::OnLocalDomainResolved( bool success, const net::IPAddressNumber& address_ipv4, const net::IPAddressNumber& address_ipv6) { - VLOG(1) << "OnLocalDomainResolved with id " << id; - - if (!address_ipv4.empty()) - VLOG(1) << "Local comain callback has valid ipv4 address with id " << id; - if (!address_ipv6.empty()) - VLOG(1) << "Local comain callback has valid ipv6 address with id " << id; + VLOG(1) << "OnLocalDomainResolved with id=" << id + << ", IPv4=" << net::IPAddressToString(address_ipv4) + << ", IPv6=" << net::IPAddressToString(address_ipv6); DCHECK(service_discovery_client_); - utility_task_runner_->PostTask(FROM_HERE, base::Bind(&SendLocalDomainResolved, - id, success, - address_ipv4, - address_ipv6)); + Send(new LocalDiscoveryHostMsg_LocalDomainResolverCallback( + id, success, address_ipv4, address_ipv6)); } +void ServiceDiscoveryMessageHandler::Send(IPC::Message* msg) { + utility_task_runner_->PostTask(FROM_HERE, + base::Bind(&SendHostMessageOnUtilityThread, + msg)); +} } // namespace local_discovery diff --git a/chrome/utility/local_discovery/service_discovery_message_handler.h b/chrome/utility/local_discovery/service_discovery_message_handler.h index 417db0f..c463448 100644 --- a/chrome/utility/local_discovery/service_discovery_message_handler.h +++ b/chrome/utility/local_discovery/service_discovery_message_handler.h @@ -93,6 +93,8 @@ class ServiceDiscoveryMessageHandler : public chrome::UtilityMessageHandler { const net::IPAddressNumber& address_ipv4, const net::IPAddressNumber& address_ipv6); + void Send(IPC::Message* msg); + ServiceWatchers service_watchers_; ServiceResolvers service_resolvers_; LocalDomainResolvers local_domain_resolvers_; |