Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / local_discovery / service_discovery_client_mac.h
blob55841baa4fcabe6de57ab38dd69af19f2e9a8014
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_MAC_H_
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_MAC_H_
8 #include <string>
10 #include "base/mac/scoped_nsobject.h"
11 #include "chrome/browser/local_discovery/service_discovery_shared_client.h"
13 namespace local_discovery {
15 // Implementation of ServiceDiscoveryClient that uses the Bonjour SDK.
16 // https://developer.apple.com/library/mac/documentation/Networking/Conceptual/
17 // NSNetServiceProgGuide/Articles/BrowsingForServices.html
18 class ServiceDiscoveryClientMac : public ServiceDiscoverySharedClient {
19 public:
20 ServiceDiscoveryClientMac();
22 private:
23 virtual ~ServiceDiscoveryClientMac();
25 // ServiceDiscoveryClient implementation.
26 virtual scoped_ptr<ServiceWatcher> CreateServiceWatcher(
27 const std::string& service_type,
28 const ServiceWatcher::UpdatedCallback& callback) OVERRIDE;
29 virtual scoped_ptr<ServiceResolver> CreateServiceResolver(
30 const std::string& service_name,
31 const ServiceResolver::ResolveCompleteCallback& callback) OVERRIDE;
32 virtual scoped_ptr<LocalDomainResolver> CreateLocalDomainResolver(
33 const std::string& domain,
34 net::AddressFamily address_family,
35 const LocalDomainResolver::IPAddressCallback& callback) OVERRIDE;
37 DISALLOW_COPY_AND_ASSIGN(ServiceDiscoveryClientMac);
40 class ServiceWatcherImplMac : public ServiceWatcher {
41 public:
42 ServiceWatcherImplMac(const std::string& service_type,
43 const ServiceWatcher::UpdatedCallback& callback);
45 void OnServicesUpdate(ServiceWatcher::UpdateType update,
46 const std::string& service);
48 private:
49 virtual ~ServiceWatcherImplMac();
51 virtual void Start() OVERRIDE;
52 virtual void DiscoverNewServices(bool force_update) OVERRIDE;
53 virtual std::string GetServiceType() const OVERRIDE;
55 std::string service_type_;
57 ServiceWatcher::UpdatedCallback callback_;
58 bool started_;
59 base::scoped_nsobject<id> delegate_;
60 base::scoped_nsobject<NSNetServiceBrowser> browser_;
62 DISALLOW_COPY_AND_ASSIGN(ServiceWatcherImplMac);
65 class ServiceResolverImplMac : public ServiceResolver {
66 public:
67 ServiceResolverImplMac(
68 const std::string& service_name,
69 const ServiceResolver::ResolveCompleteCallback& callback);
71 void OnResolveUpdate(RequestStatus);
73 // Testing methods.
74 void SetServiceForTesting(
75 base::scoped_nsobject<NSNetService> service);
77 private:
78 virtual ~ServiceResolverImplMac();
80 virtual void StartResolving() OVERRIDE;
81 virtual std::string GetName() const OVERRIDE;
83 const std::string service_name_;
84 ServiceResolver::ResolveCompleteCallback callback_;
85 bool has_resolved_;
86 base::scoped_nsobject<id> delegate_;
87 base::scoped_nsobject<NSNetService> service_;
88 ServiceDescription service_description_;
90 DISALLOW_COPY_AND_ASSIGN(ServiceResolverImplMac);
93 } // namespace local_discovery
95 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_MAC_H_