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/host_content_settings_map.h" | 5 #include "chrome/browser/content_settings/host_content_settings_map.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/time/clock.h" | 15 #include "base/time/clock.h" |
16 #include "chrome/browser/content_settings/content_settings_default_provider.h" | 16 #include "chrome/browser/content_settings/content_settings_default_provider.h" |
17 #include "chrome/browser/content_settings/content_settings_policy_provider.h" | 17 #include "chrome/browser/content_settings/content_settings_policy_provider.h" |
18 #include "chrome/browser/content_settings/content_settings_pref_provider.h" | 18 #include "chrome/browser/content_settings/content_settings_pref_provider.h" |
19 #include "chrome/browser/content_settings/content_settings_utils.h" | 19 #include "chrome/browser/content_settings/content_settings_utils.h" |
20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
22 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
23 #include "components/content_settings/core/browser/content_settings_details.h" | 23 #include "components/content_settings/core/browser/content_settings_details.h" |
24 #include "components/content_settings/core/browser/content_settings_observable_p rovider.h" | 24 #include "components/content_settings/core/browser/content_settings_observable_p rovider.h" |
25 #include "components/content_settings/core/browser/content_settings_provider.h" | 25 #include "components/content_settings/core/browser/content_settings_provider.h" |
26 #include "components/content_settings/core/browser/content_settings_rule.h" | 26 #include "components/content_settings/core/browser/content_settings_rule.h" |
27 #include "components/content_settings/core/common/content_settings_pattern.h" | 27 #include "components/content_settings/core/common/content_settings_pattern.h" |
28 #include "components/pref_registry/pref_registry_syncable.h" | 28 #include "components/pref_registry/pref_registry_syncable.h" |
29 #include "content/public/browser/browser_thread.h" | |
30 #include "content/public/common/content_switches.h" | |
31 #include "net/base/net_errors.h" | 29 #include "net/base/net_errors.h" |
32 #include "net/base/static_cookie_policy.h" | 30 #include "net/base/static_cookie_policy.h" |
33 #include "url/gurl.h" | 31 #include "url/gurl.h" |
34 | 32 |
35 #if defined(ENABLE_EXTENSIONS) | 33 #if defined(ENABLE_EXTENSIONS) |
36 #include "extensions/common/constants.h" | 34 #include "extensions/common/constants.h" |
37 #endif | 35 #endif |
38 | 36 |
39 using content::BrowserThread; | |
40 | |
41 namespace { | 37 namespace { |
42 | 38 |
43 typedef std::vector<content_settings::Rule> Rules; | 39 typedef std::vector<content_settings::Rule> Rules; |
44 | 40 |
45 typedef std::pair<std::string, std::string> StringPair; | 41 typedef std::pair<std::string, std::string> StringPair; |
46 | 42 |
47 // TODO(bauerb): Expose constants. | 43 // TODO(bauerb): Expose constants. |
48 const char* kProviderNames[] = { | 44 const char* kProviderNames[] = { |
49 "platform_app", | 45 "platform_app", |
50 "policy", | 46 "policy", |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 // Register the prefs for the content settings providers. | 117 // Register the prefs for the content settings providers. |
122 content_settings::DefaultProvider::RegisterProfilePrefs(registry); | 118 content_settings::DefaultProvider::RegisterProfilePrefs(registry); |
123 content_settings::PrefProvider::RegisterProfilePrefs(registry); | 119 content_settings::PrefProvider::RegisterProfilePrefs(registry); |
124 content_settings::PolicyProvider::RegisterProfilePrefs(registry); | 120 content_settings::PolicyProvider::RegisterProfilePrefs(registry); |
125 content_settings::OverrideProvider::RegisterProfilePrefs(registry); | 121 content_settings::OverrideProvider::RegisterProfilePrefs(registry); |
126 } | 122 } |
127 | 123 |
128 void HostContentSettingsMap::RegisterProvider( | 124 void HostContentSettingsMap::RegisterProvider( |
129 ProviderType type, | 125 ProviderType type, |
130 scoped_ptr<content_settings::ObservableProvider> provider) { | 126 scoped_ptr<content_settings::ObservableProvider> provider) { |
127 DCHECK(CalledOnValidThread()); | |
vabr (Chromium)
2014/09/23 07:51:00
Instead of trying to get this functionality from N
Jun Mukai
2014/09/23 20:48:44
That is an idea. Please see Bauer's comment.
Bernhard Bauer
2014/09/24 08:15:31
Yeah, that probably makes the most sense. You coul
vabr (Chromium)
2014/09/24 09:56:39
+1 to putting the ThreadChecker (or NonThreadSafe)
| |
131 DCHECK(!content_settings_providers_[type]); | 128 DCHECK(!content_settings_providers_[type]); |
132 provider->AddObserver(this); | 129 provider->AddObserver(this); |
133 content_settings_providers_[type] = provider.release(); | 130 content_settings_providers_[type] = provider.release(); |
134 | 131 |
135 #ifndef NDEBUG | 132 #ifndef NDEBUG |
136 DCHECK_NE(used_from_thread_id_, base::kInvalidThreadId) | 133 DCHECK_NE(used_from_thread_id_, base::kInvalidThreadId) |
137 << "Used from multiple threads before initialization complete."; | 134 << "Used from multiple threads before initialization complete."; |
138 #endif | 135 #endif |
139 | 136 |
140 OnContentSettingChanged(ContentSettingsPattern(), | 137 OnContentSettingChanged(ContentSettingsPattern(), |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 content_type, | 318 content_type, |
322 resource_identifier, | 319 resource_identifier, |
323 value); | 320 value); |
324 } | 321 } |
325 | 322 |
326 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( | 323 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( |
327 const GURL& primary_url, | 324 const GURL& primary_url, |
328 const GURL& secondary_url, | 325 const GURL& secondary_url, |
329 ContentSettingsType content_type, | 326 ContentSettingsType content_type, |
330 const std::string& resource_identifier) { | 327 const std::string& resource_identifier) { |
331 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 328 DCHECK(CalledOnValidThread()); |
332 | 329 |
333 ContentSetting setting = GetContentSetting( | 330 ContentSetting setting = GetContentSetting( |
334 primary_url, secondary_url, content_type, resource_identifier); | 331 primary_url, secondary_url, content_type, resource_identifier); |
335 if (setting == CONTENT_SETTING_ALLOW) { | 332 if (setting == CONTENT_SETTING_ALLOW) { |
336 UpdateLastUsageByPattern( | 333 UpdateLastUsageByPattern( |
337 ContentSettingsPattern::FromURLNoWildcard(primary_url), | 334 ContentSettingsPattern::FromURLNoWildcard(primary_url), |
338 ContentSettingsPattern::FromURLNoWildcard(secondary_url), | 335 ContentSettingsPattern::FromURLNoWildcard(secondary_url), |
339 content_type); | 336 content_type); |
340 } | 337 } |
341 return setting; | 338 return setting; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
566 FOR_EACH_OBSERVER(content_settings::Observer, | 563 FOR_EACH_OBSERVER(content_settings::Observer, |
567 observers_, | 564 observers_, |
568 OnContentSettingChanged(primary_pattern, | 565 OnContentSettingChanged(primary_pattern, |
569 secondary_pattern, | 566 secondary_pattern, |
570 content_type, | 567 content_type, |
571 resource_identifier)); | 568 resource_identifier)); |
572 } | 569 } |
573 | 570 |
574 HostContentSettingsMap::~HostContentSettingsMap() { | 571 HostContentSettingsMap::~HostContentSettingsMap() { |
575 DCHECK(!prefs_); | 572 DCHECK(!prefs_); |
576 STLDeleteValues(&content_settings_providers_); | |
577 } | 573 } |
578 | 574 |
579 void HostContentSettingsMap::ShutdownOnUIThread() { | 575 void HostContentSettingsMap::ShutdownOnUIThread() { |
580 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 576 DCHECK(CalledOnValidThread()); |
581 DCHECK(prefs_); | 577 DCHECK(prefs_); |
582 prefs_ = NULL; | 578 prefs_ = NULL; |
583 for (ProviderIterator it = content_settings_providers_.begin(); | 579 for (ProviderIterator it = content_settings_providers_.begin(); |
584 it != content_settings_providers_.end(); | 580 it != content_settings_providers_.end(); |
585 ++it) { | 581 ++it) { |
586 it->second->ShutdownOnUIThread(); | 582 it->second->ShutdownOnUIThread(); |
587 } | 583 } |
584 STLDeleteValues(&content_settings_providers_); | |
585 DetachFromThread(); | |
588 } | 586 } |
589 | 587 |
590 void HostContentSettingsMap::MigrateObsoleteClearOnExitPref() { | 588 void HostContentSettingsMap::MigrateObsoleteClearOnExitPref() { |
591 // Don't migrate more than once. | 589 // Don't migrate more than once. |
592 if (prefs_->HasPrefPath(prefs::kContentSettingsClearOnExitMigrated) && | 590 if (prefs_->HasPrefPath(prefs::kContentSettingsClearOnExitMigrated) && |
593 prefs_->GetBoolean(prefs::kContentSettingsClearOnExitMigrated)) { | 591 prefs_->GetBoolean(prefs::kContentSettingsClearOnExitMigrated)) { |
594 return; | 592 return; |
595 } | 593 } |
596 | 594 |
597 if (!prefs_->GetBoolean(prefs::kClearSiteDataOnExit)) { | 595 if (!prefs_->GetBoolean(prefs::kClearSiteDataOnExit)) { |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
801 } | 799 } |
802 } | 800 } |
803 | 801 |
804 if (info) { | 802 if (info) { |
805 info->source = content_settings::SETTING_SOURCE_NONE; | 803 info->source = content_settings::SETTING_SOURCE_NONE; |
806 info->primary_pattern = ContentSettingsPattern(); | 804 info->primary_pattern = ContentSettingsPattern(); |
807 info->secondary_pattern = ContentSettingsPattern(); | 805 info->secondary_pattern = ContentSettingsPattern(); |
808 } | 806 } |
809 return scoped_ptr<base::Value>(); | 807 return scoped_ptr<base::Value>(); |
810 } | 808 } |
OLD | NEW |