OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/tracing/background_tracing_config_impl.h" | 5 #include "content/browser/tracing/background_tracing_config_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 case BackgroundTracingConfigImpl::PREEMPTIVE: | 110 case BackgroundTracingConfigImpl::PREEMPTIVE: |
111 dict->SetString(kConfigModeKey, kConfigModePreemptive); | 111 dict->SetString(kConfigModeKey, kConfigModePreemptive); |
112 dict->SetString(kConfigCategoryKey, | 112 dict->SetString(kConfigCategoryKey, |
113 CategoryPresetToString(category_preset_)); | 113 CategoryPresetToString(category_preset_)); |
114 break; | 114 break; |
115 case BackgroundTracingConfigImpl::REACTIVE: | 115 case BackgroundTracingConfigImpl::REACTIVE: |
116 dict->SetString(kConfigModeKey, kConfigModeReactive); | 116 dict->SetString(kConfigModeKey, kConfigModeReactive); |
117 break; | 117 break; |
118 } | 118 } |
119 | 119 |
120 scoped_ptr<base::ListValue> configs_list(new base::ListValue()); | 120 std::unique_ptr<base::ListValue> configs_list(new base::ListValue()); |
121 for (const auto& it : rules_) { | 121 for (const auto& it : rules_) { |
122 scoped_ptr<base::DictionaryValue> config_dict(new base::DictionaryValue()); | 122 std::unique_ptr<base::DictionaryValue> config_dict( |
| 123 new base::DictionaryValue()); |
123 DCHECK(it); | 124 DCHECK(it); |
124 it->IntoDict(config_dict.get()); | 125 it->IntoDict(config_dict.get()); |
125 configs_list->Append(std::move(config_dict)); | 126 configs_list->Append(std::move(config_dict)); |
126 } | 127 } |
127 | 128 |
128 dict->Set(kConfigsKey, std::move(configs_list)); | 129 dict->Set(kConfigsKey, std::move(configs_list)); |
129 | 130 |
130 if (!scenario_name_.empty()) | 131 if (!scenario_name_.empty()) |
131 dict->SetString(kConfigScenarioName, scenario_name_); | 132 dict->SetString(kConfigScenarioName, scenario_name_); |
132 if (!enable_blink_features_.empty()) | 133 if (!enable_blink_features_.empty()) |
133 dict->SetString(kConfigEnableBlinkFeatures, enable_blink_features_); | 134 dict->SetString(kConfigEnableBlinkFeatures, enable_blink_features_); |
134 if (!disable_blink_features_.empty()) | 135 if (!disable_blink_features_.empty()) |
135 dict->SetString(kConfigDisableBlinkFeatures, disable_blink_features_); | 136 dict->SetString(kConfigDisableBlinkFeatures, disable_blink_features_); |
136 } | 137 } |
137 | 138 |
138 void BackgroundTracingConfigImpl::AddPreemptiveRule( | 139 void BackgroundTracingConfigImpl::AddPreemptiveRule( |
139 const base::DictionaryValue* dict) { | 140 const base::DictionaryValue* dict) { |
140 scoped_ptr<BackgroundTracingRule> rule = | 141 std::unique_ptr<BackgroundTracingRule> rule = |
141 BackgroundTracingRule::PreemptiveRuleFromDict(dict); | 142 BackgroundTracingRule::PreemptiveRuleFromDict(dict); |
142 if (rule) | 143 if (rule) |
143 rules_.push_back(std::move(rule)); | 144 rules_.push_back(std::move(rule)); |
144 } | 145 } |
145 | 146 |
146 void BackgroundTracingConfigImpl::AddReactiveRule( | 147 void BackgroundTracingConfigImpl::AddReactiveRule( |
147 const base::DictionaryValue* dict, | 148 const base::DictionaryValue* dict, |
148 BackgroundTracingConfigImpl::CategoryPreset category_preset) { | 149 BackgroundTracingConfigImpl::CategoryPreset category_preset) { |
149 scoped_ptr<BackgroundTracingRule> rule = | 150 std::unique_ptr<BackgroundTracingRule> rule = |
150 BackgroundTracingRule::ReactiveRuleFromDict(dict, category_preset); | 151 BackgroundTracingRule::ReactiveRuleFromDict(dict, category_preset); |
151 if (rule) | 152 if (rule) |
152 rules_.push_back(std::move(rule)); | 153 rules_.push_back(std::move(rule)); |
153 } | 154 } |
154 | 155 |
155 scoped_ptr<BackgroundTracingConfigImpl> BackgroundTracingConfigImpl::FromDict( | 156 std::unique_ptr<BackgroundTracingConfigImpl> |
156 const base::DictionaryValue* dict) { | 157 BackgroundTracingConfigImpl::FromDict(const base::DictionaryValue* dict) { |
157 DCHECK(dict); | 158 DCHECK(dict); |
158 | 159 |
159 std::string mode; | 160 std::string mode; |
160 if (!dict->GetString(kConfigModeKey, &mode)) | 161 if (!dict->GetString(kConfigModeKey, &mode)) |
161 return nullptr; | 162 return nullptr; |
162 | 163 |
163 scoped_ptr<BackgroundTracingConfigImpl> config; | 164 std::unique_ptr<BackgroundTracingConfigImpl> config; |
164 | 165 |
165 if (mode == kConfigModePreemptive) { | 166 if (mode == kConfigModePreemptive) { |
166 config = PreemptiveFromDict(dict); | 167 config = PreemptiveFromDict(dict); |
167 } else if (mode == kConfigModeReactive) { | 168 } else if (mode == kConfigModeReactive) { |
168 config = ReactiveFromDict(dict); | 169 config = ReactiveFromDict(dict); |
169 } else { | 170 } else { |
170 return nullptr; | 171 return nullptr; |
171 } | 172 } |
172 | 173 |
173 if (config) { | 174 if (config) { |
174 dict->GetString(kConfigScenarioName, &config->scenario_name_); | 175 dict->GetString(kConfigScenarioName, &config->scenario_name_); |
175 dict->GetString(kConfigEnableBlinkFeatures, | 176 dict->GetString(kConfigEnableBlinkFeatures, |
176 &config->enable_blink_features_); | 177 &config->enable_blink_features_); |
177 dict->GetString(kConfigDisableBlinkFeatures, | 178 dict->GetString(kConfigDisableBlinkFeatures, |
178 &config->disable_blink_features_); | 179 &config->disable_blink_features_); |
179 } | 180 } |
180 | 181 |
181 return config; | 182 return config; |
182 } | 183 } |
183 | 184 |
184 scoped_ptr<BackgroundTracingConfigImpl> | 185 std::unique_ptr<BackgroundTracingConfigImpl> |
185 BackgroundTracingConfigImpl::PreemptiveFromDict( | 186 BackgroundTracingConfigImpl::PreemptiveFromDict( |
186 const base::DictionaryValue* dict) { | 187 const base::DictionaryValue* dict) { |
187 DCHECK(dict); | 188 DCHECK(dict); |
188 | 189 |
189 scoped_ptr<BackgroundTracingConfigImpl> config( | 190 std::unique_ptr<BackgroundTracingConfigImpl> config( |
190 new BackgroundTracingConfigImpl(BackgroundTracingConfigImpl::PREEMPTIVE)); | 191 new BackgroundTracingConfigImpl(BackgroundTracingConfigImpl::PREEMPTIVE)); |
191 | 192 |
192 std::string category_preset_string; | 193 std::string category_preset_string; |
193 if (!dict->GetString(kConfigCategoryKey, &category_preset_string)) | 194 if (!dict->GetString(kConfigCategoryKey, &category_preset_string)) |
194 return nullptr; | 195 return nullptr; |
195 | 196 |
196 if (!StringToCategoryPreset(category_preset_string, | 197 if (!StringToCategoryPreset(category_preset_string, |
197 &config->category_preset_)) | 198 &config->category_preset_)) |
198 return nullptr; | 199 return nullptr; |
199 | 200 |
200 const base::ListValue* configs_list = nullptr; | 201 const base::ListValue* configs_list = nullptr; |
201 if (!dict->GetList(kConfigsKey, &configs_list)) | 202 if (!dict->GetList(kConfigsKey, &configs_list)) |
202 return nullptr; | 203 return nullptr; |
203 | 204 |
204 for (const auto& it : *configs_list) { | 205 for (const auto& it : *configs_list) { |
205 const base::DictionaryValue* config_dict = nullptr; | 206 const base::DictionaryValue* config_dict = nullptr; |
206 if (!it->GetAsDictionary(&config_dict)) | 207 if (!it->GetAsDictionary(&config_dict)) |
207 return nullptr; | 208 return nullptr; |
208 | 209 |
209 config->AddPreemptiveRule(config_dict); | 210 config->AddPreemptiveRule(config_dict); |
210 } | 211 } |
211 | 212 |
212 if (config->rules().empty()) | 213 if (config->rules().empty()) |
213 return nullptr; | 214 return nullptr; |
214 | 215 |
215 return config; | 216 return config; |
216 } | 217 } |
217 | 218 |
218 scoped_ptr<BackgroundTracingConfigImpl> | 219 std::unique_ptr<BackgroundTracingConfigImpl> |
219 BackgroundTracingConfigImpl::ReactiveFromDict( | 220 BackgroundTracingConfigImpl::ReactiveFromDict( |
220 const base::DictionaryValue* dict) { | 221 const base::DictionaryValue* dict) { |
221 DCHECK(dict); | 222 DCHECK(dict); |
222 | 223 |
223 scoped_ptr<BackgroundTracingConfigImpl> config( | 224 std::unique_ptr<BackgroundTracingConfigImpl> config( |
224 new BackgroundTracingConfigImpl(BackgroundTracingConfigImpl::REACTIVE)); | 225 new BackgroundTracingConfigImpl(BackgroundTracingConfigImpl::REACTIVE)); |
225 | 226 |
226 const base::ListValue* configs_list = nullptr; | 227 const base::ListValue* configs_list = nullptr; |
227 if (!dict->GetList(kConfigsKey, &configs_list)) | 228 if (!dict->GetList(kConfigsKey, &configs_list)) |
228 return nullptr; | 229 return nullptr; |
229 | 230 |
230 for (const auto& it : *configs_list) { | 231 for (const auto& it : *configs_list) { |
231 const base::DictionaryValue* config_dict = nullptr; | 232 const base::DictionaryValue* config_dict = nullptr; |
232 if (!it->GetAsDictionary(&config_dict)) | 233 if (!it->GetAsDictionary(&config_dict)) |
233 return nullptr; | 234 return nullptr; |
234 | 235 |
235 std::string category_preset_string; | 236 std::string category_preset_string; |
236 if (!config_dict->GetString(kConfigCategoryKey, &category_preset_string)) | 237 if (!config_dict->GetString(kConfigCategoryKey, &category_preset_string)) |
237 return nullptr; | 238 return nullptr; |
238 | 239 |
239 BackgroundTracingConfigImpl::CategoryPreset new_category_preset; | 240 BackgroundTracingConfigImpl::CategoryPreset new_category_preset; |
240 if (!StringToCategoryPreset(category_preset_string, &new_category_preset)) | 241 if (!StringToCategoryPreset(category_preset_string, &new_category_preset)) |
241 return nullptr; | 242 return nullptr; |
242 | 243 |
243 config->AddReactiveRule(config_dict, new_category_preset); | 244 config->AddReactiveRule(config_dict, new_category_preset); |
244 } | 245 } |
245 | 246 |
246 if (config->rules().empty()) | 247 if (config->rules().empty()) |
247 return nullptr; | 248 return nullptr; |
248 | 249 |
249 return config; | 250 return config; |
250 } | 251 } |
251 | 252 |
252 } // namspace content | 253 } // namspace content |
OLD | NEW |