Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1147)

Side by Side Diff: chrome/browser/content_settings/content_settings_pref_provider.cc

Issue 8539004: Replace SetContentSetting method of the content_settings::Provider interface with GetWebsiteSetting (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/content_settings/content_settings_pref_provider.h" 5 #include "chrome/browser/content_settings/content_settings_pref_provider.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 } 144 }
145 145
146 pref_change_registrar_.Init(prefs_); 146 pref_change_registrar_.Init(prefs_);
147 pref_change_registrar_.Add(prefs::kContentSettingsPatterns, this); 147 pref_change_registrar_.Add(prefs::kContentSettingsPatterns, this);
148 pref_change_registrar_.Add(prefs::kContentSettingsPatternPairs, this); 148 pref_change_registrar_.Add(prefs::kContentSettingsPatternPairs, this);
149 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); 149 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this);
150 pref_change_registrar_.Add(prefs::kDesktopNotificationAllowedOrigins, this); 150 pref_change_registrar_.Add(prefs::kDesktopNotificationAllowedOrigins, this);
151 pref_change_registrar_.Add(prefs::kDesktopNotificationDeniedOrigins, this); 151 pref_change_registrar_.Add(prefs::kDesktopNotificationDeniedOrigins, this);
152 } 152 }
153 153
154 void PrefProvider::SetContentSetting( 154 bool PrefProvider::SetWebsiteSetting(
155 const ContentSettingsPattern& primary_pattern, 155 const ContentSettingsPattern& primary_pattern,
156 const ContentSettingsPattern& secondary_pattern, 156 const ContentSettingsPattern& secondary_pattern,
157 ContentSettingsType content_type, 157 ContentSettingsType content_type,
158 const ResourceIdentifier& resource_identifier, 158 const ResourceIdentifier& resource_identifier,
159 ContentSetting setting) { 159 Value* value) {
160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
161 DCHECK(prefs_); 161 DCHECK(prefs_);
162 162
163 // Default settings are set using a wildcard pattern for both
164 // |primary_pattern| and |secondary_pattern|. Don't store default settings in
165 // the |PrefProvider|. The |PrefProvider| handles settings for specific
166 // sites/origins defined by the |primary_pattern| and the |secondary_pattern|.
167 // Default settings are handled by the |DefaultProvider|.
168 if (primary_pattern == ContentSettingsPattern::Wildcard() &&
169 secondary_pattern == ContentSettingsPattern::Wildcard()) {
170 return false;
171 }
172
163 // Update in memory value map. 173 // Update in memory value map.
164 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; 174 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_;
165 if (!is_incognito_) 175 if (!is_incognito_)
166 map_to_modify = &value_map_; 176 map_to_modify = &value_map_;
167 177
168 { 178 {
169 base::AutoLock auto_lock(lock_); 179 base::AutoLock auto_lock(lock_);
170 if (setting == CONTENT_SETTING_DEFAULT) { 180 if (value == NULL) {
171 map_to_modify->DeleteValue( 181 map_to_modify->DeleteValue(
172 primary_pattern, 182 primary_pattern,
173 secondary_pattern, 183 secondary_pattern,
174 content_type, 184 content_type,
175 resource_identifier); 185 resource_identifier);
176 } else { 186 } else {
177 map_to_modify->SetValue( 187 map_to_modify->SetValue(
178 primary_pattern, 188 primary_pattern,
179 secondary_pattern, 189 secondary_pattern,
180 content_type, 190 content_type,
181 resource_identifier, 191 resource_identifier,
182 Value::CreateIntegerValue(setting)); 192 value->DeepCopy());
Bernhard Bauer 2011/11/15 15:40:28 You're leaking |value|.
markusheintz_ 2011/11/15 17:36:58 Done.
183 } 193 }
184 } 194 }
185 // Update the content settings preference. 195 // Update the content settings preference.
186 if (!is_incognito_) { 196 if (!is_incognito_) {
187 UpdatePref(primary_pattern, 197 UpdatePref(primary_pattern,
188 secondary_pattern, 198 secondary_pattern,
189 content_type, 199 content_type,
190 resource_identifier, 200 resource_identifier,
191 setting); 201 value);
192 prefs_->ScheduleSavePersistentPrefs(); 202 prefs_->ScheduleSavePersistentPrefs();
193 } 203 }
194 204
195 NotifyObservers( 205 NotifyObservers(
196 primary_pattern, secondary_pattern, content_type, resource_identifier); 206 primary_pattern, secondary_pattern, content_type, resource_identifier);
207
208 return true;
197 } 209 }
198 210
199 void PrefProvider::ClearAllContentSettingsRules( 211 void PrefProvider::ClearAllContentSettingsRules(
200 ContentSettingsType content_type) { 212 ContentSettingsType content_type) {
201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
202 DCHECK(prefs_); 214 DCHECK(prefs_);
203 215
204 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; 216 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_;
205 if (!is_incognito_) 217 if (!is_incognito_)
206 map_to_modify = &value_map_; 218 map_to_modify = &value_map_;
(...skipping 11 matching lines...) Expand all
218 prefs_->ScheduleSavePersistentPrefs(); 230 prefs_->ScheduleSavePersistentPrefs();
219 } 231 }
220 232
221 for (std::vector<Rule>::const_iterator it = rules_to_delete.begin(); 233 for (std::vector<Rule>::const_iterator it = rules_to_delete.begin();
222 it != rules_to_delete.end(); ++it) { 234 it != rules_to_delete.end(); ++it) {
223 UpdatePref( 235 UpdatePref(
224 it->primary_pattern, 236 it->primary_pattern,
225 it->secondary_pattern, 237 it->secondary_pattern,
226 content_type, 238 content_type,
227 "", 239 "",
228 CONTENT_SETTING_DEFAULT); 240 NULL);
229 } 241 }
230 NotifyObservers(ContentSettingsPattern(), 242 NotifyObservers(ContentSettingsPattern(),
231 ContentSettingsPattern(), 243 ContentSettingsPattern(),
232 content_type, 244 content_type,
233 std::string()); 245 std::string());
234 } 246 }
235 247
236 void PrefProvider::Observe( 248 void PrefProvider::Observe(
237 int type, 249 int type,
238 const content::NotificationSource& source, 250 const content::NotificationSource& source,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 } 302 }
291 303
292 // //////////////////////////////////////////////////////////////////////////// 304 // ////////////////////////////////////////////////////////////////////////////
293 // Private 305 // Private
294 306
295 void PrefProvider::UpdatePref( 307 void PrefProvider::UpdatePref(
296 const ContentSettingsPattern& primary_pattern, 308 const ContentSettingsPattern& primary_pattern,
297 const ContentSettingsPattern& secondary_pattern, 309 const ContentSettingsPattern& secondary_pattern,
298 ContentSettingsType content_type, 310 ContentSettingsType content_type,
299 const ResourceIdentifier& resource_identifier, 311 const ResourceIdentifier& resource_identifier,
300 ContentSetting setting) { 312 const base::Value* value) {
301 // Ensure that |lock_| is not held by this thread, since this function will 313 // Ensure that |lock_| is not held by this thread, since this function will
302 // send out notifications (by |~DictionaryPrefUpdate|). 314 // send out notifications (by |~DictionaryPrefUpdate|).
303 AssertLockNotHeld(); 315 AssertLockNotHeld();
304 316
305 AutoReset<bool> auto_reset(&updating_preferences_, true); 317 AutoReset<bool> auto_reset(&updating_preferences_, true);
306 { 318 {
307 DictionaryPrefUpdate update(prefs_, 319 DictionaryPrefUpdate update(prefs_,
308 prefs::kContentSettingsPatternPairs); 320 prefs::kContentSettingsPatternPairs);
309 DictionaryValue* pattern_pairs_settings = update.Get(); 321 DictionaryValue* pattern_pairs_settings = update.Get();
310 UpdatePatternPairsSettings(primary_pattern, 322 UpdatePatternPairsSettings(primary_pattern,
311 secondary_pattern, 323 secondary_pattern,
312 content_type, 324 content_type,
313 resource_identifier, 325 resource_identifier,
314 setting, 326 value,
315 pattern_pairs_settings); 327 pattern_pairs_settings);
316 } 328 }
317 if (content_type != CONTENT_SETTINGS_TYPE_GEOLOCATION && 329 if (content_type != CONTENT_SETTINGS_TYPE_GEOLOCATION &&
318 content_type != CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { 330 content_type != CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
319 UpdateObsoletePatternsPref(primary_pattern, 331 UpdateObsoletePatternsPref(primary_pattern,
320 secondary_pattern, 332 secondary_pattern,
321 content_type, 333 content_type,
322 resource_identifier, 334 resource_identifier,
323 setting); 335 ValueToContentSetting(value));
324 } else if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { 336 } else if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
325 UpdateObsoleteGeolocationPref(primary_pattern, secondary_pattern, setting); 337 UpdateObsoleteGeolocationPref(
338 primary_pattern,
339 secondary_pattern,
340 ValueToContentSetting(value));
326 } else if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { 341 } else if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
327 ListPrefUpdate update_allowed_sites( 342 ListPrefUpdate update_allowed_sites(
328 prefs_, prefs::kDesktopNotificationAllowedOrigins); 343 prefs_, prefs::kDesktopNotificationAllowedOrigins);
329 ListPrefUpdate update_denied_sites( 344 ListPrefUpdate update_denied_sites(
330 prefs_, prefs::kDesktopNotificationDeniedOrigins); 345 prefs_, prefs::kDesktopNotificationDeniedOrigins);
331 UpdateObsoleteNotificationsSettings(primary_pattern, 346 UpdateObsoleteNotificationsSettings(primary_pattern,
332 secondary_pattern, 347 secondary_pattern,
333 setting, 348 ValueToContentSetting(value),
334 update_allowed_sites.Get(), 349 update_allowed_sites.Get(),
335 update_denied_sites.Get()); 350 update_denied_sites.Get());
336 } 351 }
337 } 352 }
338 353
339 void PrefProvider::ReadContentSettingsFromPref(bool overwrite) { 354 void PrefProvider::ReadContentSettingsFromPref(bool overwrite) {
340 // |DictionaryPrefUpdate| sends out notifications when destructed. This 355 // |DictionaryPrefUpdate| sends out notifications when destructed. This
341 // construction order ensures |AutoLock| gets destroyed first and |lock_| is 356 // construction order ensures |AutoLock| gets destroyed first and |lock_| is
342 // not held when the notifications are sent. Also, |auto_reset| must be still 357 // not held when the notifications are sent. Also, |auto_reset| must be still
343 // valid when the notifications are sent, so that |Observe| skips the 358 // valid when the notifications are sent, so that |Observe| skips the
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 } 515 }
501 } 516 }
502 } 517 }
503 } 518 }
504 519
505 void PrefProvider::UpdatePatternPairsSettings( 520 void PrefProvider::UpdatePatternPairsSettings(
506 const ContentSettingsPattern& primary_pattern, 521 const ContentSettingsPattern& primary_pattern,
507 const ContentSettingsPattern& secondary_pattern, 522 const ContentSettingsPattern& secondary_pattern,
508 ContentSettingsType content_type, 523 ContentSettingsType content_type,
509 const ResourceIdentifier& resource_identifier, 524 const ResourceIdentifier& resource_identifier,
510 ContentSetting setting, 525 const base::Value* value,
511 DictionaryValue* pattern_pairs_settings) { 526 DictionaryValue* pattern_pairs_settings) {
512 // Get settings dictionary for the given patterns. 527 // Get settings dictionary for the given patterns.
513 std::string pattern_str(CreatePatternString(primary_pattern, 528 std::string pattern_str(CreatePatternString(primary_pattern,
514 secondary_pattern)); 529 secondary_pattern));
515 DictionaryValue* settings_dictionary = NULL; 530 DictionaryValue* settings_dictionary = NULL;
516 bool found = pattern_pairs_settings->GetDictionaryWithoutPathExpansion( 531 bool found = pattern_pairs_settings->GetDictionaryWithoutPathExpansion(
517 pattern_str, &settings_dictionary); 532 pattern_str, &settings_dictionary);
518 533
519 if (!found && (setting != CONTENT_SETTING_DEFAULT)) { 534 if (!found && value) {
520 settings_dictionary = new DictionaryValue; 535 settings_dictionary = new DictionaryValue;
521 pattern_pairs_settings->SetWithoutPathExpansion( 536 pattern_pairs_settings->SetWithoutPathExpansion(
522 pattern_str, settings_dictionary); 537 pattern_str, settings_dictionary);
523 } 538 }
524 539
525 if (settings_dictionary) { 540 if (settings_dictionary) {
526 std::string res_dictionary_path; 541 std::string res_dictionary_path;
527 if (GetResourceTypeName(content_type, &res_dictionary_path)) { 542 if (GetResourceTypeName(content_type, &res_dictionary_path)) {
528 DictionaryValue* resource_dictionary = NULL; 543 DictionaryValue* resource_dictionary = NULL;
529 found = settings_dictionary->GetDictionary( 544 found = settings_dictionary->GetDictionary(
530 res_dictionary_path, &resource_dictionary); 545 res_dictionary_path, &resource_dictionary);
531 if (!found) { 546 if (!found) {
532 if (setting == CONTENT_SETTING_DEFAULT) 547 if (value == NULL)
533 return; // Nothing to remove. Exit early. 548 return; // Nothing to remove. Exit early.
534 resource_dictionary = new DictionaryValue; 549 resource_dictionary = new DictionaryValue;
535 settings_dictionary->Set(res_dictionary_path, resource_dictionary); 550 settings_dictionary->Set(res_dictionary_path, resource_dictionary);
536 } 551 }
537 // Update resource dictionary. 552 // Update resource dictionary.
538 if (setting == CONTENT_SETTING_DEFAULT) { 553 if (value == NULL) {
539 resource_dictionary->RemoveWithoutPathExpansion(resource_identifier, 554 resource_dictionary->RemoveWithoutPathExpansion(resource_identifier,
540 NULL); 555 NULL);
541 if (resource_dictionary->empty()) { 556 if (resource_dictionary->empty()) {
542 settings_dictionary->RemoveWithoutPathExpansion( 557 settings_dictionary->RemoveWithoutPathExpansion(
543 res_dictionary_path, NULL); 558 res_dictionary_path, NULL);
544 } 559 }
545 } else { 560 } else {
546 resource_dictionary->SetWithoutPathExpansion( 561 resource_dictionary->SetWithoutPathExpansion(
547 resource_identifier, Value::CreateIntegerValue(setting)); 562 resource_identifier, value->DeepCopy());
548 } 563 }
549 } else { 564 } else {
550 // Update settings dictionary. 565 // Update settings dictionary.
551 std::string setting_path = GetTypeName(content_type); 566 std::string setting_path = GetTypeName(content_type);
552 if (setting == CONTENT_SETTING_DEFAULT) { 567 if (value == NULL) {
553 settings_dictionary->RemoveWithoutPathExpansion(setting_path, 568 settings_dictionary->RemoveWithoutPathExpansion(setting_path,
554 NULL); 569 NULL);
555 } else { 570 } else {
556 settings_dictionary->SetWithoutPathExpansion( 571 settings_dictionary->SetWithoutPathExpansion(
557 setting_path, Value::CreateIntegerValue(setting)); 572 setting_path, value->DeepCopy());
558 } 573 }
559 } 574 }
560 // Remove the settings dictionary if it is empty. 575 // Remove the settings dictionary if it is empty.
561 if (settings_dictionary->empty()) { 576 if (settings_dictionary->empty()) {
562 pattern_pairs_settings->RemoveWithoutPathExpansion( 577 pattern_pairs_settings->RemoveWithoutPathExpansion(
563 pattern_str, NULL); 578 pattern_str, NULL);
564 } 579 }
565 } 580 }
566 } 581 }
567 582
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 ContentSettingsType content_type = static_cast<ContentSettingsType>(i); 730 ContentSettingsType content_type = static_cast<ContentSettingsType>(i);
716 731
717 int setting_int_value = CONTENT_SETTING_DEFAULT; 732 int setting_int_value = CONTENT_SETTING_DEFAULT;
718 if (host_settings_dictionary->GetIntegerWithoutPathExpansion( 733 if (host_settings_dictionary->GetIntegerWithoutPathExpansion(
719 GetTypeName(content_type), &setting_int_value)) { 734 GetTypeName(content_type), &setting_int_value)) {
720 ContentSetting setting = IntToContentSetting(setting_int_value); 735 ContentSetting setting = IntToContentSetting(setting_int_value);
721 736
722 setting = FixObsoleteCookiePromptMode(content_type, setting); 737 setting = FixObsoleteCookiePromptMode(content_type, setting);
723 setting = ClickToPlayFixup(content_type, setting); 738 setting = ClickToPlayFixup(content_type, setting);
724 739
725 // TODO(markusheintz): Maybe this check can be removed. 740 scoped_ptr<base::Value> value(Value::CreateIntegerValue(setting));
726 if (setting != CONTENT_SETTING_DEFAULT) { 741 if (setting != CONTENT_SETTING_DEFAULT) {
727 SetContentSetting( 742 SetWebsiteSetting(
728 pattern, 743 pattern,
729 pattern, 744 pattern,
730 content_type, 745 content_type,
731 "", 746 "",
732 setting); 747 value.get());
Bernhard Bauer 2011/11/15 15:40:28 |SetWebsiteSetting| takes ownership of |value|, so
markusheintz_ 2011/11/15 17:36:58 Done.
733 } 748 }
734 } 749 }
735 } 750 }
736 } 751 }
737 prefs_->ClearPref(prefs::kPerHostContentSettings); 752 prefs_->ClearPref(prefs::kPerHostContentSettings);
738 } 753 }
739 } 754 }
740 755
741 void PrefProvider::MigrateObsoletePopupsPref() { 756 void PrefProvider::MigrateObsoletePopupsPref() {
742 if (prefs_->HasPrefPath(prefs::kPopupWhitelistedHosts)) { 757 if (prefs_->HasPrefPath(prefs::kPopupWhitelistedHosts)) {
743 const ListValue* whitelist_pref = 758 const ListValue* whitelist_pref =
744 prefs_->GetList(prefs::kPopupWhitelistedHosts); 759 prefs_->GetList(prefs::kPopupWhitelistedHosts);
745 for (ListValue::const_iterator i(whitelist_pref->begin()); 760 for (ListValue::const_iterator i(whitelist_pref->begin());
746 i != whitelist_pref->end(); ++i) { 761 i != whitelist_pref->end(); ++i) {
747 std::string host; 762 std::string host;
748 (*i)->GetAsString(&host); 763 (*i)->GetAsString(&host);
749 SetContentSetting(ContentSettingsPattern::FromString(host), 764 scoped_ptr<base::Value> value(Value::CreateIntegerValue(
765 CONTENT_SETTING_ALLOW));
766 SetWebsiteSetting(ContentSettingsPattern::FromString(host),
750 ContentSettingsPattern::FromString(host), 767 ContentSettingsPattern::FromString(host),
751 CONTENT_SETTINGS_TYPE_POPUPS, 768 CONTENT_SETTINGS_TYPE_POPUPS,
752 "", 769 "",
753 CONTENT_SETTING_ALLOW); 770 value.get());
Bernhard Bauer 2011/11/15 15:40:28 Same here.
markusheintz_ 2011/11/15 17:36:58 Done.
754 } 771 }
755 prefs_->ClearPref(prefs::kPopupWhitelistedHosts); 772 prefs_->ClearPref(prefs::kPopupWhitelistedHosts);
756 } 773 }
757 } 774 }
758 775
759 void PrefProvider::MigrateObsoleteContentSettingsPatternPref() { 776 void PrefProvider::MigrateObsoleteContentSettingsPatternPref() {
760 // Ensure that |lock_| is not held by this thread, since this function will 777 // Ensure that |lock_| is not held by this thread, since this function will
761 // send out notifications (by |~DictionaryPrefUpdate|). 778 // send out notifications (by |~DictionaryPrefUpdate|).
762 AssertLockNotHeld(); 779 AssertLockNotHeld();
763 780
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 DCHECK(found); 941 DCHECK(found);
925 942
926 for (DictionaryValue::key_iterator j = 943 for (DictionaryValue::key_iterator j =
927 requesting_origin_settings->begin_keys(); 944 requesting_origin_settings->begin_keys();
928 j != requesting_origin_settings->end_keys(); 945 j != requesting_origin_settings->end_keys();
929 ++j) { 946 ++j) {
930 const std::string& secondary_key(*j); 947 const std::string& secondary_key(*j);
931 GURL secondary_url(secondary_key); 948 GURL secondary_url(secondary_key);
932 DCHECK(secondary_url.is_valid()); 949 DCHECK(secondary_url.is_valid());
933 950
934 int setting_value; 951 base::Value* value = NULL;
935 found = requesting_origin_settings->GetIntegerWithoutPathExpansion( 952 found = requesting_origin_settings->GetWithoutPathExpansion(
936 secondary_key, &setting_value); 953 secondary_key, &value);
937 DCHECK(found); 954 DCHECK(found);
938 955
939 ContentSettingsPattern primary_pattern = 956 ContentSettingsPattern primary_pattern =
940 ContentSettingsPattern::FromURLNoWildcard(primary_url); 957 ContentSettingsPattern::FromURLNoWildcard(primary_url);
941 ContentSettingsPattern secondary_pattern = 958 ContentSettingsPattern secondary_pattern =
942 ContentSettingsPattern::FromURLNoWildcard(secondary_url); 959 ContentSettingsPattern::FromURLNoWildcard(secondary_url);
943 DCHECK(primary_pattern.IsValid() && secondary_pattern.IsValid()); 960 DCHECK(primary_pattern.IsValid() && secondary_pattern.IsValid());
944 961
945 UpdatePatternPairsSettings(primary_pattern, 962 UpdatePatternPairsSettings(primary_pattern,
946 secondary_pattern, 963 secondary_pattern,
947 CONTENT_SETTINGS_TYPE_GEOLOCATION, 964 CONTENT_SETTINGS_TYPE_GEOLOCATION,
948 std::string(), 965 std::string(),
949 IntToContentSetting(setting_value), 966 value,
950 pattern_pairs_settings); 967 pattern_pairs_settings);
951 } 968 }
952 } 969 }
953 } 970 }
954 971
955 void PrefProvider::MigrateObsoleteNotificationsPrefs() { 972 void PrefProvider::MigrateObsoleteNotificationsPrefs() {
956 // Ensure that |lock_| is not held by this thread, since this function will 973 // Ensure that |lock_| is not held by this thread, since this function will
957 // send out notifications (by |~DictionaryPrefUpdate|). 974 // send out notifications (by |~DictionaryPrefUpdate|).
958 AssertLockNotHeld(); 975 AssertLockNotHeld();
959 976
960 // The notifications settings in the preferences 977 // The notifications settings in the preferences
961 // prefs::kContentSettingsPatternPairs do not contain the latest 978 // prefs::kContentSettingsPatternPairs do not contain the latest
962 // notifications settings. So all notification settings are cleared and 979 // notifications settings. So all notification settings are cleared and
963 // migrated from the obsolete preferences for notifications settings that 980 // migrated from the obsolete preferences for notifications settings that
964 // contain the latest settings. 981 // contain the latest settings.
965 DictionaryPrefUpdate update(prefs_, prefs::kContentSettingsPatternPairs); 982 DictionaryPrefUpdate update(prefs_, prefs::kContentSettingsPatternPairs);
966 DictionaryValue* pattern_pairs_settings = update.Get(); 983 DictionaryValue* pattern_pairs_settings = update.Get();
967 ClearSettings(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, pattern_pairs_settings); 984 ClearSettings(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, pattern_pairs_settings);
968 985
969 const ListValue* allowed_origins = 986 const ListValue* allowed_origins =
970 prefs_->GetList(prefs::kDesktopNotificationAllowedOrigins); 987 prefs_->GetList(prefs::kDesktopNotificationAllowedOrigins);
971 for (size_t i = 0; i < allowed_origins->GetSize(); ++i) { 988 for (size_t i = 0; i < allowed_origins->GetSize(); ++i) {
972 std::string url_string; 989 std::string url_string;
973 bool status = allowed_origins->GetString(i, &url_string); 990 bool status = allowed_origins->GetString(i, &url_string);
974 DCHECK(status); 991 DCHECK(status);
975 ContentSettingsPattern primary_pattern = 992 ContentSettingsPattern primary_pattern =
976 ContentSettingsPattern::FromURLNoWildcard(GURL(url_string)); 993 ContentSettingsPattern::FromURLNoWildcard(GURL(url_string));
977 DCHECK(primary_pattern.IsValid()); 994 DCHECK(primary_pattern.IsValid());
995 scoped_ptr<base::Value> value(
996 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
978 UpdatePatternPairsSettings(primary_pattern, 997 UpdatePatternPairsSettings(primary_pattern,
979 ContentSettingsPattern::Wildcard(), 998 ContentSettingsPattern::Wildcard(),
980 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 999 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
981 std::string(), 1000 std::string(),
982 CONTENT_SETTING_ALLOW, 1001 value.get(),
983 pattern_pairs_settings); 1002 pattern_pairs_settings);
984 } 1003 }
985 1004
986 const ListValue* denied_origins = 1005 const ListValue* denied_origins =
987 prefs_->GetList(prefs::kDesktopNotificationDeniedOrigins); 1006 prefs_->GetList(prefs::kDesktopNotificationDeniedOrigins);
988 for (size_t i = 0; i < denied_origins->GetSize(); ++i) { 1007 for (size_t i = 0; i < denied_origins->GetSize(); ++i) {
989 std::string url_string; 1008 std::string url_string;
990 bool status = denied_origins->GetString(i, &url_string); 1009 bool status = denied_origins->GetString(i, &url_string);
991 DCHECK(status); 1010 DCHECK(status);
992 ContentSettingsPattern primary_pattern = 1011 ContentSettingsPattern primary_pattern =
993 ContentSettingsPattern::FromURLNoWildcard(GURL(url_string)); 1012 ContentSettingsPattern::FromURLNoWildcard(GURL(url_string));
994 DCHECK(primary_pattern.IsValid()); 1013 DCHECK(primary_pattern.IsValid());
1014 scoped_ptr<base::Value> value(
1015 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
995 UpdatePatternPairsSettings(primary_pattern, 1016 UpdatePatternPairsSettings(primary_pattern,
996 ContentSettingsPattern::Wildcard(), 1017 ContentSettingsPattern::Wildcard(),
997 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 1018 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
998 std::string(), 1019 std::string(),
999 CONTENT_SETTING_BLOCK, 1020 value.get(),
1000 pattern_pairs_settings); 1021 pattern_pairs_settings);
1001 } 1022 }
1002 } 1023 }
1003 1024
1004 void PrefProvider::SyncObsoletePrefs() { 1025 void PrefProvider::SyncObsoletePrefs() {
1005 // Ensure that |lock_| is not held by this thread, since this function will 1026 // Ensure that |lock_| is not held by this thread, since this function will
1006 // send out notifications (by |~DictionaryPrefUpdate|). 1027 // send out notifications (by |~DictionaryPrefUpdate|).
1007 AssertLockNotHeld(); 1028 AssertLockNotHeld();
1008 1029
1009 DCHECK(prefs_); 1030 DCHECK(prefs_);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 1080
1060 void PrefProvider::AssertLockNotHeld() const { 1081 void PrefProvider::AssertLockNotHeld() const {
1061 #if !defined(NDEBUG) 1082 #if !defined(NDEBUG)
1062 // |Lock::Acquire()| will assert if the lock is held by this thread. 1083 // |Lock::Acquire()| will assert if the lock is held by this thread.
1063 lock_.Acquire(); 1084 lock_.Acquire();
1064 lock_.Release(); 1085 lock_.Release();
1065 #endif 1086 #endif
1066 } 1087 }
1067 1088
1068 } // namespace content_settings 1089 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698