Commit 9be6fcb3 authored by Mihai Sardarescu's avatar Mihai Sardarescu Committed by Commit Bot

[unity] Introduce unified consent service

This CL adds the skeleton for the unified consent service. The role of this service is to
manage the preferences for unified consent. The initial implementation adds the pref
that monitors whether the user has consented for URL-keyed anonymized data collection.
It also resets this preference to false when the user signs out of Chrome.

Design document: http://go/project-unity-dd (internal only).

Bug: 823809, 814973

Change-Id: If902eee16843b8df73b543c151e7155d966441a7
Reviewed-on: https://chromium-review.googlesource.com/1074658
Commit-Queue: Mihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarThomas Tangl <tangltom@chromium.org>
Cr-Commit-Position: refs/heads/master@{#564774}
parent 1c75475f
......@@ -1518,6 +1518,8 @@ jumbo_split_static_library("browser") {
"translate/translate_service.h",
"undo/bookmark_undo_service_factory.cc",
"undo/bookmark_undo_service_factory.h",
"unified_consent/unified_consent_service_factory.cc",
"unified_consent/unified_consent_service_factory.h",
"update_client/chrome_update_query_params_delegate.cc",
"update_client/chrome_update_query_params_delegate.h",
"usb/usb_blocklist.cc",
......@@ -1757,6 +1759,7 @@ jumbo_split_static_library("browser") {
"//components/ukm:observers",
"//components/ukm/content/debug_page",
"//components/undo",
"//components/unified_consent",
"//components/update_client",
"//components/upload_list",
"//components/url_formatter",
......
......@@ -81,6 +81,7 @@
#include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h"
#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
#include "chrome/browser/undo/bookmark_undo_service_factory.h"
#include "chrome/browser/unified_consent/unified_consent_service_factory.h"
#include "chrome/browser/web_data_service_factory.h"
#include "chrome/common/buildflags.h"
#include "components/feature_engagement/buildflags.h"
......@@ -371,6 +372,7 @@ void ChromeBrowserMainExtraPartsProfiles::
TriggeredProfileResetterFactory::GetInstance();
#endif
UINetworkQualityEstimatorServiceFactory::GetInstance();
UnifiedConsentServiceFactory::GetInstance();
UrlLanguageHistogramFactory::GetInstance();
#if !defined(OS_ANDROID)
UsbChooserContextFactory::GetInstance();
......
// Copyright 2018 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 "chrome/browser/unified_consent/unified_consent_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/unified_consent_helper.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/unified_consent/unified_consent_service.h"
UnifiedConsentServiceFactory::UnifiedConsentServiceFactory()
: BrowserContextKeyedServiceFactory(
"UnifiedConsentService",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(IdentityManagerFactory::GetInstance());
}
UnifiedConsentServiceFactory::~UnifiedConsentServiceFactory() = default;
// static
UnifiedConsentService* UnifiedConsentServiceFactory::GetForProfile(
Profile* profile) {
return static_cast<UnifiedConsentService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
// static
UnifiedConsentServiceFactory* UnifiedConsentServiceFactory::GetInstance() {
return base::Singleton<UnifiedConsentServiceFactory>::get();
}
void UnifiedConsentServiceFactory::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {
UnifiedConsentService::RegisterPrefs(registry);
}
KeyedService* UnifiedConsentServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
Profile* profile = Profile::FromBrowserContext(context);
if (!IsUnifiedConsentEnabled(profile))
return nullptr;
return new UnifiedConsentService(
profile->GetPrefs(), IdentityManagerFactory::GetForProfile(profile));
}
bool UnifiedConsentServiceFactory::ServiceIsNULLWhileTesting() const {
return false;
}
bool UnifiedConsentServiceFactory::ServiceIsCreatedWithBrowserContext() const {
return true;
}
// Copyright 2018 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 CHROME_BROWSER_UNIFIED_CONSENT_UNIFIED_CONSENT_SERVICE_FACTORY_H_
#define CHROME_BROWSER_UNIFIED_CONSENT_UNIFIED_CONSENT_SERVICE_FACTORY_H_
#include "base/macros.h"
#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class Profile;
class UnifiedConsentService;
class UnifiedConsentServiceFactory : public BrowserContextKeyedServiceFactory {
public:
// Returns the instance of UnifiedConsentService associated with |profile|
// (creating one if none exists). Returns nullptr if this profile cannot have
// a UnifiedConsentService (e.g. UnifiedConsent is not enabled for |profile|
// or |profile| is incognito).
static UnifiedConsentService* GetForProfile(Profile* profile);
// Returns an instance of the factory singleton.
static UnifiedConsentServiceFactory* GetInstance();
private:
friend struct base::DefaultSingletonTraits<UnifiedConsentServiceFactory>;
UnifiedConsentServiceFactory();
~UnifiedConsentServiceFactory() override;
// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* profile) const override;
void RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) override;
bool ServiceIsNULLWhileTesting() const override;
bool ServiceIsCreatedWithBrowserContext() const override;
DISALLOW_COPY_AND_ASSIGN(UnifiedConsentServiceFactory);
};
#endif // CHROME_BROWSER_UNIFIED_CONSENT_UNIFIED_CONSENT_SERVICE_FACTORY_H_
# Copyright 2018 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.
static_library("unified_consent") {
sources = [
"pref_names.cc",
"pref_names.h",
"unified_consent_service.cc",
"unified_consent_service.h",
]
deps = [
"//base",
"//components/pref_registry",
"//components/signin/core/browser",
"//components/sync",
"//services/identity/public/cpp",
]
}
include_rules = [
"+components/keyed_service/core",
"+components/pref_registry",
"+components/prefs",
"+services/identity/public/cpp",
]
msarda@chromium.org
tangltom@chromium.org
# TEAM: chrome-signin@chromium.org
# COMPONENT: Services>SignIn
The Unified Consent component contains the browser keyed service that
manages user consent when the Unified Consent feature is enabled. It also
holds the prefs and the APIs allowing the various Chromium features to verify if
the user has given consent for a given feature.
This component is currently in development.
The component is used on all platforms (desktop, ChromeOS, Android and iOS).
// Copyright 2018 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 "components/unified_consent/pref_names.h"
namespace prefs {
const char kUrlKeyedAnonymizedDataCollectionEnabled[] =
"url_keyed_anonymized_data_collection.enabled";
} // namespace prefs
// Copyright 2018 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 COMPONENTS_UNIFIED_CONSENT_PREF_NAMES_H_
#define COMPONENTS_UNIFIED_CONSENT_PREF_NAMES_H_
namespace prefs {
extern const char kUrlKeyedAnonymizedDataCollectionEnabled[];
} // namespace prefs
#endif // COMPONENTS_UNIFIED_CONSENT_PREF_NAMES_H_
// Copyright 2018 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 "components/unified_consent/unified_consent_service.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/unified_consent/pref_names.h"
UnifiedConsentService::UnifiedConsentService(
PrefService* pref_service,
identity::IdentityManager* identity_manager)
: pref_service_(pref_service), identity_manager_(identity_manager) {
DCHECK(pref_service_);
DCHECK(identity_manager_);
identity_manager_->AddObserver(this);
}
UnifiedConsentService::~UnifiedConsentService() {}
void UnifiedConsentService::RegisterPrefs(
user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterBooleanPref(prefs::kUrlKeyedAnonymizedDataCollectionEnabled,
false);
}
void UnifiedConsentService::Shutdown() {
identity_manager_->RemoveObserver(this);
}
void UnifiedConsentService::OnPrimaryAccountCleared(
const AccountInfo& account_info) {
// By design, signing out of Chrome automatically disables the user consent
// for making search and browsing better.
pref_service_->SetBoolean(prefs::kUrlKeyedAnonymizedDataCollectionEnabled,
false);
}
// Copyright 2018 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 COMPONENTS_UNIFIED_CONSENT_UNIFIED_CONSENT_SERVICE_H_
#define COMPONENTS_UNIFIED_CONSENT_UNIFIED_CONSENT_SERVICE_H_
#include <memory>
#include "base/macros.h"
#include "base/observer_list.h"
#include "components/keyed_service/core/keyed_service.h"
#include "services/identity/public/cpp/identity_manager.h"
namespace user_prefs {
class PrefRegistrySyncable;
}
class PrefService;
// A browser-context keyed service that is used to manage the user consent
// when UnifiedConsent feature is enabled.
class UnifiedConsentService : public KeyedService,
public identity::IdentityManager::Observer {
public:
UnifiedConsentService(PrefService* pref_service,
identity::IdentityManager* identity_manager);
~UnifiedConsentService() override;
// Register the prefs used by this UnifiedConsentService.
static void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry);
// KeyedService:
void Shutdown() override;
// IdentityManager::Observer:
void OnPrimaryAccountCleared(
const AccountInfo& previous_primary_account_info) override;
private:
PrefService* pref_service_;
identity::IdentityManager* identity_manager_;
DISALLOW_COPY_AND_ASSIGN(UnifiedConsentService);
};
#endif // COMPONENTS_UNIFIED_CONSENT_UNIFIED_CONSENT_SERVICE_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