Chromium Code Reviews| 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" | |
| 21 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 22 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 23 #include "components/content_settings/core/browser/content_settings_details.h" | 22 #include "components/content_settings/core/browser/content_settings_details.h" |
| 24 #include "components/content_settings/core/browser/content_settings_observable_p rovider.h" | 23 #include "components/content_settings/core/browser/content_settings_observable_p rovider.h" |
| 25 #include "components/content_settings/core/browser/content_settings_provider.h" | 24 #include "components/content_settings/core/browser/content_settings_provider.h" |
| 26 #include "components/content_settings/core/browser/content_settings_rule.h" | 25 #include "components/content_settings/core/browser/content_settings_rule.h" |
| 27 #include "components/content_settings/core/common/content_settings_pattern.h" | 26 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 28 #include "components/pref_registry/pref_registry_syncable.h" | 27 #include "components/pref_registry/pref_registry_syncable.h" |
| 29 #include "content/public/browser/browser_thread.h" | |
| 30 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
| 31 #include "net/base/static_cookie_policy.h" | 29 #include "net/base/static_cookie_policy.h" |
| 32 #include "url/gurl.h" | 30 #include "url/gurl.h" |
| 33 | 31 |
| 34 #if defined(ENABLE_EXTENSIONS) | 32 #if defined(ENABLE_EXTENSIONS) |
| 35 #include "extensions/common/constants.h" | 33 #include "extensions/common/constants.h" |
| 36 #endif | 34 #endif |
| 37 | 35 |
| 38 using content::BrowserThread; | |
| 39 | |
| 40 namespace { | 36 namespace { |
| 41 | 37 |
| 42 typedef std::vector<content_settings::Rule> Rules; | 38 typedef std::vector<content_settings::Rule> Rules; |
| 43 | 39 |
| 44 typedef std::pair<std::string, std::string> StringPair; | 40 typedef std::pair<std::string, std::string> StringPair; |
| 45 | 41 |
| 46 // TODO(bauerb): Expose constants. | 42 // TODO(bauerb): Expose constants. |
| 47 const char* kProviderNames[] = { | 43 const char* kProviderNames[] = { |
| 48 "platform_app", | 44 "platform_app", |
| 49 "policy", | 45 "policy", |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 74 } // namespace | 70 } // namespace |
| 75 | 71 |
| 76 HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs, | 72 HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs, |
| 77 bool incognito) | 73 bool incognito) |
| 78 : | 74 : |
| 79 #ifndef NDEBUG | 75 #ifndef NDEBUG |
| 80 used_from_thread_id_(base::PlatformThread::CurrentId()), | 76 used_from_thread_id_(base::PlatformThread::CurrentId()), |
| 81 #endif | 77 #endif |
| 82 prefs_(prefs), | 78 prefs_(prefs), |
| 83 is_off_the_record_(incognito) { | 79 is_off_the_record_(incognito) { |
| 80 // This should be called on the UI thread, otherwise |thread_checker_| handles | |
|
Bernhard Bauer
2014/10/15 12:37:02
Why is this comment here? It might make more sense
Jun Mukai
2014/10/15 23:46:18
I misunderstood your previous comment. Moved back
| |
| 81 // CalledOnValidThread() wrongly. | |
| 84 content_settings::ObservableProvider* policy_provider = | 82 content_settings::ObservableProvider* policy_provider = |
| 85 new content_settings::PolicyProvider(prefs_); | 83 new content_settings::PolicyProvider(prefs_); |
| 86 policy_provider->AddObserver(this); | 84 policy_provider->AddObserver(this); |
| 87 content_settings_providers_[POLICY_PROVIDER] = policy_provider; | 85 content_settings_providers_[POLICY_PROVIDER] = policy_provider; |
| 88 | 86 |
| 89 content_settings::ObservableProvider* pref_provider = | 87 content_settings::ObservableProvider* pref_provider = |
| 90 new content_settings::PrefProvider(prefs_, is_off_the_record_); | 88 new content_settings::PrefProvider(prefs_, is_off_the_record_); |
| 91 pref_provider->AddObserver(this); | 89 pref_provider->AddObserver(this); |
| 92 content_settings_providers_[PREF_PROVIDER] = pref_provider; | 90 content_settings_providers_[PREF_PROVIDER] = pref_provider; |
| 93 | 91 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 content_type, | 318 content_type, |
| 321 resource_identifier, | 319 resource_identifier, |
| 322 value); | 320 value); |
| 323 } | 321 } |
| 324 | 322 |
| 325 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( | 323 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( |
| 326 const GURL& primary_url, | 324 const GURL& primary_url, |
| 327 const GURL& secondary_url, | 325 const GURL& secondary_url, |
| 328 ContentSettingsType content_type, | 326 ContentSettingsType content_type, |
| 329 const std::string& resource_identifier) { | 327 const std::string& resource_identifier) { |
| 330 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 328 DCHECK(thread_checker_.CalledOnValidThread()); |
| 331 | 329 |
| 332 ContentSetting setting = GetContentSetting( | 330 ContentSetting setting = GetContentSetting( |
| 333 primary_url, secondary_url, content_type, resource_identifier); | 331 primary_url, secondary_url, content_type, resource_identifier); |
| 334 if (setting == CONTENT_SETTING_ALLOW) { | 332 if (setting == CONTENT_SETTING_ALLOW) { |
| 335 UpdateLastUsageByPattern( | 333 UpdateLastUsageByPattern( |
| 336 ContentSettingsPattern::FromURLNoWildcard(primary_url), | 334 ContentSettingsPattern::FromURLNoWildcard(primary_url), |
| 337 ContentSettingsPattern::FromURLNoWildcard(secondary_url), | 335 ContentSettingsPattern::FromURLNoWildcard(secondary_url), |
| 338 content_type); | 336 content_type); |
| 339 } | 337 } |
| 340 return setting; | 338 return setting; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 content_type, | 567 content_type, |
| 570 resource_identifier)); | 568 resource_identifier)); |
| 571 } | 569 } |
| 572 | 570 |
| 573 HostContentSettingsMap::~HostContentSettingsMap() { | 571 HostContentSettingsMap::~HostContentSettingsMap() { |
| 574 DCHECK(!prefs_); | 572 DCHECK(!prefs_); |
| 575 STLDeleteValues(&content_settings_providers_); | 573 STLDeleteValues(&content_settings_providers_); |
| 576 } | 574 } |
| 577 | 575 |
| 578 void HostContentSettingsMap::ShutdownOnUIThread() { | 576 void HostContentSettingsMap::ShutdownOnUIThread() { |
| 579 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 577 DCHECK(thread_checker_.CalledOnValidThread()); |
| 580 DCHECK(prefs_); | 578 DCHECK(prefs_); |
| 581 prefs_ = NULL; | 579 prefs_ = NULL; |
| 582 for (ProviderIterator it = content_settings_providers_.begin(); | 580 for (ProviderIterator it = content_settings_providers_.begin(); |
| 583 it != content_settings_providers_.end(); | 581 it != content_settings_providers_.end(); |
| 584 ++it) { | 582 ++it) { |
| 585 it->second->ShutdownOnUIThread(); | 583 it->second->ShutdownOnUIThread(); |
| 586 } | 584 } |
| 587 } | 585 } |
| 588 | 586 |
| 589 void HostContentSettingsMap::MigrateObsoleteClearOnExitPref() { | 587 void HostContentSettingsMap::MigrateObsoleteClearOnExitPref() { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 800 } | 798 } |
| 801 } | 799 } |
| 802 | 800 |
| 803 if (info) { | 801 if (info) { |
| 804 info->source = content_settings::SETTING_SOURCE_NONE; | 802 info->source = content_settings::SETTING_SOURCE_NONE; |
| 805 info->primary_pattern = ContentSettingsPattern(); | 803 info->primary_pattern = ContentSettingsPattern(); |
| 806 info->secondary_pattern = ContentSettingsPattern(); | 804 info->secondary_pattern = ContentSettingsPattern(); |
| 807 } | 805 } |
| 808 return scoped_ptr<base::Value>(); | 806 return scoped_ptr<base::Value>(); |
| 809 } | 807 } |
| OLD | NEW |