Revert 285173 "Removed InProcessBrowserTest::CleanUpOnMainThread()"
[chromium-blink-merge.git] / chrome / browser / extensions / api / content_settings / content_settings_service.cc
blob4a7e4151999b6c9b4bcd2d8e82796b8ee14ffcd4
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() {}
20 // static
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,
38 bool is_enabled) {
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,
54 &content_settings)) {
55 content_settings_store_->SetExtensionContentSettingFromList(
56 extension_id,
57 content_settings,
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,
69 bool state) {
70 content_settings_store_->SetExtensionState(extension_id, state);
73 } // namespace extensions