Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/host_session_options.h" | 5 #include "remoting/host/host_session_options.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 | 12 |
| 13 namespace remoting { | 13 namespace remoting { |
| 14 namespace protocol { | |
| 15 | 14 |
| 16 namespace { | 15 namespace { |
| 17 | 16 |
| 18 static constexpr char kSeparator = ','; | 17 static constexpr char kSeparator = ','; |
| 19 static constexpr char kKeyValueSeparator = ':'; | 18 static constexpr char kKeyValueSeparator = ':'; |
| 20 | 19 |
| 21 // Whether |value| is good to be added to HostSessionOptions as a value. | 20 // Whether |value| is good to be added to HostSessionOptions as a value. |
| 22 bool ValueIsValid(const std::string& value) { | 21 bool ValueIsValid(const std::string& value) { |
| 23 return value.find(kSeparator) == std::string::npos && | 22 return value.find(kSeparator) == std::string::npos && |
| 24 value.find(kKeyValueSeparator) == std::string::npos && | 23 value.find(kKeyValueSeparator) == std::string::npos && |
| 25 base::IsStringASCII(value); | 24 base::IsStringASCII(value); |
| 26 } | 25 } |
| 27 | 26 |
| 28 // Whether |key| is good to be added to HostSessionOptions as a key. | 27 // Whether |key| is good to be added to HostSessionOptions as a key. |
| 29 bool KeyIsValid(const std::string& key) { | 28 bool KeyIsValid(const std::string& key) { |
| 30 return !key.empty() && ValueIsValid(key); | 29 return !key.empty() && ValueIsValid(key); |
| 31 } | 30 } |
| 32 | 31 |
| 33 } // namespace | 32 } // namespace |
| 34 | 33 |
| 35 HostSessionOptions::HostSessionOptions() = default; | 34 HostSessionOptions::HostSessionOptions() = default; |
| 36 HostSessionOptions::~HostSessionOptions() = default; | 35 HostSessionOptions::~HostSessionOptions() = default; |
| 37 | 36 |
| 37 HostSessionOptions::HostSessionOptions(const std::string& parameter) | |
| 38 : HostSessionOptions() { | |
|
Sergey Ulanov
2017/01/23 00:51:35
Don't need to call this constructor explicitly
Hzj_jie
2017/02/08 01:56:29
Done.
| |
| 39 Import(parameter); | |
| 40 } | |
| 41 | |
| 38 void HostSessionOptions::Append(const std::string& key, | 42 void HostSessionOptions::Append(const std::string& key, |
| 39 const std::string& value) { | 43 const std::string& value) { |
| 40 DCHECK(KeyIsValid(key)); | 44 DCHECK(KeyIsValid(key)); |
| 41 DCHECK(ValueIsValid(value)); | 45 DCHECK(ValueIsValid(value)); |
| 42 options_[key] = value; | 46 options_[key] = value; |
| 43 } | 47 } |
| 44 | 48 |
| 45 base::Optional<std::string> HostSessionOptions::Get( | 49 base::Optional<std::string> HostSessionOptions::Get( |
| 46 const std::string& key) const { | 50 const std::string& key) const { |
| 47 auto it = options_.find(key); | 51 auto it = options_.find(key); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 73 kKeyValueSeparator, | 77 kKeyValueSeparator, |
| 74 kSeparator, | 78 kSeparator, |
| 75 &result); | 79 &result); |
| 76 for (const auto& pair : result) { | 80 for (const auto& pair : result) { |
| 77 if (KeyIsValid(pair.first) && ValueIsValid(pair.second)) { | 81 if (KeyIsValid(pair.first) && ValueIsValid(pair.second)) { |
| 78 Append(pair.first, pair.second); | 82 Append(pair.first, pair.second); |
| 79 } | 83 } |
| 80 } | 84 } |
| 81 } | 85 } |
| 82 | 86 |
| 83 } // namespace protocol | |
| 84 } // namespace remoting | 87 } // namespace remoting |
| OLD | NEW |