| OLD | NEW |
| (Empty) |
| 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 namespace api { | |
| 17 namespace dial { | |
| 18 | |
| 19 struct DialDevice; | |
| 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 | |
| 37 const std::string& device_id() const { return device_id_; } | |
| 38 void set_device_id(const std::string& id) { | |
| 39 device_id_ = id; | |
| 40 } | |
| 41 | |
| 42 const std::string& label() const { return label_; } | |
| 43 void set_label(const std::string& label) { | |
| 44 label_ = label; | |
| 45 } | |
| 46 | |
| 47 const GURL& device_description_url() const; | |
| 48 void set_device_description_url(const GURL& url); | |
| 49 | |
| 50 const base::Time& response_time() const { return response_time_; } | |
| 51 void set_response_time(const base::Time& response_time) { | |
| 52 response_time_ = response_time; | |
| 53 } | |
| 54 | |
| 55 int max_age() const { return max_age_; } | |
| 56 void set_max_age(int max_age) { max_age_ = max_age; } | |
| 57 bool has_max_age() const { return max_age_ >= 0; } | |
| 58 | |
| 59 int config_id() const { return config_id_; } | |
| 60 void set_config_id(int config_id) { config_id_ = config_id; } | |
| 61 bool has_config_id() const { return config_id_ >= 0; } | |
| 62 | |
| 63 // Fills the |device| API struct from this instance. | |
| 64 void FillDialDevice(api::dial::DialDevice* device) const; | |
| 65 | |
| 66 // Updates this DeviceData based on information from a new response in | |
| 67 // |new_data|. Returns |true| if a field was updated that is visible through | |
| 68 // the DIAL API. | |
| 69 bool UpdateFrom(const DialDeviceData& new_data); | |
| 70 | |
| 71 // Validates that the URL is valid for the device description. | |
| 72 static bool IsDeviceDescriptionUrl(const GURL& url); | |
| 73 | |
| 74 private: | |
| 75 // Hardware identifier from the DIAL response. Not exposed to API clients. | |
| 76 std::string device_id_; | |
| 77 | |
| 78 // Identifies this device to clients of the API as a proxy for the hardware | |
| 79 // identifier. Automatically generated by the DIAL registry. | |
| 80 std::string label_; | |
| 81 | |
| 82 // The device description URL. | |
| 83 GURL device_description_url_; | |
| 84 | |
| 85 // The time that the most recent response was received. | |
| 86 base::Time response_time_; | |
| 87 | |
| 88 // Optional (-1 means unset). | |
| 89 int max_age_; | |
| 90 | |
| 91 // Optional (-1 means unset). | |
| 92 int config_id_; | |
| 93 }; | |
| 94 | |
| 95 struct DialDeviceDescriptionData { | |
| 96 public: | |
| 97 DialDeviceDescriptionData() = default; | |
| 98 DialDeviceDescriptionData(const std::string& device_description, | |
| 99 const GURL& app_url); | |
| 100 | |
| 101 std::string device_description; | |
| 102 GURL app_url; | |
| 103 }; | |
| 104 | |
| 105 } // namespace dial | |
| 106 } // namespace api | |
| 107 } // namespace extensions | |
| 108 | |
| 109 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_DEVICE_DATA_H_ | |
| OLD | NEW |