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

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
« no previous file with comments | « remoting/host/host_attributes.h ('k') | remoting/host/host_attributes_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <type_traits>
8
9 #include "base/atomicops.h"
10 #include "base/logging.h"
11 #include "base/macros.h"
12 #include "build/build_config.h"
13
14 #if defined(OS_WIN)
15 #include "third_party/webrtc/modules/desktop_capture/win/screen_capturer_win_dir ectx.h"
16 #endif
17
18 namespace remoting {
19
20 namespace {
21 static constexpr char kSeparator[] = ",";
22
23 struct Attribute {
24 const char* name;
25 bool(* get_value_func)();
26 };
27
28 inline constexpr bool IsDebug() {
29 #if defined(NDEBUG)
30 return false;
31 #else
32 return true;
33 #endif
34 }
35
36 // By using arraysize() macro in base/macros.h, it's illegal to have empty
37 // arrays.
38 //
39 // error: no matching function for call to 'ArraySizeHelper'
40 // note: candidate template ignored: substitution failure
41 // [with T = const remoting::StaticAttribute, N = 0]:
42 // zero-length arrays are not permitted in C++.
43 //
44 // So we need IsDebug() function, and "Debug-Build" Attribute.
45
46 static constexpr Attribute kAttributes[] = {
47 { "Debug-Build", &IsDebug },
48 #if defined(OS_WIN)
49 { "DirectX-Capturer", &webrtc::ScreenCapturerWinDirectx::IsSupported },
50 // TODO(zijiehe): Add DirectX version attributes. Blocked by change
51 // https://codereview.chromium.org/2468083002/.
52 #endif
53 };
54
55 } // namespace
56
57 static_assert(std::is_pod<Attribute>::value, "Attribute should be POD.");
58
59 std::string GetHostAttributes() {
60 std::string result;
61 // By using ranged for-loop, MSVC throws error C3316:
62 // 'const remoting::StaticAttribute [0]':
63 // an array of unknown size cannot be used in a range-based for statement.
64 for (size_t i = 0; i < arraysize(kAttributes); i++) {
65 const auto& attribute = kAttributes[i];
66 DCHECK_EQ(std::string(attribute.name).find(kSeparator), std::string::npos);
67 if (attribute.get_value_func()) {
68 if (!result.empty()) {
69 result.append(kSeparator);
70 }
71 result.append(attribute.name);
72 }
73 }
74
75 return result;
76 }
77
78 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/host_attributes.h ('k') | remoting/host/host_attributes_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698