OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/extensions/extension_management_test_util.h" | |
6 | |
7 #include "components/crx_file/id_util.h" | |
8 | |
9 namespace extensions { | |
10 | |
11 namespace schema = schema_constants; | |
12 | |
13 namespace { | |
14 | |
15 std::string make_path(std::string a, std::string b) { | |
16 return a + "." + b; | |
17 } | |
18 | |
19 const std::string kInstallSourcesPath = | |
20 make_path(schema::kWildcard, schema::kInstallSources); | |
21 const std::string kAllowedTypesPath = | |
22 make_path(schema::kWildcard, schema::kAllowedTypes); | |
Joao da Silva
2014/09/18 15:23:53
Don't define std::string globals like this, becaus
binjin
2014/09/18 15:49:03
Done.
| |
23 | |
24 } // namespace | |
25 | |
26 ExtensionManagementPrefUpdaterBase::ExtensionManagementPrefUpdaterBase() { | |
27 } | |
28 | |
29 ExtensionManagementPrefUpdaterBase::~ExtensionManagementPrefUpdaterBase() { | |
30 } | |
31 | |
32 void ExtensionManagementPrefUpdaterBase::SetBlacklistedByDefault(bool value) { | |
33 pref_->SetString(make_path(schema::kWildcard, schema::kInstallationMode), | |
34 value ? schema::kBlocked : schema::kAllowed); | |
35 } | |
36 | |
37 void ExtensionManagementPrefUpdaterBase:: | |
38 ClearInstallationModesForIndividualExtensions() { | |
39 for (base::DictionaryValue::Iterator it(*pref_.get()); !it.IsAtEnd(); | |
40 it.Advance()) { | |
41 DCHECK(it.value().IsType(base::Value::TYPE_DICTIONARY)); | |
42 if (it.key() != schema::kWildcard) { | |
43 DCHECK(crx_file::id_util::IdIsValid(it.key())); | |
44 pref_->Remove(make_path(it.key(), schema::kInstallationMode), NULL); | |
45 pref_->Remove(make_path(it.key(), schema::kUpdateUrl), NULL); | |
46 } | |
47 } | |
48 } | |
49 | |
50 void | |
51 ExtensionManagementPrefUpdaterBase::SetIndividualExtensionInstallationAllowed( | |
52 const ExtensionId& id, | |
53 bool allowed) { | |
54 DCHECK(crx_file::id_util::IdIsValid(id)); | |
55 pref_->SetString(make_path(id, schema::kInstallationMode), | |
56 allowed ? schema::kAllowed : schema::kBlocked); | |
57 pref_->Remove(make_path(id, schema::kUpdateUrl), NULL); | |
58 } | |
59 | |
60 void ExtensionManagementPrefUpdaterBase::SetIndividualExtensionAutoInstalled( | |
61 const ExtensionId& id, | |
62 const std::string& update_url, | |
63 bool forced) { | |
64 DCHECK(crx_file::id_util::IdIsValid(id)); | |
65 pref_->SetString(make_path(id, schema::kInstallationMode), | |
66 forced ? schema::kForceInstalled : schema::kNormalInstalled); | |
67 pref_->SetString(make_path(id, schema::kUpdateUrl), update_url); | |
68 } | |
69 | |
70 void ExtensionManagementPrefUpdaterBase::UnsetInstallSources() { | |
71 pref_->Remove(kInstallSourcesPath, NULL); | |
72 } | |
73 | |
74 void ExtensionManagementPrefUpdaterBase::ClearInstallSources() { | |
75 ClearList(kInstallSourcesPath); | |
76 } | |
77 | |
78 void ExtensionManagementPrefUpdaterBase::AddInstallSource( | |
79 const std::string& install_source) { | |
80 AddStringToList(kInstallSourcesPath, install_source); | |
81 } | |
82 | |
83 void ExtensionManagementPrefUpdaterBase::RemoveInstallSource( | |
84 const std::string& install_source) { | |
85 RemoveStringFromList(kInstallSourcesPath, install_source); | |
86 } | |
87 | |
88 void ExtensionManagementPrefUpdaterBase::UnsetAllowedTypes() { | |
89 pref_->Remove(kAllowedTypesPath, NULL); | |
90 } | |
91 | |
92 void ExtensionManagementPrefUpdaterBase::ClearAllowedTypes() { | |
93 ClearList(kAllowedTypesPath); | |
94 } | |
95 | |
96 void ExtensionManagementPrefUpdaterBase::AddAllowedType( | |
97 const std::string& allowed_type) { | |
98 AddStringToList(kAllowedTypesPath, allowed_type); | |
99 } | |
100 | |
101 const base::DictionaryValue* ExtensionManagementPrefUpdaterBase::GetPref() { | |
102 return pref_.get(); | |
103 } | |
104 | |
105 void ExtensionManagementPrefUpdaterBase::SetPref(base::DictionaryValue* pref) { | |
106 pref_.reset(pref); | |
107 } | |
108 | |
109 scoped_ptr<base::DictionaryValue> | |
110 ExtensionManagementPrefUpdaterBase::TakePref() { | |
111 return pref_.Pass(); | |
112 } | |
113 | |
114 void ExtensionManagementPrefUpdaterBase::RemoveAllowedType( | |
115 const std::string& allowd_type) { | |
116 RemoveStringFromList(kAllowedTypesPath, allowd_type); | |
117 } | |
118 | |
119 void ExtensionManagementPrefUpdaterBase::ClearList(const std::string& path) { | |
120 base::ListValue* list_value = NULL; | |
121 if (pref_->GetList(path, &list_value)) | |
122 list_value->Clear(); | |
123 else | |
124 pref_->Set(path, new base::ListValue()); | |
Joao da Silva
2014/09/18 15:23:53
This also overrides existing lists, so it works fo
binjin
2014/09/18 15:49:03
Done.
| |
125 } | |
126 | |
127 void ExtensionManagementPrefUpdaterBase::AddStringToList( | |
128 const std::string& path, | |
129 const std::string& str) { | |
130 base::ListValue* list_value = NULL; | |
131 if (!pref_->GetList(path, &list_value)) { | |
132 list_value = new base::ListValue(); | |
133 pref_->Set(path, list_value); | |
134 } | |
135 CHECK(list_value->AppendIfNotPresent(new base::StringValue(str))); | |
136 } | |
137 | |
138 void ExtensionManagementPrefUpdaterBase::RemoveStringFromList( | |
139 const std::string& path, | |
140 const std::string& str) { | |
141 base::ListValue* list_value = NULL; | |
142 if (pref_->GetList(path, &list_value)) | |
143 CHECK(list_value->Remove(base::StringValue(str), NULL)); | |
144 } | |
145 | |
146 } // namespace extensions | |
OLD | NEW |