Skip to content

Commit

Permalink
[WebLayer] Implement CookieSettingsFactory
Browse files Browse the repository at this point in the history
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
clarkduvall authored and Commit Bot committed Mar 30, 2020
1 parent 9eaedfd commit bac8e1e
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
2 changes: 2 additions & 0 deletions weblayer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
59 changes: 59 additions & 0 deletions weblayer/browser/cookie_settings_factory.cc
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
44 changes: 44 additions & 0 deletions weblayer/browser/cookie_settings_factory.h
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_

0 comments on commit bac8e1e

Please sign in to comment.