1 // Copyright 2014 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 "chrome/browser/extensions/api/content_settings/content_settings_service.h"
7 #include "base/lazy_instance.h"
8 #include "chrome/browser/extensions/api/content_settings/content_settings_store.h"
9 #include "extensions/browser/extension_prefs.h"
10 #include "extensions/browser/extension_prefs_scope.h"
11 #include "extensions/browser/pref_names.h"
13 namespace extensions
{
15 ContentSettingsService::ContentSettingsService(content::BrowserContext
* context
)
16 : content_settings_store_(new ContentSettingsStore()) {}
18 ContentSettingsService::~ContentSettingsService() {}
21 ContentSettingsService
* ContentSettingsService::Get(
22 content::BrowserContext
* context
) {
23 return BrowserContextKeyedAPIFactory
<ContentSettingsService
>::Get(context
);
26 // BrowserContextKeyedAPI implementation.
27 BrowserContextKeyedAPIFactory
<ContentSettingsService
>*
28 ContentSettingsService::GetFactoryInstance() {
29 static base::LazyInstance
<
30 BrowserContextKeyedAPIFactory
<ContentSettingsService
> > factory
=
31 LAZY_INSTANCE_INITIALIZER
;
32 return factory
.Pointer();
35 void ContentSettingsService::OnExtensionRegistered(
36 const std::string
& extension_id
,
37 const base::Time
& install_time
,
39 content_settings_store_
->RegisterExtension(
40 extension_id
, install_time
, is_enabled
);
43 void ContentSettingsService::OnExtensionPrefsLoaded(
44 const std::string
& extension_id
,
45 const ExtensionPrefs
* prefs
) {
46 const base::ListValue
* content_settings
= NULL
;
47 if (prefs
->ReadPrefAsList(
48 extension_id
, pref_names::kPrefContentSettings
, &content_settings
)) {
49 content_settings_store_
->SetExtensionContentSettingFromList(
50 extension_id
, content_settings
, kExtensionPrefsScopeRegular
);
52 if (prefs
->ReadPrefAsList(extension_id
,
53 pref_names::kPrefIncognitoContentSettings
,
55 content_settings_store_
->SetExtensionContentSettingFromList(
58 kExtensionPrefsScopeIncognitoPersistent
);
62 void ContentSettingsService::OnExtensionPrefsDeleted(
63 const std::string
& extension_id
) {
64 content_settings_store_
->UnregisterExtension(extension_id
);
67 void ContentSettingsService::OnExtensionStateChanged(
68 const std::string
& extension_id
,
70 content_settings_store_
->SetExtensionState(extension_id
, state
);
73 } // namespace extensions