| Index: chrome/browser/local_discovery/device_description.cc
|
| diff --git a/chrome/browser/local_discovery/device_description.cc b/chrome/browser/local_discovery/device_description.cc
|
| index d2faed066544d1082ff9f8a6ed47ad6924906e76..71e748dbcc1a98c205027e4ea0b14276ef508516 100644
|
| --- a/chrome/browser/local_discovery/device_description.cc
|
| +++ b/chrome/browser/local_discovery/device_description.cc
|
| @@ -15,66 +15,43 @@ namespace local_discovery {
|
|
|
| namespace {
|
|
|
| -DeviceDescription::ConnectionState
|
| -ConnectionStateFromString(const std::string& str) {
|
| - if (LowerCaseEqualsASCII(str, kPrivetConnectionStatusOnline)) {
|
| - return DeviceDescription::ONLINE;
|
| - } else if (LowerCaseEqualsASCII(str, kPrivetConnectionStatusOffline)) {
|
| - return DeviceDescription::OFFLINE;
|
| - } else if (LowerCaseEqualsASCII(str, kPrivetConnectionStatusConnecting)) {
|
| - return DeviceDescription::CONNECTING;
|
| - } else if (LowerCaseEqualsASCII(str, kPrivetConnectionStatusNotConfigured)) {
|
| - return DeviceDescription::NOT_CONFIGURED;
|
| +std::string GetValueByName(const std::vector<std::string>& metadata,
|
| + const std::string& name) {
|
| + std::string prefix(name + "=");
|
| + for (const std::string& record : metadata) {
|
| + if (StartsWithASCII(record, prefix, false)) {
|
| + return record.substr(prefix.size());
|
| + }
|
| }
|
| -
|
| - return DeviceDescription::UNKNOWN;
|
| + return std::string();
|
| }
|
|
|
| } // namespace
|
|
|
| -DeviceDescription::DeviceDescription()
|
| - : version(0),
|
| - connection_state(UNKNOWN) {
|
| -}
|
| -
|
| -DeviceDescription::~DeviceDescription() {
|
| +DeviceDescription::DeviceDescription() : version(0) {
|
| }
|
|
|
| -void DeviceDescription::FillFromServiceDescription(
|
| +DeviceDescription::DeviceDescription(
|
| const ServiceDescription& service_description) {
|
| address = service_description.address;
|
| - ip_address = service_description.ip_address;
|
| - last_seen = service_description.last_seen;
|
| -
|
| - for (std::vector<std::string>::const_iterator i =
|
| - service_description.metadata.begin();
|
| - i != service_description.metadata.end();
|
| - i++) {
|
| - size_t equals_pos = i->find_first_of('=');
|
| - if (equals_pos == std::string::npos)
|
| - continue; // We do not parse non key-value TXT records
|
|
|
| - std::string key = i->substr(0, equals_pos);
|
| - std::string value = i->substr(equals_pos + 1);
|
| -
|
| - if (LowerCaseEqualsASCII(key, kPrivetTxtKeyVersion)) {
|
| - if (!base::StringToInt(value, &version))
|
| - continue; // Unknown version.
|
| - } else if (LowerCaseEqualsASCII(key, kPrivetTxtKeyName)) {
|
| - name = value;
|
| - } else if (LowerCaseEqualsASCII(key, kPrivetTxtKeyDescription)) {
|
| - description = value;
|
| - } else if (LowerCaseEqualsASCII(key, kPrivetTxtKeyURL)) {
|
| - url = value;
|
| - } else if (LowerCaseEqualsASCII(key, kPrivetTxtKeyType)) {
|
| - type = value;
|
| - } else if (LowerCaseEqualsASCII(key, kPrivetTxtKeyID)) {
|
| - id = value;
|
| - } else if (LowerCaseEqualsASCII(key, kPrivetTxtKeyConnectionState)) {
|
| - connection_state = ConnectionStateFromString(value);
|
| - }
|
| + const std::vector<std::string>& metadata = service_description.metadata;
|
| + if (!base::StringToInt(GetValueByName(metadata, kPrivetTxtKeyVersion),
|
| + &version)) {
|
| + version = 0;
|
| + }
|
| + name = GetValueByName(metadata, kPrivetTxtKeyName);
|
| + description = GetValueByName(metadata, kPrivetTxtKeyDescription);
|
| + if (version >= 3) {
|
| + type = GetValueByName(metadata, kPrivetTxtKeyDevicesClass);
|
| + id = GetValueByName(metadata, kPrivetTxtKeyGcdID);
|
| + } else {
|
| + type = GetValueByName(metadata, kPrivetTxtKeyType);
|
| + id = GetValueByName(metadata, kPrivetTxtKeyID);
|
| }
|
| }
|
|
|
| +DeviceDescription::~DeviceDescription() {
|
| +}
|
|
|
| } // namespace local_discovery
|
|
|