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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_DEVICE_DATA_H_ 6 #define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_DEVICE_DATA_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/time/time.h" 12 #include "base/values.h" 13 #include "url/gurl.h" 14 15 namespace net { 16 class IPAddress; 17 } 18 19 namespace media_router { 20 21 // Dial device information that is used within the DialService and Registry on 22 // the IO thread. It is updated as new information arrives and a list of 23 // DialDeviceData is copied and sent to event listeners on the UI thread. 24 class DialDeviceData { 25 public: 26 DialDeviceData(); 27 DialDeviceData(const std::string& device_id, 28 const GURL& device_description_url, 29 const base::Time& response_time); 30 DialDeviceData(const DialDeviceData& other); 31 ~DialDeviceData(); 32 33 bool operator==(const DialDeviceData& other_data) const { 34 return device_id_ == other_data.device_id_; 35 } 36 device_id()37 const std::string& device_id() const { return device_id_; } set_device_id(const std::string & id)38 void set_device_id(const std::string& id) { device_id_ = id; } 39 label()40 const std::string& label() const { return label_; } set_label(const std::string & label)41 void set_label(const std::string& label) { label_ = label; } 42 43 const GURL& device_description_url() const; 44 void set_device_description_url(const GURL& url); 45 response_time()46 const base::Time& response_time() const { return response_time_; } set_response_time(const base::Time & response_time)47 void set_response_time(const base::Time& response_time) { 48 response_time_ = response_time; 49 } 50 max_age()51 int max_age() const { return max_age_; } set_max_age(int max_age)52 void set_max_age(int max_age) { max_age_ = max_age; } has_max_age()53 bool has_max_age() const { return max_age_ >= 0; } 54 config_id()55 int config_id() const { return config_id_; } set_config_id(int config_id)56 void set_config_id(int config_id) { config_id_ = config_id; } has_config_id()57 bool has_config_id() const { return config_id_ >= 0; } 58 59 // Updates this DeviceData based on information from a new response in 60 // |new_data|. Returns |true| if a field was updated that is visible through 61 // the DIAL API. 62 bool UpdateFrom(const DialDeviceData& new_data); 63 64 // Validates that the URL is valid for the device description. 65 static bool IsDeviceDescriptionUrl(const GURL& url); 66 67 // Returns true if |app_url| is a valid DIAL Application URL with a hostname 68 // matching |expected_ip_address|. 69 static bool IsValidDialAppUrl(const GURL& url, 70 const net::IPAddress& expected_ip_address); 71 72 private: 73 // Hardware identifier from the DIAL response. Not exposed to API clients. 74 std::string device_id_; 75 76 // Identifies this device to clients of the API as a proxy for the hardware 77 // identifier. Automatically generated by the DIAL registry. 78 std::string label_; 79 80 // The device description URL. 81 GURL device_description_url_; 82 83 // The time that the most recent response was received. 84 base::Time response_time_; 85 86 // Optional (-1 means unset). 87 int max_age_; 88 89 // Optional (-1 means unset). 90 int config_id_; 91 }; 92 93 // TODO(mfoltz): Do we need this as well as ParsedDialDeviceDescriptionData? 94 struct DialDeviceDescriptionData { 95 public: 96 DialDeviceDescriptionData() = default; 97 DialDeviceDescriptionData(const std::string& device_description, 98 const GURL& app_url); 99 ~DialDeviceDescriptionData() = default; 100 101 bool operator==(const DialDeviceDescriptionData& other_data) const; 102 103 std::string device_description; 104 GURL app_url; 105 }; 106 107 } // namespace media_router 108 109 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_DEVICE_DATA_H_ 110