Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: webrtc/test/field_trial.cc

Issue 1215713019: Fix follow-up in webrtc/test/field_trial.cc. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 28 matching lines...) Expand all
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. 48 // Catch an error if this is called more than once.
49 assert(field_trials_initiated_ == false); 49 assert(!field_trials_initiated_);
50 field_trials_initiated_ = true; 50 field_trials_initiated_ = true;
51 51
52 if (trials_string.empty()) 52 if (trials_string.empty())
53 return; 53 return;
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;
(...skipping 10 matching lines...) Expand all
70 if (field_trials_.find(name) != field_trials_.end() && 70 if (field_trials_.find(name) != field_trials_.end() &&
71 field_trials_.find(name)->second != group_name) 71 field_trials_.find(name)->second != group_name)
72 break; 72 break;
73 73
74 field_trials_[name] = group_name; 74 field_trials_[name] = group_name;
75 75
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 // Using fprintf as LOG does not print when this is called early in 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 crashes in both debug and release mode.
84 abort(); 84 abort();
85 } 85 }
86 86
87 ScopedFieldTrials::ScopedFieldTrials(const std::string& config) 87 ScopedFieldTrials::ScopedFieldTrials(const std::string& config)
88 : previous_field_trials_(field_trials_) { 88 : previous_field_trials_(field_trials_) {
89 assert(field_trials_initiated_); 89 assert(field_trials_initiated_);
90 field_trials_initiated_ = false; 90 field_trials_initiated_ = false;
91 field_trials_ = std::map<std::string, std::string>(); 91 field_trials_.clear();
92 InitFieldTrialsFromString(config); 92 InitFieldTrialsFromString(config);
93 } 93 }
94 94
95 ScopedFieldTrials::~ScopedFieldTrials() { 95 ScopedFieldTrials::~ScopedFieldTrials() {
96 // Should still be initialized, since InitFieldTrials is called from ctor.
97 // That's why we don't restore the flag.
98 assert(field_trials_initiated_);
96 field_trials_ = previous_field_trials_; 99 field_trials_ = previous_field_trials_;
97 } 100 }
98 101
99 } // namespace test 102 } // namespace test
100 } // namespace webrtc 103 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698