Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: components/content_settings/core/browser/host_content_settings_map.cc

Issue 2938163002: Store base::Value in ContentSettingPatternSource instead of an enum (Closed)
Patch Set: rebased Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/content_settings/core/browser/host_content_settings_map.h" 5 #include "components/content_settings/core/browser/host_content_settings_map.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
18 #include "base/time/clock.h" 18 #include "base/time/clock.h"
19 #include "base/values.h"
19 #include "build/build_config.h" 20 #include "build/build_config.h"
20 #include "components/content_settings/core/browser/content_settings_default_prov ider.h" 21 #include "components/content_settings/core/browser/content_settings_default_prov ider.h"
21 #include "components/content_settings/core/browser/content_settings_details.h" 22 #include "components/content_settings/core/browser/content_settings_details.h"
22 #include "components/content_settings/core/browser/content_settings_info.h" 23 #include "components/content_settings/core/browser/content_settings_info.h"
23 #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"
24 #include "components/content_settings/core/browser/content_settings_policy_provi der.h" 25 #include "components/content_settings/core/browser/content_settings_policy_provi der.h"
25 #include "components/content_settings/core/browser/content_settings_pref_provide r.h" 26 #include "components/content_settings/core/browser/content_settings_pref_provide r.h"
26 #include "components/content_settings/core/browser/content_settings_provider.h" 27 #include "components/content_settings/core/browser/content_settings_provider.h"
27 #include "components/content_settings/core/browser/content_settings_registry.h" 28 #include "components/content_settings/core/browser/content_settings_registry.h"
28 #include "components/content_settings/core/browser/content_settings_rule.h" 29 #include "components/content_settings/core/browser/content_settings_rule.h"
29 #include "components/content_settings/core/browser/content_settings_utils.h" 30 #include "components/content_settings/core/browser/content_settings_utils.h"
30 #include "components/content_settings/core/browser/website_settings_registry.h" 31 #include "components/content_settings/core/browser/website_settings_registry.h"
31 #include "components/content_settings/core/common/content_settings_pattern.h" 32 #include "components/content_settings/core/common/content_settings_pattern.h"
33 #include "components/content_settings/core/common/content_settings_utils.h"
32 #include "components/content_settings/core/common/pref_names.h" 34 #include "components/content_settings/core/common/pref_names.h"
33 #include "components/pref_registry/pref_registry_syncable.h" 35 #include "components/pref_registry/pref_registry_syncable.h"
34 #include "components/prefs/pref_service.h" 36 #include "components/prefs/pref_service.h"
35 #include "net/base/net_errors.h" 37 #include "net/base/net_errors.h"
36 #include "net/base/static_cookie_policy.h" 38 #include "net/base/static_cookie_policy.h"
37 #include "url/gurl.h" 39 #include "url/gurl.h"
38 40
39 using content_settings::WebsiteSettingsInfo; 41 using content_settings::WebsiteSettingsInfo;
40 using content_settings::ContentSettingsInfo; 42 using content_settings::ContentSettingsInfo;
41 43
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 if (!content_settings::ContentSettingsRegistry::GetInstance()->Get(type)) 524 if (!content_settings::ContentSettingsRegistry::GetInstance()->Get(type))
523 continue; 525 continue;
524 ContentSettingsForOneType settings; 526 ContentSettingsForOneType settings;
525 GetSettingsForOneType(type, std::string(), &settings); 527 GetSettingsForOneType(type, std::string(), &settings);
526 528
527 for (const ContentSettingPatternSource& setting_entry : settings) { 529 for (const ContentSettingPatternSource& setting_entry : settings) {
528 // Migrate user preference settings only. 530 // Migrate user preference settings only.
529 if (setting_entry.source != "preference") 531 if (setting_entry.source != "preference")
530 continue; 532 continue;
531 // Migrate ALLOW settings only. 533 // Migrate ALLOW settings only.
532 if (setting_entry.setting != CONTENT_SETTING_ALLOW) 534 if (setting_entry.GetContentSetting() != CONTENT_SETTING_ALLOW)
533 continue; 535 continue;
534 // Skip default settings. 536 // Skip default settings.
535 if (setting_entry.primary_pattern == ContentSettingsPattern::Wildcard()) 537 if (setting_entry.primary_pattern == ContentSettingsPattern::Wildcard())
536 continue; 538 continue;
537 539
538 if (setting_entry.secondary_pattern != 540 if (setting_entry.secondary_pattern !=
539 ContentSettingsPattern::Wildcard()) { 541 ContentSettingsPattern::Wildcard()) {
540 NOTREACHED(); 542 NOTREACHED();
541 continue; 543 continue;
542 } 544 }
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 const std::string& resource_identifier, 731 const std::string& resource_identifier,
730 ContentSettingsForOneType* settings, 732 ContentSettingsForOneType* settings,
731 bool incognito) const { 733 bool incognito) const {
732 std::unique_ptr<content_settings::RuleIterator> rule_iterator( 734 std::unique_ptr<content_settings::RuleIterator> rule_iterator(
733 provider->GetRuleIterator(content_type, resource_identifier, incognito)); 735 provider->GetRuleIterator(content_type, resource_identifier, incognito));
734 if (!rule_iterator) 736 if (!rule_iterator)
735 return; 737 return;
736 738
737 while (rule_iterator->HasNext()) { 739 while (rule_iterator->HasNext()) {
738 const content_settings::Rule& rule = rule_iterator->Next(); 740 const content_settings::Rule& rule = rule_iterator->Next();
739 ContentSetting setting_value = CONTENT_SETTING_DEFAULT; 741 std::unique_ptr<base::Value> setting_value;
740 // TODO(bauerb): Return rules as a list of values, not content settings. 742 // TODO(bauerb): Return rules as a list of values, not content settings.
741 // Handle the case using base::Values for its exceptions and default 743 // Handle the case using base::Values for its exceptions and default
742 // setting. Here we assume all the exceptions are granted as 744 // setting. Here we assume all the exceptions are granted as
743 // |CONTENT_SETTING_ALLOW|. 745 // |CONTENT_SETTING_ALLOW|.
744 if (!content_settings::ContentSettingsRegistry::GetInstance()->Get( 746 if (!content_settings::ContentSettingsRegistry::GetInstance()->Get(
745 content_type) && 747 content_type) &&
746 rule.value.get() && 748 rule.value.get() &&
747 rule.primary_pattern != ContentSettingsPattern::Wildcard()) { 749 rule.primary_pattern != ContentSettingsPattern::Wildcard()) {
748 setting_value = CONTENT_SETTING_ALLOW; 750 setting_value =
751 content_settings::ContentSettingToValue(CONTENT_SETTING_ALLOW);
749 } else { 752 } else {
750 setting_value = content_settings::ValueToContentSetting(rule.value.get()); 753 setting_value = base::MakeUnique<base::Value>(*(rule.value));
751 } 754 }
752 settings->push_back(ContentSettingPatternSource( 755 settings->push_back(ContentSettingPatternSource(
753 rule.primary_pattern, rule.secondary_pattern, setting_value, 756 rule.primary_pattern, rule.secondary_pattern, std::move(setting_value),
754 kProviderNamesSourceMap[provider_type].provider_name, incognito)); 757 kProviderNamesSourceMap[provider_type].provider_name, incognito));
755 } 758 }
756 } 759 }
757 760
758 void HostContentSettingsMap::UsedContentSettingsProviders() const { 761 void HostContentSettingsMap::UsedContentSettingsProviders() const {
759 #ifndef NDEBUG 762 #ifndef NDEBUG
760 if (used_from_thread_id_ == base::kInvalidThreadId) 763 if (used_from_thread_id_ == base::kInvalidThreadId)
761 return; 764 return;
762 765
763 if (base::PlatformThread::CurrentId() != used_from_thread_id_) 766 if (base::PlatformThread::CurrentId() != used_from_thread_id_)
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 } 910 }
908 } 911 }
909 } 912 }
910 return std::unique_ptr<base::Value>(); 913 return std::unique_ptr<base::Value>();
911 } 914 }
912 915
913 void HostContentSettingsMap::SetClockForTesting( 916 void HostContentSettingsMap::SetClockForTesting(
914 std::unique_ptr<base::Clock> clock) { 917 std::unique_ptr<base::Clock> clock) {
915 pref_provider_->SetClockForTesting(std::move(clock)); 918 pref_provider_->SetClockForTesting(std::move(clock));
916 } 919 }
OLDNEW
« no previous file with comments | « components/content_settings/core/browser/cookie_settings.cc ('k') | components/content_settings/core/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698