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_EXTENSIONS_API_DIAL_DIAL_DEVICE_DATA_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_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 extensions { 16 17 namespace api { 18 namespace dial { 19 struct DialDevice; 20 } // namespace api 21 } // namespace dial 22 23 // Dial device information that is used within the DialService and Registry on 24 // the IO thread. It is updated as new information arrives and a list of 25 // DialDeviceData is copied and sent to event listeners on the UI thread. 26 class DialDeviceData { 27 public: 28 DialDeviceData(); 29 DialDeviceData(const std::string& device_id, 30 const GURL& device_description_url, 31 const base::Time& response_time); 32 ~DialDeviceData(); 33 34 bool operator==(const DialDeviceData& other_data) const { 35 return device_id_ == other_data.device_id_; 36 } 37 38 const std::string& device_id() const { return device_id_; } 39 void set_device_id(const std::string& id) { 40 device_id_ = id; 41 } 42 43 const std::string& label() const { return label_; } 44 void set_label(const std::string& label) { 45 label_ = label; 46 } 47 48 const GURL& device_description_url() const; 49 void set_device_description_url(const GURL& url); 50 51 const base::Time& response_time() const { return response_time_; } 52 void set_response_time(const base::Time& response_time) { 53 response_time_ = response_time; 54 } 55 56 int max_age() const { return max_age_; } 57 void set_max_age(int max_age) { max_age_ = max_age; } 58 bool has_max_age() const { return max_age_ >= 0; } 59 60 int config_id() const { return config_id_; } 61 void set_config_id(int config_id) { config_id_ = config_id; } 62 bool has_config_id() const { return config_id_ >= 0; } 63 64 // Fills the |device| API struct from this instance. 65 void FillDialDevice(api::dial::DialDevice* device) const; 66 67 // Updates this DeviceData based on information from a new response in 68 // |new_data|. Returns |true| if a field was updated that is visible through 69 // the DIAL API. 70 bool UpdateFrom(const DialDeviceData& new_data); 71 72 // Validates that the URL is valid for the device description. 73 static bool IsDeviceDescriptionUrl(const GURL& url); 74 75 private: 76 // Hardware identifier from the DIAL response. Not exposed to API clients. 77 std::string device_id_; 78 79 // Identifies this device to clients of the API as a proxy for the hardware 80 // identifier. Automatically generated by the DIAL registry. 81 std::string label_; 82 83 // The device description URL. 84 GURL device_description_url_; 85 86 // The time that the most recent response was received. 87 base::Time response_time_; 88 89 // Optional (-1 means unset). 90 int max_age_; 91 92 // Optional (-1 means unset). 93 int config_id_; 94 }; 95 96 } // namespace extensions 97 98 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_DEVICE_DATA_H_ 99