Chromium Code Reviews| Index: chrome/browser/renderer_preferences_util.cc |
| diff --git a/chrome/browser/renderer_preferences_util.cc b/chrome/browser/renderer_preferences_util.cc |
| index 1a1a910a0b300ae00e0d8a30c1cd8973bf31bd8f..c57dc48e1ab663c6b02ecf5debaadc5d39a535f8 100644 |
| --- a/chrome/browser/renderer_preferences_util.cc |
| +++ b/chrome/browser/renderer_preferences_util.cc |
| @@ -4,7 +4,11 @@ |
| #include "chrome/browser/renderer_preferences_util.h" |
| +#include <string> |
| + |
| #include "base/macros.h" |
| +#include "base/strings/string_number_conversions.h" |
| +#include "base/strings/string_util.h" |
| #include "build/build_config.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/common/pref_names.h" |
| @@ -28,6 +32,44 @@ |
| #include "ui/views/linux_ui/linux_ui.h" |
| #endif |
| +namespace { |
| + |
| +// Parses a string |range| with a port range in the form "<min>-<max>". |
|
Guido Urdaneta
2016/07/06 08:56:55
This code is largely duplicated from remoting/prot
tommi (sloooow) - chröme
2016/07/06 10:46:42
I don't think it's a huge deal. The TODO below is
|
| +// If |range| is not in the correct format or contains an invalid range, zero |
| +// is written to |min_port| and |max_port|. |
| +// TODO(guidou): Consider replacing with remoting/protocol/port_range.cc |
| +void ParsePortRange(const std::string& range, |
| + uint16_t* min_port, |
| + uint16_t* max_port) { |
| + *min_port = 0; |
| + *max_port = 0; |
| + |
| + if (range.empty()) |
| + return; |
| + |
| + size_t separator_index = range.find('-'); |
| + if (separator_index == std::string::npos) |
| + return; |
| + |
| + base::StringPiece min_port_string = base::TrimWhitespaceASCII( |
| + range.substr(0, separator_index), base::TRIM_ALL); |
| + base::StringPiece max_port_string = base::TrimWhitespaceASCII( |
| + range.substr(separator_index + 1), base::TRIM_ALL); |
| + unsigned min_port_uint, max_port_uint; |
| + if (!base::StringToUint(min_port_string, &min_port_uint) || |
| + !base::StringToUint(max_port_string, &max_port_uint)) { |
| + return; |
| + } |
| + if (min_port == 0 || min_port_uint > max_port_uint || |
| + max_port_uint > UINT16_MAX) |
|
tommi (sloooow) - chröme
2016/07/06 10:46:43
{}
(could run git cl format)
Guido Urdaneta
2016/07/07 09:27:55
Done.
|
| + return; |
| + |
| + *min_port = static_cast<uint16_t>(min_port_uint); |
| + *max_port = static_cast<uint16_t>(max_port_uint); |
| +} |
| + |
| +} // namespace |
| + |
| namespace renderer_preferences_util { |
| void UpdateFromSystemSettings(content::RendererPreferences* prefs, |
| @@ -55,6 +97,10 @@ void UpdateFromSystemSettings(content::RendererPreferences* prefs, |
| prefs->webrtc_ip_handling_policy = |
| pref_service->GetString(prefs::kWebRTCIPHandlingPolicy); |
| } |
| + std::string webrtc_udp_port_range = |
| + pref_service->GetString(prefs::kWebRTCUDPPortRange); |
| + ParsePortRange(webrtc_udp_port_range, &prefs->webrtc_udp_min_port, |
| + &prefs->webrtc_udp_max_port); |
| #endif |
| #if defined(USE_DEFAULT_RENDER_THEME) |