| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/local_discovery/device_description.h" | 5 #include "chrome/browser/local_discovery/device_description.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "chrome/browser/local_discovery/privet_constants.h" | 11 #include "chrome/browser/local_discovery/privet_constants.h" |
| 12 #include "chrome/common/local_discovery/service_discovery_client.h" | 12 #include "chrome/common/local_discovery/service_discovery_client.h" |
| 13 | 13 |
| 14 namespace local_discovery { | 14 namespace local_discovery { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 DeviceDescription::ConnectionState | 18 DeviceDescription::ConnectionState |
| 19 ConnectionStateFromString(const std::string& str) { | 19 ConnectionStateFromString(const std::string& str) { |
| 20 if (LowerCaseEqualsASCII(str, kPrivetConnectionStatusOnline)) { | 20 if (base::LowerCaseEqualsASCII(str, kPrivetConnectionStatusOnline)) { |
| 21 return DeviceDescription::ONLINE; | 21 return DeviceDescription::ONLINE; |
| 22 } else if (LowerCaseEqualsASCII(str, kPrivetConnectionStatusOffline)) { | 22 } else if (base::LowerCaseEqualsASCII(str, kPrivetConnectionStatusOffline)) { |
| 23 return DeviceDescription::OFFLINE; | 23 return DeviceDescription::OFFLINE; |
| 24 } else if (LowerCaseEqualsASCII(str, kPrivetConnectionStatusConnecting)) { | 24 } else if (base::LowerCaseEqualsASCII(str, |
| 25 kPrivetConnectionStatusConnecting)) { |
| 25 return DeviceDescription::CONNECTING; | 26 return DeviceDescription::CONNECTING; |
| 26 } else if (LowerCaseEqualsASCII(str, kPrivetConnectionStatusNotConfigured)) { | 27 } else if (base::LowerCaseEqualsASCII(str, |
| 28 kPrivetConnectionStatusNotConfigured)) { |
| 27 return DeviceDescription::NOT_CONFIGURED; | 29 return DeviceDescription::NOT_CONFIGURED; |
| 28 } | 30 } |
| 29 | 31 |
| 30 return DeviceDescription::UNKNOWN; | 32 return DeviceDescription::UNKNOWN; |
| 31 } | 33 } |
| 32 | 34 |
| 33 } // namespace | 35 } // namespace |
| 34 | 36 |
| 35 DeviceDescription::DeviceDescription() | 37 DeviceDescription::DeviceDescription() |
| 36 : version(0), | 38 : version(0), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 50 service_description.metadata.begin(); | 52 service_description.metadata.begin(); |
| 51 i != service_description.metadata.end(); | 53 i != service_description.metadata.end(); |
| 52 i++) { | 54 i++) { |
| 53 size_t equals_pos = i->find_first_of('='); | 55 size_t equals_pos = i->find_first_of('='); |
| 54 if (equals_pos == std::string::npos) | 56 if (equals_pos == std::string::npos) |
| 55 continue; // We do not parse non key-value TXT records | 57 continue; // We do not parse non key-value TXT records |
| 56 | 58 |
| 57 std::string key = i->substr(0, equals_pos); | 59 std::string key = i->substr(0, equals_pos); |
| 58 std::string value = i->substr(equals_pos + 1); | 60 std::string value = i->substr(equals_pos + 1); |
| 59 | 61 |
| 60 if (LowerCaseEqualsASCII(key, kPrivetTxtKeyVersion)) { | 62 if (base::LowerCaseEqualsASCII(key, kPrivetTxtKeyVersion)) { |
| 61 if (!base::StringToInt(value, &version)) | 63 if (!base::StringToInt(value, &version)) |
| 62 continue; // Unknown version. | 64 continue; // Unknown version. |
| 63 } else if (LowerCaseEqualsASCII(key, kPrivetTxtKeyName)) { | 65 } else if (base::LowerCaseEqualsASCII(key, kPrivetTxtKeyName)) { |
| 64 name = value; | 66 name = value; |
| 65 } else if (LowerCaseEqualsASCII(key, kPrivetTxtKeyDescription)) { | 67 } else if (base::LowerCaseEqualsASCII(key, kPrivetTxtKeyDescription)) { |
| 66 description = value; | 68 description = value; |
| 67 } else if (LowerCaseEqualsASCII(key, kPrivetTxtKeyURL)) { | 69 } else if (base::LowerCaseEqualsASCII(key, kPrivetTxtKeyURL)) { |
| 68 url = value; | 70 url = value; |
| 69 } else if (LowerCaseEqualsASCII(key, kPrivetTxtKeyType)) { | 71 } else if (base::LowerCaseEqualsASCII(key, kPrivetTxtKeyType)) { |
| 70 type = value; | 72 type = value; |
| 71 } else if (LowerCaseEqualsASCII(key, kPrivetTxtKeyID)) { | 73 } else if (base::LowerCaseEqualsASCII(key, kPrivetTxtKeyID)) { |
| 72 id = value; | 74 id = value; |
| 73 } else if (LowerCaseEqualsASCII(key, kPrivetTxtKeyConnectionState)) { | 75 } else if (base::LowerCaseEqualsASCII(key, kPrivetTxtKeyConnectionState)) { |
| 74 connection_state = ConnectionStateFromString(value); | 76 connection_state = ConnectionStateFromString(value); |
| 75 } | 77 } |
| 76 } | 78 } |
| 77 } | 79 } |
| 78 | 80 |
| 79 | 81 |
| 80 } // namespace local_discovery | 82 } // namespace local_discovery |
| OLD | NEW |