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

Side by Side Diff: components/content_settings/core/browser/host_content_settings_map.cc

Issue 2075103002: Change ContentSettingsType's scoping type and hookup migration code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@do_migration_after_sync
Patch Set: revise test Created 4 years, 4 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "components/content_settings/core/browser/host_content_settings_map.h" 5 #include "components/content_settings/core/browser/host_content_settings_map.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 128 }
129 129
130 content_settings::PatternPair GetPatternsFromScopingType( 130 content_settings::PatternPair GetPatternsFromScopingType(
131 WebsiteSettingsInfo::ScopingType scoping_type, 131 WebsiteSettingsInfo::ScopingType scoping_type,
132 const GURL& primary_url, 132 const GURL& primary_url,
133 const GURL& secondary_url) { 133 const GURL& secondary_url) {
134 DCHECK(!primary_url.is_empty()); 134 DCHECK(!primary_url.is_empty());
135 content_settings::PatternPair patterns; 135 content_settings::PatternPair patterns;
136 136
137 switch (scoping_type) { 137 switch (scoping_type) {
138 case WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE: 138 case WebsiteSettingsInfo::TOP_LEVEL_ORIGIN_ONLY_SCOPE:
139 case WebsiteSettingsInfo::REQUESTING_DOMAIN_ONLY_SCOPE:
140 patterns.first = ContentSettingsPattern::FromURL(primary_url);
141 patterns.second = ContentSettingsPattern::Wildcard();
142 break;
143 case WebsiteSettingsInfo::REQUESTING_ORIGIN_ONLY_SCOPE: 139 case WebsiteSettingsInfo::REQUESTING_ORIGIN_ONLY_SCOPE:
144 patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url); 140 patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url);
145 patterns.second = ContentSettingsPattern::Wildcard(); 141 patterns.second = ContentSettingsPattern::Wildcard();
146 break; 142 break;
147 case WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE: 143 case WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE:
148 DCHECK(!secondary_url.is_empty()); 144 DCHECK(!secondary_url.is_empty());
149 patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url); 145 patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url);
150 patterns.second = 146 patterns.second =
151 ContentSettingsPattern::FromURLNoWildcard(secondary_url); 147 ContentSettingsPattern::FromURLNoWildcard(secondary_url);
152 break; 148 break;
153 } 149 }
154 return patterns; 150 return patterns;
155 } 151 }
156 152
157 } // namespace 153 } // namespace
158 154
159 HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs, 155 HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs,
160 bool is_incognito_profile, 156 bool is_incognito_profile,
161 bool is_guest_profile) 157 bool is_guest_profile)
162 : 158 :
163 #ifndef NDEBUG 159 #ifndef NDEBUG
164 used_from_thread_id_(base::PlatformThread::CurrentId()), 160 used_from_thread_id_(base::PlatformThread::CurrentId()),
165 #endif 161 #endif
166 prefs_(prefs), 162 prefs_(prefs),
167 is_off_the_record_(is_incognito_profile || is_guest_profile) { 163 is_off_the_record_(is_incognito_profile || is_guest_profile),
164 weak_ptr_factory_(this) {
168 DCHECK(!(is_incognito_profile && is_guest_profile)); 165 DCHECK(!(is_incognito_profile && is_guest_profile));
169 166
170 content_settings::PolicyProvider* policy_provider = 167 content_settings::PolicyProvider* policy_provider =
171 new content_settings::PolicyProvider(prefs_); 168 new content_settings::PolicyProvider(prefs_);
172 content_settings_providers_[POLICY_PROVIDER] = policy_provider; 169 content_settings_providers_[POLICY_PROVIDER] = policy_provider;
173 policy_provider->AddObserver(this); 170 policy_provider->AddObserver(this);
174 171
175 pref_provider_ = 172 pref_provider_ =
176 new content_settings::PrefProvider(prefs_, is_off_the_record_); 173 new content_settings::PrefProvider(prefs_, is_off_the_record_);
177 content_settings_providers_[PREF_PROVIDER] = pref_provider_; 174 content_settings_providers_[PREF_PROVIDER] = pref_provider_;
178 pref_provider_->AddObserver(this); 175 pref_provider_->AddObserver(this);
179 176
180 // This ensures that content settings are cleared for the guest profile. This 177 // This ensures that content settings are cleared for the guest profile. This
181 // wouldn't be needed except that we used to allow settings to be stored for 178 // wouldn't be needed except that we used to allow settings to be stored for
182 // the guest profile and so we need to ensure those get cleared. 179 // the guest profile and so we need to ensure those get cleared.
183 if (is_guest_profile) 180 if (is_guest_profile)
184 pref_provider_->ClearPrefs(); 181 pref_provider_->ClearPrefs();
185 182
186 content_settings::ObservableProvider* default_provider = 183 content_settings::ObservableProvider* default_provider =
187 new content_settings::DefaultProvider(prefs_, is_off_the_record_); 184 new content_settings::DefaultProvider(prefs_, is_off_the_record_);
188 default_provider->AddObserver(this); 185 default_provider->AddObserver(this);
189 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; 186 content_settings_providers_[DEFAULT_PROVIDER] = default_provider;
190 187
191 MigrateKeygenSettings(); 188 MigrateKeygenSettings();
192 189 MigrateDomainScopedSettings(false);
193 RecordNumberOfExceptions(); 190 RecordNumberOfExceptions();
194 } 191 }
195 192
196 // static 193 // static
197 void HostContentSettingsMap::RegisterProfilePrefs( 194 void HostContentSettingsMap::RegisterProfilePrefs(
198 user_prefs::PrefRegistrySyncable* registry) { 195 user_prefs::PrefRegistrySyncable* registry) {
199 // Ensure the content settings are all registered. 196 // Ensure the content settings are all registered.
200 content_settings::ContentSettingsRegistry::GetInstance(); 197 content_settings::ContentSettingsRegistry::GetInstance();
201 198
202 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); 199 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0);
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 590
594 if (status == NOT_MIGRATED) { 591 if (status == NOT_MIGRATED) {
595 prefs_->SetInteger(prefs::kDomainToOriginMigrationStatus, 592 prefs_->SetInteger(prefs::kDomainToOriginMigrationStatus,
596 MIGRATED_BEFORE_SYNC); 593 MIGRATED_BEFORE_SYNC);
597 } else if (status == MIGRATED_BEFORE_SYNC) { 594 } else if (status == MIGRATED_BEFORE_SYNC) {
598 prefs_->SetInteger(prefs::kDomainToOriginMigrationStatus, 595 prefs_->SetInteger(prefs::kDomainToOriginMigrationStatus,
599 MIGRATED_AFTER_SYNC); 596 MIGRATED_AFTER_SYNC);
600 } 597 }
601 } 598 }
602 599
600 base::WeakPtr<HostContentSettingsMap> HostContentSettingsMap::GetWeakPtr() {
601 return weak_ptr_factory_.GetWeakPtr();
602 }
603
603 void HostContentSettingsMap::RecordNumberOfExceptions() { 604 void HostContentSettingsMap::RecordNumberOfExceptions() {
604 for (const content_settings::WebsiteSettingsInfo* info : 605 for (const content_settings::WebsiteSettingsInfo* info :
605 *content_settings::WebsiteSettingsRegistry::GetInstance()) { 606 *content_settings::WebsiteSettingsRegistry::GetInstance()) {
606 ContentSettingsType content_type = info->type(); 607 ContentSettingsType content_type = info->type();
607 const std::string type_name = info->name(); 608 const std::string type_name = info->name();
608 609
609 ContentSettingsForOneType settings; 610 ContentSettingsForOneType settings;
610 GetSettingsForOneType(content_type, std::string(), &settings); 611 GetSettingsForOneType(content_type, std::string(), &settings);
611 size_t num_exceptions = 0; 612 size_t num_exceptions = 0;
612 for (const ContentSettingPatternSource& setting_entry : settings) { 613 for (const ContentSettingPatternSource& setting_entry : settings) {
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 rule.secondary_pattern.Matches(secondary_url)) { 950 rule.secondary_pattern.Matches(secondary_url)) {
950 if (primary_pattern) 951 if (primary_pattern)
951 *primary_pattern = rule.primary_pattern; 952 *primary_pattern = rule.primary_pattern;
952 if (secondary_pattern) 953 if (secondary_pattern)
953 *secondary_pattern = rule.secondary_pattern; 954 *secondary_pattern = rule.secondary_pattern;
954 return base::WrapUnique(rule.value.get()->DeepCopy()); 955 return base::WrapUnique(rule.value.get()->DeepCopy());
955 } 956 }
956 } 957 }
957 return std::unique_ptr<base::Value>(); 958 return std::unique_ptr<base::Value>();
958 } 959 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698