Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_UTILITY_H_ | 5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_MDNS_H_ |
| 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_UTILITY_H_ | 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_MDNS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
| 11 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" | 11 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" |
| 12 #include "chrome/common/local_discovery/service_discovery_client.h" | 12 #include "chrome/common/local_discovery/service_discovery_client.h" |
| 13 #include "net/base/network_change_notifier.h" | 13 #include "net/base/network_change_notifier.h" |
| 14 #include "net/dns/mdns_client.h" | |
| 14 | 15 |
| 15 namespace local_discovery { | 16 namespace local_discovery { |
| 16 | 17 |
| 17 class ServiceDiscoveryHostClient; | 18 // Implementation of ServiceDiscoverySharedClient with front-end of UI thread |
| 18 | 19 // and networking code on IO thread. |
| 19 // Wrapper for ServiceDiscoveryHostClient to hide restarting of utility process | 20 class ServiceDiscoveryClientMdns |
| 20 // from mdns users. | |
| 21 class ServiceDiscoveryClientUtility | |
| 22 : public ServiceDiscoverySharedClient, | 21 : public ServiceDiscoverySharedClient, |
| 23 public net::NetworkChangeNotifier::NetworkChangeObserver { | 22 public net::NetworkChangeNotifier::NetworkChangeObserver { |
| 24 public: | 23 public: |
| 25 ServiceDiscoveryClientUtility(); | 24 class Proxy; |
| 25 ServiceDiscoveryClientMdns(); | |
| 26 | 26 |
| 27 // ServiceDiscoveryClient implementation. | 27 // ServiceDiscoveryClient implementation. |
| 28 virtual scoped_ptr<ServiceWatcher> CreateServiceWatcher( | 28 virtual scoped_ptr<ServiceWatcher> CreateServiceWatcher( |
| 29 const std::string& service_type, | 29 const std::string& service_type, |
| 30 const ServiceWatcher::UpdatedCallback& callback) OVERRIDE; | 30 const ServiceWatcher::UpdatedCallback& callback) OVERRIDE; |
| 31 virtual scoped_ptr<ServiceResolver> CreateServiceResolver( | 31 virtual scoped_ptr<ServiceResolver> CreateServiceResolver( |
| 32 const std::string& service_name, | 32 const std::string& service_name, |
| 33 const ServiceResolver::ResolveCompleteCallback& callback) OVERRIDE; | 33 const ServiceResolver::ResolveCompleteCallback& callback) OVERRIDE; |
| 34 virtual scoped_ptr<LocalDomainResolver> CreateLocalDomainResolver( | 34 virtual scoped_ptr<LocalDomainResolver> CreateLocalDomainResolver( |
| 35 const std::string& domain, | 35 const std::string& domain, |
| 36 net::AddressFamily address_family, | 36 net::AddressFamily address_family, |
| 37 const LocalDomainResolver::IPAddressCallback& callback) OVERRIDE; | 37 const LocalDomainResolver::IPAddressCallback& callback) OVERRIDE; |
| 38 | 38 |
| 39 // net::NetworkChangeNotifier::NetworkChangeObserver implementation. | 39 // net::NetworkChangeNotifier::NetworkChangeObserver implementation. |
| 40 virtual void OnNetworkChanged( | 40 virtual void OnNetworkChanged( |
| 41 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | 41 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 friend class base::RefCounted<ServiceDiscoveryClientUtility>; | 44 virtual ~ServiceDiscoveryClientMdns(); |
| 45 | 45 |
| 46 virtual ~ServiceDiscoveryClientUtility(); | |
| 47 void ScheduleStartNewClient(); | 46 void ScheduleStartNewClient(); |
| 48 void StartNewClient(); | 47 void StartNewClient(); |
| 48 void OnInterfaceListReady(const net::InterfaceIndexFamilyList& interfaces); | |
| 49 void OnMdnsInitialized(bool success); | |
| 49 void ReportSuccess(); | 50 void ReportSuccess(); |
| 51 void InvalidateWeakPtrs(); | |
| 52 void Reset(); | |
| 50 | 53 |
| 51 scoped_refptr<ServiceDiscoveryHostClient> host_client_; | 54 bool PostToMdnsThread(const base::Closure& task); |
| 55 | |
| 56 std::set<Proxy*> proxies_; | |
| 57 | |
| 58 scoped_refptr<base::SequencedTaskRunner> mdns_runner_; | |
| 59 | |
| 60 // Access only on |mdns_runner_| thread. | |
| 61 scoped_ptr<net::MDnsClient> mdns_; | |
| 62 | |
| 63 // Access only on |mdns_runner_| thread. | |
| 64 scoped_ptr<ServiceDiscoveryClient> client_; | |
|
Noam Samuel
2014/04/28 20:40:51
Should these have custom destructors so they are d
| |
| 65 | |
| 66 // If false delay tasks until initialization is posted to |mdns_runner_| | |
| 67 // thread. | |
| 68 bool need_dalay_mdns_tasks_; | |
| 69 | |
| 70 // Delayed |mdns_runner_| tasks. | |
| 71 std::vector<base::Closure> delayed_tasks_; | |
| 72 | |
| 52 int restart_attempts_; | 73 int restart_attempts_; |
| 53 base::WeakPtrFactory<ServiceDiscoveryClientUtility> weak_ptr_factory_; | 74 base::WeakPtrFactory<ServiceDiscoveryClientMdns> weak_ptr_factory_; |
| 54 | 75 |
| 55 DISALLOW_COPY_AND_ASSIGN(ServiceDiscoveryClientUtility); | 76 DISALLOW_COPY_AND_ASSIGN(ServiceDiscoveryClientMdns); |
| 56 }; | 77 }; |
| 57 | 78 |
| 58 } // namespace local_discovery | 79 } // namespace local_discovery |
| 59 | 80 |
| 60 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_UTILITY_H_ | 81 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_MDNS_H_ |
| OLD | NEW |