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/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
14 const char kDummyExtensionScheme
[] = ":no-extension-scheme:";
20 scoped_refptr
<content_settings::CookieSettings
>
21 CookieSettingsFactory::GetForBrowserState(
22 ios::ChromeBrowserState
* browser_state
) {
23 return static_cast<content_settings::CookieSettings
*>(
24 GetInstance()->GetServiceForBrowserState(browser_state
, true).get());
28 CookieSettingsFactory
* CookieSettingsFactory::GetInstance() {
29 return Singleton
<CookieSettingsFactory
>::get();
32 CookieSettingsFactory::CookieSettingsFactory()
33 : RefcountedBrowserStateKeyedServiceFactory(
35 BrowserStateDependencyManager::GetInstance()) {
38 CookieSettingsFactory::~CookieSettingsFactory() {
41 void CookieSettingsFactory::RegisterBrowserStatePrefs(
42 user_prefs::PrefRegistrySyncable
* registry
) {
43 content_settings::CookieSettings::RegisterProfilePrefs(registry
);
46 web::BrowserState
* CookieSettingsFactory::GetBrowserStateToUse(
47 web::BrowserState
* context
) const {
48 // The incognito browser state has its own content settings map. Therefore, it
49 // should get its own CookieSettings.
50 return GetBrowserStateOwnInstanceInIncognito(context
);
53 scoped_refptr
<RefcountedKeyedService
>
54 CookieSettingsFactory::BuildServiceInstanceFor(
55 web::BrowserState
* context
) const {
56 ios::ChromeBrowserState
* browser_state
=
57 ios::ChromeBrowserState::FromBrowserState(context
);
58 return new content_settings::CookieSettings(
59 browser_state
->GetHostContentSettingsMap(), browser_state
->GetPrefs(),
60 kDummyExtensionScheme
);