OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_COMMON_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_IMPL_H_ | 5 #ifndef CHROME_COMMON_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_IMPL_H_ |
6 #define CHROME_COMMON_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_IMPL_H_ | 6 #define CHROME_COMMON_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/cancelable_callback.h" | 13 #include "base/cancelable_callback.h" |
14 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "chrome/common/local_discovery/service_discovery_client.h" | 17 #include "chrome/common/local_discovery/service_discovery_client.h" |
18 #include "net/dns/mdns_client.h" | 18 #include "net/dns/mdns_client.h" |
19 | 19 |
20 namespace local_discovery { | 20 namespace local_discovery { |
21 | 21 |
22 class ServiceDiscoveryClientImpl : public ServiceDiscoveryClient { | 22 class ServiceDiscoveryClientImpl : public ServiceDiscoveryClient { |
23 public: | 23 public: |
24 // |mdns_client| must outlive the Service Discovery Client. | 24 // |mdns_client| must outlive the Service Discovery Client. |
25 explicit ServiceDiscoveryClientImpl(net::MDnsClient* mdns_client); | 25 explicit ServiceDiscoveryClientImpl(net::MDnsClient* mdns_client); |
26 virtual ~ServiceDiscoveryClientImpl(); | 26 ~ServiceDiscoveryClientImpl() override; |
27 | 27 |
28 // ServiceDiscoveryClient implementation: | 28 // ServiceDiscoveryClient implementation: |
29 virtual scoped_ptr<ServiceWatcher> CreateServiceWatcher( | 29 scoped_ptr<ServiceWatcher> CreateServiceWatcher( |
30 const std::string& service_type, | 30 const std::string& service_type, |
31 const ServiceWatcher::UpdatedCallback& callback) override; | 31 const ServiceWatcher::UpdatedCallback& callback) override; |
32 | 32 |
33 virtual scoped_ptr<ServiceResolver> CreateServiceResolver( | 33 scoped_ptr<ServiceResolver> CreateServiceResolver( |
34 const std::string& service_name, | 34 const std::string& service_name, |
35 const ServiceResolver::ResolveCompleteCallback& callback) override; | 35 const ServiceResolver::ResolveCompleteCallback& callback) override; |
36 | 36 |
37 virtual scoped_ptr<LocalDomainResolver> CreateLocalDomainResolver( | 37 scoped_ptr<LocalDomainResolver> CreateLocalDomainResolver( |
38 const std::string& domain, | 38 const std::string& domain, |
39 net::AddressFamily address_family, | 39 net::AddressFamily address_family, |
40 const LocalDomainResolver::IPAddressCallback& callback) override; | 40 const LocalDomainResolver::IPAddressCallback& callback) override; |
41 | 41 |
42 private: | 42 private: |
43 net::MDnsClient* mdns_client_; | 43 net::MDnsClient* mdns_client_; |
44 | 44 |
45 DISALLOW_COPY_AND_ASSIGN(ServiceDiscoveryClientImpl); | 45 DISALLOW_COPY_AND_ASSIGN(ServiceDiscoveryClientImpl); |
46 }; | 46 }; |
47 | 47 |
48 class ServiceWatcherImpl : public ServiceWatcher, | 48 class ServiceWatcherImpl : public ServiceWatcher, |
49 public net::MDnsListener::Delegate, | 49 public net::MDnsListener::Delegate, |
50 public base::SupportsWeakPtr<ServiceWatcherImpl> { | 50 public base::SupportsWeakPtr<ServiceWatcherImpl> { |
51 public: | 51 public: |
52 ServiceWatcherImpl(const std::string& service_type, | 52 ServiceWatcherImpl(const std::string& service_type, |
53 const ServiceWatcher::UpdatedCallback& callback, | 53 const ServiceWatcher::UpdatedCallback& callback, |
54 net::MDnsClient* mdns_client); | 54 net::MDnsClient* mdns_client); |
55 // Listening will automatically stop when the destructor is called. | 55 // Listening will automatically stop when the destructor is called. |
56 virtual ~ServiceWatcherImpl(); | 56 ~ServiceWatcherImpl() override; |
57 | 57 |
58 // ServiceWatcher implementation: | 58 // ServiceWatcher implementation: |
59 virtual void Start() override; | 59 void Start() override; |
60 | 60 |
61 virtual void DiscoverNewServices(bool force_update) override; | 61 void DiscoverNewServices(bool force_update) override; |
62 | 62 |
63 virtual void SetActivelyRefreshServices( | 63 void SetActivelyRefreshServices(bool actively_refresh_services) override; |
64 bool actively_refresh_services) override; | |
65 | 64 |
66 virtual std::string GetServiceType() const override; | 65 std::string GetServiceType() const override; |
67 | 66 |
68 virtual void OnRecordUpdate(net::MDnsListener::UpdateType update, | 67 void OnRecordUpdate(net::MDnsListener::UpdateType update, |
69 const net::RecordParsed* record) override; | 68 const net::RecordParsed* record) override; |
70 | 69 |
71 virtual void OnNsecRecord(const std::string& name, unsigned rrtype) override; | 70 void OnNsecRecord(const std::string& name, unsigned rrtype) override; |
72 | 71 |
73 virtual void OnCachePurged() override; | 72 void OnCachePurged() override; |
74 | 73 |
75 virtual void OnTransactionResponse( | 74 virtual void OnTransactionResponse( |
76 scoped_ptr<net::MDnsTransaction>* transaction, | 75 scoped_ptr<net::MDnsTransaction>* transaction, |
77 net::MDnsTransaction::Result result, | 76 net::MDnsTransaction::Result result, |
78 const net::RecordParsed* record); | 77 const net::RecordParsed* record); |
79 | 78 |
80 private: | 79 private: |
81 struct ServiceListeners { | 80 struct ServiceListeners { |
82 ServiceListeners(const std::string& service_name, | 81 ServiceListeners(const std::string& service_name, |
83 ServiceWatcherImpl* watcher, | 82 ServiceWatcherImpl* watcher, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 }; | 154 }; |
156 | 155 |
157 class ServiceResolverImpl | 156 class ServiceResolverImpl |
158 : public ServiceResolver, | 157 : public ServiceResolver, |
159 public base::SupportsWeakPtr<ServiceResolverImpl> { | 158 public base::SupportsWeakPtr<ServiceResolverImpl> { |
160 public: | 159 public: |
161 ServiceResolverImpl(const std::string& service_name, | 160 ServiceResolverImpl(const std::string& service_name, |
162 const ServiceResolver::ResolveCompleteCallback& callback, | 161 const ServiceResolver::ResolveCompleteCallback& callback, |
163 net::MDnsClient* mdns_client); | 162 net::MDnsClient* mdns_client); |
164 | 163 |
165 virtual ~ServiceResolverImpl(); | 164 ~ServiceResolverImpl() override; |
166 | 165 |
167 // ServiceResolver implementation: | 166 // ServiceResolver implementation: |
168 virtual void StartResolving() override; | 167 void StartResolving() override; |
169 | 168 |
170 virtual std::string GetName() const override; | 169 std::string GetName() const override; |
171 | 170 |
172 private: | 171 private: |
173 // Respond to transaction finishing for SRV records. | 172 // Respond to transaction finishing for SRV records. |
174 void SrvRecordTransactionResponse(net::MDnsTransaction::Result status, | 173 void SrvRecordTransactionResponse(net::MDnsTransaction::Result status, |
175 const net::RecordParsed* record); | 174 const net::RecordParsed* record); |
176 | 175 |
177 // Respond to transaction finishing for TXT records. | 176 // Respond to transaction finishing for TXT records. |
178 void TxtRecordTransactionResponse(net::MDnsTransaction::Result status, | 177 void TxtRecordTransactionResponse(net::MDnsTransaction::Result status, |
179 const net::RecordParsed* record); | 178 const net::RecordParsed* record); |
180 | 179 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 223 |
225 DISALLOW_COPY_AND_ASSIGN(ServiceResolverImpl); | 224 DISALLOW_COPY_AND_ASSIGN(ServiceResolverImpl); |
226 }; | 225 }; |
227 | 226 |
228 class LocalDomainResolverImpl : public LocalDomainResolver { | 227 class LocalDomainResolverImpl : public LocalDomainResolver { |
229 public: | 228 public: |
230 LocalDomainResolverImpl(const std::string& domain, | 229 LocalDomainResolverImpl(const std::string& domain, |
231 net::AddressFamily address_family, | 230 net::AddressFamily address_family, |
232 const IPAddressCallback& callback, | 231 const IPAddressCallback& callback, |
233 net::MDnsClient* mdns_client); | 232 net::MDnsClient* mdns_client); |
234 virtual ~LocalDomainResolverImpl(); | 233 ~LocalDomainResolverImpl() override; |
235 | 234 |
236 virtual void Start() override; | 235 void Start() override; |
237 | 236 |
238 const std::string& domain() { return domain_; } | 237 const std::string& domain() { return domain_; } |
239 | 238 |
240 private: | 239 private: |
241 void OnTransactionComplete( | 240 void OnTransactionComplete( |
242 net::MDnsTransaction::Result result, | 241 net::MDnsTransaction::Result result, |
243 const net::RecordParsed* record); | 242 const net::RecordParsed* record); |
244 | 243 |
245 scoped_ptr<net::MDnsTransaction> CreateTransaction(uint16 type); | 244 scoped_ptr<net::MDnsTransaction> CreateTransaction(uint16 type); |
246 | 245 |
(...skipping 17 matching lines...) Expand all Loading... |
264 | 263 |
265 base::CancelableCallback<void()> timeout_callback_; | 264 base::CancelableCallback<void()> timeout_callback_; |
266 | 265 |
267 DISALLOW_COPY_AND_ASSIGN(LocalDomainResolverImpl); | 266 DISALLOW_COPY_AND_ASSIGN(LocalDomainResolverImpl); |
268 }; | 267 }; |
269 | 268 |
270 | 269 |
271 } // namespace local_discovery | 270 } // namespace local_discovery |
272 | 271 |
273 #endif // CHROME_COMMON_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_IMPL_H_ | 272 #endif // CHROME_COMMON_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_IMPL_H_ |
OLD | NEW |