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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: remoting/host/host_attributes.cc
diff --git a/remoting/host/host_attributes.cc b/remoting/host/host_attributes.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7b14fb306b8462e44abd3d198ddbecaddd2dcb2c
--- /dev/null
+++ b/remoting/host/host_attributes.cc
@@ -0,0 +1,77 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/host/host_attributes.h"
+
+#include "base/logging.h"
+#include "base/strings/string_piece.h"
+#include "remoting/host/directx_attributes.h"
+
+namespace remoting {
+
+namespace {
+static constexpr char kSeparator[] = ",";
+} // namespace
+
+HostAttributes::HostAttributes() {
+ RegisterDirectxAttributes();
+}
+
+HostAttributes::~HostAttributes() = default;
+HostAttributes::HostAttributes(HostAttributes&& other) = default;
+HostAttributes::HostAttributes(const HostAttributes& other) = default;
+HostAttributes& HostAttributes::operator=(HostAttributes&& other) = default;
+HostAttributes& HostAttributes::operator=(
+ const HostAttributes& other) = default;
+
+std::string HostAttributes::ToString() const {
+ std::string result;
+ for (const auto& str : static_values_) {
+ DCHECK(!str.empty());
+ if (!result.empty()) {
+ result.append(kSeparator);
+ }
+ result.append(str);
+ }
+
+ for (const auto& pair : dynamic_values_) {
+ DCHECK(!pair.first.empty());
+ DCHECK(!pair.second.is_null());
+ if (pair.second.Run()) {
+ if (!result.empty()) {
+ result.append(kSeparator);
+ }
+ result.append(pair.first);
+ }
+ }
+
+ return result;
+}
+
+void HostAttributes::Register(const std::string& key) {
+ DCHECK(key.find(kSeparator) == std::string::npos);
+ DCHECK(dynamic_values_.find(key) == dynamic_values_.end());
+ DCHECK(static_values_.find(key) == static_values_.end());
+ static_values_.insert(key);
+}
+
+void HostAttributes::Register(const std::string& key,
+ const base::Callback<bool()>& value) {
+ DCHECK(key.find(kSeparator) == std::string::npos);
+ DCHECK(dynamic_values_.find(key) == dynamic_values_.end());
+ DCHECK(static_values_.find(key) == static_values_.end());
+ dynamic_values_[key] = value;
+}
+
+// static
+bool HostAttributes::ContainsAttribute(const std::string& output,
+ const std::string& key) {
+ return output == key ||
+ base::StringPiece(output).ends_with(std::string(kSeparator) + key) ||
+ base::StringPiece(output).starts_with(key + kSeparator) ||
+ output.find(std::string(kSeparator) + key + kSeparator) !=
+ std::string::npos;
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698