| 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 "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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 DCHECK(prefs_); | 181 DCHECK(prefs_); |
| 182 | 182 |
| 183 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; | 183 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; |
| 184 if (!is_incognito_) | 184 if (!is_incognito_) |
| 185 map_to_modify = &value_map_; | 185 map_to_modify = &value_map_; |
| 186 | 186 |
| 187 std::vector<Rule> rules_to_delete; | 187 std::vector<Rule> rules_to_delete; |
| 188 { | 188 { |
| 189 base::AutoLock auto_lock(lock_); | 189 base::AutoLock auto_lock(lock_); |
| 190 scoped_ptr<RuleIterator> rule_iterator( | 190 scoped_ptr<RuleIterator> rule_iterator( |
| 191 map_to_modify->GetRuleIterator(content_type, "", NULL)); | 191 map_to_modify->GetRuleIterator(content_type, std::string(), NULL)); |
| 192 // Copy the rules; we cannot call |UpdatePref| while holding |lock_|. | 192 // Copy the rules; we cannot call |UpdatePref| while holding |lock_|. |
| 193 while (rule_iterator->HasNext()) | 193 while (rule_iterator->HasNext()) |
| 194 rules_to_delete.push_back(rule_iterator->Next()); | 194 rules_to_delete.push_back(rule_iterator->Next()); |
| 195 | 195 |
| 196 map_to_modify->DeleteValues(content_type, ""); | 196 map_to_modify->DeleteValues(content_type, std::string()); |
| 197 } | 197 } |
| 198 | 198 |
| 199 for (std::vector<Rule>::const_iterator it = rules_to_delete.begin(); | 199 for (std::vector<Rule>::const_iterator it = rules_to_delete.begin(); |
| 200 it != rules_to_delete.end(); ++it) { | 200 it != rules_to_delete.end(); ++it) { |
| 201 UpdatePref( | 201 UpdatePref(it->primary_pattern, |
| 202 it->primary_pattern, | 202 it->secondary_pattern, |
| 203 it->secondary_pattern, | 203 content_type, |
| 204 content_type, | 204 std::string(), |
| 205 "", | 205 NULL); |
| 206 NULL); | |
| 207 } | 206 } |
| 208 NotifyObservers(ContentSettingsPattern(), | 207 NotifyObservers(ContentSettingsPattern(), |
| 209 ContentSettingsPattern(), | 208 ContentSettingsPattern(), |
| 210 content_type, | 209 content_type, |
| 211 std::string()); | 210 std::string()); |
| 212 } | 211 } |
| 213 | 212 |
| 214 PrefProvider::~PrefProvider() { | 213 PrefProvider::~PrefProvider() { |
| 215 DCHECK(!prefs_); | 214 DCHECK(!prefs_); |
| 216 } | 215 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 pattern_str, NULL); | 299 pattern_str, NULL); |
| 301 } | 300 } |
| 302 } | 301 } |
| 303 } | 302 } |
| 304 } | 303 } |
| 305 | 304 |
| 306 | 305 |
| 307 void PrefProvider::MigrateObsoleteMediaContentSetting() { | 306 void PrefProvider::MigrateObsoleteMediaContentSetting() { |
| 308 std::vector<Rule> rules_to_delete; | 307 std::vector<Rule> rules_to_delete; |
| 309 { | 308 { |
| 310 scoped_ptr<RuleIterator> rule_iterator( | 309 scoped_ptr<RuleIterator> rule_iterator(GetRuleIterator( |
| 311 GetRuleIterator(CONTENT_SETTINGS_TYPE_MEDIASTREAM, "", false)); | 310 CONTENT_SETTINGS_TYPE_MEDIASTREAM, std::string(), false)); |
| 312 while (rule_iterator->HasNext()) { | 311 while (rule_iterator->HasNext()) { |
| 313 // Skip default setting and rules without a value. | 312 // Skip default setting and rules without a value. |
| 314 const content_settings::Rule& rule = rule_iterator->Next(); | 313 const content_settings::Rule& rule = rule_iterator->Next(); |
| 315 DCHECK(rule.primary_pattern != ContentSettingsPattern::Wildcard()); | 314 DCHECK(rule.primary_pattern != ContentSettingsPattern::Wildcard()); |
| 316 if (!rule.value.get()) | 315 if (!rule.value.get()) |
| 317 continue; | 316 continue; |
| 318 rules_to_delete.push_back(rule); | 317 rules_to_delete.push_back(rule); |
| 319 } | 318 } |
| 320 } | 319 } |
| 321 | 320 |
| 322 for (std::vector<Rule>::const_iterator it = rules_to_delete.begin(); | 321 for (std::vector<Rule>::const_iterator it = rules_to_delete.begin(); |
| 323 it != rules_to_delete.end(); ++it) { | 322 it != rules_to_delete.end(); ++it) { |
| 324 const DictionaryValue* value_dict = NULL; | 323 const DictionaryValue* value_dict = NULL; |
| 325 if (!it->value->GetAsDictionary(&value_dict) || value_dict->empty()) | 324 if (!it->value->GetAsDictionary(&value_dict) || value_dict->empty()) |
| 326 return; | 325 return; |
| 327 | 326 |
| 328 std::string audio_device, video_device; | 327 std::string audio_device, video_device; |
| 329 value_dict->GetString(kAudioKey, &audio_device); | 328 value_dict->GetString(kAudioKey, &audio_device); |
| 330 value_dict->GetString(kVideoKey, &video_device); | 329 value_dict->GetString(kVideoKey, &video_device); |
| 331 // Add the exception to the new microphone content setting. | 330 // Add the exception to the new microphone content setting. |
| 332 if (!audio_device.empty()) { | 331 if (!audio_device.empty()) { |
| 333 SetWebsiteSetting(it->primary_pattern, | 332 SetWebsiteSetting(it->primary_pattern, |
| 334 it->secondary_pattern, | 333 it->secondary_pattern, |
| 335 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 334 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
| 336 "", | 335 std::string(), |
| 337 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); | 336 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); |
| 338 } | 337 } |
| 339 // Add the exception to the new camera content setting. | 338 // Add the exception to the new camera content setting. |
| 340 if (!video_device.empty()) { | 339 if (!video_device.empty()) { |
| 341 SetWebsiteSetting(it->primary_pattern, | 340 SetWebsiteSetting(it->primary_pattern, |
| 342 it->secondary_pattern, | 341 it->secondary_pattern, |
| 343 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 342 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| 344 "", | 343 std::string(), |
| 345 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); | 344 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); |
| 346 } | 345 } |
| 347 | 346 |
| 348 // Remove the old exception in CONTENT_SETTINGS_TYPE_MEDIASTREAM. | 347 // Remove the old exception in CONTENT_SETTINGS_TYPE_MEDIASTREAM. |
| 349 SetWebsiteSetting(it->primary_pattern, | 348 SetWebsiteSetting(it->primary_pattern, |
| 350 it->secondary_pattern, | 349 it->secondary_pattern, |
| 351 CONTENT_SETTINGS_TYPE_MEDIASTREAM, | 350 CONTENT_SETTINGS_TYPE_MEDIASTREAM, |
| 352 "", | 351 std::string(), |
| 353 NULL); | 352 NULL); |
| 354 } | 353 } |
| 355 } | 354 } |
| 356 | 355 |
| 357 void PrefProvider::ReadContentSettingsFromPref(bool overwrite) { | 356 void PrefProvider::ReadContentSettingsFromPref(bool overwrite) { |
| 358 // |DictionaryPrefUpdate| sends out notifications when destructed. This | 357 // |DictionaryPrefUpdate| sends out notifications when destructed. This |
| 359 // construction order ensures |AutoLock| gets destroyed first and |lock_| is | 358 // construction order ensures |AutoLock| gets destroyed first and |lock_| is |
| 360 // not held when the notifications are sent. Also, |auto_reset| must be still | 359 // not held when the notifications are sent. Also, |auto_reset| must be still |
| 361 // valid when the notifications are sent, so that |Observe| skips the | 360 // valid when the notifications are sent, so that |Observe| skips the |
| 362 // notification. | 361 // notification. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 ContentSetting(setting)); | 447 ContentSetting(setting)); |
| 449 value = Value::CreateIntegerValue(setting); | 448 value = Value::CreateIntegerValue(setting); |
| 450 } | 449 } |
| 451 } | 450 } |
| 452 | 451 |
| 453 // |value_map_| will take the ownership of |value|. | 452 // |value_map_| will take the ownership of |value|. |
| 454 if (value != NULL) { | 453 if (value != NULL) { |
| 455 value_map_.SetValue(pattern_pair.first, | 454 value_map_.SetValue(pattern_pair.first, |
| 456 pattern_pair.second, | 455 pattern_pair.second, |
| 457 content_type, | 456 content_type, |
| 458 ResourceIdentifier(""), | 457 ResourceIdentifier(), |
| 459 value); | 458 value); |
| 460 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { | 459 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { |
| 461 ContentSetting s = ValueToContentSetting(value); | 460 ContentSetting s = ValueToContentSetting(value); |
| 462 switch (s) { | 461 switch (s) { |
| 463 case CONTENT_SETTING_ALLOW : | 462 case CONTENT_SETTING_ALLOW : |
| 464 ++cookies_allow_exception_count; | 463 ++cookies_allow_exception_count; |
| 465 break; | 464 break; |
| 466 case CONTENT_SETTING_BLOCK : | 465 case CONTENT_SETTING_BLOCK : |
| 467 ++cookies_block_exception_count; | 466 ++cookies_block_exception_count; |
| 468 break; | 467 break; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 | 563 |
| 565 void PrefProvider::AssertLockNotHeld() const { | 564 void PrefProvider::AssertLockNotHeld() const { |
| 566 #if !defined(NDEBUG) | 565 #if !defined(NDEBUG) |
| 567 // |Lock::Acquire()| will assert if the lock is held by this thread. | 566 // |Lock::Acquire()| will assert if the lock is held by this thread. |
| 568 lock_.Acquire(); | 567 lock_.Acquire(); |
| 569 lock_.Release(); | 568 lock_.Release(); |
| 570 #endif | 569 #endif |
| 571 } | 570 } |
| 572 | 571 |
| 573 } // namespace content_settings | 572 } // namespace content_settings |
| OLD | NEW |