Chromium Code Reviews| Index: chrome/browser/policy/policy_prefs_browsertest.cc |
| diff --git a/chrome/browser/policy/policy_prefs_browsertest.cc b/chrome/browser/policy/policy_prefs_browsertest.cc |
| index 1a41f524b77c30a8afeaaab5bb879e776cfb093c..aa9826b36b57915b3e718e08370d031be8d796c7 100644 |
| --- a/chrome/browser/policy/policy_prefs_browsertest.cc |
| +++ b/chrome/browser/policy/policy_prefs_browsertest.cc |
| @@ -18,7 +18,6 @@ |
| #include "base/logging.h" |
| #include "base/macros.h" |
| #include "base/memory/ptr_util.h" |
| -#include "base/memory/scoped_vector.h" |
| #include "base/memory/weak_ptr.h" |
| #include "base/run_loop.h" |
| #include "base/stl_util.h" |
| @@ -131,11 +130,12 @@ class PrefMapping { |
| return indicator_selector_; |
| } |
| - const ScopedVector<IndicatorTestCase>& indicator_test_cases() const { |
| + const std::vector<std::unique_ptr<IndicatorTestCase>>& indicator_test_cases() |
| + const { |
| return indicator_test_cases_; |
| } |
| - void AddIndicatorTestCase(IndicatorTestCase* test_case) { |
| - indicator_test_cases_.push_back(test_case); |
| + void AddIndicatorTestCase(std::unique_ptr<IndicatorTestCase> test_case) { |
| + indicator_test_cases_.push_back(std::move(test_case)); |
|
Lei Zhang
2017/03/23 02:59:26
#include <utility>
leonhsl(Using Gerrit)
2017/03/23 15:03:17
Done.
|
| } |
| private: |
| @@ -146,7 +146,7 @@ class PrefMapping { |
| const std::string indicator_test_url_; |
| const std::string indicator_test_setup_js_; |
| const std::string indicator_selector_; |
| - ScopedVector<IndicatorTestCase> indicator_test_cases_; |
| + std::vector<std::unique_ptr<IndicatorTestCase>> indicator_test_cases_; |
| DISALLOW_COPY_AND_ASSIGN(PrefMapping); |
| }; |
| @@ -202,11 +202,11 @@ class PolicyTestCase { |
| test_policy_.MergeDictionary(&policy); |
| } |
| - const ScopedVector<PrefMapping>& pref_mappings() const { |
| + const std::vector<std::unique_ptr<PrefMapping>>& pref_mappings() const { |
| return pref_mappings_; |
| } |
| - void AddPrefMapping(PrefMapping* pref_mapping) { |
| - pref_mappings_.push_back(pref_mapping); |
| + void AddPrefMapping(std::unique_ptr<PrefMapping> pref_mapping) { |
| + pref_mappings_.push_back(std::move(pref_mapping)); |
| } |
| const std::string& indicator_selector() const { return indicator_selector_; } |
| @@ -217,7 +217,7 @@ class PolicyTestCase { |
| bool can_be_recommended_; |
| std::vector<std::string> supported_os_; |
| base::DictionaryValue test_policy_; |
| - ScopedVector<PrefMapping> pref_mappings_; |
| + std::vector<std::unique_ptr<PrefMapping>> pref_mappings_; |
| std::string indicator_selector_; |
| DISALLOW_COPY_AND_ASSIGN(PolicyTestCase); |
| @@ -339,13 +339,9 @@ class PolicyTestCases { |
| &indicator_test_setup_js); |
| std::string indicator_selector; |
| pref_mapping_dict->GetString("indicator_selector", &indicator_selector); |
| - PrefMapping* pref_mapping = new PrefMapping(pref, |
| - is_local_state, |
| - check_for_mandatory, |
| - check_for_recommended, |
| - indicator_test_url, |
| - indicator_test_setup_js, |
| - indicator_selector); |
| + auto pref_mapping = base::MakeUnique<PrefMapping>( |
| + pref, is_local_state, check_for_mandatory, check_for_recommended, |
| + indicator_test_url, indicator_test_setup_js, indicator_selector); |
| const base::ListValue* indicator_tests = NULL; |
| if (pref_mapping_dict->GetList("indicator_tests", &indicator_tests)) { |
| for (size_t i = 0; i < indicator_tests->GetSize(); ++i) { |
| @@ -362,10 +358,10 @@ class PolicyTestCases { |
| bool readonly = false; |
| indicator_test_dict->GetBoolean("readonly", &readonly); |
| pref_mapping->AddIndicatorTestCase( |
| - new IndicatorTestCase(*policy, value, readonly)); |
| + base::MakeUnique<IndicatorTestCase>(*policy, value, readonly)); |
| } |
| } |
| - policy_test_case->AddPrefMapping(pref_mapping); |
| + policy_test_case->AddPrefMapping(std::move(pref_mapping)); |
| } |
| } |
| return policy_test_case; |
| @@ -557,17 +553,14 @@ IN_PROC_BROWSER_TEST_F(PolicyPrefsTest, PolicyToPrefsMapping) { |
| policy->second.begin(); |
| test_case != policy->second.end(); |
| ++test_case) { |
| - const ScopedVector<PrefMapping>& pref_mappings = |
| - (*test_case)->pref_mappings(); |
| + const auto& pref_mappings = (*test_case)->pref_mappings(); |
| if (!(*test_case)->IsSupported() || pref_mappings.empty()) |
| continue; |
| LOG(INFO) << "Testing policy: " << policy->first; |
| - for (ScopedVector<PrefMapping>::const_iterator pref_mapping = |
| - pref_mappings.begin(); |
| - pref_mapping != pref_mappings.end(); |
| - ++pref_mapping) { |
| + for (auto pref_mapping = pref_mappings.begin(); |
|
Lei Zhang
2017/03/23 02:59:26
Can this be a range-based for-loop instead? Ditto
leonhsl(Using Gerrit)
2017/03/23 15:03:17
Done. And also for below 2X.
|
| + pref_mapping != pref_mappings.end(); ++pref_mapping) { |
| // Skip Chrome OS preferences that use a different backend and cannot be |
| // retrieved through the prefs mechanism. |
| if (base::StartsWith((*pref_mapping)->pref(), kCrosSettingsPrefix, |
| @@ -632,14 +625,11 @@ IN_PROC_BROWSER_TEST_P(PolicyPrefIndicatorTest, CheckPolicyIndicators) { |
| PolicyTestCase* policy_test_case = *test_case; |
| if (!policy_test_case->IsSupported()) |
| continue; |
| - const ScopedVector<PrefMapping>& pref_mappings = |
| - policy_test_case->pref_mappings(); |
| + const auto& pref_mappings = policy_test_case->pref_mappings(); |
| if (policy_test_case->indicator_selector().empty()) { |
| bool has_pref_indicator_tests = false; |
| - for (ScopedVector<PrefMapping>::const_iterator pref_mapping = |
| - pref_mappings.begin(); |
| - pref_mapping != pref_mappings.end(); |
| - ++pref_mapping) { |
| + for (auto pref_mapping = pref_mappings.begin(); |
| + pref_mapping != pref_mappings.end(); ++pref_mapping) { |
| PrefService* prefs = |
| (*pref_mapping)->is_local_state() ? local_state : user_prefs; |
| if (prefs->FindPreference((*pref_mapping)->pref())) |
| @@ -686,11 +676,9 @@ IN_PROC_BROWSER_TEST_P(PolicyPrefIndicatorTest, CheckPolicyIndicators) { |
| false); |
| } |
| - for (ScopedVector<PrefMapping>::const_iterator |
| - pref_mapping = pref_mappings.begin(); |
| - pref_mapping != pref_mappings.end(); |
| - ++pref_mapping) { |
| - const ScopedVector<IndicatorTestCase>& indicator_test_cases = |
| + for (auto pref_mapping = pref_mappings.begin(); |
| + pref_mapping != pref_mappings.end(); ++pref_mapping) { |
| + const auto& indicator_test_cases = |
| (*pref_mapping)->indicator_test_cases(); |
| if (indicator_test_cases.empty()) |
| continue; |
| @@ -716,8 +704,7 @@ IN_PROC_BROWSER_TEST_P(PolicyPrefIndicatorTest, CheckPolicyIndicators) { |
| std::string indicator_selector = (*pref_mapping)->indicator_selector(); |
| if (indicator_selector.empty()) |
| indicator_selector = "[pref=\"" + (*pref_mapping)->pref() + "\"]"; |
| - for (ScopedVector<IndicatorTestCase>::const_iterator |
| - indicator_test_case = indicator_test_cases.begin(); |
| + for (auto indicator_test_case = indicator_test_cases.begin(); |
| indicator_test_case != indicator_test_cases.end(); |
| ++indicator_test_case) { |
| // Check that no controlled setting indicator is visible when no value |