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