1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/content_settings/core/browser/website_settings_registry.h"
7 #include "base/logging.h"
8 #include "components/content_settings/core/common/content_settings.h"
12 base::LazyInstance
<content_settings::WebsiteSettingsRegistry
> g_instance
=
13 LAZY_INSTANCE_INITIALIZER
;
17 namespace content_settings
{
20 WebsiteSettingsRegistry
* WebsiteSettingsRegistry::GetInstance() {
21 return g_instance
.Pointer();
24 WebsiteSettingsRegistry::WebsiteSettingsRegistry() {
28 WebsiteSettingsRegistry::~WebsiteSettingsRegistry() {}
30 void WebsiteSettingsRegistry::ResetForTest() {
31 website_settings_info_
.clear();
35 const WebsiteSettingsInfo
* WebsiteSettingsRegistry::Get(
36 ContentSettingsType type
) const {
37 const auto& it
= website_settings_info_
.find(type
);
38 if (it
!= website_settings_info_
.end())
43 const WebsiteSettingsInfo
* WebsiteSettingsRegistry::GetByName(
44 const std::string
& name
) const {
45 for (const auto& entry
: website_settings_info_
) {
46 if (entry
.second
->name() == name
)
52 const WebsiteSettingsInfo
* WebsiteSettingsRegistry::Register(
53 ContentSettingsType type
,
54 const std::string
& name
,
55 scoped_ptr
<base::Value
> initial_default_value
,
56 WebsiteSettingsInfo::SyncStatus sync_status
,
57 WebsiteSettingsInfo::LossyStatus lossy_status
) {
58 WebsiteSettingsInfo
* info
= new WebsiteSettingsInfo(
59 type
, name
, initial_default_value
.Pass(), sync_status
, lossy_status
);
60 website_settings_info_
.set(info
->type(), make_scoped_ptr(info
));
64 WebsiteSettingsRegistry::const_iterator
WebsiteSettingsRegistry::begin() const {
65 return const_iterator(website_settings_info_
.begin());
68 WebsiteSettingsRegistry::const_iterator
WebsiteSettingsRegistry::end() const {
69 return const_iterator(website_settings_info_
.end());
72 void WebsiteSettingsRegistry::Init() {
73 // TODO(raymes): This registration code should not have to be in a single
74 // location. It should be possible to register a setting from the code
75 // associated with it.
77 // WARNING: The string names of the permissions passed in below are used to
78 // generate preference names and should never be changed!
81 Register(CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE
,
82 "auto-select-certificate", nullptr, WebsiteSettingsInfo::UNSYNCABLE
,
83 WebsiteSettingsInfo::NOT_LOSSY
);
84 Register(CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS
, "ssl-cert-decisions",
85 nullptr, WebsiteSettingsInfo::UNSYNCABLE
,
86 WebsiteSettingsInfo::NOT_LOSSY
);
87 Register(CONTENT_SETTINGS_TYPE_APP_BANNER
, "app-banner", nullptr,
88 WebsiteSettingsInfo::UNSYNCABLE
, WebsiteSettingsInfo::LOSSY
);
89 Register(CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT
, "site-engagement", nullptr,
90 WebsiteSettingsInfo::UNSYNCABLE
, WebsiteSettingsInfo::LOSSY
);
93 } // namespace content_settings