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 #include "chrome/browser/local_discovery/service_discovery_client_mac.h" | 5 #include "chrome/browser/local_discovery/service_discovery_client_mac.h" |
| 6 | 6 |
| 7 #import <arpa/inet.h> | 7 #import <arpa/inet.h> |
| 8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
| 9 #import <net/if_dl.h> | 9 #import <net/if_dl.h> |
| 10 | 10 |
| 11 #include "base/debug/dump_without_crashing.h" | 11 #include "base/debug/dump_without_crashing.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "net/base/ip_address_number.h" | 17 #include "net/base/ip_address.h" |
| 18 #include "net/base/ip_endpoint.h" | 18 #include "net/base/ip_endpoint.h" |
| 19 | 19 |
| 20 using local_discovery::ServiceWatcherImplMac; | 20 using local_discovery::ServiceWatcherImplMac; |
| 21 using local_discovery::ServiceResolverImplMac; | 21 using local_discovery::ServiceResolverImplMac; |
| 22 | 22 |
| 23 @interface NetServiceBrowserDelegate | 23 @interface NetServiceBrowserDelegate |
| 24 : NSObject<NSNetServiceBrowserDelegate, NSNetServiceDelegate> { | 24 : NSObject<NSNetServiceBrowserDelegate, NSNetServiceDelegate> { |
| 25 @private | 25 @private |
| 26 ServiceWatcherImplMac::NetServiceBrowserContainer* container_; // weak. | 26 ServiceWatcherImplMac::NetServiceBrowserContainer* container_; // weak. |
| 27 base::scoped_nsobject<NSMutableArray> services_; | 27 base::scoped_nsobject<NSMutableArray> services_; |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 service_description_.service_name = service_name_; | 345 service_description_.service_name = service_name_; |
| 346 | 346 |
| 347 for (NSData* address in [service_ addresses]) { | 347 for (NSData* address in [service_ addresses]) { |
| 348 const void* bytes = [address bytes]; | 348 const void* bytes = [address bytes]; |
| 349 int length = [address length]; | 349 int length = [address length]; |
| 350 const sockaddr* socket = static_cast<const sockaddr*>(bytes); | 350 const sockaddr* socket = static_cast<const sockaddr*>(bytes); |
| 351 net::IPEndPoint end_point; | 351 net::IPEndPoint end_point; |
| 352 if (end_point.FromSockAddr(socket, length)) { | 352 if (end_point.FromSockAddr(socket, length)) { |
| 353 service_description_.address = | 353 service_description_.address = |
| 354 net::HostPortPair::FromIPEndPoint(end_point); | 354 net::HostPortPair::FromIPEndPoint(end_point); |
| 355 service_description_.ip_address = end_point.address(); | 355 service_description_.ip_address = net::IPAddress( |
|
eroman
2015/12/21 20:47:33
net::IPAddress::address() needs to (eventually) re
martijnc
2016/01/27 22:50:52
Done.
| |
| 356 &end_point.address().front(), end_point.address().size()); | |
| 356 break; | 357 break; |
| 357 } | 358 } |
| 358 } | 359 } |
| 359 | 360 |
| 360 if (service_description_.address.host().empty()) { | 361 if (!service_description_.address.host().size()) { |
| 361 VLOG(1) << "Service IP is not resolved: " << service_name_; | 362 VLOG(1) << "Service IP is not resolved: " << service_name_; |
| 362 callback_runner_->PostTask( | 363 callback_runner_->PostTask( |
| 363 FROM_HERE, | 364 FROM_HERE, |
| 364 base::Bind(callback_, STATUS_KNOWN_NONEXISTENT, ServiceDescription())); | 365 base::Bind(callback_, STATUS_KNOWN_NONEXISTENT, ServiceDescription())); |
| 365 return; | 366 return; |
| 366 } | 367 } |
| 367 | 368 |
| 368 ParseTxtRecord([service_ TXTRecordData], &service_description_.metadata); | 369 ParseTxtRecord([service_ TXTRecordData], &service_description_.metadata); |
| 369 | 370 |
| 370 // TODO(justinlin): Implement last_seen. | 371 // TODO(justinlin): Implement last_seen. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 481 container_->OnResolveUpdate(local_discovery::ServiceResolver::STATUS_SUCCESS); | 482 container_->OnResolveUpdate(local_discovery::ServiceResolver::STATUS_SUCCESS); |
| 482 } | 483 } |
| 483 | 484 |
| 484 - (void)netService:(NSNetService *)sender | 485 - (void)netService:(NSNetService *)sender |
| 485 didNotResolve:(NSDictionary *)errorDict { | 486 didNotResolve:(NSDictionary *)errorDict { |
| 486 container_->OnResolveUpdate( | 487 container_->OnResolveUpdate( |
| 487 local_discovery::ServiceResolver::STATUS_REQUEST_TIMEOUT); | 488 local_discovery::ServiceResolver::STATUS_REQUEST_TIMEOUT); |
| 488 } | 489 } |
| 489 | 490 |
| 490 @end | 491 @end |
| OLD | NEW |