forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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/+/2127418 Reviewed-by: John Abd-El-Malek <jam@chromium.org> Commit-Queue: Clark DuVall <cduvall@chromium.org> Cr-Commit-Position: refs/heads/master@{#754708}
- Loading branch information
1 parent
9eaedfd
commit bac8e1e
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// 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_ |