Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / local_discovery / service_discovery_client_utility.h
blobb9f9bec14cd9e0b64a46f4506f04125d64f5f625
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_UTILITY_H_
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_UTILITY_H_
8 #include <string>
10 #include "base/cancelable_callback.h"
11 #include "chrome/browser/local_discovery/service_discovery_shared_client.h"
12 #include "chrome/common/local_discovery/service_discovery_client.h"
13 #include "net/base/network_change_notifier.h"
15 namespace local_discovery {
17 class ServiceDiscoveryHostClient;
19 // Wrapper for ServiceDiscoveryHostClient to hide restarting of utility process
20 // from mdns users.
21 class ServiceDiscoveryClientUtility
22 : public ServiceDiscoverySharedClient,
23 public net::NetworkChangeNotifier::NetworkChangeObserver {
24 public:
25 ServiceDiscoveryClientUtility();
27 // ServiceDiscoveryClient implementation.
28 scoped_ptr<ServiceWatcher> CreateServiceWatcher(
29 const std::string& service_type,
30 const ServiceWatcher::UpdatedCallback& callback) override;
31 scoped_ptr<ServiceResolver> CreateServiceResolver(
32 const std::string& service_name,
33 const ServiceResolver::ResolveCompleteCallback& callback) override;
34 scoped_ptr<LocalDomainResolver> CreateLocalDomainResolver(
35 const std::string& domain,
36 net::AddressFamily address_family,
37 const LocalDomainResolver::IPAddressCallback& callback) override;
39 // net::NetworkChangeNotifier::NetworkChangeObserver implementation.
40 void OnNetworkChanged(
41 net::NetworkChangeNotifier::ConnectionType type) override;
43 private:
44 friend class base::RefCounted<ServiceDiscoveryClientUtility>;
46 ~ServiceDiscoveryClientUtility() override;
47 void ScheduleStartNewClient();
48 void StartNewClient();
49 void ReportSuccess();
51 scoped_refptr<ServiceDiscoveryHostClient> host_client_;
52 int restart_attempts_;
53 base::WeakPtrFactory<ServiceDiscoveryClientUtility> weak_ptr_factory_;
55 DISALLOW_COPY_AND_ASSIGN(ServiceDiscoveryClientUtility);
58 } // namespace local_discovery
60 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_UTILITY_H_