Commit bac8e1eb authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

[WebLayer] Implement CookieSettingsFactory

We need CookieSettings for adding the header necessary for the manage
accounts feature.

Bug: 1054160
Change-Id: I736267acaed75d23362ff96c77bd4a1b1634c707
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2127418Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754708}
parent 9eaedfd9
......@@ -115,6 +115,8 @@ source_set("weblayer_lib_base") {
"browser/controls_visibility_reason.h",
"browser/cookie_manager_impl.cc",
"browser/cookie_manager_impl.h",
"browser/cookie_settings_factory.cc",
"browser/cookie_settings_factory.h",
"browser/download_impl.cc",
"browser/download_impl.h",
"browser/download_manager_delegate_impl.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "weblayer/browser/cookie_settings_factory.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "weblayer/browser/browser_context_impl.h"
#include "weblayer/browser/host_content_settings_map_factory.h"
namespace weblayer {
// static
scoped_refptr<content_settings::CookieSettings>
CookieSettingsFactory::GetForBrowserContext(
content::BrowserContext* browser_context) {
return static_cast<content_settings::CookieSettings*>(
GetInstance()->GetServiceForBrowserContext(browser_context, true).get());
}
// static
CookieSettingsFactory* CookieSettingsFactory::GetInstance() {
static base::NoDestructor<CookieSettingsFactory> factory;
return factory.get();
}
CookieSettingsFactory::CookieSettingsFactory()
: RefcountedBrowserContextKeyedServiceFactory(
"CookieSettings",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(HostContentSettingsMapFactory::GetInstance());
}
CookieSettingsFactory::~CookieSettingsFactory() = default;
void CookieSettingsFactory::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {
content_settings::CookieSettings::RegisterProfilePrefs(registry);
}
content::BrowserContext* CookieSettingsFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return context;
}
scoped_refptr<RefcountedKeyedService>
CookieSettingsFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new content_settings::CookieSettings(
HostContentSettingsMapFactory::GetForBrowserContext(context),
static_cast<BrowserContextImpl*>(context)->pref_service(),
context->IsOffTheRecord());
}
} // namespace weblayer
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WEBLAYER_BROWSER_COOKIE_SETTINGS_FACTORY_H_
#define WEBLAYER_BROWSER_COOKIE_SETTINGS_FACTORY_H_
#include "base/no_destructor.h"
#include "components/keyed_service/content/refcounted_browser_context_keyed_service_factory.h"
namespace content_settings {
class CookieSettings;
}
namespace weblayer {
class CookieSettingsFactory
: public RefcountedBrowserContextKeyedServiceFactory {
public:
CookieSettingsFactory(const CookieSettingsFactory&) = delete;
CookieSettingsFactory& operator=(const CookieSettingsFactory&) = delete;
static scoped_refptr<content_settings::CookieSettings> GetForBrowserContext(
content::BrowserContext* browser_context);
static CookieSettingsFactory* GetInstance();
private:
friend class base::NoDestructor<CookieSettingsFactory>;
CookieSettingsFactory();
~CookieSettingsFactory() override;
// BrowserContextKeyedServiceFactory methods:
void RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
scoped_refptr<RefcountedKeyedService> BuildServiceInstanceFor(
content::BrowserContext* context) const override;
};
} // namespace weblayer
#endif // WEBLAYER_BROWSER_COOKIE_SETTINGS_FACTORY_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment