Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: remoting/host/host_attributes.cc

Issue 2464293002: [Chromoting] GetHostAttributes with tests (Closed)
Patch Set: Resolve review comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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 #include "remoting/host/host_attributes.h"
6
7 #include "base/logging.h"
8 #include "base/strings/string_piece.h"
9 #include "remoting/host/directx_attributes.h"
10
11 namespace remoting {
12
13 namespace {
14 static constexpr char kSeparator[] = ",";
15 } // namespace
16
17 HostAttributes::HostAttributes() {
18 RegisterDirectxAttributes();
19 }
20
21 HostAttributes::~HostAttributes() = default;
22 HostAttributes::HostAttributes(HostAttributes&& other) = default;
23 HostAttributes::HostAttributes(const HostAttributes& other) = default;
24 HostAttributes& HostAttributes::operator=(HostAttributes&& other) = default;
25 HostAttributes& HostAttributes::operator=(
26 const HostAttributes& other) = default;
27
28 std::string HostAttributes::ToString() const {
29 std::string result;
30 for (const auto& str : static_values_) {
31 DCHECK(!str.empty());
32 if (!result.empty()) {
33 result.append(kSeparator);
34 }
35 result.append(str);
36 }
37
38 for (const auto& pair : dynamic_values_) {
39 DCHECK(!pair.first.empty());
40 DCHECK(!pair.second.is_null());
41 if (pair.second.Run()) {
42 if (!result.empty()) {
43 result.append(kSeparator);
44 }
45 result.append(pair.first);
46 }
47 }
48
49 return result;
50 }
51
52 void HostAttributes::Register(const std::string& key) {
53 DCHECK(key.find(kSeparator) == std::string::npos);
54 DCHECK(dynamic_values_.find(key) == dynamic_values_.end());
55 DCHECK(static_values_.find(key) == static_values_.end());
56 static_values_.insert(key);
57 }
58
59 void HostAttributes::Register(const std::string& key,
60 const base::Callback<bool()>& value) {
61 DCHECK(key.find(kSeparator) == std::string::npos);
62 DCHECK(dynamic_values_.find(key) == dynamic_values_.end());
63 DCHECK(static_values_.find(key) == static_values_.end());
64 dynamic_values_[key] = value;
65 }
66
67 // static
68 bool HostAttributes::ContainsAttribute(const std::string& output,
69 const std::string& key) {
70 return output == key ||
71 base::StringPiece(output).ends_with(std::string(kSeparator) + key) ||
72 base::StringPiece(output).starts_with(key + kSeparator) ||
73 output.find(std::string(kSeparator) + key + kSeparator) !=
74 std::string::npos;
75 }
76
77 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698