Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / local_discovery / service_discovery_client_mdns.h
blobc741f51ab5e81a765716e2bb81fe50eaaea54f6f
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_MDNS_H_
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_MDNS_H_
8 #include <set>
9 #include <string>
11 #include "base/cancelable_callback.h"
12 #include "chrome/browser/local_discovery/service_discovery_shared_client.h"
13 #include "chrome/common/local_discovery/service_discovery_client.h"
14 #include "net/base/network_change_notifier.h"
15 #include "net/dns/mdns_client.h"
17 namespace local_discovery {
19 // Implementation of ServiceDiscoverySharedClient with front-end of UI thread
20 // and networking code on IO thread.
21 class ServiceDiscoveryClientMdns
22 : public ServiceDiscoverySharedClient,
23 public net::NetworkChangeNotifier::NetworkChangeObserver {
24 public:
25 class Proxy;
26 ServiceDiscoveryClientMdns();
28 // ServiceDiscoveryClient implementation.
29 virtual scoped_ptr<ServiceWatcher> CreateServiceWatcher(
30 const std::string& service_type,
31 const ServiceWatcher::UpdatedCallback& callback) OVERRIDE;
32 virtual scoped_ptr<ServiceResolver> CreateServiceResolver(
33 const std::string& service_name,
34 const ServiceResolver::ResolveCompleteCallback& callback) OVERRIDE;
35 virtual scoped_ptr<LocalDomainResolver> CreateLocalDomainResolver(
36 const std::string& domain,
37 net::AddressFamily address_family,
38 const LocalDomainResolver::IPAddressCallback& callback) OVERRIDE;
40 // net::NetworkChangeNotifier::NetworkChangeObserver implementation.
41 virtual void OnNetworkChanged(
42 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
44 private:
45 virtual ~ServiceDiscoveryClientMdns();
47 void ScheduleStartNewClient();
48 void StartNewClient();
49 void OnInterfaceListReady(const net::InterfaceIndexFamilyList& interfaces);
50 void OnMdnsInitialized(bool success);
51 void ReportSuccess();
52 void InvalidateWeakPtrs();
53 void Reset();
55 bool PostToMdnsThread(const base::Closure& task);
57 std::set<Proxy*> proxies_;
59 scoped_refptr<base::SequencedTaskRunner> mdns_runner_;
61 // Access only on |mdns_runner_| thread.
62 scoped_ptr<net::MDnsClient> mdns_;
64 // Access only on |mdns_runner_| thread.
65 scoped_ptr<ServiceDiscoveryClient> client_;
67 // Counter of restart attempts we have made after network change.
68 int restart_attempts_;
70 // If false delay tasks until initialization is posted to |mdns_runner_|
71 // thread.
72 bool need_dalay_mdns_tasks_;
74 // Delayed |mdns_runner_| tasks.
75 std::vector<base::Closure> delayed_tasks_;
77 base::WeakPtrFactory<ServiceDiscoveryClientMdns> weak_ptr_factory_;
79 DISALLOW_COPY_AND_ASSIGN(ServiceDiscoveryClientMdns);
82 } // namespace local_discovery
84 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_MDNS_H_