OLD | NEW |
---|---|
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 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
585 const ContentSettingsPattern& primary_pattern, | 585 const ContentSettingsPattern& primary_pattern, |
586 const ContentSettingsPattern& secondary_pattern, | 586 const ContentSettingsPattern& secondary_pattern, |
587 ContentSetting setting) { | 587 ContentSetting setting) { |
588 // Ensure that |lock_| is not held by this thread, since this function will | 588 // Ensure that |lock_| is not held by this thread, since this function will |
589 // send out notifications (by |~DictionaryPrefUpdate|). | 589 // send out notifications (by |~DictionaryPrefUpdate|). |
590 AssertLockNotHeld(); | 590 AssertLockNotHeld(); |
591 | 591 |
592 if (!prefs_) | 592 if (!prefs_) |
593 return; | 593 return; |
594 | 594 |
595 // Ignor settings with wildcard patterns as they are not supported by the | |
Bernhard Bauer
2011/11/23 18:43:33
Nit: "Ignore"
markusheintz_
2011/11/23 18:52:28
Done.
| |
596 // obsolete preference. | |
597 if (primary_pattern == ContentSettingsPattern::Wildcard() || | |
598 secondary_pattern == ContentSettingsPattern::Wildcard()) { | |
599 return; | |
600 } | |
601 | |
595 const GURL requesting_origin(primary_pattern.ToString()); | 602 const GURL requesting_origin(primary_pattern.ToString()); |
596 const GURL embedding_origin(secondary_pattern.ToString()); | 603 const GURL embedding_origin(secondary_pattern.ToString()); |
597 DCHECK(requesting_origin.is_valid() && embedding_origin.is_valid()); | 604 DCHECK(requesting_origin.is_valid() && embedding_origin.is_valid()); |
598 | 605 |
599 DictionaryPrefUpdate update(prefs_, prefs::kGeolocationContentSettings); | 606 DictionaryPrefUpdate update(prefs_, prefs::kGeolocationContentSettings); |
600 DictionaryValue* obsolete_geolocation_settings = update.Get(); | 607 DictionaryValue* obsolete_geolocation_settings = update.Get(); |
601 DictionaryValue* requesting_origin_settings_dictionary = NULL; | 608 DictionaryValue* requesting_origin_settings_dictionary = NULL; |
602 obsolete_geolocation_settings->GetDictionaryWithoutPathExpansion( | 609 obsolete_geolocation_settings->GetDictionaryWithoutPathExpansion( |
603 requesting_origin.spec(), &requesting_origin_settings_dictionary); | 610 requesting_origin.spec(), &requesting_origin_settings_dictionary); |
604 if (setting == CONTENT_SETTING_DEFAULT) { | 611 if (setting == CONTENT_SETTING_DEFAULT) { |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
919 | 926 |
920 if (!prefs_->HasPrefPath(prefs::kGeolocationContentSettings)) | 927 if (!prefs_->HasPrefPath(prefs::kGeolocationContentSettings)) |
921 return; | 928 return; |
922 | 929 |
923 DictionaryPrefUpdate update(prefs_, | 930 DictionaryPrefUpdate update(prefs_, |
924 prefs::kContentSettingsPatternPairs); | 931 prefs::kContentSettingsPatternPairs); |
925 DictionaryValue* pattern_pairs_settings = update.Get(); | 932 DictionaryValue* pattern_pairs_settings = update.Get(); |
926 | 933 |
927 const DictionaryValue* geolocation_settings = | 934 const DictionaryValue* geolocation_settings = |
928 prefs_->GetDictionary(prefs::kGeolocationContentSettings); | 935 prefs_->GetDictionary(prefs::kGeolocationContentSettings); |
936 | |
937 std::vector<std::pair<std::string, std::string> > corrupted_keys; | |
929 for (DictionaryValue::key_iterator i = | 938 for (DictionaryValue::key_iterator i = |
930 geolocation_settings->begin_keys(); | 939 geolocation_settings->begin_keys(); |
931 i != geolocation_settings->end_keys(); | 940 i != geolocation_settings->end_keys(); |
932 ++i) { | 941 ++i) { |
933 const std::string& primary_key(*i); | 942 const std::string& primary_key(*i); |
934 GURL primary_url(primary_key); | 943 GURL primary_url(primary_key); |
935 DCHECK(primary_url.is_valid()); | 944 DCHECK(primary_url.is_valid()); |
936 | 945 |
937 DictionaryValue* requesting_origin_settings = NULL; | 946 DictionaryValue* requesting_origin_settings = NULL; |
938 bool found = geolocation_settings->GetDictionaryWithoutPathExpansion( | 947 bool found = geolocation_settings->GetDictionaryWithoutPathExpansion( |
939 primary_key, &requesting_origin_settings); | 948 primary_key, &requesting_origin_settings); |
940 DCHECK(found); | 949 DCHECK(found); |
941 | 950 |
942 for (DictionaryValue::key_iterator j = | 951 for (DictionaryValue::key_iterator j = |
943 requesting_origin_settings->begin_keys(); | 952 requesting_origin_settings->begin_keys(); |
944 j != requesting_origin_settings->end_keys(); | 953 j != requesting_origin_settings->end_keys(); |
945 ++j) { | 954 ++j) { |
946 const std::string& secondary_key(*j); | 955 const std::string& secondary_key(*j); |
947 GURL secondary_url(secondary_key); | 956 GURL secondary_url(secondary_key); |
948 DCHECK(secondary_url.is_valid()); | 957 // Save corrupted keys to remove them later. |
958 if (!secondary_url.is_valid()) { | |
959 corrupted_keys.push_back(std::make_pair(primary_key, secondary_key)); | |
960 continue; | |
961 } | |
949 | 962 |
950 base::Value* value = NULL; | 963 base::Value* value = NULL; |
951 found = requesting_origin_settings->GetWithoutPathExpansion( | 964 found = requesting_origin_settings->GetWithoutPathExpansion( |
952 secondary_key, &value); | 965 secondary_key, &value); |
953 DCHECK(found); | 966 DCHECK(found); |
954 | 967 |
955 ContentSettingsPattern primary_pattern = | 968 ContentSettingsPattern primary_pattern = |
956 ContentSettingsPattern::FromURLNoWildcard(primary_url); | 969 ContentSettingsPattern::FromURLNoWildcard(primary_url); |
957 ContentSettingsPattern secondary_pattern = | 970 ContentSettingsPattern secondary_pattern = |
958 ContentSettingsPattern::FromURLNoWildcard(secondary_url); | 971 ContentSettingsPattern::FromURLNoWildcard(secondary_url); |
959 DCHECK(primary_pattern.IsValid() && secondary_pattern.IsValid()); | 972 DCHECK(primary_pattern.IsValid() && secondary_pattern.IsValid()); |
960 | 973 |
961 UpdatePatternPairsSettings(primary_pattern, | 974 UpdatePatternPairsSettings(primary_pattern, |
962 secondary_pattern, | 975 secondary_pattern, |
963 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 976 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
964 std::string(), | 977 std::string(), |
965 value, | 978 value, |
966 pattern_pairs_settings); | 979 pattern_pairs_settings); |
967 } | 980 } |
968 } | 981 } |
982 | |
983 // Remove corrupted keys. | |
984 DictionaryPrefUpdate update_geo_settings( | |
985 prefs_, prefs::kGeolocationContentSettings); | |
986 base::DictionaryValue* geo_dict = update_geo_settings.Get(); | |
987 std::vector<std::pair<std::string, std::string> >::iterator key_pair; | |
988 for (key_pair = corrupted_keys.begin(); | |
989 key_pair != corrupted_keys.end(); | |
990 ++key_pair) { | |
991 base::DictionaryValue* dict; | |
992 bool found = geo_dict->GetDictionaryWithoutPathExpansion( | |
993 key_pair->first, &dict); | |
994 DCHECK(found); | |
995 DCHECK(dict->HasKey(key_pair->second)); | |
996 dict->RemoveWithoutPathExpansion(key_pair->second, NULL); | |
997 if (dict->empty()) | |
Bernhard Bauer
2011/11/23 18:43:33
Removing empty dictionaries isn't necessary; the P
markusheintz_
2011/11/23 18:52:28
True! We recently talked about this.
| |
998 geo_dict->RemoveWithoutPathExpansion(key_pair->first, NULL); | |
999 } | |
969 } | 1000 } |
970 | 1001 |
971 void PrefProvider::MigrateObsoleteNotificationsPrefs() { | 1002 void PrefProvider::MigrateObsoleteNotificationsPrefs() { |
972 // Ensure that |lock_| is not held by this thread, since this function will | 1003 // Ensure that |lock_| is not held by this thread, since this function will |
973 // send out notifications (by |~DictionaryPrefUpdate|). | 1004 // send out notifications (by |~DictionaryPrefUpdate|). |
974 AssertLockNotHeld(); | 1005 AssertLockNotHeld(); |
975 | 1006 |
976 // The notifications settings in the preferences | 1007 // The notifications settings in the preferences |
977 // prefs::kContentSettingsPatternPairs do not contain the latest | 1008 // prefs::kContentSettingsPatternPairs do not contain the latest |
978 // notifications settings. So all notification settings are cleared and | 1009 // notifications settings. So all notification settings are cleared and |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1079 | 1110 |
1080 void PrefProvider::AssertLockNotHeld() const { | 1111 void PrefProvider::AssertLockNotHeld() const { |
1081 #if !defined(NDEBUG) | 1112 #if !defined(NDEBUG) |
1082 // |Lock::Acquire()| will assert if the lock is held by this thread. | 1113 // |Lock::Acquire()| will assert if the lock is held by this thread. |
1083 lock_.Acquire(); | 1114 lock_.Acquire(); |
1084 lock_.Release(); | 1115 lock_.Release(); |
1085 #endif | 1116 #endif |
1086 } | 1117 } |
1087 | 1118 |
1088 } // namespace content_settings | 1119 } // namespace content_settings |
OLD | NEW |