OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_override_provider.h" | 5 #include "chrome/browser/content_settings/content_settings_override_provider.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/prefs/scoped_user_pref_update.h" | 11 #include "base/prefs/scoped_user_pref_update.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/content_settings/content_settings_utils.h" | 13 #include "chrome/browser/content_settings/content_settings_utils.h" |
14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
15 #include "components/content_settings/core/browser/content_settings_rule.h" | 15 #include "components/content_settings/core/browser/content_settings_rule.h" |
16 #include "components/content_settings/core/common/content_settings.h" | 16 #include "components/content_settings/core/common/content_settings.h" |
17 #include "components/content_settings/core/common/content_settings_pattern.h" | 17 #include "components/content_settings/core/common/content_settings_pattern.h" |
18 #include "components/pref_registry/pref_registry_syncable.h" | 18 #include "components/pref_registry/pref_registry_syncable.h" |
19 #include "content/public/browser/browser_thread.h" | |
20 | |
21 using content::BrowserThread; | |
22 | 19 |
23 namespace content_settings { | 20 namespace content_settings { |
24 | 21 |
25 namespace { | 22 namespace { |
26 | 23 |
27 class OverrideRuleIterator : public RuleIterator { | 24 class OverrideRuleIterator : public RuleIterator { |
28 public: | 25 public: |
29 explicit OverrideRuleIterator(bool is_allowed) : is_done_(is_allowed) {} | 26 explicit OverrideRuleIterator(bool is_allowed) : is_done_(is_allowed) {} |
30 | 27 |
31 virtual bool HasNext() const OVERRIDE { return !is_done_; } | 28 virtual bool HasNext() const OVERRIDE { return !is_done_; } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 return false; | 84 return false; |
88 } | 85 } |
89 | 86 |
90 void OverrideProvider::ShutdownOnUIThread() { | 87 void OverrideProvider::ShutdownOnUIThread() { |
91 DCHECK(prefs_); | 88 DCHECK(prefs_); |
92 prefs_ = NULL; | 89 prefs_ = NULL; |
93 } | 90 } |
94 | 91 |
95 void OverrideProvider::SetOverrideSetting(ContentSettingsType content_type, | 92 void OverrideProvider::SetOverrideSetting(ContentSettingsType content_type, |
96 bool enabled) { | 93 bool enabled) { |
97 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 94 DCHECK(CalledOnValidThread()); |
98 DCHECK(prefs_); | 95 DCHECK(prefs_); |
99 | 96 |
100 // Disallow incognito to change the state. | 97 // Disallow incognito to change the state. |
101 DCHECK(!is_incognito_); | 98 DCHECK(!is_incognito_); |
102 | 99 |
103 base::AutoLock lock(lock_); | 100 base::AutoLock lock(lock_); |
104 DictionaryPrefUpdate update(prefs_, prefs::kOverrideContentSettings); | 101 DictionaryPrefUpdate update(prefs_, prefs::kOverrideContentSettings); |
105 base::DictionaryValue* default_settings_dictionary = update.Get(); | 102 base::DictionaryValue* default_settings_dictionary = update.Get(); |
106 if (enabled) { | 103 if (enabled) { |
107 allowed_settings_[content_type] = true; | 104 allowed_settings_[content_type] = true; |
108 default_settings_dictionary->RemoveWithoutPathExpansion( | 105 default_settings_dictionary->RemoveWithoutPathExpansion( |
109 GetTypeName(content_type), NULL); | 106 GetTypeName(content_type), NULL); |
110 } else { | 107 } else { |
111 allowed_settings_[content_type] = false; | 108 allowed_settings_[content_type] = false; |
112 default_settings_dictionary->SetWithoutPathExpansion( | 109 default_settings_dictionary->SetWithoutPathExpansion( |
113 GetTypeName(content_type), new base::FundamentalValue(true)); | 110 GetTypeName(content_type), new base::FundamentalValue(true)); |
114 } | 111 } |
115 } | 112 } |
116 | 113 |
117 bool OverrideProvider::IsEnabled(ContentSettingsType content_type) const { | 114 bool OverrideProvider::IsEnabled(ContentSettingsType content_type) const { |
118 base::AutoLock lock(lock_); | 115 base::AutoLock lock(lock_); |
119 return allowed_settings_[content_type]; | 116 return allowed_settings_[content_type]; |
120 } | 117 } |
121 | 118 |
122 void OverrideProvider::ReadOverrideSettings() { | 119 void OverrideProvider::ReadOverrideSettings() { |
123 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 120 DCHECK(CalledOnValidThread()); |
124 const base::DictionaryValue* blocked_settings_dictionary = | 121 const base::DictionaryValue* blocked_settings_dictionary = |
125 prefs_->GetDictionary(prefs::kOverrideContentSettings); | 122 prefs_->GetDictionary(prefs::kOverrideContentSettings); |
126 | 123 |
127 for (int type = 0; type < CONTENT_SETTINGS_NUM_TYPES; ++type) { | 124 for (int type = 0; type < CONTENT_SETTINGS_NUM_TYPES; ++type) { |
128 ContentSettingsType content_setting = ContentSettingsType(type); | 125 ContentSettingsType content_setting = ContentSettingsType(type); |
129 allowed_settings_[content_setting] = | 126 allowed_settings_[content_setting] = |
130 !blocked_settings_dictionary->HasKey(GetTypeName(content_setting)); | 127 !blocked_settings_dictionary->HasKey(GetTypeName(content_setting)); |
131 } | 128 } |
132 } | 129 } |
133 | 130 |
134 } // namespace content_settings | 131 } // namespace content_settings |
OLD | NEW |