Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "content/renderer/media/media_stream_constraints_util.h" | |
| 6 | |
| 7 #include <sstream> | |
| 8 | |
| 9 #include "base/strings/string_number_conversions.h" | |
| 10 #include "base/strings/utf_string_conversions.h" | |
| 11 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | |
| 12 #include "third_party/WebKit/public/platform/WebString.h" | |
| 13 | |
| 14 namespace content { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 // Convert a string ("true", "false") to a boolean. | |
| 19 bool FromString(const std::string& string, bool* value) { | |
|
tommi (sloooow) - chröme
2014/04/30 10:58:44
nit: FromString doesn't quite describe what the fu
no longer working on chromium
2014/05/02 12:24:02
changed it to ConvertStringToBoolean, is it ok?
tommi (sloooow) - chröme
2014/05/03 10:26:28
Yes thanks. that's very clear.
| |
| 20 std::istringstream iss(string); | |
|
tommi (sloooow) - chröme
2014/04/30 10:58:44
using istringstream here is complete overkill!
jus
no longer working on chromium
2014/05/02 12:24:02
That is what libjingle is using. I discussed this
tommi (sloooow) - chröme
2014/05/03 10:26:28
Well, imho istringstream here is overkill and if y
no longer working on chromium
2014/05/05 12:55:56
I agree with you, done with changing it to using s
| |
| 21 iss >> std::boolalpha >> *value; | |
| 22 return !iss.fail(); | |
| 23 } | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 27 bool GetConstraintValue(const blink::WebMediaConstraints& constraints, | |
| 28 const std::string& key, | |
| 29 bool* value) { | |
| 30 return GetMandatoryConstraintValue(constraints, key, value) || | |
| 31 GetOptionalConstraintValue(constraints, key, value); | |
| 32 } | |
| 33 | |
| 34 bool GetConstraintValue(const blink::WebMediaConstraints& constraints, | |
| 35 const std::string& key, | |
| 36 int* value) { | |
| 37 return GetMandatoryConstraintValue(constraints, key, value) || | |
| 38 GetOptionalConstraintValue(constraints, key, value); | |
| 39 } | |
| 40 | |
| 41 bool GetConstraintValue(const blink::WebMediaConstraints& constraints, | |
| 42 const std::string& key, | |
| 43 std::string* value) { | |
| 44 blink::WebString value_str; | |
| 45 if (!constraints.getMandatoryConstraintValue(base::UTF8ToUTF16(key), | |
| 46 value_str) && | |
| 47 !constraints.getOptionalConstraintValue(base::UTF8ToUTF16(key), | |
| 48 value_str)) { | |
| 49 return false; | |
| 50 } | |
| 51 | |
| 52 *value = value_str.utf8(); | |
| 53 return true; | |
| 54 } | |
| 55 | |
| 56 bool GetMandatoryConstraintValue(const blink::WebMediaConstraints& constraints, | |
| 57 const std::string& key, | |
| 58 bool* value) { | |
| 59 blink::WebString value_str; | |
| 60 if (!constraints.getMandatoryConstraintValue(base::UTF8ToUTF16(key), | |
| 61 value_str)) { | |
| 62 return false; | |
| 63 } | |
| 64 | |
| 65 return FromString(value_str.utf8(), value); | |
| 66 } | |
| 67 | |
| 68 bool GetMandatoryConstraintValue(const blink::WebMediaConstraints& constraints, | |
| 69 const std::string& key, | |
| 70 int* value) { | |
| 71 blink::WebString value_str; | |
| 72 if (!constraints.getMandatoryConstraintValue(base::UTF8ToUTF16(key), | |
| 73 value_str)) { | |
| 74 return false; | |
| 75 } | |
| 76 | |
| 77 return base::StringToInt(value_str.utf8(), value); | |
|
tommi (sloooow) - chröme
2014/04/30 10:58:44
StringToInt?
no longer working on chromium
2014/05/02 12:24:02
Yes, I think I have already answered this question
| |
| 78 } | |
| 79 | |
| 80 bool GetOptionalConstraintValue(const blink::WebMediaConstraints& constraints, | |
| 81 const std::string& key, | |
| 82 bool* value) { | |
| 83 blink::WebString value_str; | |
| 84 if (!constraints.getOptionalConstraintValue(base::UTF8ToUTF16(key), | |
| 85 value_str)) { | |
| 86 return false; | |
| 87 } | |
| 88 | |
| 89 return FromString(value_str.utf8(), value); | |
| 90 } | |
| 91 | |
| 92 bool GetOptionalConstraintValue(const blink::WebMediaConstraints& constraints, | |
| 93 const std::string& key, | |
| 94 int* value) { | |
| 95 blink::WebString value_str; | |
| 96 if (!constraints.getOptionalConstraintValue(base::UTF8ToUTF16(key), | |
| 97 value_str)) { | |
| 98 return false; | |
| 99 } | |
| 100 | |
| 101 return base::StringToInt(value_str.utf8(), value); | |
|
tommi (sloooow) - chröme
2014/04/30 10:58:44
StringToInt?
no longer working on chromium
2014/05/02 12:24:02
Ditto.
| |
| 102 } | |
| 103 | |
| 104 } // namespace content | |
| OLD | NEW |