Commit 819f2045 authored by Mihai Sardarescu's avatar Mihai Sardarescu Committed by Commit Bot

[unified-consent] Remove UnifiedConsentServiceClient.

Consent for Google service is no longer unified. This CL is removing the
client of the UnifiedConsentService as it is now obsolete.

Bug: 929372

TBR=asvitkine

Change-Id: I4cacda2c65e97e13dd79304a337468897a1a0414
Reviewed-on: https://chromium-review.googlesource.com/c/1460918
Commit-Queue: Mihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarThomas Tangl <tangltom@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630460}
parent b4d6b211
......@@ -1685,8 +1685,6 @@ jumbo_split_static_library("browser") {
"translate/translate_service.h",
"undo/bookmark_undo_service_factory.cc",
"undo/bookmark_undo_service_factory.h",
"unified_consent/chrome_unified_consent_service_client.cc",
"unified_consent/chrome_unified_consent_service_client.h",
"unified_consent/unified_consent_service_factory.cc",
"unified_consent/unified_consent_service_factory.h",
"update_client/chrome_update_query_params_delegate.cc",
......@@ -5411,8 +5409,6 @@ static_library("test_support") {
"subresource_filter/test_ruleset_publisher.h",
"sync/profile_sync_test_util.cc",
"sync/profile_sync_test_util.h",
"unified_consent/unified_consent_test_util.cc",
"unified_consent/unified_consent_test_util.h",
]
configs += [ "//build/config:precompiled_headers" ]
......
......@@ -114,7 +114,6 @@ class ChromeMetricsServiceAccessor : public metrics::MetricsServiceAccessor {
friend class safe_browsing::SafeBrowsingUIManager;
friend class ChromeMetricsServiceClient;
friend class ChromePasswordManagerClient;
friend class ChromeUnifiedConsentServiceClient;
friend bool nux::IsNuxOnboardingEnabled(Profile* profile);
// Testing related friends.
......
......@@ -24,7 +24,6 @@
#include "chrome/browser/signin/test_signin_client_builder.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/profile_sync_test_util.h"
#include "chrome/browser/unified_consent/chrome_unified_consent_service_client.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
......@@ -747,23 +746,12 @@ TEST_F(DiceTurnSyncOnHelperTestWithUnifiedConsent,
EXPECT_CALL(*GetProfileSyncServiceMock()->GetUserSettingsMock(),
SetFirstSetupComplete())
.Times(1);
using Service = UnifiedConsentServiceClient::Service;
using ServiceState = UnifiedConsentServiceClient::ServiceState;
PrefService* pref_service = profile()->GetPrefs();
ChromeUnifiedConsentServiceClient consent_service_client(pref_service);
std::unique_ptr<UrlKeyedDataCollectionConsentHelper>
url_keyed_collection_helper = UrlKeyedDataCollectionConsentHelper::
NewAnonymizedDataCollectionConsentHelper(
pref_service,
ProfileSyncServiceFactory::GetForProfile(profile()));
for (int i = 0; i <= static_cast<int>(Service::kLast); ++i) {
Service service = static_cast<Service>(i);
if (consent_service_client.IsServiceSupported(service)) {
consent_service_client.SetServiceEnabled(service, false);
EXPECT_EQ(ServiceState::kDisabled,
consent_service_client.GetServiceState(service));
}
}
EXPECT_FALSE(url_keyed_collection_helper->IsEnabled());
// Signin flow.
......@@ -775,13 +763,6 @@ TEST_F(DiceTurnSyncOnHelperTestWithUnifiedConsent,
EXPECT_TRUE(identity_manager()->HasAccountWithRefreshToken(account_id()));
EXPECT_EQ(account_id(), identity_manager()->GetPrimaryAccountId());
CheckDelegateCalls();
for (int i = 0; i <= static_cast<int>(Service::kLast); ++i) {
Service service = static_cast<Service>(i);
if (consent_service_client.IsServiceSupported(service)) {
EXPECT_EQ(ServiceState::kEnabled,
consent_service_client.GetServiceState(service));
}
}
EXPECT_TRUE(url_keyed_collection_helper->IsEnabled());
}
......
// 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/chrome_unified_consent_service_client.h"
ChromeUnifiedConsentServiceClient::ChromeUnifiedConsentServiceClient(
PrefService* pref_service) {}
ChromeUnifiedConsentServiceClient::~ChromeUnifiedConsentServiceClient() {}
ChromeUnifiedConsentServiceClient::ServiceState
ChromeUnifiedConsentServiceClient::GetServiceState(Service service) {
return ServiceState::kNotSupported;
}
void ChromeUnifiedConsentServiceClient::SetServiceEnabled(Service service,
bool enabled) {}
// 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_CHROME_UNIFIED_CONSENT_SERVICE_CLIENT_H_
#define CHROME_BROWSER_UNIFIED_CONSENT_CHROME_UNIFIED_CONSENT_SERVICE_CLIENT_H_
#include "base/macros.h"
#include "components/unified_consent/unified_consent_service_client.h"
class PrefService;
class ChromeUnifiedConsentServiceClient
: public unified_consent::UnifiedConsentServiceClient {
public:
explicit ChromeUnifiedConsentServiceClient(PrefService* pref_service);
~ChromeUnifiedConsentServiceClient() override;
// unified_consent::UnifiedConsentServiceClient:
ServiceState GetServiceState(Service service) override;
void SetServiceEnabled(Service service, bool enabled) override;
DISALLOW_COPY_AND_ASSIGN(ChromeUnifiedConsentServiceClient);
};
#endif // CHROME_BROWSER_UNIFIED_CONSENT_CHROME_UNIFIED_CONSENT_SERVICE_CLIENT_H_
......@@ -10,7 +10,6 @@
#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/unified_consent/chrome_unified_consent_service_client.h"
#include "chrome/browser/unified_consent/unified_consent_service_factory.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/testing_profile.h"
......@@ -29,22 +28,6 @@ class UnifiedConsentBrowserTest : public SyncTest {
: SyncTest(SINGLE_CLIENT), scoped_unified_consent_state_(feature_state) {}
~UnifiedConsentBrowserTest() override = default;
void DisableGoogleServices() {
ChromeUnifiedConsentServiceClient consent_service_client(
browser()->profile()->GetPrefs());
for (int i = 0;
i <= static_cast<int>(UnifiedConsentServiceClient::Service::kLast);
++i) {
UnifiedConsentServiceClient::Service service =
static_cast<UnifiedConsentServiceClient::Service>(i);
if (consent_service_client.IsServiceSupported(service)) {
consent_service_client.SetServiceEnabled(service, false);
EXPECT_EQ(UnifiedConsentServiceClient::ServiceState::kDisabled,
consent_service_client.GetServiceState(service));
}
}
}
void EnableSync() {
Profile* profile = browser()->profile();
ProfileSyncServiceFactory::GetForProfile(profile)
......@@ -83,10 +66,6 @@ class UnifiedConsentDisabledBrowserTest : public UnifiedConsentBrowserTest {
// Tests that the settings histogram is recorded if unified consent is enabled.
// The histogram is recorded during profile initialization.
IN_PROC_BROWSER_TEST_F(UnifiedConsentBrowserTest, PRE_SettingsHistogram_None) {
DisableGoogleServices();
}
IN_PROC_BROWSER_TEST_F(UnifiedConsentBrowserTest, SettingsHistogram_None) {
histogram_tester_.ExpectUniqueSample(
"UnifiedConsent.SyncAndGoogleServicesSettings",
......@@ -95,11 +74,6 @@ IN_PROC_BROWSER_TEST_F(UnifiedConsentBrowserTest, SettingsHistogram_None) {
// Tests that the settings histogram is recorded if unified consent is disabled.
// The histogram is recorded during profile initialization.
IN_PROC_BROWSER_TEST_F(UnifiedConsentDisabledBrowserTest,
PRE_SettingsHistogram_None) {
DisableGoogleServices();
}
IN_PROC_BROWSER_TEST_F(UnifiedConsentDisabledBrowserTest,
SettingsHistogram_None) {
histogram_tester_.ExpectUniqueSample(
......
......@@ -7,7 +7,6 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/unified_consent/chrome_unified_consent_service_client.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
......@@ -50,10 +49,8 @@ KeyedService* UnifiedConsentServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
Profile* profile = Profile::FromBrowserContext(context);
PrefService* pref_service = profile->GetPrefs();
auto service_client =
std::make_unique<ChromeUnifiedConsentServiceClient>(pref_service);
// Record settings for pre- and post-UnifiedConsent users.
RecordSettingsHistogram(service_client.get(), pref_service);
RecordSettingsHistogram(pref_service);
syncer::SyncService* sync_service =
ProfileSyncServiceFactory::GetSyncServiceForProfile(profile);
......@@ -61,14 +58,13 @@ KeyedService* UnifiedConsentServiceFactory::BuildServiceInstanceFor(
return nullptr;
if (!unified_consent::IsUnifiedConsentFeatureEnabled()) {
UnifiedConsentService::RollbackIfNeeded(pref_service, sync_service,
service_client.get());
UnifiedConsentService::RollbackIfNeeded(pref_service, sync_service);
return nullptr;
}
return new UnifiedConsentService(
std::move(service_client), pref_service,
IdentityManagerFactory::GetForProfile(profile), sync_service);
pref_service, IdentityManagerFactory::GetForProfile(profile),
sync_service);
}
bool UnifiedConsentServiceFactory::ServiceIsNULLWhileTesting() const {
......
// 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_test_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/unified_consent/unified_consent_service_factory.h"
#include "components/unified_consent/feature.h"
#include "components/unified_consent/unified_consent_service.h"
#include "components/unified_consent/unified_consent_service_client.h"
namespace {
using Service = unified_consent::UnifiedConsentServiceClient::Service;
using ServiceState = unified_consent::UnifiedConsentServiceClient::ServiceState;
class FakeUnifiedConsentServiceClient
: public unified_consent::UnifiedConsentServiceClient {
public:
FakeUnifiedConsentServiceClient() = default;
~FakeUnifiedConsentServiceClient() override = default;
// UnifiedConsentServiceClient:
ServiceState GetServiceState(Service service) override {
return ServiceState::kNotSupported;
}
void SetServiceEnabled(Service service, bool enabled) override {}
};
} // namespace
std::unique_ptr<KeyedService> BuildUnifiedConsentServiceForTesting(
content::BrowserContext* context) {
Profile* profile = Profile::FromBrowserContext(context);
if (!unified_consent::IsUnifiedConsentFeatureEnabled())
return nullptr;
return std::make_unique<unified_consent::UnifiedConsentService>(
std::make_unique<FakeUnifiedConsentServiceClient>(), profile->GetPrefs(),
IdentityManagerFactory::GetForProfile(profile),
ProfileSyncServiceFactory::GetSyncServiceForProfile(profile));
}
// 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_TEST_UTIL_H_
#define CHROME_BROWSER_UNIFIED_CONSENT_UNIFIED_CONSENT_TEST_UTIL_H_
#include <memory>
namespace content {
class BrowserContext;
}
class KeyedService;
// Helper function to be used with KeyedService::SetTestingFactory().
std::unique_ptr<KeyedService> BuildUnifiedConsentServiceForTesting(
content::BrowserContext* context);
#endif // CHROME_BROWSER_UNIFIED_CONSENT_UNIFIED_CONSENT_TEST_UTIL_H_
......@@ -12,8 +12,6 @@ static_library("unified_consent") {
"unified_consent_metrics.h",
"unified_consent_service.cc",
"unified_consent_service.h",
"unified_consent_service_client.cc",
"unified_consent_service_client.h",
"url_keyed_data_collection_consent_helper.cc",
"url_keyed_data_collection_consent_helper.h",
]
......@@ -21,7 +19,6 @@ static_library("unified_consent") {
"//base",
"//components/autofill/core/common",
"//components/browser_sync",
"//components/contextual_search/core:browser",
"//components/pref_registry",
"//components/signin/core/browser",
"//components/sync",
......@@ -58,8 +55,6 @@ source_set("unit_tests") {
":test_support",
":unified_consent",
"//base/test:test_support",
"//components/autofill/core/common",
"//components/contextual_search/core:browser",
"//components/sync",
"//components/sync:test_support_driver",
"//components/sync_preferences:test_support",
......
......@@ -40,22 +40,6 @@ bool RecordSettingsHistogramFromPref(const char* pref_name,
return true;
}
// Checks if a service is enabled and if so, records a sample in the
// SyncAndGoogleServicesSettings histogram. Returns true if a sample was
// recorded.
bool RecordSettingsHistogramFromService(
UnifiedConsentServiceClient* client,
UnifiedConsentServiceClient::Service service,
SettingsHistogramValue value) {
if (client->GetServiceState(service) !=
UnifiedConsentServiceClient::ServiceState::kEnabled) {
return false;
}
RecordSettingsHistogramSample(value);
return true;
}
void RecordSyncDataTypeSample(SyncDataType data_type) {
UMA_HISTOGRAM_ENUMERATION(
"UnifiedConsent.SyncAndGoogleServicesSettings.AfterAdvancedOptIn."
......@@ -65,8 +49,7 @@ void RecordSyncDataTypeSample(SyncDataType data_type) {
} // namespace
void RecordSettingsHistogram(UnifiedConsentServiceClient* service_client,
PrefService* pref_service) {
void RecordSettingsHistogram(PrefService* pref_service) {
bool metric_recorded = false;
metric_recorded |= RecordSettingsHistogramFromPref(
......@@ -75,14 +58,6 @@ void RecordSettingsHistogram(UnifiedConsentServiceClient* service_client,
metric_recorded |= RecordSettingsHistogramFromPref(
prefs::kUrlKeyedAnonymizedDataCollectionEnabled, pref_service,
metrics::SettingsHistogramValue::kUrlKeyedAnonymizedDataCollection);
metric_recorded |= RecordSettingsHistogramFromService(
service_client,
UnifiedConsentServiceClient::Service::kSafeBrowsingExtendedReporting,
metrics::SettingsHistogramValue::kSafeBrowsingExtendedReporting);
metric_recorded |= RecordSettingsHistogramFromService(
service_client, UnifiedConsentServiceClient::Service::kSpellCheck,
metrics::SettingsHistogramValue::kSpellCheck);
if (!metric_recorded)
RecordSettingsHistogramSample(metrics::SettingsHistogramValue::kNone);
}
......
......@@ -5,7 +5,7 @@
#ifndef COMPONENTS_UNIFIED_CONSENT_UNIFIED_CONSENT_METRICS_H_
#define COMPONENTS_UNIFIED_CONSENT_UNIFIED_CONSENT_METRICS_H_
#include "components/unified_consent/unified_consent_service_client.h"
class PrefService;
namespace syncer {
class SyncUserSettings;
......@@ -51,8 +51,7 @@ enum class SyncDataType {
// Records settings entries in the SyncAndGoogleServicesSettings.
// kNone is recorded when none of the settings is enabled.
void RecordSettingsHistogram(UnifiedConsentServiceClient* service_client,
PrefService* pref_service);
void RecordSettingsHistogram(PrefService* pref_service);
// Records the sync data types that were turned off during the advanced sync
// opt-in flow. When none of the data types were turned off, kNone is recorded.
......
......@@ -9,7 +9,6 @@
#include "base/scoped_observer.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "build/build_config.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/sync/base/model_type.h"
......@@ -21,15 +20,12 @@
namespace unified_consent {
UnifiedConsentService::UnifiedConsentService(
std::unique_ptr<UnifiedConsentServiceClient> service_client,
PrefService* pref_service,
identity::IdentityManager* identity_manager,
syncer::SyncService* sync_service)
: service_client_(std::move(service_client)),
pref_service_(pref_service),
: pref_service_(pref_service),
identity_manager_(identity_manager),
sync_service_(sync_service) {
DCHECK(service_client_);
DCHECK(pref_service_);
DCHECK(identity_manager_);
DCHECK(sync_service_);
......@@ -58,10 +54,8 @@ void UnifiedConsentService::RegisterPrefs(
// static
void UnifiedConsentService::RollbackIfNeeded(
PrefService* user_pref_service,
syncer::SyncService* sync_service,
UnifiedConsentServiceClient* service_client) {
syncer::SyncService* sync_service) {
DCHECK(user_pref_service);
DCHECK(service_client);
if (user_pref_service->GetInteger(prefs::kUnifiedConsentMigrationState) ==
static_cast<int>(MigrationState::kNotInitialized)) {
......@@ -69,16 +63,6 @@ void UnifiedConsentService::RollbackIfNeeded(
return;
}
// Turn off all off-by-default services if services were enabled due to
// unified consent.
if (user_pref_service->GetBoolean(
prefs::kAllUnifiedConsentServicesWereEnabled)) {
service_client->SetServiceEnabled(Service::kSafeBrowsingExtendedReporting,
false);
service_client->SetServiceEnabled(Service::kSpellCheck, false);
service_client->SetServiceEnabled(Service::kContextualSearch, false);
}
// Clear all unified consent prefs.
user_pref_service->ClearPref(prefs::kUrlKeyedAnonymizedDataCollectionEnabled);
user_pref_service->ClearPref(prefs::kUnifiedConsentMigrationState);
......@@ -97,14 +81,6 @@ void UnifiedConsentService::EnableGoogleServices() {
// Enable all Google services except sync.
pref_service_->SetBoolean(prefs::kUrlKeyedAnonymizedDataCollectionEnabled,
true);
for (int i = 0; i <= static_cast<int>(Service::kLast); ++i) {
Service service = static_cast<Service>(i);
if (service_client_->GetServiceState(service) !=
ServiceState::kNotSupported) {
service_client_->SetServiceEnabled(service, true);
}
}
pref_service_->SetBoolean(prefs::kAllUnifiedConsentServicesWereEnabled, true);
}
......@@ -122,11 +98,6 @@ void UnifiedConsentService::OnPrimaryAccountCleared(
// services.
pref_service_->SetBoolean(prefs::kUrlKeyedAnonymizedDataCollectionEnabled,
false);
service_client_->SetServiceEnabled(Service::kSafeBrowsingExtendedReporting,
false);
service_client_->SetServiceEnabled(Service::kSpellCheck, false);
service_client_->SetServiceEnabled(Service::kContextualSearch, false);
if (GetMigrationState() != MigrationState::kCompleted) {
// When the user signs out, the migration is complete.
SetMigrationState(MigrationState::kCompleted);
......
......@@ -13,7 +13,6 @@
#include "components/sync/base/model_type.h"
#include "components/sync/driver/sync_service_observer.h"
#include "components/unified_consent/unified_consent_metrics.h"
#include "components/unified_consent/unified_consent_service_client.h"
#include "services/identity/public/cpp/identity_manager.h"
namespace user_prefs {
......@@ -28,9 +27,6 @@ class SyncService;
namespace unified_consent {
using Service = UnifiedConsentServiceClient::Service;
using ServiceState = UnifiedConsentServiceClient::ServiceState;
enum class MigrationState : int {
kNotInitialized = 0,
kInProgressWaitForSyncInit = 1,
......@@ -45,7 +41,6 @@ class UnifiedConsentService : public KeyedService,
public syncer::SyncServiceObserver {
public:
UnifiedConsentService(
std::unique_ptr<UnifiedConsentServiceClient> service_client,
PrefService* pref_service,
identity::IdentityManager* identity_manager,
syncer::SyncService* sync_service);
......@@ -57,8 +52,7 @@ class UnifiedConsentService : public KeyedService,
// Rolls back changes made during migration. This method does nothing if the
// user hasn't migrated to unified consent yet.
static void RollbackIfNeeded(PrefService* user_pref_service,
syncer::SyncService* sync_service,
UnifiedConsentServiceClient* service_client);
syncer::SyncService* sync_service);
// Enables all Google services tied to unified consent.
// Note: Sync has to be enabled through the SyncService. It is *not* enabled
......@@ -88,7 +82,6 @@ class UnifiedConsentService : public KeyedService,
// |OnStateChanged| when the sync engine is initialized.
void UpdateSettingsForMigration();
std::unique_ptr<UnifiedConsentServiceClient> service_client_;
PrefService* pref_service_;
identity::IdentityManager* identity_manager_;
syncer::SyncService* sync_service_;
......
// 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_client.h"
#include "base/bind.h"
namespace unified_consent {
UnifiedConsentServiceClient::UnifiedConsentServiceClient() {}
UnifiedConsentServiceClient::~UnifiedConsentServiceClient() {}
bool UnifiedConsentServiceClient::IsServiceSupported(Service service) {
return GetServiceState(service) != ServiceState::kNotSupported;
}
void UnifiedConsentServiceClient::AddObserver(Observer* observer) {
observer_list_.AddObserver(observer);
}
void UnifiedConsentServiceClient::RemoveObserver(Observer* observer) {
observer_list_.RemoveObserver(observer);
}
void UnifiedConsentServiceClient::ObserveServicePrefChange(
Service service,
const std::string& pref_name,
PrefService* pref_service) {
service_prefs_[pref_name] = service;
// First access to the pref registrar of |pref_service| in the map
// automatically creates an entry for it.
PrefChangeRegistrar* pref_change_registrar =
&(pref_change_registrars_[pref_service]);
if (!pref_change_registrar->prefs())
pref_change_registrar->Init(pref_service);
pref_change_registrar->Add(
pref_name,
base::BindRepeating(&UnifiedConsentServiceClient::OnPrefChanged,
base::Unretained(this)));
}
void UnifiedConsentServiceClient::FireOnServiceStateChanged(Service service) {
for (auto& observer : observer_list_)
observer.OnServiceStateChanged(service);
}
void UnifiedConsentServiceClient::OnPrefChanged(const std::string& pref_name) {
DCHECK(service_prefs_.count(pref_name));
FireOnServiceStateChanged(service_prefs_[pref_name]);
}
} // namespace unified_consent
// 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_CLIENT_H_
#define COMPONENTS_UNIFIED_CONSENT_UNIFIED_CONSENT_SERVICE_CLIENT_H_
#include <map>
#include <string>
#include "base/observer_list.h"
#include "components/prefs/pref_change_registrar.h"
class PrefService;
namespace unified_consent {
class UnifiedConsentServiceClient {
public:
enum class Service {
// Extended safe browsing.
kSafeBrowsingExtendedReporting,
// Spell checking.
kSpellCheck,
// Contextual search.
kContextualSearch,
// Last element of the enum, used for iteration.
kLast = kContextualSearch,
};
enum class ServiceState {
// The service is not supported on this platform.
kNotSupported,
// The service is supported, but disabled.
kDisabled,
// The service is enabled.
kEnabled
};
class Observer {
public:
// Called when the service state of |service| changes.
virtual void OnServiceStateChanged(Service service) = 0;
};
UnifiedConsentServiceClient();
virtual ~UnifiedConsentServiceClient();
// Returns the ServiceState for |service|.
virtual ServiceState GetServiceState(Service service) = 0;
// Sets |service| enabled if it is supported on this platform.
virtual void SetServiceEnabled(Service service, bool enabled) = 0;
// Returns whether |service| is supported on this platform.
bool IsServiceSupported(Service service);
// Methods to register or remove observers.
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
protected:
// This method adds |pref_name| to the list of prefs that will be observed for
// changes. Whenever there's a change in the pref, all
// |UnifiedConsentServiceClient::Observer|s are fired.
void ObserveServicePrefChange(Service service,
const std::string& pref_name,
PrefService* pref_service);
// Fires |OnServiceStateChanged| on all observers.
void FireOnServiceStateChanged(Service service);
private:
// Callback for the pref change registrars.
void OnPrefChanged(const std::string& pref_name);
base::ObserverList<Observer, true>::Unchecked observer_list_;
// Matches the pref name to it's service.
std::map<std::string, Service> service_prefs_;
// Matches pref service to it's change registrar.
std::map<PrefService*, PrefChangeRegistrar> pref_change_registrars_;
DISALLOW_COPY_AND_ASSIGN(UnifiedConsentServiceClient);
};
} // namespace unified_consent
#endif // COMPONENTS_UNIFIED_CONSENT_UNIFIED_CONSENT_SERVICE_CLIENT_H_
......@@ -11,7 +11,6 @@
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_task_environment.h"
#include "build/build_config.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/sync/base/sync_prefs.h"
#include "components/sync/driver/sync_user_settings.h"
#include "components/sync/driver/test_sync_service.h"
......@@ -19,7 +18,6 @@
#include "components/unified_consent/pref_names.h"
#include "components/unified_consent/scoped_unified_consent.h"
#include "components/unified_consent/unified_consent_metrics.h"
#include "components/unified_consent/unified_consent_service_client.h"
#include "services/identity/public/cpp/identity_test_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -45,83 +43,13 @@ class TestSyncService : public syncer::TestSyncService {
DISALLOW_COPY_AND_ASSIGN(TestSyncService);
};
const char kSpellCheckDummyEnabled[] = "spell_check_dummy.enabled";
class FakeUnifiedConsentServiceClient : public UnifiedConsentServiceClient {
public:
FakeUnifiedConsentServiceClient(PrefService* pref_service)
: pref_service_(pref_service) {
// When the |kSpellCheckDummyEnabled| pref is changed, all observers should
// be fired.
ObserveServicePrefChange(Service::kSpellCheck, kSpellCheckDummyEnabled,
pref_service);
}
~FakeUnifiedConsentServiceClient() override = default;
// UnifiedConsentServiceClient:
ServiceState GetServiceState(Service service) override {
if (is_not_supported_[service])
return ServiceState::kNotSupported;
bool enabled;
// Special treatment for spell check.
if (service == Service::kSpellCheck) {
enabled = pref_service_->GetBoolean(kSpellCheckDummyEnabled);
} else {
enabled = service_enabled_[service];
}
return enabled ? ServiceState::kEnabled : ServiceState::kDisabled;
}
void SetServiceEnabled(Service service, bool enabled) override {
if (is_not_supported_[service])
return;
// Special treatment for spell check.
if (service == Service::kSpellCheck) {
pref_service_->SetBoolean(kSpellCheckDummyEnabled, enabled);
return;
}
bool should_notify_observers = service_enabled_[service] != enabled;
service_enabled_[service] = enabled;
if (should_notify_observers)
FireOnServiceStateChanged(service);
}
void SetServiceNotSupported(Service service) {
is_not_supported_[service] = true;
}
static void ClearServiceStates() {
service_enabled_.clear();
is_not_supported_.clear();
}
private:
// Service states are shared between multiple instances of this class.
static std::map<Service, bool> service_enabled_;
static std::map<Service, bool> is_not_supported_;
PrefService* pref_service_;
DISALLOW_COPY_AND_ASSIGN(FakeUnifiedConsentServiceClient);
};
std::map<Service, bool> FakeUnifiedConsentServiceClient::service_enabled_;
std::map<Service, bool> FakeUnifiedConsentServiceClient::is_not_supported_;
} // namespace
class UnifiedConsentServiceTest : public testing::Test {
public:
UnifiedConsentServiceTest() {
pref_service_.registry()->RegisterBooleanPref(
autofill::prefs::kAutofillWalletImportEnabled, false);
UnifiedConsentService::RegisterPrefs(pref_service_.registry());
syncer::SyncPrefs::RegisterProfilePrefs(pref_service_.registry());
pref_service_.registry()->RegisterBooleanPref(kSpellCheckDummyEnabled,
false);
FakeUnifiedConsentServiceClient::ClearServiceStates();
service_client_ =
std::make_unique<FakeUnifiedConsentServiceClient>(&pref_service_);
}
~UnifiedConsentServiceTest() override {
......@@ -129,25 +57,15 @@ class UnifiedConsentServiceTest : public testing::Test {
consent_service_->Shutdown();
}
void CreateConsentService(bool client_services_on_by_default = false) {
void CreateConsentService() {
if (!scoped_unified_consent_) {
SetUnifiedConsentFeatureState(
unified_consent::UnifiedConsentFeatureState::kEnabled);
}
auto client =
std::make_unique<FakeUnifiedConsentServiceClient>(&pref_service_);
if (client_services_on_by_default) {
for (int i = 0; i <= static_cast<int>(Service::kLast); ++i) {
Service service = static_cast<Service>(i);
client->SetServiceEnabled(service, true);
}
pref_service_.SetBoolean(prefs::kUrlKeyedAnonymizedDataCollectionEnabled,
true);
}
consent_service_ = std::make_unique<UnifiedConsentService>(
std::move(client), &pref_service_,
identity_test_environment_.identity_manager(), &sync_service_);
&pref_service_, identity_test_environment_.identity_manager(),
&sync_service_);
sync_service_.FireStateChanged();
// Run until idle so the migration can finish.
......@@ -165,16 +83,8 @@ class UnifiedConsentServiceTest : public testing::Test {
}
bool AreAllGoogleServicesEnabled() {
for (int i = 0; i <= static_cast<int>(Service::kLast); ++i) {
Service service = static_cast<Service>(i);
if (service_client_->GetServiceState(service) == ServiceState::kDisabled)
return false;
}
if (!pref_service_.GetBoolean(
prefs::kUrlKeyedAnonymizedDataCollectionEnabled))
return false;
return true;
return pref_service_.GetBoolean(
prefs::kUrlKeyedAnonymizedDataCollectionEnabled);
}
unified_consent::MigrationState GetMigrationState() {
......@@ -189,8 +99,6 @@ class UnifiedConsentServiceTest : public testing::Test {
identity::IdentityTestEnvironment identity_test_environment_;
TestSyncService sync_service_;
std::unique_ptr<UnifiedConsentService> consent_service_;
std::unique_ptr<FakeUnifiedConsentServiceClient> service_client_;
std::unique_ptr<ScopedUnifiedConsent> scoped_unified_consent_;
DISALLOW_COPY_AND_ASSIGN(UnifiedConsentServiceTest);
......@@ -219,9 +127,6 @@ TEST_F(UnifiedConsentServiceTest, EnableServices_WithUnsupportedService) {
identity_test_environment_.SetPrimaryAccount("testaccount");
EXPECT_FALSE(pref_service_.GetBoolean(
prefs::kUrlKeyedAnonymizedDataCollectionEnabled));
service_client_->SetServiceNotSupported(Service::kSpellCheck);
EXPECT_EQ(service_client_->GetServiceState(Service::kSpellCheck),
ServiceState::kNotSupported);
EXPECT_FALSE(AreAllGoogleServicesEnabled());
// Enable services and check expectations.
......@@ -263,13 +168,6 @@ TEST_F(UnifiedConsentServiceTest, ClearPrimaryAccountDisablesSomeServices) {
EXPECT_FALSE(AreAllGoogleServicesEnabled());
EXPECT_FALSE(pref_service_.GetBoolean(
prefs::kUrlKeyedAnonymizedDataCollectionEnabled));
EXPECT_EQ(service_client_->GetServiceState(Service::kSpellCheck),
ServiceState::kDisabled);
EXPECT_EQ(
service_client_->GetServiceState(Service::kSafeBrowsingExtendedReporting),
ServiceState::kDisabled);
EXPECT_EQ(service_client_->GetServiceState(Service::kContextualSearch),
ServiceState::kDisabled);
}
TEST_F(UnifiedConsentServiceTest, Migration_NotSignedIn) {
......@@ -299,20 +197,11 @@ TEST_F(UnifiedConsentServiceTest, Rollback_UserOptedIntoUnifiedConsent) {
SetUnifiedConsentFeatureState(UnifiedConsentFeatureState::kDisabled);
// Rollback
UnifiedConsentService::RollbackIfNeeded(&pref_service_, &sync_service_,
service_client_.get());
UnifiedConsentService::RollbackIfNeeded(&pref_service_, &sync_service_);
// Unified consent prefs should be cleared.
EXPECT_EQ(unified_consent::MigrationState::kNotInitialized,
GetMigrationState());
// Off-by-default services should be turned off.
EXPECT_NE(ServiceState::kEnabled,
service_client_->GetServiceState(
Service::kSafeBrowsingExtendedReporting));
EXPECT_NE(ServiceState::kEnabled,
service_client_->GetServiceState(Service::kSpellCheck));
EXPECT_NE(ServiceState::kEnabled,
service_client_->GetServiceState(Service::kContextualSearch));
}
} // namespace unified_consent
......@@ -5,8 +5,6 @@
source_set("unified_consent") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"unified_consent_service_client_impl.cc",
"unified_consent_service_client_impl.h",
"unified_consent_service_factory.cc",
"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.
#include "ios/chrome/browser/unified_consent/unified_consent_service_client_impl.h"
UnifiedConsentServiceClientImpl::ServiceState
UnifiedConsentServiceClientImpl::GetServiceState(Service service) {
switch (service) {
case Service::kSafeBrowsingExtendedReporting:
case Service::kSpellCheck:
case Service::kContextualSearch:
return ServiceState::kNotSupported;
}
NOTREACHED();
}
void UnifiedConsentServiceClientImpl::SetServiceEnabled(Service service,
bool enabled) {
if (GetServiceState(service) == ServiceState::kNotSupported)
return;
NOTREACHED();
}
// 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 IOS_CHROME_BROWSER_UNIFIED_CONSENT_UNIFIED_CONSENT_SERVICE_CLIENT_IMPL_H_
#define IOS_CHROME_BROWSER_UNIFIED_CONSENT_UNIFIED_CONSENT_SERVICE_CLIENT_IMPL_H_
#include "base/macros.h"
#include "components/unified_consent/unified_consent_service_client.h"
// iOS implementation for UnifiedConsentServiceClient.
class UnifiedConsentServiceClientImpl
: public unified_consent::UnifiedConsentServiceClient {
public:
UnifiedConsentServiceClientImpl() = default;
~UnifiedConsentServiceClientImpl() override = default;
// unified_consent::UnifiedConsentServiceClient overrides:
ServiceState GetServiceState(Service service) override;
void SetServiceEnabled(Service service, bool enabled) override;
DISALLOW_COPY_AND_ASSIGN(UnifiedConsentServiceClientImpl);
};
#endif // IOS_CHROME_BROWSER_UNIFIED_CONSENT_UNIFIED_CONSENT_SERVICE_CLIENT_IMPL_H_
......@@ -13,7 +13,6 @@
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/signin/identity_manager_factory.h"
#include "ios/chrome/browser/sync/profile_sync_service_factory.h"
#include "ios/chrome/browser/unified_consent/unified_consent_service_client_impl.h"
UnifiedConsentServiceFactory::UnifiedConsentServiceFactory()
: BrowserStateKeyedServiceFactory(
......@@ -53,8 +52,6 @@ UnifiedConsentServiceFactory::BuildServiceInstanceFor(
ios::ChromeBrowserState* browser_state =
ios::ChromeBrowserState::FromBrowserState(context);
PrefService* user_pref_service = browser_state->GetPrefs();
std::unique_ptr<unified_consent::UnifiedConsentServiceClient> service_client =
std::make_unique<UnifiedConsentServiceClientImpl>();
identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForBrowserState(browser_state);
......@@ -62,16 +59,14 @@ UnifiedConsentServiceFactory::BuildServiceInstanceFor(
ProfileSyncServiceFactory::GetForBrowserState(browser_state);
// Record settings for pre- and post-UnifiedConsent users.
unified_consent::metrics::RecordSettingsHistogram(service_client.get(),
user_pref_service);
unified_consent::metrics::RecordSettingsHistogram(user_pref_service);
if (!unified_consent::IsUnifiedConsentFeatureEnabled()) {
unified_consent::UnifiedConsentService::RollbackIfNeeded(
user_pref_service, sync_service, service_client.get());
unified_consent::UnifiedConsentService::RollbackIfNeeded(user_pref_service,
sync_service);
return nullptr;
}
return std::make_unique<unified_consent::UnifiedConsentService>(
std::move(service_client), user_pref_service, identity_manager,
sync_service);
user_pref_service, identity_manager, sync_service);
}
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