| 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_number.h" | 17 #include "net/base/ip_address.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::IPAddressNumber& ip_address = service_description.ip_address; | 180 const net::IPAddress& ip_address = service_description.ip_address; |
| 181 if (ip_address.size() != net::kIPv4AddressSize && | 181 if (!ip_address.IsValid()) { |
| 182 ip_address.size() != net::kIPv6AddressSize) { | |
| 183 // An invalid IP address is not queryable. | 182 // An invalid IP address is not queryable. |
| 184 return; | 183 return; |
| 185 } | 184 } |
| 186 const std::string& name = service_description.service_name; | 185 const std::string& name = service_description.service_name; |
| 187 std::string host = net::IPAddressToString(ip_address); | 186 std::string host = ip_address.ToString(); |
| 188 service_hostname_map_[name] = host; | 187 service_hostname_map_[name] = host; |
| 189 device_info_map_[host] = ServiceDescriptionToDeviceInfo(service_description); | 188 device_info_map_[host] = ServiceDescriptionToDeviceInfo(service_description); |
| 190 } | 189 } |
| 191 | 190 |
| 192 void CastDeviceProvider::OnDeviceRemoved(const std::string& service_name) { | 191 void CastDeviceProvider::OnDeviceRemoved(const std::string& service_name) { |
| 193 VLOG(1) << "Device removed: " << service_name; | 192 VLOG(1) << "Device removed: " << service_name; |
| 194 auto it = service_hostname_map_.find(service_name); | 193 auto it = service_hostname_map_.find(service_name); |
| 195 if (it == service_hostname_map_.end()) | 194 if (it == service_hostname_map_.end()) |
| 196 return; | 195 return; |
| 197 const std::string& hostname = it->second; | 196 const std::string& hostname = it->second; |
| 198 device_info_map_.erase(hostname); | 197 device_info_map_.erase(hostname); |
| 199 service_hostname_map_.erase(it); | 198 service_hostname_map_.erase(it); |
| 200 } | 199 } |
| 201 | 200 |
| 202 void CastDeviceProvider::OnDeviceCacheFlushed() { | 201 void CastDeviceProvider::OnDeviceCacheFlushed() { |
| 203 VLOG(1) << "Device cache flushed"; | 202 VLOG(1) << "Device cache flushed"; |
| 204 service_hostname_map_.clear(); | 203 service_hostname_map_.clear(); |
| 205 device_info_map_.clear(); | 204 device_info_map_.clear(); |
| 206 } | 205 } |
| OLD | NEW |