OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "extensions/browser/extension_pref_value_map.h" | 5 #include "extensions/browser/extension_pref_value_map.h" |
6 | 6 |
7 #include "base/prefs/pref_value_map.h" | 7 #include "base/prefs/pref_value_map.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 | 10 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 ExtensionEntryMap::const_iterator ext = entries_.find(extension_id); | 73 ExtensionEntryMap::const_iterator ext = entries_.find(extension_id); |
74 if (ext == entries_.end()) { | 74 if (ext == entries_.end()) { |
75 NOTREACHED(); | 75 NOTREACHED(); |
76 return false; | 76 return false; |
77 } | 77 } |
78 | 78 |
79 if (incognito && !ext->second->incognito_enabled) | 79 if (incognito && !ext->second->incognito_enabled) |
80 return false; | 80 return false; |
81 | 81 |
82 ExtensionEntryMap::const_iterator winner = | 82 ExtensionEntryMap::const_iterator winner = |
83 GetEffectivePrefValueController(pref_key, incognito, NULL); | 83 GetEffectivePrefValueController(pref_key, incognito, nullptr); |
84 if (winner == entries_.end()) | 84 if (winner == entries_.end()) |
85 return true; | 85 return true; |
86 | 86 |
87 return winner->second->install_time <= ext->second->install_time; | 87 return winner->second->install_time <= ext->second->install_time; |
88 } | 88 } |
89 | 89 |
90 void ExtensionPrefValueMap::ClearAllIncognitoSessionOnlyPreferences() { | 90 void ExtensionPrefValueMap::ClearAllIncognitoSessionOnlyPreferences() { |
91 typedef std::set<std::string> KeySet; | 91 typedef std::set<std::string> KeySet; |
92 KeySet deleted_keys; | 92 KeySet deleted_keys; |
93 | 93 |
94 ExtensionEntryMap::iterator i; | 94 ExtensionEntryMap::iterator i; |
95 for (i = entries_.begin(); i != entries_.end(); ++i) { | 95 for (i = entries_.begin(); i != entries_.end(); ++i) { |
96 PrefValueMap& inc_prefs = | 96 PrefValueMap& inc_prefs = |
97 i->second->incognito_profile_preferences_session_only; | 97 i->second->incognito_profile_preferences_session_only; |
98 PrefValueMap::iterator j; | 98 PrefValueMap::iterator j; |
99 for (j = inc_prefs.begin(); j != inc_prefs.end(); ++j) | 99 for (j = inc_prefs.begin(); j != inc_prefs.end(); ++j) |
100 deleted_keys.insert(j->first); | 100 deleted_keys.insert(j->first); |
101 inc_prefs.Clear(); | 101 inc_prefs.Clear(); |
102 } | 102 } |
103 | 103 |
104 KeySet::iterator k; | 104 KeySet::iterator k; |
105 for (k = deleted_keys.begin(); k != deleted_keys.end(); ++k) | 105 for (k = deleted_keys.begin(); k != deleted_keys.end(); ++k) |
106 NotifyPrefValueChanged(*k); | 106 NotifyPrefValueChanged(*k); |
107 } | 107 } |
108 | 108 |
109 bool ExtensionPrefValueMap::DoesExtensionControlPref( | 109 bool ExtensionPrefValueMap::DoesExtensionControlPref( |
110 const std::string& extension_id, | 110 const std::string& extension_id, |
111 const std::string& pref_key, | 111 const std::string& pref_key, |
112 bool* from_incognito) const { | 112 bool* from_incognito) const { |
113 bool incognito = (from_incognito != NULL); | 113 bool incognito = (from_incognito != nullptr); |
114 ExtensionEntryMap::const_iterator winner = | 114 ExtensionEntryMap::const_iterator winner = |
115 GetEffectivePrefValueController(pref_key, incognito, from_incognito); | 115 GetEffectivePrefValueController(pref_key, incognito, from_incognito); |
116 if (winner == entries_.end()) | 116 if (winner == entries_.end()) |
117 return false; | 117 return false; |
118 return winner->first == extension_id; | 118 return winner->first == extension_id; |
119 } | 119 } |
120 | 120 |
121 void ExtensionPrefValueMap::RegisterExtension(const std::string& ext_id, | 121 void ExtensionPrefValueMap::RegisterExtension(const std::string& ext_id, |
122 const base::Time& install_time, | 122 const base::Time& install_time, |
123 bool is_enabled, | 123 bool is_enabled, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 case extensions::kExtensionPrefsScopeRegular: | 186 case extensions::kExtensionPrefsScopeRegular: |
187 return &(i->second->regular_profile_preferences); | 187 return &(i->second->regular_profile_preferences); |
188 case extensions::kExtensionPrefsScopeRegularOnly: | 188 case extensions::kExtensionPrefsScopeRegularOnly: |
189 return &(i->second->regular_only_profile_preferences); | 189 return &(i->second->regular_only_profile_preferences); |
190 case extensions::kExtensionPrefsScopeIncognitoPersistent: | 190 case extensions::kExtensionPrefsScopeIncognitoPersistent: |
191 return &(i->second->incognito_profile_preferences_persistent); | 191 return &(i->second->incognito_profile_preferences_persistent); |
192 case extensions::kExtensionPrefsScopeIncognitoSessionOnly: | 192 case extensions::kExtensionPrefsScopeIncognitoSessionOnly: |
193 return &(i->second->incognito_profile_preferences_session_only); | 193 return &(i->second->incognito_profile_preferences_session_only); |
194 } | 194 } |
195 NOTREACHED(); | 195 NOTREACHED(); |
196 return NULL; | 196 return nullptr; |
197 } | 197 } |
198 | 198 |
199 const PrefValueMap* ExtensionPrefValueMap::GetExtensionPrefValueMap( | 199 const PrefValueMap* ExtensionPrefValueMap::GetExtensionPrefValueMap( |
200 const std::string& ext_id, | 200 const std::string& ext_id, |
201 ExtensionPrefsScope scope) const { | 201 ExtensionPrefsScope scope) const { |
202 ExtensionEntryMap::const_iterator i = entries_.find(ext_id); | 202 ExtensionEntryMap::const_iterator i = entries_.find(ext_id); |
203 CHECK(i != entries_.end()); | 203 CHECK(i != entries_.end()); |
204 switch (scope) { | 204 switch (scope) { |
205 case extensions::kExtensionPrefsScopeRegular: | 205 case extensions::kExtensionPrefsScopeRegular: |
206 return &(i->second->regular_profile_preferences); | 206 return &(i->second->regular_profile_preferences); |
207 case extensions::kExtensionPrefsScopeRegularOnly: | 207 case extensions::kExtensionPrefsScopeRegularOnly: |
208 return &(i->second->regular_only_profile_preferences); | 208 return &(i->second->regular_only_profile_preferences); |
209 case extensions::kExtensionPrefsScopeIncognitoPersistent: | 209 case extensions::kExtensionPrefsScopeIncognitoPersistent: |
210 return &(i->second->incognito_profile_preferences_persistent); | 210 return &(i->second->incognito_profile_preferences_persistent); |
211 case extensions::kExtensionPrefsScopeIncognitoSessionOnly: | 211 case extensions::kExtensionPrefsScopeIncognitoSessionOnly: |
212 return &(i->second->incognito_profile_preferences_session_only); | 212 return &(i->second->incognito_profile_preferences_session_only); |
213 } | 213 } |
214 NOTREACHED(); | 214 NOTREACHED(); |
215 return NULL; | 215 return nullptr; |
216 } | 216 } |
217 | 217 |
218 void ExtensionPrefValueMap::GetExtensionControlledKeys( | 218 void ExtensionPrefValueMap::GetExtensionControlledKeys( |
219 const ExtensionEntry& entry, | 219 const ExtensionEntry& entry, |
220 std::set<std::string>* out) const { | 220 std::set<std::string>* out) const { |
221 PrefValueMap::const_iterator i; | 221 PrefValueMap::const_iterator i; |
222 | 222 |
223 const PrefValueMap& regular_prefs = entry.regular_profile_preferences; | 223 const PrefValueMap& regular_prefs = entry.regular_profile_preferences; |
224 for (i = regular_prefs.begin(); i != regular_prefs.end(); ++i) | 224 for (i = regular_prefs.begin(); i != regular_prefs.end(); ++i) |
225 out->insert(i->first); | 225 out->insert(i->first); |
(...skipping 14 matching lines...) Expand all Loading... |
240 out->insert(i->first); | 240 out->insert(i->first); |
241 } | 241 } |
242 | 242 |
243 const base::Value* ExtensionPrefValueMap::GetEffectivePrefValue( | 243 const base::Value* ExtensionPrefValueMap::GetEffectivePrefValue( |
244 const std::string& key, | 244 const std::string& key, |
245 bool incognito, | 245 bool incognito, |
246 bool* from_incognito) const { | 246 bool* from_incognito) const { |
247 ExtensionEntryMap::const_iterator winner = | 247 ExtensionEntryMap::const_iterator winner = |
248 GetEffectivePrefValueController(key, incognito, from_incognito); | 248 GetEffectivePrefValueController(key, incognito, from_incognito); |
249 if (winner == entries_.end()) | 249 if (winner == entries_.end()) |
250 return NULL; | 250 return nullptr; |
251 | 251 |
252 const base::Value* value = NULL; | 252 const base::Value* value = nullptr; |
253 const std::string& ext_id = winner->first; | 253 const std::string& ext_id = winner->first; |
254 | 254 |
255 // First search for incognito session only preferences. | 255 // First search for incognito session only preferences. |
256 if (incognito) { | 256 if (incognito) { |
257 DCHECK(winner->second->incognito_enabled); | 257 DCHECK(winner->second->incognito_enabled); |
258 const PrefValueMap* prefs = GetExtensionPrefValueMap( | 258 const PrefValueMap* prefs = GetExtensionPrefValueMap( |
259 ext_id, extensions::kExtensionPrefsScopeIncognitoSessionOnly); | 259 ext_id, extensions::kExtensionPrefsScopeIncognitoSessionOnly); |
260 prefs->GetValue(key, &value); | 260 prefs->GetValue(key, &value); |
261 if (value) | 261 if (value) |
262 return value; | 262 return value; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 const bool enabled = i->second->enabled; | 300 const bool enabled = i->second->enabled; |
301 const bool incognito_enabled = i->second->incognito_enabled; | 301 const bool incognito_enabled = i->second->incognito_enabled; |
302 | 302 |
303 if (!enabled) | 303 if (!enabled) |
304 continue; | 304 continue; |
305 if (install_time < winners_install_time) | 305 if (install_time < winners_install_time) |
306 continue; | 306 continue; |
307 if (incognito && !incognito_enabled) | 307 if (incognito && !incognito_enabled) |
308 continue; | 308 continue; |
309 | 309 |
310 const base::Value* value = NULL; | 310 const base::Value* value = nullptr; |
311 const PrefValueMap* prefs = GetExtensionPrefValueMap( | 311 const PrefValueMap* prefs = GetExtensionPrefValueMap( |
312 ext_id, extensions::kExtensionPrefsScopeRegular); | 312 ext_id, extensions::kExtensionPrefsScopeRegular); |
313 if (prefs->GetValue(key, &value)) { | 313 if (prefs->GetValue(key, &value)) { |
314 winner = i; | 314 winner = i; |
315 winners_install_time = install_time; | 315 winners_install_time = install_time; |
316 if (from_incognito) | 316 if (from_incognito) |
317 *from_incognito = false; | 317 *from_incognito = false; |
318 } | 318 } |
319 | 319 |
320 if (!incognito) { | 320 if (!incognito) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 } | 367 } |
368 | 368 |
369 void ExtensionPrefValueMap::RemoveObserver( | 369 void ExtensionPrefValueMap::RemoveObserver( |
370 ExtensionPrefValueMap::Observer* observer) { | 370 ExtensionPrefValueMap::Observer* observer) { |
371 observers_.RemoveObserver(observer); | 371 observers_.RemoveObserver(observer); |
372 } | 372 } |
373 | 373 |
374 std::string ExtensionPrefValueMap::GetExtensionControllingPref( | 374 std::string ExtensionPrefValueMap::GetExtensionControllingPref( |
375 const std::string& pref_key) const { | 375 const std::string& pref_key) const { |
376 ExtensionEntryMap::const_iterator winner = | 376 ExtensionEntryMap::const_iterator winner = |
377 GetEffectivePrefValueController(pref_key, false, NULL); | 377 GetEffectivePrefValueController(pref_key, false, nullptr); |
378 if (winner == entries_.end()) | 378 if (winner == entries_.end()) |
379 return std::string(); | 379 return std::string(); |
380 return winner->first; | 380 return winner->first; |
381 } | 381 } |
382 | 382 |
383 void ExtensionPrefValueMap::NotifyInitializationCompleted() { | 383 void ExtensionPrefValueMap::NotifyInitializationCompleted() { |
384 FOR_EACH_OBSERVER(ExtensionPrefValueMap::Observer, observers_, | 384 FOR_EACH_OBSERVER(ExtensionPrefValueMap::Observer, observers_, |
385 OnInitializationCompleted()); | 385 OnInitializationCompleted()); |
386 } | 386 } |
387 | 387 |
388 void ExtensionPrefValueMap::NotifyPrefValueChanged( | 388 void ExtensionPrefValueMap::NotifyPrefValueChanged( |
389 const std::set<std::string>& keys) { | 389 const std::set<std::string>& keys) { |
390 std::set<std::string>::const_iterator i; | 390 std::set<std::string>::const_iterator i; |
391 for (i = keys.begin(); i != keys.end(); ++i) | 391 for (i = keys.begin(); i != keys.end(); ++i) |
392 NotifyPrefValueChanged(*i); | 392 NotifyPrefValueChanged(*i); |
393 } | 393 } |
394 | 394 |
395 void ExtensionPrefValueMap::NotifyPrefValueChanged(const std::string& key) { | 395 void ExtensionPrefValueMap::NotifyPrefValueChanged(const std::string& key) { |
396 FOR_EACH_OBSERVER(ExtensionPrefValueMap::Observer, observers_, | 396 FOR_EACH_OBSERVER(ExtensionPrefValueMap::Observer, observers_, |
397 OnPrefValueChanged(key)); | 397 OnPrefValueChanged(key)); |
398 } | 398 } |
399 | 399 |
400 void ExtensionPrefValueMap::NotifyOfDestruction() { | 400 void ExtensionPrefValueMap::NotifyOfDestruction() { |
401 FOR_EACH_OBSERVER(ExtensionPrefValueMap::Observer, observers_, | 401 FOR_EACH_OBSERVER(ExtensionPrefValueMap::Observer, observers_, |
402 OnExtensionPrefValueMapDestruction()); | 402 OnExtensionPrefValueMapDestruction()); |
403 } | 403 } |
OLD | NEW |