OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/subresource_filter/core/browser/subresource_filter_features .h" | 5 #include "components/subresource_filter/core/browser/subresource_filter_features .h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <ostream> | 8 #include <ostream> |
9 #include <sstream> | 9 #include <sstream> |
10 #include <string> | 10 #include <string> |
11 #include <tuple> | 11 #include <tuple> |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
16 #include "base/memory/ptr_util.h" | |
16 #include "base/metrics/field_trial_params.h" | 17 #include "base/metrics/field_trial_params.h" |
17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
19 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
20 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
22 #include "base/trace_event/trace_event_argument.h" | |
21 #include "base/values.h" | 23 #include "base/values.h" |
22 #include "components/variations/variations_associated_data.h" | 24 #include "components/variations/variations_associated_data.h" |
23 | 25 |
24 namespace subresource_filter { | 26 namespace subresource_filter { |
25 | 27 |
26 namespace { | 28 namespace { |
27 | 29 |
28 // Helpers -------------------------------------------------------------------- | 30 // Helpers -------------------------------------------------------------------- |
29 | 31 |
30 class CommaSeparatedStrings { | 32 class CommaSeparatedStrings { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 const std::vector<Configuration>& configs) { | 213 const std::vector<Configuration>& configs) { |
212 base::StringPiece greatest_flavor; | 214 base::StringPiece greatest_flavor; |
213 for (const auto& config : configs) { | 215 for (const auto& config : configs) { |
214 base::StringPiece flavor = config.general_settings.ruleset_flavor; | 216 base::StringPiece flavor = config.general_settings.ruleset_flavor; |
215 if (flavor > greatest_flavor) | 217 if (flavor > greatest_flavor) |
216 greatest_flavor = flavor; | 218 greatest_flavor = flavor; |
217 } | 219 } |
218 return greatest_flavor; | 220 return greatest_flavor; |
219 } | 221 } |
220 | 222 |
223 std::unique_ptr<base::DictionaryValue> ConfigToDictionaryValue( | |
224 const Configuration& config) { | |
225 auto dict = base::MakeUnique<base::DictionaryValue>(); | |
226 dict->SetString( | |
227 "activation_scope", | |
228 StreamToString(config.activation_conditions.activation_scope)); | |
229 dict->SetString("activation_list", | |
230 StreamToString(config.activation_conditions.activation_list)); | |
231 dict->SetInteger("priority", config.activation_conditions.priority); | |
232 dict->SetString("activation_level", | |
233 StreamToString(config.activation_options.activation_level)); | |
234 dict->SetDouble("performance_measurement_rate", | |
235 config.activation_options.performance_measurement_rate); | |
236 dict->SetBoolean("should_suppress_notifications", | |
237 config.activation_options.should_suppress_notifications); | |
238 dict->SetBoolean("should_whitelist_site_on_reload", | |
239 config.activation_options.should_whitelist_site_on_reload); | |
240 dict->SetString("ruleset_flavor", | |
241 StreamToString(config.general_settings.ruleset_flavor)); | |
242 return dict; | |
243 } | |
244 | |
221 // Globals -------------------------------------------------------------------- | 245 // Globals -------------------------------------------------------------------- |
222 | 246 |
223 base::LazyInstance<base::Lock>::Leaky g_active_configurations_lock = | 247 base::LazyInstance<base::Lock>::Leaky g_active_configurations_lock = |
224 LAZY_INSTANCE_INITIALIZER; | 248 LAZY_INSTANCE_INITIALIZER; |
225 | 249 |
226 base::LazyInstance<scoped_refptr<ConfigurationList>>::Leaky | 250 base::LazyInstance<scoped_refptr<ConfigurationList>>::Leaky |
227 g_active_configurations = LAZY_INSTANCE_INITIALIZER; | 251 g_active_configurations = LAZY_INSTANCE_INITIALIZER; |
228 | 252 |
229 } // namespace | 253 } // namespace |
230 | 254 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 config.general_settings.ruleset_flavor); | 337 config.general_settings.ruleset_flavor); |
314 }; | 338 }; |
315 return tie(*this) == tie(rhs); | 339 return tie(*this) == tie(rhs); |
316 } | 340 } |
317 | 341 |
318 bool Configuration::operator!=(const Configuration& rhs) const { | 342 bool Configuration::operator!=(const Configuration& rhs) const { |
319 return !(*this == rhs); | 343 return !(*this == rhs); |
320 } | 344 } |
321 | 345 |
322 std::ostream& operator<<(std::ostream& os, const Configuration& config) { | 346 std::ostream& operator<<(std::ostream& os, const Configuration& config) { |
323 base::DictionaryValue dict; | 347 std::unique_ptr<base::DictionaryValue> dict = ConfigToDictionaryValue(config); |
324 dict.SetString("activation_scope", | |
325 StreamToString(config.activation_conditions.activation_scope)); | |
326 dict.SetString("activation_list", | |
327 StreamToString(config.activation_conditions.activation_list)); | |
328 dict.SetInteger("priority", config.activation_conditions.priority); | |
329 dict.SetString("activation_level", | |
330 StreamToString(config.activation_options.activation_level)); | |
331 dict.SetDouble("performance_measurement_rate", | |
332 config.activation_options.performance_measurement_rate); | |
333 dict.SetBoolean("should_suppress_notifications", | |
334 config.activation_options.should_suppress_notifications); | |
335 dict.SetBoolean("should_whitelist_site_on_reload", | |
336 config.activation_options.should_whitelist_site_on_reload); | |
337 dict.SetString("ruleset_flavor", | |
338 StreamToString(config.general_settings.ruleset_flavor)); | |
339 std::string json; | 348 std::string json; |
340 base::JSONWriter::WriteWithOptions( | 349 base::JSONWriter::WriteWithOptions( |
341 dict, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json); | 350 *dict, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json); |
342 return os << json; | 351 return os << json; |
343 } | 352 } |
344 | 353 |
354 std::unique_ptr<base::trace_event::TracedValue> Configuration::GetTracedValue() | |
355 const { | |
356 auto value = base::MakeUnique<base::trace_event::TracedValue>(); | |
357 value->SetValue("Configuration", ConfigToDictionaryValue(*this)); | |
engedy
2017/05/15 12:10:38
nit: Note that this method is deprecated. Might wa
Charlie Harrison
2017/05/15 15:14:22
Discussed with Primiano who recommended we use the
| |
358 return value; | |
359 } | |
360 | |
345 // ConfigurationList ---------------------------------------------------------- | 361 // ConfigurationList ---------------------------------------------------------- |
346 | 362 |
347 ConfigurationList::ConfigurationList(std::vector<Configuration> configs) | 363 ConfigurationList::ConfigurationList(std::vector<Configuration> configs) |
348 : configs_by_decreasing_priority_( | 364 : configs_by_decreasing_priority_( |
349 SortConfigsByDecreasingPriority(std::move(configs))), | 365 SortConfigsByDecreasingPriority(std::move(configs))), |
350 lexicographically_greatest_ruleset_flavor_( | 366 lexicographically_greatest_ruleset_flavor_( |
351 GetLexicographicallyGreatestRulesetFlavor( | 367 GetLexicographicallyGreatestRulesetFlavor( |
352 configs_by_decreasing_priority_)) {} | 368 configs_by_decreasing_priority_)) {} |
353 ConfigurationList::~ConfigurationList() = default; | 369 ConfigurationList::~ConfigurationList() = default; |
354 | 370 |
(...skipping 12 matching lines...) Expand all Loading... | |
367 scoped_refptr<ConfigurationList> new_configs) { | 383 scoped_refptr<ConfigurationList> new_configs) { |
368 base::AutoLock lock(g_active_configurations_lock.Get()); | 384 base::AutoLock lock(g_active_configurations_lock.Get()); |
369 auto old_configs = std::move(g_active_configurations.Get()); | 385 auto old_configs = std::move(g_active_configurations.Get()); |
370 g_active_configurations.Get() = std::move(new_configs); | 386 g_active_configurations.Get() = std::move(new_configs); |
371 return old_configs; | 387 return old_configs; |
372 } | 388 } |
373 | 389 |
374 } // namespace testing | 390 } // namespace testing |
375 | 391 |
376 } // namespace subresource_filter | 392 } // namespace subresource_filter |
OLD | NEW |