| OLD | NEW | 
|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/devtools/device/cast_device_provider.h" | 5 #include "chrome/browser/devtools/device/cast_device_provider.h" | 
| 6 | 6 | 
| 7 #include <map> | 7 #include <map> | 
| 8 #include <set> | 8 #include <set> | 
| 9 #include <string> | 9 #include <string> | 
| 10 #include <vector> | 10 #include <vector> | 
| 11 | 11 | 
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" | 
| 13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" | 
| 14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" | 
| 15 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" | 15 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" | 
| 16 #include "net/base/host_port_pair.h" | 16 #include "net/base/host_port_pair.h" | 
| 17 #include "net/base/ip_address.h" | 17 #include "net/base/ip_address_number.h" | 
| 18 | 18 | 
| 19 using local_discovery::ServiceDescription; | 19 using local_discovery::ServiceDescription; | 
| 20 using local_discovery::ServiceDiscoveryDeviceLister; | 20 using local_discovery::ServiceDiscoveryDeviceLister; | 
| 21 using local_discovery::ServiceDiscoverySharedClient; | 21 using local_discovery::ServiceDiscoverySharedClient; | 
| 22 | 22 | 
| 23 namespace { | 23 namespace { | 
| 24 | 24 | 
| 25 const int kCastInspectPort = 9222; | 25 const int kCastInspectPort = 9222; | 
| 26 const char kCastServiceType[] = "_googlecast._tcp.local"; | 26 const char kCastServiceType[] = "_googlecast._tcp.local"; | 
| 27 const char kUnknownCastDevice[] = "Unknown Cast Device"; | 27 const char kUnknownCastDevice[] = "Unknown Cast Device"; | 
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 170   tcp_provider_->OpenSocket(serial, socket_name, callback); | 170   tcp_provider_->OpenSocket(serial, socket_name, callback); | 
| 171 } | 171 } | 
| 172 | 172 | 
| 173 void CastDeviceProvider::OnDeviceChanged( | 173 void CastDeviceProvider::OnDeviceChanged( | 
| 174     bool added, | 174     bool added, | 
| 175     const ServiceDescription& service_description) { | 175     const ServiceDescription& service_description) { | 
| 176   VLOG(1) << "Device " << (added ? "added: " : "changed: ") | 176   VLOG(1) << "Device " << (added ? "added: " : "changed: ") | 
| 177           << service_description.service_name; | 177           << service_description.service_name; | 
| 178   if (service_description.service_type() != kCastServiceType) | 178   if (service_description.service_type() != kCastServiceType) | 
| 179     return; | 179     return; | 
| 180   const net::IPAddress& ip_address = service_description.ip_address; | 180   const net::IPAddressNumber& ip_address = service_description.ip_address; | 
| 181   if (!ip_address.IsValid()) { | 181   if (ip_address.size() != net::kIPv4AddressSize && | 
|  | 182       ip_address.size() != net::kIPv6AddressSize) { | 
| 182     // An invalid IP address is not queryable. | 183     // An invalid IP address is not queryable. | 
| 183     return; | 184     return; | 
| 184   } | 185   } | 
| 185   const std::string& name = service_description.service_name; | 186   const std::string& name = service_description.service_name; | 
| 186   std::string host = ip_address.ToString(); | 187   std::string host = net::IPAddressToString(ip_address); | 
| 187   service_hostname_map_[name] = host; | 188   service_hostname_map_[name] = host; | 
| 188   device_info_map_[host] = ServiceDescriptionToDeviceInfo(service_description); | 189   device_info_map_[host] = ServiceDescriptionToDeviceInfo(service_description); | 
| 189 } | 190 } | 
| 190 | 191 | 
| 191 void CastDeviceProvider::OnDeviceRemoved(const std::string& service_name) { | 192 void CastDeviceProvider::OnDeviceRemoved(const std::string& service_name) { | 
| 192   VLOG(1) << "Device removed: " << service_name; | 193   VLOG(1) << "Device removed: " << service_name; | 
| 193   auto it = service_hostname_map_.find(service_name); | 194   auto it = service_hostname_map_.find(service_name); | 
| 194   if (it == service_hostname_map_.end()) | 195   if (it == service_hostname_map_.end()) | 
| 195     return; | 196     return; | 
| 196   const std::string& hostname = it->second; | 197   const std::string& hostname = it->second; | 
| 197   device_info_map_.erase(hostname); | 198   device_info_map_.erase(hostname); | 
| 198   service_hostname_map_.erase(it); | 199   service_hostname_map_.erase(it); | 
| 199 } | 200 } | 
| 200 | 201 | 
| 201 void CastDeviceProvider::OnDeviceCacheFlushed() { | 202 void CastDeviceProvider::OnDeviceCacheFlushed() { | 
| 202   VLOG(1) << "Device cache flushed"; | 203   VLOG(1) << "Device cache flushed"; | 
| 203   service_hostname_map_.clear(); | 204   service_hostname_map_.clear(); | 
| 204   device_info_map_.clear(); | 205   device_info_map_.clear(); | 
| 205 } | 206 } | 
| OLD | NEW | 
|---|