Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: chrome/browser/devtools/device/cast_device_provider.cc

Issue 1534583002: Migrate Local Discovery from net::IPAddressNumber to net::IPAddress. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "net/base/host_port_pair.h" 15 #include "net/base/host_port_pair.h"
16 #include "net/base/ip_address_number.h" 16 #include "net/base/ip_address.h"
17 17
18 using local_discovery::ServiceDiscoverySharedClient; 18 using local_discovery::ServiceDiscoverySharedClient;
19 19
20 namespace { 20 namespace {
21 21
22 const int kCastInspectPort = 9222; 22 const int kCastInspectPort = 9222;
23 const char kCastServiceType[] = "_googlecast._tcp.local"; 23 const char kCastServiceType[] = "_googlecast._tcp.local";
24 const char kUnknownCastDevice[] = "Unknown Cast Device"; 24 const char kUnknownCastDevice[] = "Unknown Cast Device";
25 25
26 typedef std::map<std::string, std::string> ServiceTxtRecordMap; 26 typedef std::map<std::string, std::string> ServiceTxtRecordMap;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 tcp_provider_->OpenSocket(serial, socket_name, callback); 164 tcp_provider_->OpenSocket(serial, socket_name, callback);
165 } 165 }
166 166
167 void CastDeviceProvider::OnDeviceChanged( 167 void CastDeviceProvider::OnDeviceChanged(
168 bool added, 168 bool added,
169 const ServiceDescription& service_description) { 169 const ServiceDescription& service_description) {
170 VLOG(1) << "Device " << (added ? "added: " : "changed: ") 170 VLOG(1) << "Device " << (added ? "added: " : "changed: ")
171 << service_description.service_name; 171 << service_description.service_name;
172 if (service_description.service_type() != kCastServiceType) 172 if (service_description.service_type() != kCastServiceType)
173 return; 173 return;
174 net::IPAddressNumber ip_address = service_description.ip_address; 174 net::IPAddress ip_address = service_description.ip_address;
175 if (ip_address.size() != net::kIPv4AddressSize && 175 if (!ip_address.IsIPv4() && !ip_address.IsIPv6()) {
palmer 2015/12/22 01:09:10 An IsValid (or is_valid) member function might mak
martijnc 2016/01/27 22:50:52 Done.
176 ip_address.size() != net::kIPv6AddressSize) {
177 // An invalid IP address is not queryable. 176 // An invalid IP address is not queryable.
178 return; 177 return;
179 } 178 }
180 std::string name = service_description.service_name; 179 std::string name = service_description.service_name;
181 std::string host = net::IPAddressToString(ip_address); 180 std::string host = ip_address.ToString();
182 service_hostname_map_[name] = host; 181 service_hostname_map_[name] = host;
183 device_info_map_[host] = ServiceDescriptionToDeviceInfo(service_description); 182 device_info_map_[host] = ServiceDescriptionToDeviceInfo(service_description);
184 } 183 }
185 184
186 void CastDeviceProvider::OnDeviceRemoved(const std::string& service_name) { 185 void CastDeviceProvider::OnDeviceRemoved(const std::string& service_name) {
187 VLOG(1) << "Device removed: " << service_name; 186 VLOG(1) << "Device removed: " << service_name;
188 auto it_hostname = service_hostname_map_.find(service_name); 187 auto it_hostname = service_hostname_map_.find(service_name);
189 if (it_hostname == service_hostname_map_.end()) 188 if (it_hostname == service_hostname_map_.end())
190 return; 189 return;
191 std::string hostname = it_hostname->second; 190 std::string hostname = it_hostname->second;
192 service_hostname_map_.erase(it_hostname); 191 service_hostname_map_.erase(it_hostname);
193 auto it_device = device_info_map_.find(hostname); 192 auto it_device = device_info_map_.find(hostname);
194 if (it_device == device_info_map_.end()) 193 if (it_device == device_info_map_.end())
195 return; 194 return;
196 device_info_map_.erase(it_device); 195 device_info_map_.erase(it_device);
197 } 196 }
198 197
199 void CastDeviceProvider::OnDeviceCacheFlushed() { 198 void CastDeviceProvider::OnDeviceCacheFlushed() {
200 VLOG(1) << "Device cache flushed"; 199 VLOG(1) << "Device cache flushed";
201 service_hostname_map_.clear(); 200 service_hostname_map_.clear();
202 device_info_map_.clear(); 201 device_info_map_.clear();
203 } 202 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698