| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/media/router/discovery/dial/dial_device_data.h" | 5 #include "chrome/browser/media/router/discovery/dial/dial_device_data.h" |
| 6 #include "net/base/ip_address.h" |
| 6 | 7 |
| 7 namespace media_router { | 8 namespace media_router { |
| 8 | 9 |
| 9 DialDeviceData::DialDeviceData() : max_age_(-1), config_id_(-1) {} | 10 DialDeviceData::DialDeviceData() : max_age_(-1), config_id_(-1) {} |
| 10 | 11 |
| 11 DialDeviceData::DialDeviceData(const std::string& device_id, | 12 DialDeviceData::DialDeviceData(const std::string& device_id, |
| 12 const GURL& device_description_url, | 13 const GURL& device_description_url, |
| 13 const base::Time& response_time) | 14 const base::Time& response_time) |
| 14 : device_id_(device_id), | 15 : device_id_(device_id), |
| 15 device_description_url_(device_description_url), | 16 device_description_url_(device_description_url), |
| 16 response_time_(response_time), | 17 response_time_(response_time), |
| 17 max_age_(-1), | 18 max_age_(-1), |
| 18 config_id_(-1) {} | 19 config_id_(-1) {} |
| 19 | 20 |
| 20 DialDeviceData::DialDeviceData(const DialDeviceData& other) = default; | 21 DialDeviceData::DialDeviceData(const DialDeviceData& other) = default; |
| 21 | 22 |
| 22 DialDeviceData::~DialDeviceData() {} | 23 DialDeviceData::~DialDeviceData() {} |
| 23 | 24 |
| 24 const GURL& DialDeviceData::device_description_url() const { | 25 const GURL& DialDeviceData::device_description_url() const { |
| 25 return device_description_url_; | 26 return device_description_url_; |
| 26 } | 27 } |
| 27 | 28 |
| 28 void DialDeviceData::set_device_description_url(const GURL& url) { | 29 void DialDeviceData::set_device_description_url(const GURL& url) { |
| 29 device_description_url_ = url; | 30 device_description_url_ = url; |
| 30 } | 31 } |
| 31 | 32 |
| 32 // static | 33 // static |
| 33 bool DialDeviceData::IsDeviceDescriptionUrl(const GURL& url) { | 34 bool DialDeviceData::IsDeviceDescriptionUrl(const GURL& url) { |
| 34 return url.is_valid() && !url.is_empty() && url.SchemeIsHTTPOrHTTPS(); | 35 if (!url.is_valid() || url.is_empty() || !url.SchemeIsHTTPOrHTTPS()) |
| 36 return false; |
| 37 |
| 38 net::IPAddress address; |
| 39 if (!net::ParseURLHostnameToAddress(url.host(), &address)) |
| 40 return false; |
| 41 |
| 42 // TODO(crbug.com/679432): check that this IP address matches the address that |
| 43 // we received the SSDP advertisement from. |
| 44 return address.IsReserved(); |
| 35 } | 45 } |
| 36 | 46 |
| 37 bool DialDeviceData::UpdateFrom(const DialDeviceData& new_data) { | 47 bool DialDeviceData::UpdateFrom(const DialDeviceData& new_data) { |
| 38 DCHECK(new_data.device_id() == device_id_); | 48 DCHECK(new_data.device_id() == device_id_); |
| 39 DCHECK(new_data.label().empty()); | 49 DCHECK(new_data.label().empty()); |
| 40 std::string label_tmp(label_); | 50 std::string label_tmp(label_); |
| 41 bool updated_api_visible_field = | 51 bool updated_api_visible_field = |
| 42 (new_data.device_description_url() != device_description_url_) || | 52 (new_data.device_description_url() != device_description_url_) || |
| 43 (new_data.config_id() != config_id_); | 53 (new_data.config_id() != config_id_); |
| 44 *this = new_data; | 54 *this = new_data; |
| 45 label_ = label_tmp; | 55 label_ = label_tmp; |
| 46 return updated_api_visible_field; | 56 return updated_api_visible_field; |
| 47 } | 57 } |
| 48 | 58 |
| 49 DialDeviceDescriptionData::DialDeviceDescriptionData( | 59 DialDeviceDescriptionData::DialDeviceDescriptionData( |
| 50 const std::string& device_description, | 60 const std::string& device_description, |
| 51 const GURL& app_url) | 61 const GURL& app_url) |
| 52 : device_description(device_description), app_url(app_url) {} | 62 : device_description(device_description), app_url(app_url) {} |
| 53 | 63 |
| 54 } // namespace media_router | 64 } // namespace media_router |
| OLD | NEW |