Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / remoting / jingle_glue / network_settings.cc
blobd3e464c9f1d4379a414761312f4711163e230673
1 // Copyright 2014 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.
5 #include "remoting/jingle_glue/network_settings.h"
7 #include <limits.h>
8 #include <stdlib.h>
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h"
13 namespace remoting {
15 // static
16 bool NetworkSettings::ParsePortRange(const std::string& port_range,
17 int* out_min_port,
18 int* out_max_port) {
19 size_t separator_index = port_range.find('-');
20 if (separator_index == std::string::npos)
21 return false;
23 std::string min_port_string, max_port_string;
24 base::TrimWhitespaceASCII(port_range.substr(0, separator_index),
25 base::TRIM_ALL,
26 &min_port_string);
27 base::TrimWhitespaceASCII(port_range.substr(separator_index + 1),
28 base::TRIM_ALL,
29 &max_port_string);
31 unsigned min_port, max_port;
32 if (!base::StringToUint(min_port_string, &min_port) ||
33 !base::StringToUint(max_port_string, &max_port)) {
34 return false;
37 if (min_port == 0 || min_port > max_port || max_port > USHRT_MAX)
38 return false;
40 *out_min_port = static_cast<int>(min_port);
41 *out_max_port = static_cast<int>(max_port);
42 return true;
45 } // namespace remoting