OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... | |
38 return it->second; | 38 return it->second; |
39 } | 39 } |
40 } // namespace field_trial | 40 } // namespace field_trial |
41 | 41 |
42 namespace test { | 42 namespace test { |
43 // Note: this code is copied from src/base/metrics/field_trial.cc since the aim | 43 // Note: this code is copied from src/base/metrics/field_trial.cc since the aim |
44 // is to mimic chromium --force-fieldtrials. | 44 // is to mimic chromium --force-fieldtrials. |
45 void InitFieldTrialsFromString(const std::string& trials_string) { | 45 void InitFieldTrialsFromString(const std::string& trials_string) { |
46 static const char kPersistentStringSeparator = '/'; | 46 static const char kPersistentStringSeparator = '/'; |
47 | 47 |
48 // Catch an error if this is called more than once. | |
49 assert(field_trials_initiated_ == false); | |
48 field_trials_initiated_ = true; | 50 field_trials_initiated_ = true; |
49 | 51 |
50 if (trials_string.empty()) { | 52 if (trials_string == "") |
tommi
2015/07/08 09:01:35
nit: empty() is better than comparison
pbos-webrtc
2015/07/08 12:10:36
I think == "" reads better. It's also under test c
tommi
2015/07/08 12:21:12
Here are some reasons for why I don't agree:
* It'
pbos-webrtc
2015/07/08 12:44:18
So my argument is readability (which is personal).
tommi
2015/07/08 13:36:59
std::string is a container. http://stackoverflow.c
pbos-webrtc
2015/07/08 15:49:46
I like those compilers.
No I'm not saying that I'
| |
51 field_trials_.clear(); | |
52 return; | 53 return; |
53 } | |
54 | 54 |
55 size_t next_item = 0; | 55 size_t next_item = 0; |
56 while (next_item < trials_string.length()) { | 56 while (next_item < trials_string.length()) { |
57 size_t name_end = trials_string.find(kPersistentStringSeparator, next_item); | 57 size_t name_end = trials_string.find(kPersistentStringSeparator, next_item); |
58 if (name_end == trials_string.npos || next_item == name_end) | 58 if (name_end == trials_string.npos || next_item == name_end) |
59 break; | 59 break; |
60 size_t group_name_end = trials_string.find(kPersistentStringSeparator, | 60 size_t group_name_end = trials_string.find(kPersistentStringSeparator, |
61 name_end + 1); | 61 name_end + 1); |
62 if (group_name_end == trials_string.npos || name_end + 1 == group_name_end) | 62 if (group_name_end == trials_string.npos || name_end + 1 == group_name_end) |
63 break; | 63 break; |
(...skipping 12 matching lines...) Expand all Loading... | |
76 // Successfully parsed all field trials from the string. | 76 // Successfully parsed all field trials from the string. |
77 if (next_item == trials_string.length()) | 77 if (next_item == trials_string.length()) |
78 return; | 78 return; |
79 } | 79 } |
80 // LOG does not prints when this is called early on main. | 80 // LOG does not prints when this is called early on main. |
81 fprintf(stderr, "Invalid field trials string.\n"); | 81 fprintf(stderr, "Invalid field trials string.\n"); |
82 | 82 |
83 // Using abort so it crashs both in debug and release mode. | 83 // Using abort so it crashs both in debug and release mode. |
84 abort(); | 84 abort(); |
85 } | 85 } |
86 | |
87 ScopedFieldTrials::ScopedFieldTrials(const std::string& config) | |
88 : previous_field_trials_(field_trials_) { | |
89 assert(field_trials_initiated_); | |
90 field_trials_initiated_ = false; | |
91 field_trials_ = std::map<std::string, std::string>(); | |
tommi
2015/07/08 09:01:35
why not clear()?
pbos-webrtc
2015/07/08 12:10:36
Brain fart, ptal: https://codereview.webrtc.org/12
| |
92 InitFieldTrialsFromString(config); | |
93 } | |
94 | |
95 ScopedFieldTrials::~ScopedFieldTrials() { | |
96 field_trials_ = previous_field_trials_; | |
tommi
2015/07/08 09:01:35
also restore field_trials_initiated_ ?
pbos-webrtc
2015/07/08 12:10:36
Not necessary (InitFieldTrialsFromString called fr
tommi
2015/07/08 12:21:12
I would still want the preconditions to mast the p
pbos-webrtc
2015/07/08 12:44:17
It works. field_trials_initiated_ doesn't need to
tommi
2015/07/08 13:36:59
Ah, I see.
| |
97 } | |
98 | |
86 } // namespace test | 99 } // namespace test |
87 } // namespace webrtc | 100 } // namespace webrtc |
OLD | NEW |