Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / browser / local_discovery / device_description.cc
blob71e748dbcc1a98c205027e4ea0b14276ef508516
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_number_conversions.h"
10 #include "base/strings/string_util.h"
11 #include "chrome/browser/local_discovery/privet_constants.h"
12 #include "chrome/common/local_discovery/service_discovery_client.h"
14 namespace local_discovery {
16 namespace {
18 std::string GetValueByName(const std::vector<std::string>& metadata,
19 const std::string& name) {
20 std::string prefix(name + "=");
21 for (const std::string& record : metadata) {
22 if (StartsWithASCII(record, prefix, false)) {
23 return record.substr(prefix.size());
26 return std::string();
29 } // namespace
31 DeviceDescription::DeviceDescription() : version(0) {
34 DeviceDescription::DeviceDescription(
35 const ServiceDescription& service_description) {
36 address = service_description.address;
38 const std::vector<std::string>& metadata = service_description.metadata;
39 if (!base::StringToInt(GetValueByName(metadata, kPrivetTxtKeyVersion),
40 &version)) {
41 version = 0;
43 name = GetValueByName(metadata, kPrivetTxtKeyName);
44 description = GetValueByName(metadata, kPrivetTxtKeyDescription);
45 if (version >= 3) {
46 type = GetValueByName(metadata, kPrivetTxtKeyDevicesClass);
47 id = GetValueByName(metadata, kPrivetTxtKeyGcdID);
48 } else {
49 type = GetValueByName(metadata, kPrivetTxtKeyType);
50 id = GetValueByName(metadata, kPrivetTxtKeyID);
54 DeviceDescription::~DeviceDescription() {
57 } // namespace local_discovery