OLD | NEW |
---|---|
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 |
11 #include "base/bind.h" | |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
18 #include "base/time/clock.h" | 19 #include "base/time/clock.h" |
19 #include "build/build_config.h" | 20 #include "build/build_config.h" |
20 #include "components/content_settings/core/browser/content_settings_default_prov ider.h" | 21 #include "components/content_settings/core/browser/content_settings_default_prov ider.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url); | 133 patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url); |
133 patterns.second = | 134 patterns.second = |
134 ContentSettingsPattern::FromURLNoWildcard(secondary_url); | 135 ContentSettingsPattern::FromURLNoWildcard(secondary_url); |
135 break; | 136 break; |
136 } | 137 } |
137 return patterns; | 138 return patterns; |
138 } | 139 } |
139 | 140 |
140 } // namespace | 141 } // namespace |
141 | 142 |
142 HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs, | 143 HostContentSettingsMap::HostContentSettingsMap( |
143 bool is_incognito_profile, | 144 PrefService* prefs, |
144 bool is_guest_profile) | 145 bool is_incognito_profile, |
146 bool is_guest_profile, | |
147 syncable_prefs::PrefServiceSyncable* pref_service) | |
145 : | 148 : |
146 #ifndef NDEBUG | 149 #ifndef NDEBUG |
147 used_from_thread_id_(base::PlatformThread::CurrentId()), | 150 used_from_thread_id_(base::PlatformThread::CurrentId()), |
148 #endif | 151 #endif |
149 prefs_(prefs), | 152 prefs_(prefs), |
150 is_off_the_record_(is_incognito_profile || is_guest_profile) { | 153 is_off_the_record_(is_incognito_profile || is_guest_profile), |
154 pref_service_(pref_service) { | |
151 DCHECK(!(is_incognito_profile && is_guest_profile)); | 155 DCHECK(!(is_incognito_profile && is_guest_profile)); |
152 | 156 |
153 content_settings::PolicyProvider* policy_provider = | 157 content_settings::PolicyProvider* policy_provider = |
154 new content_settings::PolicyProvider(prefs_); | 158 new content_settings::PolicyProvider(prefs_); |
155 content_settings_providers_[POLICY_PROVIDER] = policy_provider; | 159 content_settings_providers_[POLICY_PROVIDER] = policy_provider; |
156 policy_provider->AddObserver(this); | 160 policy_provider->AddObserver(this); |
157 | 161 |
158 pref_provider_ = | 162 pref_provider_ = |
159 new content_settings::PrefProvider(prefs_, is_off_the_record_); | 163 new content_settings::PrefProvider(prefs_, is_off_the_record_); |
160 content_settings_providers_[PREF_PROVIDER] = pref_provider_; | 164 content_settings_providers_[PREF_PROVIDER] = pref_provider_; |
161 pref_provider_->AddObserver(this); | 165 pref_provider_->AddObserver(this); |
162 | 166 |
163 // This ensures that content settings are cleared for the guest profile. This | 167 // This ensures that content settings are cleared for the guest profile. This |
164 // wouldn't be needed except that we used to allow settings to be stored for | 168 // wouldn't be needed except that we used to allow settings to be stored for |
165 // the guest profile and so we need to ensure those get cleared. | 169 // the guest profile and so we need to ensure those get cleared. |
166 if (is_guest_profile) | 170 if (is_guest_profile) |
167 pref_provider_->ClearPrefs(); | 171 pref_provider_->ClearPrefs(); |
168 | 172 |
169 content_settings::ObservableProvider* default_provider = | 173 content_settings::ObservableProvider* default_provider = |
170 new content_settings::DefaultProvider(prefs_, is_off_the_record_); | 174 new content_settings::DefaultProvider(prefs_, is_off_the_record_); |
171 default_provider->AddObserver(this); | 175 default_provider->AddObserver(this); |
172 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; | 176 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; |
173 | 177 |
174 MigrateKeygenSettings(); | 178 MigrateKeygenSettings(); |
175 | 179 |
176 RecordNumberOfExceptions(); | 180 RecordNumberOfExceptions(); |
181 | |
182 if (pref_service_) { | |
183 pref_service_->RegisterMergeDataFinishedCallback( | |
184 base::Bind(&HostContentSettingsMap::MigrateDomainScopedSettings, | |
185 base::Unretained(this))); | |
raymes
2016/06/29 03:50:01
We should probably use a WeakPtr here instead of b
lshang
2016/06/30 05:03:36
Done.
| |
186 } | |
177 } | 187 } |
178 | 188 |
179 // static | 189 // static |
180 void HostContentSettingsMap::RegisterProfilePrefs( | 190 void HostContentSettingsMap::RegisterProfilePrefs( |
181 user_prefs::PrefRegistrySyncable* registry) { | 191 user_prefs::PrefRegistrySyncable* registry) { |
182 // Ensure the content settings are all registered. | 192 // Ensure the content settings are all registered. |
183 content_settings::ContentSettingsRegistry::GetInstance(); | 193 content_settings::ContentSettingsRegistry::GetInstance(); |
184 | 194 |
185 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); | 195 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); |
186 | 196 |
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
912 rule.secondary_pattern.Matches(secondary_url)) { | 922 rule.secondary_pattern.Matches(secondary_url)) { |
913 if (primary_pattern) | 923 if (primary_pattern) |
914 *primary_pattern = rule.primary_pattern; | 924 *primary_pattern = rule.primary_pattern; |
915 if (secondary_pattern) | 925 if (secondary_pattern) |
916 *secondary_pattern = rule.secondary_pattern; | 926 *secondary_pattern = rule.secondary_pattern; |
917 return base::WrapUnique(rule.value.get()->DeepCopy()); | 927 return base::WrapUnique(rule.value.get()->DeepCopy()); |
918 } | 928 } |
919 } | 929 } |
920 return std::unique_ptr<base::Value>(); | 930 return std::unique_ptr<base::Value>(); |
921 } | 931 } |
OLD | NEW |