Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "build/build_config.h" | |
| 12 #if defined(OS_WIN) | |
| 13 #include "remoting/host/host_attributes_win.h" | |
| 14 #else | |
| 15 #include "remoting/host/host_attributes_empty.h" | |
| 16 #endif | |
| 17 | |
| 18 namespace remoting { | |
| 19 | |
| 20 namespace { | |
| 21 static constexpr char kSeparator[] = ","; | |
| 22 } // namespace | |
| 23 | |
| 24 static_assert(std::is_pod<DynamicAttribute>::value, | |
| 25 "DynamicAttribute should be POD."); | |
| 26 static_assert(std::is_pod<StaticAttribute>::value, | |
| 27 "StaticAttribute should be POD."); | |
| 28 | |
| 29 const char* StaticAttribute::name() const { | |
| 30 return attribute.name; | |
| 31 } | |
| 32 | |
| 33 bool StaticAttribute::EvaluatedValue() { | |
| 34 if (evaluated) { | |
| 35 return value; | |
| 36 } else { | |
| 37 value = attribute.value(); | |
| 38 base::subtle::MemoryBarrier(); | |
| 39 evaluated = true; | |
| 40 return value; | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 std::string GetHostAttributes() { | |
| 45 std::string result; | |
| 46 // By using ranged for-loop, MSVC throws error C3316: | |
| 47 // 'const remoting::StaticAttribute [0]': | |
| 48 // an array of unknown size cannot be used in a range-based for statement. | |
| 49 // | |
| 50 // By using arraysize() macro in base/macros.h, it's illegal, | |
| 51 // error: no matching function for call to 'ArraySizeHelper' | |
| 52 // note: candidate template ignored: substitution failure | |
| 53 // [with T = const remoting::StaticAttribute, N = 0]: | |
| 54 // zero-length arrays are not permitted in C++. | |
| 55 // | |
| 56 // So a traditional sizeof is used here. | |
| 57 #define SIZE_OF_ARRAY(x, y) static_cast<int>(sizeof(x) / sizeof(y)) | |
|
Sergey Ulanov
2016/11/07 20:11:33
Add something in kDynamicAttributes and use arrays
Hzj_jie
2016/11/08 01:29:53
Done.
| |
| 58 for (int i = 0; | |
| 59 i < SIZE_OF_ARRAY(kStaticAttributes, StaticAttribute); | |
| 60 i++) { | |
| 61 auto& static_attribute = kStaticAttributes[i]; | |
| 62 DCHECK(std::string(static_attribute.name()).find(kSeparator) == | |
| 63 std::string::npos); | |
| 64 if (static_attribute.EvaluatedValue()) { | |
| 65 if (!result.empty()) { | |
| 66 result.append(kSeparator); | |
| 67 } | |
| 68 result.append(static_attribute.name()); | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 for (int i = 0; | |
| 73 i < SIZE_OF_ARRAY(kDynamicAttributes, StaticAttribute); | |
|
Sergey Ulanov
2016/11/07 20:11:33
type is wrong here. This macro could be implemente
Hzj_jie
2016/11/08 01:29:54
Done.
| |
| 74 i++) { | |
| 75 const auto& dynamic_attribute = kDynamicAttributes[i]; | |
| 76 DCHECK(std::string(dynamic_attribute.name).find(kSeparator) == | |
| 77 std::string::npos); | |
| 78 if (dynamic_attribute.value()) { | |
| 79 if (!result.empty()) { | |
| 80 result.append(kSeparator); | |
| 81 } | |
| 82 result.append(dynamic_attribute.name); | |
| 83 } | |
| 84 } | |
| 85 #undef SIZE_OF_ARRAY | |
| 86 | |
| 87 return result; | |
| 88 } | |
| 89 | |
| 90 } // namespace remoting | |
| OLD | NEW |