| 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 <list> | 7 #include <list> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/auto_reset.h" |
| 12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 14 #include "chrome/browser/content_settings/content_settings_details.h" | 15 #include "chrome/browser/content_settings/content_settings_details.h" |
| 15 #include "chrome/browser/content_settings/content_settings_pattern.h" | 16 #include "chrome/browser/content_settings/content_settings_pattern.h" |
| 16 #include "chrome/browser/content_settings/content_settings_utils.h" | 17 #include "chrome/browser/content_settings/content_settings_utils.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 19 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/content_settings.h" | 22 #include "chrome/common/content_settings.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 setting == CONTENT_SETTING_ASK) { | 142 setting == CONTENT_SETTING_ASK) { |
| 142 return CONTENT_SETTING_BLOCK; | 143 return CONTENT_SETTING_BLOCK; |
| 143 } | 144 } |
| 144 return setting; | 145 return setting; |
| 145 } | 146 } |
| 146 | 147 |
| 147 } // namespace | 148 } // namespace |
| 148 | 149 |
| 149 namespace content_settings { | 150 namespace content_settings { |
| 150 | 151 |
| 151 PrefDefaultProvider::PrefDefaultProvider(Profile* profile) | 152 PrefDefaultProvider::PrefDefaultProvider(HostContentSettingsMap* map, |
| 152 : profile_(profile), | 153 PrefService* prefs, |
| 153 is_incognito_(profile_->IsOffTheRecord()), | 154 bool incognito) |
| 155 : host_content_settings_map_(map), |
| 156 prefs_(prefs), |
| 157 is_incognito_(incognito), |
| 154 updating_preferences_(false) { | 158 updating_preferences_(false) { |
| 155 initializing_ = true; | 159 DCHECK(prefs_); |
| 156 PrefService* prefs = profile->GetPrefs(); | 160 MigrateObsoleteNotificationPref(); |
| 157 | |
| 158 MigrateObsoleteNotificationPref(prefs); | |
| 159 | 161 |
| 160 // Read global defaults. | 162 // Read global defaults. |
| 161 DCHECK_EQ(arraysize(kTypeNames), | 163 DCHECK_EQ(arraysize(kTypeNames), |
| 162 static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES)); | 164 static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES)); |
| 163 ReadDefaultSettings(true); | 165 ReadDefaultSettings(true); |
| 164 if (default_content_settings_.settings[CONTENT_SETTINGS_TYPE_COOKIES] == | 166 if (default_content_settings_.settings[CONTENT_SETTINGS_TYPE_COOKIES] == |
| 165 CONTENT_SETTING_BLOCK) { | 167 CONTENT_SETTING_BLOCK) { |
| 166 UserMetrics::RecordAction( | 168 UserMetrics::RecordAction( |
| 167 UserMetricsAction("CookieBlockingEnabledPerDefault")); | 169 UserMetricsAction("CookieBlockingEnabledPerDefault")); |
| 168 } else { | 170 } else { |
| 169 UserMetrics::RecordAction( | 171 UserMetrics::RecordAction( |
| 170 UserMetricsAction("CookieBlockingDisabledPerDefault")); | 172 UserMetricsAction("CookieBlockingDisabledPerDefault")); |
| 171 } | 173 } |
| 172 | 174 |
| 173 pref_change_registrar_.Init(prefs); | 175 pref_change_registrar_.Init(prefs_); |
| 174 pref_change_registrar_.Add(prefs::kDefaultContentSettings, this); | 176 pref_change_registrar_.Add(prefs::kDefaultContentSettings, this); |
| 175 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | |
| 176 Source<Profile>(profile_)); | |
| 177 initializing_ = false; | |
| 178 } | 177 } |
| 179 | 178 |
| 180 PrefDefaultProvider::~PrefDefaultProvider() { | 179 PrefDefaultProvider::~PrefDefaultProvider() { |
| 181 UnregisterObservers(); | 180 DCHECK(!prefs_); |
| 182 } | 181 } |
| 183 | 182 |
| 184 ContentSetting PrefDefaultProvider::ProvideDefaultSetting( | 183 ContentSetting PrefDefaultProvider::ProvideDefaultSetting( |
| 185 ContentSettingsType content_type) const { | 184 ContentSettingsType content_type) const { |
| 186 base::AutoLock lock(lock_); | 185 base::AutoLock lock(lock_); |
| 187 return default_content_settings_.settings[content_type]; | 186 return default_content_settings_.settings[content_type]; |
| 188 } | 187 } |
| 189 | 188 |
| 190 void PrefDefaultProvider::UpdateDefaultSetting( | 189 void PrefDefaultProvider::UpdateDefaultSetting( |
| 191 ContentSettingsType content_type, | 190 ContentSettingsType content_type, |
| 192 ContentSetting setting) { | 191 ContentSetting setting) { |
| 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 193 DCHECK(prefs_); |
| 194 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. | 194 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. |
| 195 | 195 |
| 196 // The default settings may not be directly modified for OTR sessions. | 196 // The default settings may not be directly modified for OTR sessions. |
| 197 // Instead, they are synced to the main profile's setting. | 197 // Instead, they are synced to the main profile's setting. |
| 198 if (is_incognito_) | 198 if (is_incognito_) |
| 199 return; | 199 return; |
| 200 | 200 |
| 201 PrefService* prefs = profile_->GetPrefs(); | |
| 202 | |
| 203 std::string dictionary_path(kTypeNames[content_type]); | 201 std::string dictionary_path(kTypeNames[content_type]); |
| 204 updating_preferences_ = true; | |
| 205 { | 202 { |
| 203 AutoReset<bool> auto_reset(&updating_preferences_, true); |
| 206 base::AutoLock lock(lock_); | 204 base::AutoLock lock(lock_); |
| 207 DictionaryPrefUpdate update(prefs, prefs::kDefaultContentSettings); | 205 DictionaryPrefUpdate update(prefs_, prefs::kDefaultContentSettings); |
| 208 DictionaryValue* default_settings_dictionary = update.Get(); | 206 DictionaryValue* default_settings_dictionary = update.Get(); |
| 209 if ((setting == CONTENT_SETTING_DEFAULT) || | 207 if ((setting == CONTENT_SETTING_DEFAULT) || |
| 210 (setting == kDefaultSettings[content_type])) { | 208 (setting == kDefaultSettings[content_type])) { |
| 211 default_content_settings_.settings[content_type] = | 209 default_content_settings_.settings[content_type] = |
| 212 kDefaultSettings[content_type]; | 210 kDefaultSettings[content_type]; |
| 213 default_settings_dictionary->RemoveWithoutPathExpansion(dictionary_path, | 211 default_settings_dictionary->RemoveWithoutPathExpansion(dictionary_path, |
| 214 NULL); | 212 NULL); |
| 215 } else { | 213 } else { |
| 216 default_content_settings_.settings[content_type] = setting; | 214 default_content_settings_.settings[content_type] = setting; |
| 217 default_settings_dictionary->SetWithoutPathExpansion( | 215 default_settings_dictionary->SetWithoutPathExpansion( |
| 218 dictionary_path, Value::CreateIntegerValue(setting)); | 216 dictionary_path, Value::CreateIntegerValue(setting)); |
| 219 } | 217 } |
| 220 } | 218 } |
| 221 updating_preferences_ = false; | |
| 222 | 219 |
| 223 ContentSettingsDetails details( | 220 ContentSettingsDetails details( |
| 224 ContentSettingsPattern(), | 221 ContentSettingsPattern(), |
| 225 ContentSettingsPattern(), | 222 ContentSettingsPattern(), |
| 226 content_type, | 223 content_type, |
| 227 std::string()); | 224 std::string()); |
| 228 NotifyObservers(details); | 225 NotifyObservers(details); |
| 229 } | 226 } |
| 230 | 227 |
| 231 bool PrefDefaultProvider::DefaultSettingIsManaged( | 228 bool PrefDefaultProvider::DefaultSettingIsManaged( |
| 232 ContentSettingsType content_type) const { | 229 ContentSettingsType content_type) const { |
| 233 return false; | 230 return false; |
| 234 } | 231 } |
| 235 | 232 |
| 236 void PrefDefaultProvider::Observe(NotificationType type, | 233 void PrefDefaultProvider::Observe(NotificationType type, |
| 237 const NotificationSource& source, | 234 const NotificationSource& source, |
| 238 const NotificationDetails& details) { | 235 const NotificationDetails& details) { |
| 239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 240 | 237 |
| 241 if (type == NotificationType::PREF_CHANGED) { | 238 if (type == NotificationType::PREF_CHANGED) { |
| 242 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); | 239 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); |
| 243 if (updating_preferences_) | 240 if (updating_preferences_) |
| 244 return; | 241 return; |
| 245 | 242 |
| 246 std::string* name = Details<std::string>(details).ptr(); | 243 std::string* name = Details<std::string>(details).ptr(); |
| 247 if (*name == prefs::kDefaultContentSettings) { | 244 if (*name == prefs::kDefaultContentSettings) { |
| 248 ReadDefaultSettings(true); | 245 ReadDefaultSettings(true); |
| 249 } else { | 246 } else { |
| 250 NOTREACHED() << "Unexpected preference observed"; | 247 NOTREACHED() << "Unexpected preference observed"; |
| 251 return; | 248 return; |
| 252 } | 249 } |
| 253 | 250 |
| 254 if (!is_incognito_) { | 251 ContentSettingsDetails details(ContentSettingsPattern(), |
| 255 ContentSettingsDetails details(ContentSettingsPattern(), | 252 ContentSettingsPattern(), |
| 256 ContentSettingsPattern(), | 253 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 257 CONTENT_SETTINGS_TYPE_DEFAULT, | 254 std::string()); |
| 258 std::string()); | 255 NotifyObservers(details); |
| 259 NotifyObservers(details); | |
| 260 } | |
| 261 } else if (type == NotificationType::PROFILE_DESTROYED) { | |
| 262 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); | |
| 263 UnregisterObservers(); | |
| 264 } else { | 256 } else { |
| 265 NOTREACHED() << "Unexpected notification"; | 257 NOTREACHED() << "Unexpected notification"; |
| 266 } | 258 } |
| 267 } | 259 } |
| 268 | 260 |
| 269 void PrefDefaultProvider::UnregisterObservers() { | 261 void PrefDefaultProvider::ShutdownOnUIThread() { |
| 270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 271 if (!profile_) | 263 DCHECK(prefs_); |
| 272 return; | |
| 273 pref_change_registrar_.RemoveAll(); | 264 pref_change_registrar_.RemoveAll(); |
| 274 notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED, | 265 prefs_ = NULL; |
| 275 Source<Profile>(profile_)); | 266 host_content_settings_map_ = NULL; |
| 276 profile_ = NULL; | |
| 277 } | 267 } |
| 278 | 268 |
| 279 void PrefDefaultProvider::ReadDefaultSettings(bool overwrite) { | 269 void PrefDefaultProvider::ReadDefaultSettings(bool overwrite) { |
| 280 PrefService* prefs = profile_->GetPrefs(); | |
| 281 const DictionaryValue* default_settings_dictionary = | 270 const DictionaryValue* default_settings_dictionary = |
| 282 prefs->GetDictionary(prefs::kDefaultContentSettings); | 271 prefs_->GetDictionary(prefs::kDefaultContentSettings); |
| 283 | 272 |
| 284 base::AutoLock lock(lock_); | 273 base::AutoLock lock(lock_); |
| 285 | 274 |
| 286 if (overwrite) | 275 if (overwrite) |
| 287 default_content_settings_ = ContentSettings(); | 276 default_content_settings_ = ContentSettings(); |
| 288 | 277 |
| 289 // Careful: The returned value could be NULL if the pref has never been set. | 278 // Careful: The returned value could be NULL if the pref has never been set. |
| 290 if (default_settings_dictionary != NULL) { | 279 if (default_settings_dictionary != NULL) { |
| 291 GetSettingsFromDictionary(default_settings_dictionary, | 280 GetSettingsFromDictionary(default_settings_dictionary, |
| 292 &default_content_settings_); | 281 &default_content_settings_); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] = CONTENT_SETTING_BLOCK; | 316 settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] = CONTENT_SETTING_BLOCK; |
| 328 | 317 |
| 329 settings->settings[CONTENT_SETTINGS_TYPE_PLUGINS] = | 318 settings->settings[CONTENT_SETTINGS_TYPE_PLUGINS] = |
| 330 ClickToPlayFixup(CONTENT_SETTINGS_TYPE_PLUGINS, | 319 ClickToPlayFixup(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 331 settings->settings[CONTENT_SETTINGS_TYPE_PLUGINS]); | 320 settings->settings[CONTENT_SETTINGS_TYPE_PLUGINS]); |
| 332 } | 321 } |
| 333 | 322 |
| 334 void PrefDefaultProvider::NotifyObservers( | 323 void PrefDefaultProvider::NotifyObservers( |
| 335 const ContentSettingsDetails& details) { | 324 const ContentSettingsDetails& details) { |
| 336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 337 if (initializing_ || profile_ == NULL) | 326 if (host_content_settings_map_ == NULL) |
| 338 return; | 327 return; |
| 339 NotificationService::current()->Notify( | 328 NotificationService::current()->Notify( |
| 340 NotificationType::CONTENT_SETTINGS_CHANGED, | 329 NotificationType::CONTENT_SETTINGS_CHANGED, |
| 341 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()), | 330 Source<HostContentSettingsMap>(host_content_settings_map_), |
| 342 Details<const ContentSettingsDetails>(&details)); | 331 Details<const ContentSettingsDetails>(&details)); |
| 343 } | 332 } |
| 344 | 333 |
| 345 void PrefDefaultProvider::MigrateObsoleteNotificationPref(PrefService* prefs) { | 334 void PrefDefaultProvider::MigrateObsoleteNotificationPref() { |
| 346 if (prefs->HasPrefPath(prefs::kDesktopNotificationDefaultContentSetting)) { | 335 if (prefs_->HasPrefPath(prefs::kDesktopNotificationDefaultContentSetting)) { |
| 347 ContentSetting setting = IntToContentSetting( | 336 ContentSetting setting = IntToContentSetting( |
| 348 prefs->GetInteger(prefs::kDesktopNotificationDefaultContentSetting)); | 337 prefs_->GetInteger(prefs::kDesktopNotificationDefaultContentSetting)); |
| 349 UpdateDefaultSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting); | 338 UpdateDefaultSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting); |
| 350 prefs->ClearPref(prefs::kDesktopNotificationDefaultContentSetting); | 339 prefs_->ClearPref(prefs::kDesktopNotificationDefaultContentSetting); |
| 351 } | 340 } |
| 352 } | 341 } |
| 353 | 342 |
| 354 // static | 343 // static |
| 355 void PrefDefaultProvider::RegisterUserPrefs(PrefService* prefs) { | 344 void PrefDefaultProvider::RegisterUserPrefs(PrefService* prefs) { |
| 356 // The registration of the preference prefs::kDefaultContentSettings should | 345 // The registration of the preference prefs::kDefaultContentSettings should |
| 357 // also include the default values for default content settings. This allows | 346 // also include the default values for default content settings. This allows |
| 358 // functional tests to get default content settings by reading the preference | 347 // functional tests to get default content settings by reading the preference |
| 359 // prefs::kDefaultContentSettings via pyauto. | 348 // prefs::kDefaultContentSettings via pyauto. |
| 360 // TODO(markusheintz): Write pyauto hooks for the content settings map as | 349 // TODO(markusheintz): Write pyauto hooks for the content settings map as |
| (...skipping 26 matching lines...) Expand all Loading... |
| 387 | 376 |
| 388 // Obsolete prefs, for migration: | 377 // Obsolete prefs, for migration: |
| 389 prefs->RegisterDictionaryPref(prefs::kContentSettingsPatterns, | 378 prefs->RegisterDictionaryPref(prefs::kContentSettingsPatterns, |
| 390 PrefService::SYNCABLE_PREF); | 379 PrefService::SYNCABLE_PREF); |
| 391 prefs->RegisterListPref(prefs::kPopupWhitelistedHosts, | 380 prefs->RegisterListPref(prefs::kPopupWhitelistedHosts, |
| 392 PrefService::UNSYNCABLE_PREF); | 381 PrefService::UNSYNCABLE_PREF); |
| 393 prefs->RegisterDictionaryPref(prefs::kPerHostContentSettings, | 382 prefs->RegisterDictionaryPref(prefs::kPerHostContentSettings, |
| 394 PrefService::UNSYNCABLE_PREF); | 383 PrefService::UNSYNCABLE_PREF); |
| 395 } | 384 } |
| 396 | 385 |
| 397 PrefProvider::PrefProvider(Profile* profile) | 386 PrefProvider::PrefProvider(HostContentSettingsMap* map, |
| 398 : profile_(profile), | 387 PrefService* prefs, |
| 399 is_incognito_(profile_->IsOffTheRecord()), | 388 bool incognito) |
| 389 : prefs_(prefs), |
| 390 host_content_settings_map_(map), |
| 391 is_incognito_(incognito), |
| 400 updating_preferences_(false) { | 392 updating_preferences_(false) { |
| 401 Init(); | 393 DCHECK(prefs_); |
| 402 } | 394 if (!is_incognito_) { |
| 403 | 395 // Migrate obsolete preferences. |
| 404 void PrefProvider::Init() { | 396 MigrateObsoletePerhostPref(); |
| 405 initializing_ = true; | 397 MigrateObsoletePopupsPref(); |
| 406 PrefService* prefs = profile_->GetPrefs(); | 398 MigrateObsoleteContentSettingsPatternPref(); |
| 407 | 399 } |
| 408 // Migrate obsolete preferences. | |
| 409 MigrateObsoletePerhostPref(prefs); | |
| 410 MigrateObsoletePopupsPref(prefs); | |
| 411 MigrateObsoleteContentSettingsPatternPref(prefs); | |
| 412 | 400 |
| 413 // Verify preferences version. | 401 // Verify preferences version. |
| 414 if (!prefs->HasPrefPath(prefs::kContentSettingsVersion)) { | 402 if (!prefs_->HasPrefPath(prefs::kContentSettingsVersion)) { |
| 415 prefs->SetInteger(prefs::kContentSettingsVersion, | 403 prefs_->SetInteger(prefs::kContentSettingsVersion, |
| 416 ContentSettingsPattern::kContentSettingsPatternVersion); | 404 ContentSettingsPattern::kContentSettingsPatternVersion); |
| 417 } | 405 } |
| 418 if (prefs->GetInteger(prefs::kContentSettingsVersion) > | 406 if (prefs_->GetInteger(prefs::kContentSettingsVersion) > |
| 419 ContentSettingsPattern::kContentSettingsPatternVersion) { | 407 ContentSettingsPattern::kContentSettingsPatternVersion) { |
| 420 LOG(ERROR) << "Unknown content settings version in preferences."; | 408 LOG(ERROR) << "Unknown content settings version in preferences."; |
| 421 return; | 409 return; |
| 422 } | 410 } |
| 423 | 411 |
| 424 // Read content settings exceptions. | 412 // Read content settings exceptions. |
| 425 ReadContentSettingsFromPref(false); | 413 ReadContentSettingsFromPref(false); |
| 426 | 414 |
| 427 if (!is_incognito_) { | 415 if (!is_incognito_) { |
| 428 UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfExceptions", | 416 UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfExceptions", |
| 429 value_map_.size()); | 417 value_map_.size()); |
| 430 } | 418 } |
| 431 | 419 |
| 432 pref_change_registrar_.Init(prefs); | 420 pref_change_registrar_.Init(prefs_); |
| 433 pref_change_registrar_.Add(prefs::kContentSettingsPatterns, this); | 421 pref_change_registrar_.Add(prefs::kContentSettingsPatterns, this); |
| 434 pref_change_registrar_.Add(prefs::kContentSettingsPatternPairs, this); | 422 pref_change_registrar_.Add(prefs::kContentSettingsPatternPairs, this); |
| 435 | |
| 436 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | |
| 437 Source<Profile>(profile_)); | |
| 438 initializing_ = false; | |
| 439 } | 423 } |
| 440 | 424 |
| 441 ContentSetting PrefProvider::GetContentSetting( | 425 ContentSetting PrefProvider::GetContentSetting( |
| 442 const GURL& primary_url, | 426 const GURL& primary_url, |
| 443 const GURL& secondary_url, | 427 const GURL& secondary_url, |
| 444 ContentSettingsType content_type, | 428 ContentSettingsType content_type, |
| 445 const ResourceIdentifier& resource_identifier) const { | 429 const ResourceIdentifier& resource_identifier) const { |
| 446 // For a |PrefProvider| used in a |HostContentSettingsMap| of a non incognito | 430 // For a |PrefProvider| used in a |HostContentSettingsMap| of a non incognito |
| 447 // profile, this will always return NULL. | 431 // profile, this will always return NULL. |
| 448 // TODO(markusheintz): I don't like this. I'd like to have an | 432 // TODO(markusheintz): I don't like this. I'd like to have an |
| 449 // IncognitoProviderWrapper that wrapps the pref provider for a host content | 433 // IncognitoProviderWrapper that wrapps the pref provider for a host content |
| 450 // settings map of an incognito profile. | 434 // settings map of an incognito profile. |
| 451 Value* incognito_value = incognito_value_map_.GetValue( | 435 Value* incognito_value = incognito_value_map_.GetValue( |
| 452 primary_url, | 436 primary_url, |
| 453 secondary_url, | 437 secondary_url, |
| 454 content_type, | 438 content_type, |
| 455 resource_identifier); | 439 resource_identifier); |
| 456 if (incognito_value) | 440 if (incognito_value) |
| 457 return ValueToContentSetting(incognito_value); | 441 return ValueToContentSetting(incognito_value); |
| 458 | 442 |
| 459 Value* value = value_map_.GetValue( | 443 Value* value = value_map_.GetValue( |
| 460 primary_url, | 444 primary_url, |
| 461 secondary_url, | 445 secondary_url, |
| 462 content_type, | 446 content_type, |
| 463 resource_identifier); | 447 resource_identifier); |
| 464 if (value) | 448 if (value) |
| 465 return ValueToContentSetting(value); | 449 return ValueToContentSetting(value); |
| 466 | 450 |
| 467 return CONTENT_SETTING_DEFAULT; | 451 return CONTENT_SETTING_DEFAULT; |
| 468 } | 452 } |
| 469 | 453 |
| 470 void PrefProvider::GetAllContentSettingsRules( | 454 void PrefProvider::GetAllContentSettingsRules( |
| 471 ContentSettingsType content_type, | 455 ContentSettingsType content_type, |
| 472 const ResourceIdentifier& resource_identifier, | 456 const ResourceIdentifier& resource_identifier, |
| 473 Rules* content_setting_rules) const { | 457 Rules* content_setting_rules) const { |
| 474 DCHECK(content_setting_rules); | 458 DCHECK(content_setting_rules); |
| 475 content_setting_rules->clear(); | 459 content_setting_rules->clear(); |
| 476 | 460 |
| 477 const OriginIdentifierValueMap* map_to_return = | 461 const OriginIdentifierValueMap* map_to_return = |
| 478 is_incognito_ ? &incognito_value_map_ : &value_map_; | 462 is_incognito_ ? &incognito_value_map_ : &value_map_; |
| 479 | 463 |
| 480 base::AutoLock auto_lock(lock_); | 464 base::AutoLock auto_lock(lock_); |
| 481 for (OriginIdentifierValueMap::const_iterator entry = map_to_return->begin(); | 465 for (OriginIdentifierValueMap::const_iterator entry = map_to_return->begin(); |
| 482 entry != map_to_return->end(); | 466 entry != map_to_return->end(); |
| 483 ++entry) { | 467 ++entry) { |
| 484 if (entry->content_type == content_type && | 468 if (entry->content_type == content_type && |
| 485 entry->identifier == resource_identifier) { | 469 entry->identifier == resource_identifier) { |
| 486 ContentSetting setting = ValueToContentSetting(entry->value.get()); | 470 ContentSetting setting = ValueToContentSetting(entry->value.get()); |
| 487 DCHECK(setting != CONTENT_SETTING_DEFAULT); | 471 DCHECK(setting != CONTENT_SETTING_DEFAULT); |
| 488 Rule new_rule(entry->primary_pattern, | 472 Rule new_rule(entry->primary_pattern, |
| 489 entry->secondary_pattern, | 473 entry->secondary_pattern, |
| 490 setting); | 474 setting); |
| 491 content_setting_rules->push_back(new_rule); | 475 content_setting_rules->push_back(new_rule); |
| 492 } | 476 } |
| 493 } | 477 } |
| 494 } | 478 } |
| 495 | 479 |
| 496 void PrefProvider::SetContentSetting( | 480 void PrefProvider::SetContentSetting( |
| 497 const ContentSettingsPattern& primary_pattern, | 481 const ContentSettingsPattern& primary_pattern, |
| 498 const ContentSettingsPattern& secondary_pattern, | 482 const ContentSettingsPattern& secondary_pattern, |
| 499 ContentSettingsType content_type, | 483 ContentSettingsType content_type, |
| 500 const ResourceIdentifier& resource_identifier, | 484 const ResourceIdentifier& resource_identifier, |
| 501 ContentSetting setting) { | 485 ContentSetting setting) { |
| 486 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 487 DCHECK(prefs_); |
| 502 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. | 488 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. |
| 503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 504 | 489 |
| 505 // Update in memory value map. | 490 // Update in memory value map. |
| 506 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; | 491 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; |
| 507 if (!is_incognito_) | 492 if (!is_incognito_) |
| 508 map_to_modify = &value_map_; | 493 map_to_modify = &value_map_; |
| 509 | 494 |
| 510 { | 495 { |
| 511 base::AutoLock auto_lock(lock_); | 496 base::AutoLock auto_lock(lock_); |
| 512 if (setting == CONTENT_SETTING_DEFAULT) { | 497 if (setting == CONTENT_SETTING_DEFAULT) { |
| 513 map_to_modify->DeleteValue( | 498 map_to_modify->DeleteValue( |
| 514 primary_pattern, | 499 primary_pattern, |
| 515 secondary_pattern, | 500 secondary_pattern, |
| 516 content_type, | 501 content_type, |
| 517 resource_identifier); | 502 resource_identifier); |
| 518 } else { | 503 } else { |
| 519 map_to_modify->SetValue( | 504 map_to_modify->SetValue( |
| 520 primary_pattern, | 505 primary_pattern, |
| 521 secondary_pattern, | 506 secondary_pattern, |
| 522 content_type, | 507 content_type, |
| 523 resource_identifier, | 508 resource_identifier, |
| 524 Value::CreateIntegerValue(setting)); | 509 Value::CreateIntegerValue(setting)); |
| 525 } | 510 } |
| 526 } | 511 } |
| 527 | 512 |
| 528 // Update the content settings preference. | 513 // Update the content settings preference. |
| 529 if (!is_incognito_ && profile_) { | 514 if (!is_incognito_) { |
| 530 UpdatePref(primary_pattern, | 515 UpdatePref(primary_pattern, |
| 531 secondary_pattern, | 516 secondary_pattern, |
| 532 content_type, | 517 content_type, |
| 533 resource_identifier, | 518 resource_identifier, |
| 534 setting); | 519 setting); |
| 535 } | 520 } |
| 536 | 521 |
| 537 ContentSettingsDetails details( | 522 ContentSettingsDetails details( |
| 538 primary_pattern, secondary_pattern, content_type, std::string()); | 523 primary_pattern, secondary_pattern, content_type, resource_identifier); |
| 539 NotifyObservers(details); | 524 NotifyObservers(details); |
| 540 } | 525 } |
| 541 | 526 |
| 542 void PrefProvider::ClearAllContentSettingsRules( | 527 void PrefProvider::ClearAllContentSettingsRules( |
| 543 ContentSettingsType content_type) { | 528 ContentSettingsType content_type) { |
| 529 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 544 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. | 530 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. |
| 531 DCHECK(prefs_); |
| 545 | 532 |
| 546 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; | 533 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; |
| 547 if (!is_incognito_) | 534 if (!is_incognito_) |
| 548 map_to_modify = &value_map_; | 535 map_to_modify = &value_map_; |
| 549 | 536 |
| 550 { | 537 { |
| 551 base::AutoLock auto_lock(lock_); | 538 base::AutoLock auto_lock(lock_); |
| 552 OriginIdentifierValueMap::iterator entry(map_to_modify->begin()); | 539 OriginIdentifierValueMap::iterator entry(map_to_modify->begin()); |
| 553 while (entry != map_to_modify->end()) { | 540 while (entry != map_to_modify->end()) { |
| 554 if (entry->content_type == content_type) { | 541 if (entry->content_type == content_type) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 574 NotifyObservers(details); | 561 NotifyObservers(details); |
| 575 } | 562 } |
| 576 | 563 |
| 577 void PrefProvider::Observe( | 564 void PrefProvider::Observe( |
| 578 NotificationType type, | 565 NotificationType type, |
| 579 const NotificationSource& source, | 566 const NotificationSource& source, |
| 580 const NotificationDetails& details) { | 567 const NotificationDetails& details) { |
| 581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 568 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 582 | 569 |
| 583 if (type == NotificationType::PREF_CHANGED) { | 570 if (type == NotificationType::PREF_CHANGED) { |
| 584 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); | 571 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); |
| 585 if (updating_preferences_) | 572 if (updating_preferences_) |
| 586 return; | 573 return; |
| 587 | 574 |
| 588 std::string* name = Details<std::string>(details).ptr(); | 575 std::string* name = Details<std::string>(details).ptr(); |
| 589 if (*name == prefs::kContentSettingsPatternPairs) { | 576 if (*name == prefs::kContentSettingsPatternPairs) { |
| 590 SyncObsoletePref(profile_->GetPrefs()); | 577 SyncObsoletePref(); |
| 591 ReadContentSettingsFromPref(true); | 578 ReadContentSettingsFromPref(true); |
| 592 } else if (*name == prefs::kContentSettingsPatterns) { | 579 } else if (*name == prefs::kContentSettingsPatterns) { |
| 593 updating_preferences_ = true; | 580 AutoReset<bool> auto_reset(&updating_preferences_, true); |
| 594 MigrateObsoleteContentSettingsPatternPref(profile_->GetPrefs()); | 581 MigrateObsoleteContentSettingsPatternPref(); |
| 595 updating_preferences_ = false; | |
| 596 ReadContentSettingsFromPref(true); | 582 ReadContentSettingsFromPref(true); |
| 597 } else { | 583 } else { |
| 598 NOTREACHED() << "Unexpected preference observed"; | 584 NOTREACHED() << "Unexpected preference observed"; |
| 599 return; | 585 return; |
| 600 } | 586 } |
| 601 | 587 |
| 602 if (!is_incognito_) { | 588 ContentSettingsDetails details(ContentSettingsPattern(), |
| 603 ContentSettingsDetails details(ContentSettingsPattern(), | 589 ContentSettingsPattern(), |
| 604 ContentSettingsPattern(), | 590 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 605 CONTENT_SETTINGS_TYPE_DEFAULT, | 591 std::string()); |
| 606 std::string()); | 592 NotifyObservers(details); |
| 607 NotifyObservers(details); | |
| 608 } | |
| 609 } else if (type == NotificationType::PROFILE_DESTROYED) { | |
| 610 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); | |
| 611 UnregisterObservers(); | |
| 612 } else { | 593 } else { |
| 613 NOTREACHED() << "Unexpected notification"; | 594 NOTREACHED() << "Unexpected notification"; |
| 614 } | 595 } |
| 615 } | 596 } |
| 616 | 597 |
| 617 PrefProvider::~PrefProvider() { | 598 PrefProvider::~PrefProvider() { |
| 618 UnregisterObservers(); | 599 DCHECK(!prefs_); |
| 619 } | 600 } |
| 620 | 601 |
| 621 // //////////////////////////////////////////////////////////////////////////// | 602 // //////////////////////////////////////////////////////////////////////////// |
| 622 // Private | 603 // Private |
| 623 | 604 |
| 624 void PrefProvider::UpdatePref( | 605 void PrefProvider::UpdatePref( |
| 625 const ContentSettingsPattern& primary_pattern, | 606 const ContentSettingsPattern& primary_pattern, |
| 626 const ContentSettingsPattern& secondary_pattern, | 607 const ContentSettingsPattern& secondary_pattern, |
| 627 ContentSettingsType content_type, | 608 ContentSettingsType content_type, |
| 628 const ResourceIdentifier& resource_identifier, | 609 const ResourceIdentifier& resource_identifier, |
| 629 ContentSetting setting) { | 610 ContentSetting setting) { |
| 630 updating_preferences_ = true; | 611 AutoReset<bool> auto_reset(&updating_preferences_, true); |
| 631 UpdatePatternPairsPref(primary_pattern, | 612 UpdatePatternPairsPref(primary_pattern, |
| 632 secondary_pattern, | 613 secondary_pattern, |
| 633 content_type, | 614 content_type, |
| 634 resource_identifier, | 615 resource_identifier, |
| 635 setting); | 616 setting); |
| 636 UpdatePatternsPref(primary_pattern, | 617 UpdatePatternsPref(primary_pattern, |
| 637 secondary_pattern, | 618 secondary_pattern, |
| 638 content_type, | 619 content_type, |
| 639 resource_identifier, | 620 resource_identifier, |
| 640 setting); | 621 setting); |
| 641 updating_preferences_ = false; | |
| 642 } | 622 } |
| 643 | 623 |
| 644 void PrefProvider::ReadContentSettingsFromPref(bool overwrite) { | 624 void PrefProvider::ReadContentSettingsFromPref(bool overwrite) { |
| 645 base::AutoLock auto_lock(lock_); | 625 base::AutoLock auto_lock(lock_); |
| 646 | 626 |
| 647 PrefService* prefs = profile_->GetPrefs(); | |
| 648 const DictionaryValue* all_settings_dictionary = | 627 const DictionaryValue* all_settings_dictionary = |
| 649 prefs->GetDictionary(prefs::kContentSettingsPatternPairs); | 628 prefs_->GetDictionary(prefs::kContentSettingsPatternPairs); |
| 650 | 629 |
| 651 if (overwrite) | 630 if (overwrite) |
| 652 value_map_.clear(); | 631 value_map_.clear(); |
| 653 | 632 |
| 654 updating_preferences_ = true; | 633 AutoReset<bool> auto_reset(&updating_preferences_, true); |
| 655 // Careful: The returned value could be NULL if the pref has never been set. | 634 // Careful: The returned value could be NULL if the pref has never been set. |
| 656 if (all_settings_dictionary != NULL) { | 635 if (all_settings_dictionary != NULL) { |
| 657 DictionaryPrefUpdate update(prefs, prefs::kContentSettingsPatternPairs); | 636 DictionaryPrefUpdate update(prefs_, prefs::kContentSettingsPatternPairs); |
| 658 DictionaryValue* mutable_settings; | 637 DictionaryValue* mutable_settings; |
| 659 scoped_ptr<DictionaryValue> mutable_settings_scope; | 638 scoped_ptr<DictionaryValue> mutable_settings_scope; |
| 660 | 639 |
| 661 if (!is_incognito_) { | 640 if (!is_incognito_) { |
| 662 mutable_settings = update.Get(); | 641 mutable_settings = update.Get(); |
| 663 } else { | 642 } else { |
| 664 // Create copy as we do not want to persist anything in OTR prefs. | 643 // Create copy as we do not want to persist anything in OTR prefs. |
| 665 mutable_settings = all_settings_dictionary->DeepCopy(); | 644 mutable_settings = all_settings_dictionary->DeepCopy(); |
| 666 mutable_settings_scope.reset(mutable_settings); | 645 mutable_settings_scope.reset(mutable_settings); |
| 667 } | 646 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 value_map_.SetValue(pattern_pair.first, | 704 value_map_.SetValue(pattern_pair.first, |
| 726 pattern_pair.second, | 705 pattern_pair.second, |
| 727 content_type, | 706 content_type, |
| 728 ResourceIdentifier(""), | 707 ResourceIdentifier(""), |
| 729 Value::CreateIntegerValue(setting)); | 708 Value::CreateIntegerValue(setting)); |
| 730 } | 709 } |
| 731 } | 710 } |
| 732 } | 711 } |
| 733 } | 712 } |
| 734 } | 713 } |
| 735 updating_preferences_ = false; | |
| 736 } | 714 } |
| 737 | 715 |
| 738 void PrefProvider::UpdatePatternsPref( | 716 void PrefProvider::UpdatePatternsPref( |
| 739 const ContentSettingsPattern& primary_pattern, | 717 const ContentSettingsPattern& primary_pattern, |
| 740 const ContentSettingsPattern& secondary_pattern, | 718 const ContentSettingsPattern& secondary_pattern, |
| 741 ContentSettingsType content_type, | 719 ContentSettingsType content_type, |
| 742 const ResourceIdentifier& resource_identifier, | 720 const ResourceIdentifier& resource_identifier, |
| 743 ContentSetting setting) { | 721 ContentSetting setting) { |
| 744 DictionaryPrefUpdate update(profile_->GetPrefs(), | 722 DictionaryPrefUpdate update(prefs_, |
| 745 prefs::kContentSettingsPatterns); | 723 prefs::kContentSettingsPatterns); |
| 746 DictionaryValue* all_settings_dictionary = update.Get(); | 724 DictionaryValue* all_settings_dictionary = update.Get(); |
| 747 | 725 |
| 748 // Get settings dictionary for |primary_pattern|. | 726 // Get settings dictionary for |primary_pattern|. |
| 749 std::string pattern_str(primary_pattern.ToString()); | 727 std::string pattern_str(primary_pattern.ToString()); |
| 750 DictionaryValue* settings_dictionary = NULL; | 728 DictionaryValue* settings_dictionary = NULL; |
| 751 bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion( | 729 bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion( |
| 752 pattern_str, &settings_dictionary); | 730 pattern_str, &settings_dictionary); |
| 753 | 731 |
| 754 if (!found && (setting != CONTENT_SETTING_DEFAULT)) { | 732 if (!found && (setting != CONTENT_SETTING_DEFAULT)) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 } | 778 } |
| 801 } | 779 } |
| 802 } | 780 } |
| 803 | 781 |
| 804 void PrefProvider::UpdatePatternPairsPref( | 782 void PrefProvider::UpdatePatternPairsPref( |
| 805 const ContentSettingsPattern& primary_pattern, | 783 const ContentSettingsPattern& primary_pattern, |
| 806 const ContentSettingsPattern& secondary_pattern, | 784 const ContentSettingsPattern& secondary_pattern, |
| 807 ContentSettingsType content_type, | 785 ContentSettingsType content_type, |
| 808 const ResourceIdentifier& resource_identifier, | 786 const ResourceIdentifier& resource_identifier, |
| 809 ContentSetting setting) { | 787 ContentSetting setting) { |
| 810 DictionaryPrefUpdate update(profile_->GetPrefs(), | 788 DictionaryPrefUpdate update(prefs_, |
| 811 prefs::kContentSettingsPatternPairs); | 789 prefs::kContentSettingsPatternPairs); |
| 812 DictionaryValue* all_settings_dictionary = update.Get(); | 790 DictionaryValue* all_settings_dictionary = update.Get(); |
| 813 | 791 |
| 814 // Get settings dictionary for the given patterns. | 792 // Get settings dictionary for the given patterns. |
| 815 std::string pattern_str(CreatePatternString(primary_pattern, | 793 std::string pattern_str(CreatePatternString(primary_pattern, |
| 816 secondary_pattern)); | 794 secondary_pattern)); |
| 817 DictionaryValue* settings_dictionary = NULL; | 795 DictionaryValue* settings_dictionary = NULL; |
| 818 bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion( | 796 bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion( |
| 819 pattern_str, &settings_dictionary); | 797 pattern_str, &settings_dictionary); |
| 820 | 798 |
| 821 if (!found && (setting != CONTENT_SETTING_DEFAULT)) { | 799 if (!found && (setting != CONTENT_SETTING_DEFAULT)) { |
| 822 settings_dictionary = new DictionaryValue; | 800 settings_dictionary = new DictionaryValue; |
| 823 all_settings_dictionary->SetWithoutPathExpansion( | 801 all_settings_dictionary->SetWithoutPathExpansion( |
| 824 pattern_str, settings_dictionary); | 802 pattern_str, settings_dictionary); |
| 825 } | 803 } |
| 826 | 804 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 } | 839 } |
| 862 } | 840 } |
| 863 // Remove the settings dictionary if it is empty. | 841 // Remove the settings dictionary if it is empty. |
| 864 if (settings_dictionary->empty()) { | 842 if (settings_dictionary->empty()) { |
| 865 all_settings_dictionary->RemoveWithoutPathExpansion( | 843 all_settings_dictionary->RemoveWithoutPathExpansion( |
| 866 pattern_str, NULL); | 844 pattern_str, NULL); |
| 867 } | 845 } |
| 868 } | 846 } |
| 869 } | 847 } |
| 870 | 848 |
| 849 // static |
| 871 void PrefProvider::CanonicalizeContentSettingsExceptions( | 850 void PrefProvider::CanonicalizeContentSettingsExceptions( |
| 872 DictionaryValue* all_settings_dictionary) { | 851 DictionaryValue* all_settings_dictionary) { |
| 873 DCHECK(all_settings_dictionary); | 852 DCHECK(all_settings_dictionary); |
| 874 | 853 |
| 875 std::vector<std::string> remove_items; | 854 std::vector<std::string> remove_items; |
| 876 std::vector<std::pair<std::string, std::string> > move_items; | 855 std::vector<std::pair<std::string, std::string> > move_items; |
| 877 for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys()); | 856 for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys()); |
| 878 i != all_settings_dictionary->end_keys(); ++i) { | 857 i != all_settings_dictionary->end_keys(); ++i) { |
| 879 const std::string& pattern_str(*i); | 858 const std::string& pattern_str(*i); |
| 880 std::pair<ContentSettingsPattern, ContentSettingsPattern> pattern_pair = | 859 std::pair<ContentSettingsPattern, ContentSettingsPattern> pattern_pair = |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 all_settings_dictionary->RemoveWithoutPathExpansion( | 892 all_settings_dictionary->RemoveWithoutPathExpansion( |
| 914 move_items[i].first, &pattern_settings_dictionary); | 893 move_items[i].first, &pattern_settings_dictionary); |
| 915 all_settings_dictionary->SetWithoutPathExpansion( | 894 all_settings_dictionary->SetWithoutPathExpansion( |
| 916 move_items[i].second, pattern_settings_dictionary); | 895 move_items[i].second, pattern_settings_dictionary); |
| 917 } | 896 } |
| 918 } | 897 } |
| 919 | 898 |
| 920 void PrefProvider::NotifyObservers( | 899 void PrefProvider::NotifyObservers( |
| 921 const ContentSettingsDetails& details) { | 900 const ContentSettingsDetails& details) { |
| 922 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 901 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 923 if (initializing_ || profile_ == NULL) | 902 DCHECK(host_content_settings_map_); |
| 924 return; | |
| 925 NotificationService::current()->Notify( | 903 NotificationService::current()->Notify( |
| 926 NotificationType::CONTENT_SETTINGS_CHANGED, | 904 NotificationType::CONTENT_SETTINGS_CHANGED, |
| 927 Source<HostContentSettingsMap>( | 905 Source<HostContentSettingsMap>(host_content_settings_map_), |
| 928 profile_->GetHostContentSettingsMap()), | |
| 929 Details<const ContentSettingsDetails>(&details)); | 906 Details<const ContentSettingsDetails>(&details)); |
| 930 } | 907 } |
| 931 | 908 |
| 932 void PrefProvider::UnregisterObservers() { | 909 void PrefProvider::ShutdownOnUIThread() { |
| 933 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 910 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 934 if (!profile_) | 911 DCHECK(prefs_); |
| 935 return; | |
| 936 pref_change_registrar_.RemoveAll(); | 912 pref_change_registrar_.RemoveAll(); |
| 937 notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED, | 913 prefs_ = NULL; |
| 938 Source<Profile>(profile_)); | 914 host_content_settings_map_ = NULL; |
| 939 profile_ = NULL; | |
| 940 } | 915 } |
| 941 | 916 |
| 942 void PrefProvider::MigrateObsoletePerhostPref(PrefService* prefs) { | 917 void PrefProvider::MigrateObsoletePerhostPref() { |
| 943 if (prefs->HasPrefPath(prefs::kPerHostContentSettings)) { | 918 if (prefs_->HasPrefPath(prefs::kPerHostContentSettings)) { |
| 944 const DictionaryValue* all_settings_dictionary = | 919 const DictionaryValue* all_settings_dictionary = |
| 945 prefs->GetDictionary(prefs::kPerHostContentSettings); | 920 prefs_->GetDictionary(prefs::kPerHostContentSettings); |
| 946 DCHECK(all_settings_dictionary); | 921 DCHECK(all_settings_dictionary); |
| 947 for (DictionaryValue::key_iterator | 922 for (DictionaryValue::key_iterator |
| 948 i(all_settings_dictionary->begin_keys()); | 923 i(all_settings_dictionary->begin_keys()); |
| 949 i != all_settings_dictionary->end_keys(); ++i) { | 924 i != all_settings_dictionary->end_keys(); ++i) { |
| 950 const std::string& host(*i); | 925 const std::string& host(*i); |
| 951 ContentSettingsPattern pattern = | 926 ContentSettingsPattern pattern = |
| 952 ContentSettingsPattern::FromString( | 927 ContentSettingsPattern::FromString( |
| 953 std::string(ContentSettingsPattern::kDomainWildcard) + host); | 928 std::string(ContentSettingsPattern::kDomainWildcard) + host); |
| 954 DictionaryValue* host_settings_dictionary = NULL; | 929 DictionaryValue* host_settings_dictionary = NULL; |
| 955 bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion( | 930 bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 SetContentSetting( | 962 SetContentSetting( |
| 988 pattern, | 963 pattern, |
| 989 pattern, | 964 pattern, |
| 990 content_type, | 965 content_type, |
| 991 "", | 966 "", |
| 992 setting); | 967 setting); |
| 993 } | 968 } |
| 994 } | 969 } |
| 995 } | 970 } |
| 996 } | 971 } |
| 997 prefs->ClearPref(prefs::kPerHostContentSettings); | 972 prefs_->ClearPref(prefs::kPerHostContentSettings); |
| 998 } | 973 } |
| 999 } | 974 } |
| 1000 | 975 |
| 1001 void PrefProvider::MigrateObsoletePopupsPref(PrefService* prefs) { | 976 void PrefProvider::MigrateObsoletePopupsPref() { |
| 1002 if (prefs->HasPrefPath(prefs::kPopupWhitelistedHosts)) { | 977 if (prefs_->HasPrefPath(prefs::kPopupWhitelistedHosts)) { |
| 1003 const ListValue* whitelist_pref = | 978 const ListValue* whitelist_pref = |
| 1004 prefs->GetList(prefs::kPopupWhitelistedHosts); | 979 prefs_->GetList(prefs::kPopupWhitelistedHosts); |
| 1005 for (ListValue::const_iterator i(whitelist_pref->begin()); | 980 for (ListValue::const_iterator i(whitelist_pref->begin()); |
| 1006 i != whitelist_pref->end(); ++i) { | 981 i != whitelist_pref->end(); ++i) { |
| 1007 std::string host; | 982 std::string host; |
| 1008 (*i)->GetAsString(&host); | 983 (*i)->GetAsString(&host); |
| 1009 SetContentSetting(ContentSettingsPattern::FromString(host), | 984 SetContentSetting(ContentSettingsPattern::FromString(host), |
| 1010 ContentSettingsPattern::FromString(host), | 985 ContentSettingsPattern::FromString(host), |
| 1011 CONTENT_SETTINGS_TYPE_POPUPS, | 986 CONTENT_SETTINGS_TYPE_POPUPS, |
| 1012 "", | 987 "", |
| 1013 CONTENT_SETTING_ALLOW); | 988 CONTENT_SETTING_ALLOW); |
| 1014 } | 989 } |
| 1015 prefs->ClearPref(prefs::kPopupWhitelistedHosts); | 990 prefs_->ClearPref(prefs::kPopupWhitelistedHosts); |
| 1016 } | 991 } |
| 1017 } | 992 } |
| 1018 | 993 |
| 1019 void PrefProvider::MigrateObsoleteContentSettingsPatternPref( | 994 void PrefProvider::MigrateObsoleteContentSettingsPatternPref() { |
| 1020 PrefService* prefs) { | 995 if (prefs_->HasPrefPath(prefs::kContentSettingsPatterns) && !is_incognito_) { |
| 1021 if (prefs->HasPrefPath(prefs::kContentSettingsPatterns) && | |
| 1022 !is_incognito_) { | |
| 1023 const DictionaryValue* all_settings_dictionary = | 996 const DictionaryValue* all_settings_dictionary = |
| 1024 prefs->GetDictionary(prefs::kContentSettingsPatterns); | 997 prefs_->GetDictionary(prefs::kContentSettingsPatterns); |
| 1025 | 998 |
| 1026 DictionaryPrefUpdate update(prefs, prefs::kContentSettingsPatternPairs); | 999 DictionaryPrefUpdate update(prefs_, prefs::kContentSettingsPatternPairs); |
| 1027 DictionaryValue* exceptions_dictionary; | 1000 DictionaryValue* exceptions_dictionary; |
| 1028 exceptions_dictionary = update.Get(); | 1001 exceptions_dictionary = update.Get(); |
| 1029 for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys()); | 1002 for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys()); |
| 1030 i != all_settings_dictionary->end_keys(); | 1003 i != all_settings_dictionary->end_keys(); |
| 1031 ++i) { | 1004 ++i) { |
| 1032 const std::string& key(*i); | 1005 const std::string& key(*i); |
| 1033 | 1006 |
| 1034 // Validate pattern string and skip it if it is invalid. | 1007 // Validate pattern string and skip it if it is invalid. |
| 1035 std::pair<ContentSettingsPattern, ContentSettingsPattern> pattern_pair = | 1008 std::pair<ContentSettingsPattern, ContentSettingsPattern> pattern_pair = |
| 1036 ParsePatternString(key); | 1009 ParsePatternString(key); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1049 std::string new_pattern_str = CreatePatternString( | 1022 std::string new_pattern_str = CreatePatternString( |
| 1050 primary_pattern, ContentSettingsPattern::Wildcard()); | 1023 primary_pattern, ContentSettingsPattern::Wildcard()); |
| 1051 | 1024 |
| 1052 // Existing values are overwritten. | 1025 // Existing values are overwritten. |
| 1053 exceptions_dictionary->SetWithoutPathExpansion( | 1026 exceptions_dictionary->SetWithoutPathExpansion( |
| 1054 new_pattern_str, dictionary->DeepCopy()); | 1027 new_pattern_str, dictionary->DeepCopy()); |
| 1055 } | 1028 } |
| 1056 } | 1029 } |
| 1057 } | 1030 } |
| 1058 | 1031 |
| 1059 void PrefProvider::SyncObsoletePref(PrefService* prefs) { | 1032 void PrefProvider::SyncObsoletePref() { |
| 1060 updating_preferences_ = true; | 1033 AutoReset<bool> auto_reset(&updating_preferences_, true); |
| 1061 if (prefs->HasPrefPath(prefs::kContentSettingsPatternPairs) && | 1034 if (prefs_->HasPrefPath(prefs::kContentSettingsPatternPairs) && |
| 1062 !is_incognito_) { | 1035 !is_incognito_) { |
| 1063 const DictionaryValue* pattern_pairs_dictionary = | 1036 const DictionaryValue* pattern_pairs_dictionary = |
| 1064 prefs->GetDictionary(prefs::kContentSettingsPatternPairs); | 1037 prefs_->GetDictionary(prefs::kContentSettingsPatternPairs); |
| 1065 | 1038 |
| 1066 DictionaryPrefUpdate update(prefs, prefs::kContentSettingsPatterns); | 1039 DictionaryPrefUpdate update(prefs_, prefs::kContentSettingsPatterns); |
| 1067 DictionaryValue* obsolete_settings_dictionary = update.Get(); | 1040 DictionaryValue* obsolete_settings_dictionary = update.Get(); |
| 1068 | 1041 |
| 1069 for (DictionaryValue::key_iterator i = | 1042 for (DictionaryValue::key_iterator i = |
| 1070 pattern_pairs_dictionary->begin_keys(); | 1043 pattern_pairs_dictionary->begin_keys(); |
| 1071 i != pattern_pairs_dictionary->end_keys(); | 1044 i != pattern_pairs_dictionary->end_keys(); |
| 1072 ++i) { | 1045 ++i) { |
| 1073 const std::string& key(*i); | 1046 const std::string& key(*i); |
| 1074 // Validate pattern string and skip it if it is invalid. | 1047 // Validate pattern string and skip it if it is invalid. |
| 1075 std::pair<ContentSettingsPattern, ContentSettingsPattern> pattern_pair = | 1048 std::pair<ContentSettingsPattern, ContentSettingsPattern> pattern_pair = |
| 1076 ParsePatternString(key); | 1049 ParsePatternString(key); |
| 1077 if (!pattern_pair.first.IsValid() || !pattern_pair.second.IsValid()) | 1050 if (!pattern_pair.first.IsValid() || !pattern_pair.second.IsValid()) |
| 1078 continue; | 1051 continue; |
| 1079 | 1052 |
| 1080 // Copy dictionary | 1053 // Copy dictionary |
| 1081 DictionaryValue* dictionary = NULL; | 1054 DictionaryValue* dictionary = NULL; |
| 1082 bool found = pattern_pairs_dictionary->GetDictionaryWithoutPathExpansion( | 1055 bool found = pattern_pairs_dictionary->GetDictionaryWithoutPathExpansion( |
| 1083 key, &dictionary); | 1056 key, &dictionary); |
| 1084 DCHECK(found); | 1057 DCHECK(found); |
| 1085 std::string new_key = pattern_pair.first.ToString(); | 1058 std::string new_key = pattern_pair.first.ToString(); |
| 1086 // Existing values are overwritten. | 1059 // Existing values are overwritten. |
| 1087 obsolete_settings_dictionary->SetWithoutPathExpansion( | 1060 obsolete_settings_dictionary->SetWithoutPathExpansion( |
| 1088 new_key, dictionary->DeepCopy()); | 1061 new_key, dictionary->DeepCopy()); |
| 1089 } | 1062 } |
| 1090 } | 1063 } |
| 1091 updating_preferences_ = false; | |
| 1092 } | 1064 } |
| 1093 | 1065 |
| 1094 } // namespace content_settings | 1066 } // namespace content_settings |
| OLD | NEW |