Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / local_discovery / device_description.cc
blob8f4e3690294cee1079d76885b8baf51a7680288c
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
3 // found in the LICENSE file.
5 #include "chrome/browser/local_discovery/device_description.h"
7 #include <vector>
9 #include "base/strings/string_util.h"
10 #include "chrome/browser/local_discovery/privet_constants.h"
11 #include "chrome/common/local_discovery/service_discovery_client.h"
13 namespace local_discovery {
15 namespace {
17 DeviceDescription::ConnectionState
18 ConnectionStateFromString(const std::string& str) {
19 if (LowerCaseEqualsASCII(str, kPrivetConnectionStatusOnline)) {
20 return DeviceDescription::ONLINE;
21 } else if (LowerCaseEqualsASCII(str, kPrivetConnectionStatusOffline)) {
22 return DeviceDescription::OFFLINE;
23 } else if (LowerCaseEqualsASCII(str, kPrivetConnectionStatusConnecting)) {
24 return DeviceDescription::CONNECTING;
25 } else if (LowerCaseEqualsASCII(str, kPrivetConnectionStatusNotConfigured)) {
26 return DeviceDescription::NOT_CONFIGURED;
29 return DeviceDescription::UNKNOWN;
32 } // namespace
34 void DeviceDescription::FillFromServiceDescription(
35 const ServiceDescription& service_description) {
36 address = service_description.address;
37 ip_address = service_description.ip_address;
38 last_seen = service_description.last_seen;
40 for (std::vector<std::string>::const_iterator i =
41 service_description.metadata.begin();
42 i != service_description.metadata.end();
43 i++) {
44 size_t equals_pos = i->find_first_of('=');
45 if (equals_pos == std::string::npos)
46 continue; // We do not parse non key-value TXT records
48 std::string key = i->substr(0, equals_pos);
49 std::string value = i->substr(equals_pos + 1);
51 if (LowerCaseEqualsASCII(key, kPrivetTxtKeyName)) {
52 name = value;
53 } else if (LowerCaseEqualsASCII(key, kPrivetTxtKeyDescription)) {
54 description = value;
55 } else if (LowerCaseEqualsASCII(key, kPrivetTxtKeyURL)) {
56 url = value;
57 } else if (LowerCaseEqualsASCII(key, kPrivetTxtKeyType)) {
58 type = value;
59 } else if (LowerCaseEqualsASCII(key, kPrivetTxtKeyID)) {
60 id = value;
61 } else if (LowerCaseEqualsASCII(key, kPrivetTxtKeyConnectionState)) {
62 connection_state = ConnectionStateFromString(value);
68 } // namespace local_discovery