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

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

Powered by Google App Engine
This is Rietveld 408576698