This source file includes following definitions.
- Get
- GetFactoryInstance
- OnExtensionRegistered
- OnExtensionPrefsLoaded
- OnExtensionPrefsDeleted
- OnExtensionStateChanged
#include "chrome/browser/extensions/api/content_settings/content_settings_service.h"
#include "base/lazy_instance.h"
#include "chrome/browser/extensions/api/content_settings/content_settings_store.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_prefs_scope.h"
#include "extensions/browser/pref_names.h"
namespace extensions {
ContentSettingsService::ContentSettingsService(content::BrowserContext* context)
: content_settings_store_(new ContentSettingsStore()) {}
ContentSettingsService::~ContentSettingsService() {}
ContentSettingsService* ContentSettingsService::Get(
content::BrowserContext* context) {
return BrowserContextKeyedAPIFactory<ContentSettingsService>::Get(context);
}
BrowserContextKeyedAPIFactory<ContentSettingsService>*
ContentSettingsService::GetFactoryInstance() {
static base::LazyInstance<
BrowserContextKeyedAPIFactory<ContentSettingsService> > factory =
LAZY_INSTANCE_INITIALIZER;
return factory.Pointer();
}
void ContentSettingsService::OnExtensionRegistered(
const std::string& extension_id,
const base::Time& install_time,
bool is_enabled) {
content_settings_store_->RegisterExtension(
extension_id, install_time, is_enabled);
}
void ContentSettingsService::OnExtensionPrefsLoaded(
const std::string& extension_id,
const ExtensionPrefs* prefs) {
const base::ListValue* content_settings = NULL;
if (prefs->ReadPrefAsList(
extension_id, pref_names::kPrefContentSettings, &content_settings)) {
content_settings_store_->SetExtensionContentSettingFromList(
extension_id, content_settings, kExtensionPrefsScopeRegular);
}
if (prefs->ReadPrefAsList(extension_id,
pref_names::kPrefIncognitoContentSettings,
&content_settings)) {
content_settings_store_->SetExtensionContentSettingFromList(
extension_id,
content_settings,
kExtensionPrefsScopeIncognitoPersistent);
}
}
void ContentSettingsService::OnExtensionPrefsDeleted(
const std::string& extension_id) {
content_settings_store_->UnregisterExtension(extension_id);
}
void ContentSettingsService::OnExtensionStateChanged(
const std::string& extension_id,
bool state) {
content_settings_store_->SetExtensionState(extension_id, state);
}
}