Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / content_settings / cookie_settings_factory.cc
blobe22b45a31eaf0d6c3df5eabb28193f90d841559f
1 // Copyright (c) 2012 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/content_settings/cookie_settings_factory.h"
7 #include "base/logging.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/profiles/incognito_helpers.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "components/content_settings/core/browser/cookie_settings.h"
12 #include "components/content_settings/core/common/pref_names.h"
13 #include "components/keyed_service/content/browser_context_dependency_manager.h"
14 #include "components/pref_registry/pref_registry_syncable.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/user_metrics.h"
17 #include "extensions/common/constants.h"
19 using base::UserMetricsAction;
21 // static
22 scoped_refptr<content_settings::CookieSettings>
23 CookieSettingsFactory::GetForProfile(Profile* profile) {
24 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
25 return static_cast<content_settings::CookieSettings*>(
26 GetInstance()->GetServiceForBrowserContext(profile, true).get());
29 // static
30 CookieSettingsFactory* CookieSettingsFactory::GetInstance() {
31 return Singleton<CookieSettingsFactory>::get();
34 CookieSettingsFactory::CookieSettingsFactory()
35 : RefcountedBrowserContextKeyedServiceFactory(
36 "CookieSettings",
37 BrowserContextDependencyManager::GetInstance()) {
40 CookieSettingsFactory::~CookieSettingsFactory() {
43 void CookieSettingsFactory::RegisterProfilePrefs(
44 user_prefs::PrefRegistrySyncable* registry) {
45 content_settings::CookieSettings::RegisterProfilePrefs(registry);
48 content::BrowserContext* CookieSettingsFactory::GetBrowserContextToUse(
49 content::BrowserContext* context) const {
50 // The incognito profile has its own content settings map. Therefore, it
51 // should get its own CookieSettings.
52 return chrome::GetBrowserContextOwnInstanceInIncognito(context);
55 scoped_refptr<RefcountedKeyedService>
56 CookieSettingsFactory::BuildServiceInstanceFor(
57 content::BrowserContext* context) const {
58 Profile* profile = static_cast<Profile*>(context);
59 if (profile->GetPrefs()->GetBoolean(prefs::kBlockThirdPartyCookies)) {
60 content::RecordAction(UserMetricsAction("ThirdPartyCookieBlockingEnabled"));
61 } else {
62 content::RecordAction(
63 UserMetricsAction("ThirdPartyCookieBlockingDisabled"));
65 return new content_settings::CookieSettings(
66 profile->GetHostContentSettingsMap(), profile->GetPrefs(),
67 extensions::kExtensionScheme);