| 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/extensions/api/dial/dial_device_data.h" | 5 #include "chrome/browser/media/router/discovery/dial/dial_device_data.h" |
| 6 | 6 |
| 7 #include "chrome/common/extensions/api/dial.h" | 7 namespace media_router { |
| 8 | 8 |
| 9 namespace extensions { | 9 DialDeviceData::DialDeviceData() : max_age_(-1), config_id_(-1) {} |
| 10 namespace api { | |
| 11 namespace dial { | |
| 12 | |
| 13 DialDeviceData::DialDeviceData() : max_age_(-1), config_id_(-1) { } | |
| 14 | 10 |
| 15 DialDeviceData::DialDeviceData(const std::string& device_id, | 11 DialDeviceData::DialDeviceData(const std::string& device_id, |
| 16 const GURL& device_description_url, | 12 const GURL& device_description_url, |
| 17 const base::Time& response_time) | 13 const base::Time& response_time) |
| 18 : device_id_(device_id), device_description_url_(device_description_url), | 14 : device_id_(device_id), |
| 19 response_time_(response_time), max_age_(-1), config_id_(-1) { | 15 device_description_url_(device_description_url), |
| 20 } | 16 response_time_(response_time), |
| 17 max_age_(-1), |
| 18 config_id_(-1) {} |
| 21 | 19 |
| 22 DialDeviceData::DialDeviceData(const DialDeviceData& other) = default; | 20 DialDeviceData::DialDeviceData(const DialDeviceData& other) = default; |
| 23 | 21 |
| 24 DialDeviceData::~DialDeviceData() { } | 22 DialDeviceData::~DialDeviceData() {} |
| 25 | 23 |
| 26 const GURL& DialDeviceData::device_description_url() const { | 24 const GURL& DialDeviceData::device_description_url() const { |
| 27 return device_description_url_; | 25 return device_description_url_; |
| 28 } | 26 } |
| 29 | 27 |
| 30 void DialDeviceData::set_device_description_url(const GURL& url) { | 28 void DialDeviceData::set_device_description_url(const GURL& url) { |
| 31 device_description_url_ = url; | 29 device_description_url_ = url; |
| 32 } | 30 } |
| 33 | 31 |
| 34 // static | 32 // static |
| 35 bool DialDeviceData::IsDeviceDescriptionUrl(const GURL& url) { | 33 bool DialDeviceData::IsDeviceDescriptionUrl(const GURL& url) { |
| 36 return url.is_valid() && !url.is_empty() && url.SchemeIsHTTPOrHTTPS(); | 34 return url.is_valid() && !url.is_empty() && url.SchemeIsHTTPOrHTTPS(); |
| 37 } | 35 } |
| 38 | 36 |
| 39 bool DialDeviceData::UpdateFrom(const DialDeviceData& new_data) { | 37 bool DialDeviceData::UpdateFrom(const DialDeviceData& new_data) { |
| 40 DCHECK(new_data.device_id() == device_id_); | 38 DCHECK(new_data.device_id() == device_id_); |
| 41 DCHECK(new_data.label().empty()); | 39 DCHECK(new_data.label().empty()); |
| 42 std::string label_tmp(label_); | 40 std::string label_tmp(label_); |
| 43 bool updated_api_visible_field = | 41 bool updated_api_visible_field = |
| 44 (new_data.device_description_url() != device_description_url_) || | 42 (new_data.device_description_url() != device_description_url_) || |
| 45 (new_data.config_id() != config_id_); | 43 (new_data.config_id() != config_id_); |
| 46 *this = new_data; | 44 *this = new_data; |
| 47 label_ = label_tmp; | 45 label_ = label_tmp; |
| 48 return updated_api_visible_field; | 46 return updated_api_visible_field; |
| 49 } | 47 } |
| 50 | 48 |
| 51 void DialDeviceData::FillDialDevice(api::dial::DialDevice* device) const { | |
| 52 DCHECK(!device_id_.empty()); | |
| 53 DCHECK(IsDeviceDescriptionUrl(device_description_url_)); | |
| 54 device->device_label = label_; | |
| 55 device->device_description_url = device_description_url_.spec(); | |
| 56 if (has_config_id()) | |
| 57 device->config_id.reset(new int(config_id_)); | |
| 58 } | |
| 59 | |
| 60 DialDeviceDescriptionData::DialDeviceDescriptionData( | 49 DialDeviceDescriptionData::DialDeviceDescriptionData( |
| 61 const std::string& device_description, | 50 const std::string& device_description, |
| 62 const GURL& app_url) | 51 const GURL& app_url) |
| 63 : device_description(device_description), app_url(app_url) {} | 52 : device_description(device_description), app_url(app_url) {} |
| 64 | 53 |
| 65 } // namespace dial | 54 } // namespace media_router |
| 66 } // namespace api | |
| 67 } // namespace extensions | |
| OLD | NEW |