Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ios / chrome / browser / content_settings / cookie_settings_factory.cc
blobe2710988df3e0b8da2657d175e275cd6859bd867
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 "ios/chrome/browser/content_settings/cookie_settings_factory.h"
7 #include "base/memory/singleton.h"
8 #include "components/content_settings/core/browser/cookie_settings.h"
9 #include "components/keyed_service/ios/browser_state_dependency_manager.h"
10 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h"
11 #include "ios/chrome/browser/content_settings/host_content_settings_map_factory.h"
12 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
14 namespace {
15 const char kDummyExtensionScheme[] = ":no-extension-scheme:";
18 namespace ios {
20 // static
21 scoped_refptr<content_settings::CookieSettings>
22 CookieSettingsFactory::GetForBrowserState(
23 ios::ChromeBrowserState* browser_state) {
24 return static_cast<content_settings::CookieSettings*>(
25 GetInstance()->GetServiceForBrowserState(browser_state, true).get());
28 // static
29 CookieSettingsFactory* CookieSettingsFactory::GetInstance() {
30 return base::Singleton<CookieSettingsFactory>::get();
33 CookieSettingsFactory::CookieSettingsFactory()
34 : RefcountedBrowserStateKeyedServiceFactory(
35 "CookieSettings",
36 BrowserStateDependencyManager::GetInstance()) {
37 DependsOn(ios::HostContentSettingsMapFactory::GetInstance());
40 CookieSettingsFactory::~CookieSettingsFactory() {
43 void CookieSettingsFactory::RegisterBrowserStatePrefs(
44 user_prefs::PrefRegistrySyncable* registry) {
45 content_settings::CookieSettings::RegisterProfilePrefs(registry);
48 web::BrowserState* CookieSettingsFactory::GetBrowserStateToUse(
49 web::BrowserState* context) const {
50 // The incognito browser state has its own content settings map. Therefore, it
51 // should get its own CookieSettings.
52 return GetBrowserStateOwnInstanceInIncognito(context);
55 scoped_refptr<RefcountedKeyedService>
56 CookieSettingsFactory::BuildServiceInstanceFor(
57 web::BrowserState* context) const {
58 ios::ChromeBrowserState* browser_state =
59 ios::ChromeBrowserState::FromBrowserState(context);
60 return new content_settings::CookieSettings(
61 ios::HostContentSettingsMapFactory::GetForBrowserState(browser_state),
62 browser_state->GetPrefs(), kDummyExtensionScheme);
65 } // namespace ios