| 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 |
| 11 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
| 12 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 15 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
| 16 #include "base/prefs/scoped_user_pref_update.h" | 17 #include "base/prefs/scoped_user_pref_update.h" |
| 17 #include "base/strings/string_split.h" | 18 #include "base/strings/string_split.h" |
| 18 #include "base/time/clock.h" | 19 #include "base/time/clock.h" |
| 19 #include "base/time/default_clock.h" | 20 #include "base/time/default_clock.h" |
| 20 #include "chrome/browser/content_settings/content_settings_utils.h" | 21 #include "chrome/browser/content_settings/content_settings_utils.h" |
| 21 #include "chrome/browser/content_settings/host_content_settings_map.h" | 22 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 22 #include "chrome/common/chrome_switches.h" | |
| 23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "components/content_settings/core/browser/content_settings_rule.h" | 24 #include "components/content_settings/core/browser/content_settings_rule.h" |
| 25 #include "components/content_settings/core/common/content_settings.h" | 25 #include "components/content_settings/core/common/content_settings.h" |
| 26 #include "components/content_settings/core/common/content_settings_pattern.h" | 26 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 27 #include "components/pref_registry/pref_registry_syncable.h" | 27 #include "components/pref_registry/pref_registry_syncable.h" |
| 28 #include "content/public/browser/browser_thread.h" | |
| 29 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 30 | 29 |
| 31 using content::BrowserThread; | |
| 32 | |
| 33 namespace { | 30 namespace { |
| 34 | 31 |
| 35 typedef std::pair<std::string, std::string> StringPair; | 32 typedef std::pair<std::string, std::string> StringPair; |
| 36 typedef std::map<std::string, std::string> StringMap; | 33 typedef std::map<std::string, std::string> StringMap; |
| 37 | 34 |
| 38 const char kPerPluginPrefName[] = "per_plugin"; | 35 const char kPerPluginPrefName[] = "per_plugin"; |
| 39 const char kAudioKey[] = "audio"; | 36 const char kAudioKey[] = "audio"; |
| 40 const char kVideoKey[] = "video"; | 37 const char kVideoKey[] = "video"; |
| 41 const char kLastUsed[] = "last_used"; | 38 const char kLastUsed[] = "last_used"; |
| 42 | 39 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 base::Bind(&PrefProvider::OnContentSettingsPatternPairsChanged, | 114 base::Bind(&PrefProvider::OnContentSettingsPatternPairsChanged, |
| 118 base::Unretained(this))); | 115 base::Unretained(this))); |
| 119 } | 116 } |
| 120 | 117 |
| 121 bool PrefProvider::SetWebsiteSetting( | 118 bool PrefProvider::SetWebsiteSetting( |
| 122 const ContentSettingsPattern& primary_pattern, | 119 const ContentSettingsPattern& primary_pattern, |
| 123 const ContentSettingsPattern& secondary_pattern, | 120 const ContentSettingsPattern& secondary_pattern, |
| 124 ContentSettingsType content_type, | 121 ContentSettingsType content_type, |
| 125 const ResourceIdentifier& resource_identifier, | 122 const ResourceIdentifier& resource_identifier, |
| 126 base::Value* in_value) { | 123 base::Value* in_value) { |
| 127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 124 DCHECK(CalledOnValidThread()); |
| 128 DCHECK(prefs_); | 125 DCHECK(prefs_); |
| 129 // Default settings are set using a wildcard pattern for both | 126 // Default settings are set using a wildcard pattern for both |
| 130 // |primary_pattern| and |secondary_pattern|. Don't store default settings in | 127 // |primary_pattern| and |secondary_pattern|. Don't store default settings in |
| 131 // the |PrefProvider|. The |PrefProvider| handles settings for specific | 128 // the |PrefProvider|. The |PrefProvider| handles settings for specific |
| 132 // sites/origins defined by the |primary_pattern| and the |secondary_pattern|. | 129 // sites/origins defined by the |primary_pattern| and the |secondary_pattern|. |
| 133 // Default settings are handled by the |DefaultProvider|. | 130 // Default settings are handled by the |DefaultProvider|. |
| 134 if (primary_pattern == ContentSettingsPattern::Wildcard() && | 131 if (primary_pattern == ContentSettingsPattern::Wildcard() && |
| 135 secondary_pattern == ContentSettingsPattern::Wildcard() && | 132 secondary_pattern == ContentSettingsPattern::Wildcard() && |
| 136 resource_identifier.empty()) { | 133 resource_identifier.empty()) { |
| 137 return false; | 134 return false; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 } | 168 } |
| 172 | 169 |
| 173 NotifyObservers( | 170 NotifyObservers( |
| 174 primary_pattern, secondary_pattern, content_type, resource_identifier); | 171 primary_pattern, secondary_pattern, content_type, resource_identifier); |
| 175 | 172 |
| 176 return true; | 173 return true; |
| 177 } | 174 } |
| 178 | 175 |
| 179 void PrefProvider::ClearAllContentSettingsRules( | 176 void PrefProvider::ClearAllContentSettingsRules( |
| 180 ContentSettingsType content_type) { | 177 ContentSettingsType content_type) { |
| 181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 178 DCHECK(CalledOnValidThread()); |
| 182 DCHECK(prefs_); | 179 DCHECK(prefs_); |
| 183 | 180 |
| 184 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; | 181 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; |
| 185 if (!is_incognito_) | 182 if (!is_incognito_) |
| 186 map_to_modify = &value_map_; | 183 map_to_modify = &value_map_; |
| 187 | 184 |
| 188 std::vector<Rule> rules_to_delete; | 185 std::vector<Rule> rules_to_delete; |
| 189 { | 186 { |
| 190 base::AutoLock auto_lock(lock_); | 187 base::AutoLock auto_lock(lock_); |
| 191 scoped_ptr<RuleIterator> rule_iterator( | 188 scoped_ptr<RuleIterator> rule_iterator( |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 } | 479 } |
| 483 UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfBlockCookiesExceptions", | 480 UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfBlockCookiesExceptions", |
| 484 cookies_block_exception_count); | 481 cookies_block_exception_count); |
| 485 UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfAllowCookiesExceptions", | 482 UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfAllowCookiesExceptions", |
| 486 cookies_allow_exception_count); | 483 cookies_allow_exception_count); |
| 487 UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfSessionOnlyCookiesExceptions", | 484 UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfSessionOnlyCookiesExceptions", |
| 488 cookies_session_only_exception_count); | 485 cookies_session_only_exception_count); |
| 489 } | 486 } |
| 490 | 487 |
| 491 void PrefProvider::OnContentSettingsPatternPairsChanged() { | 488 void PrefProvider::OnContentSettingsPatternPairsChanged() { |
| 492 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 489 DCHECK(CalledOnValidThread()); |
| 493 | 490 |
| 494 if (updating_preferences_) | 491 if (updating_preferences_) |
| 495 return; | 492 return; |
| 496 | 493 |
| 497 ReadContentSettingsFromPref(true); | 494 ReadContentSettingsFromPref(true); |
| 498 | 495 |
| 499 NotifyObservers(ContentSettingsPattern(), | 496 NotifyObservers(ContentSettingsPattern(), |
| 500 ContentSettingsPattern(), | 497 ContentSettingsPattern(), |
| 501 CONTENT_SETTINGS_TYPE_DEFAULT, | 498 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 502 std::string()); | 499 std::string()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 for (size_t i = 0; i < move_items.size(); ++i) { | 549 for (size_t i = 0; i < move_items.size(); ++i) { |
| 553 scoped_ptr<base::Value> pattern_settings_dictionary; | 550 scoped_ptr<base::Value> pattern_settings_dictionary; |
| 554 all_settings_dictionary->RemoveWithoutPathExpansion( | 551 all_settings_dictionary->RemoveWithoutPathExpansion( |
| 555 move_items[i].first, &pattern_settings_dictionary); | 552 move_items[i].first, &pattern_settings_dictionary); |
| 556 all_settings_dictionary->SetWithoutPathExpansion( | 553 all_settings_dictionary->SetWithoutPathExpansion( |
| 557 move_items[i].second, pattern_settings_dictionary.release()); | 554 move_items[i].second, pattern_settings_dictionary.release()); |
| 558 } | 555 } |
| 559 } | 556 } |
| 560 | 557 |
| 561 void PrefProvider::ShutdownOnUIThread() { | 558 void PrefProvider::ShutdownOnUIThread() { |
| 562 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 559 DCHECK(CalledOnValidThread()); |
| 563 DCHECK(prefs_); | 560 DCHECK(prefs_); |
| 564 RemoveAllObservers(); | 561 RemoveAllObservers(); |
| 565 pref_change_registrar_.RemoveAll(); | 562 pref_change_registrar_.RemoveAll(); |
| 566 prefs_ = NULL; | 563 prefs_ = NULL; |
| 567 } | 564 } |
| 568 | 565 |
| 569 void PrefProvider::UpdateLastUsage( | 566 void PrefProvider::UpdateLastUsage( |
| 570 const ContentSettingsPattern& primary_pattern, | 567 const ContentSettingsPattern& primary_pattern, |
| 571 const ContentSettingsPattern& secondary_pattern, | 568 const ContentSettingsPattern& secondary_pattern, |
| 572 ContentSettingsType content_type) { | 569 ContentSettingsType content_type) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 lock_.Acquire(); | 648 lock_.Acquire(); |
| 652 lock_.Release(); | 649 lock_.Release(); |
| 653 #endif | 650 #endif |
| 654 } | 651 } |
| 655 | 652 |
| 656 void PrefProvider::SetClockForTesting(scoped_ptr<base::Clock> clock) { | 653 void PrefProvider::SetClockForTesting(scoped_ptr<base::Clock> clock) { |
| 657 clock_ = clock.Pass(); | 654 clock_ = clock.Pass(); |
| 658 } | 655 } |
| 659 | 656 |
| 660 } // namespace content_settings | 657 } // namespace content_settings |
| OLD | NEW |