| 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 #include <stddef.h> | 10 #include <stddef.h> | 
| 11 #include <stdint.h> | 11 #include <stdint.h> | 
| 12 | 12 | 
| 13 #include "base/debug/dump_without_crashing.h" | 13 #include "base/debug/dump_without_crashing.h" | 
| 14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" | 
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" | 
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" | 
| 17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" | 
| 18 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" | 
| 19 #include "net/base/ip_address.h" | 19 #include "net/base/ip_address_number.h" | 
| 20 #include "net/base/ip_endpoint.h" | 20 #include "net/base/ip_endpoint.h" | 
| 21 | 21 | 
| 22 using local_discovery::ServiceWatcherImplMac; | 22 using local_discovery::ServiceWatcherImplMac; | 
| 23 using local_discovery::ServiceResolverImplMac; | 23 using local_discovery::ServiceResolverImplMac; | 
| 24 | 24 | 
| 25 @interface NetServiceBrowserDelegate | 25 @interface NetServiceBrowserDelegate | 
| 26     : NSObject<NSNetServiceBrowserDelegate, NSNetServiceDelegate> { | 26     : NSObject<NSNetServiceBrowserDelegate, NSNetServiceDelegate> { | 
| 27  @private | 27  @private | 
| 28   ServiceWatcherImplMac::NetServiceBrowserContainer* container_;  // weak. | 28   ServiceWatcherImplMac::NetServiceBrowserContainer* container_;  // weak. | 
| 29   base::scoped_nsobject<NSMutableArray> services_; | 29   base::scoped_nsobject<NSMutableArray> services_; | 
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 347   service_description_.service_name = service_name_; | 347   service_description_.service_name = service_name_; | 
| 348 | 348 | 
| 349   for (NSData* address in [service_ addresses]) { | 349   for (NSData* address in [service_ addresses]) { | 
| 350     const void* bytes = [address bytes]; | 350     const void* bytes = [address bytes]; | 
| 351     int length = [address length]; | 351     int length = [address length]; | 
| 352     const sockaddr* socket = static_cast<const sockaddr*>(bytes); | 352     const sockaddr* socket = static_cast<const sockaddr*>(bytes); | 
| 353     net::IPEndPoint end_point; | 353     net::IPEndPoint end_point; | 
| 354     if (end_point.FromSockAddr(socket, length)) { | 354     if (end_point.FromSockAddr(socket, length)) { | 
| 355       service_description_.address = | 355       service_description_.address = | 
| 356           net::HostPortPair::FromIPEndPoint(end_point); | 356           net::HostPortPair::FromIPEndPoint(end_point); | 
| 357       service_description_.ip_address = end_point.address(); | 357       service_description_.ip_address = end_point.address().bytes(); | 
| 358       break; | 358       break; | 
| 359     } | 359     } | 
| 360   } | 360   } | 
| 361 | 361 | 
| 362   if (service_description_.address.host().empty()) { | 362   if (service_description_.address.host().empty()) { | 
| 363     VLOG(1) << "Service IP is not resolved: " << service_name_; | 363     VLOG(1) << "Service IP is not resolved: " << service_name_; | 
| 364     callback_runner_->PostTask( | 364     callback_runner_->PostTask( | 
| 365         FROM_HERE, | 365         FROM_HERE, | 
| 366         base::Bind(callback_, STATUS_KNOWN_NONEXISTENT, ServiceDescription())); | 366         base::Bind(callback_, STATUS_KNOWN_NONEXISTENT, ServiceDescription())); | 
| 367     return; | 367     return; | 
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 483   container_->OnResolveUpdate(local_discovery::ServiceResolver::STATUS_SUCCESS); | 483   container_->OnResolveUpdate(local_discovery::ServiceResolver::STATUS_SUCCESS); | 
| 484 } | 484 } | 
| 485 | 485 | 
| 486 - (void)netService:(NSNetService *)sender | 486 - (void)netService:(NSNetService *)sender | 
| 487         didNotResolve:(NSDictionary *)errorDict { | 487         didNotResolve:(NSDictionary *)errorDict { | 
| 488   container_->OnResolveUpdate( | 488   container_->OnResolveUpdate( | 
| 489       local_discovery::ServiceResolver::STATUS_REQUEST_TIMEOUT); | 489       local_discovery::ServiceResolver::STATUS_REQUEST_TIMEOUT); | 
| 490 } | 490 } | 
| 491 | 491 | 
| 492 @end | 492 @end | 
| OLD | NEW | 
|---|