Remove content packs for supervised user
Playpen Content Packs feature for supervised users has never been
launched.The code contains non-inclusive language and rather than
fixing the language is gets well deserved removal.
This change-list covers deletion of:
* SupervisedUserWhitelistInstaller
* SupervisedUserAllowlistService
* Relevant test files
It will be followed with the further cleanup in c/b/c/supervised_user
as well as in Chrome Sync code.
Bug: 1147260, 1151166
Change-Id: I938e2ba34bbe91013b54ea152b29fdff424253f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2543804
Commit-Queue: Aga Wronska <[email protected]>
Reviewed-by: Kentaro Hara <[email protected]>
Reviewed-by: Steven Holte <[email protected]>
Reviewed-by: Marc Treib <[email protected]>
Reviewed-by: Bernhard Bauer <[email protected]>
Cr-Commit-Position: refs/heads/master@{#833986}
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index 606bde2..d922c9c 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -6165,8 +6165,6 @@
if (enable_supervised_users) {
sources += [
- "component_updater/supervised_user_whitelist_installer.cc",
- "component_updater/supervised_user_whitelist_installer.h",
"content_settings/content_settings_supervised_provider.cc",
"content_settings/content_settings_supervised_provider.h",
"supervised_user/child_accounts/child_account_service.cc",
@@ -6186,8 +6184,6 @@
"supervised_user/kids_management_url_checker_client.cc",
"supervised_user/kids_management_url_checker_client.h",
"supervised_user/permission_request_creator.h",
- "supervised_user/supervised_user_allowlist_service.cc",
- "supervised_user/supervised_user_allowlist_service.h",
"supervised_user/supervised_user_constants.cc",
"supervised_user/supervised_user_constants.h",
"supervised_user/supervised_user_denylist.cc",
diff --git a/chrome/browser/browser_process.h b/chrome/browser/browser_process.h
index ee9693c..4adbeee 100644
--- a/chrome/browser/browser_process.h
+++ b/chrome/browser/browser_process.h
@@ -67,7 +67,6 @@
namespace component_updater {
class ComponentUpdateService;
-class SupervisedUserWhitelistInstaller;
}
namespace extensions {
@@ -251,11 +250,6 @@
virtual component_updater::ComponentUpdateService* component_updater() = 0;
-#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
- virtual component_updater::SupervisedUserWhitelistInstaller*
- supervised_user_whitelist_installer() = 0;
-#endif
-
virtual MediaFileSystemRegistry* media_file_system_registry() = 0;
virtual WebRtcLogUploader* webrtc_log_uploader() = 0;
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index 48698aad..2e76ca4 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -201,10 +201,6 @@
#include "chrome/browser/error_reporting/chrome_js_error_report_processor.h" // nogncheck
#endif
-#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
-#include "chrome/browser/component_updater/supervised_user_whitelist_installer.h"
-#endif
-
#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
// How often to check if the persistent instance of Chrome needs to restart
// to install an update.
@@ -408,12 +404,6 @@
notification_ui_manager_.reset();
#endif
-#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
- // The SupervisedUserWhitelistInstaller observes the ProfileAttributesStorage,
- // so it needs to be shut down before the ProfileManager.
- supervised_user_whitelist_installer_.reset();
-#endif
-
// Debugger must be cleaned up before ProfileManager.
remote_debugging_server_.reset();
devtools_auto_opener_.reset();
@@ -1068,20 +1058,6 @@
return component_updater_.get();
}
-#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
-component_updater::SupervisedUserWhitelistInstaller*
-BrowserProcessImpl::supervised_user_whitelist_installer() {
- if (!supervised_user_whitelist_installer_) {
- supervised_user_whitelist_installer_ =
- component_updater::SupervisedUserWhitelistInstaller::Create(
- component_updater(),
- &profile_manager()->GetProfileAttributesStorage(),
- local_state());
- }
- return supervised_user_whitelist_installer_.get();
-}
-#endif // BUILDFLAG(ENABLE_SUPERVISED_USERS)
-
void BrowserProcessImpl::OnKeepAliveStateChanged(bool is_keeping_alive) {
if (is_keeping_alive)
Pin();
diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h
index e600e77..7cfbdefc 100644
--- a/chrome/browser/browser_process_impl.h
+++ b/chrome/browser/browser_process_impl.h
@@ -184,10 +184,6 @@
#endif
component_updater::ComponentUpdateService* component_updater() override;
-#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
- component_updater::SupervisedUserWhitelistInstaller*
- supervised_user_whitelist_installer() override;
-#endif
MediaFileSystemRegistry* media_file_system_registry() override;
WebRtcLogUploader* webrtc_log_uploader() override;
network_time::NetworkTimeTracker* network_time_tracker() override;
@@ -373,11 +369,6 @@
// but some users of component updater only install per-user.
std::unique_ptr<component_updater::ComponentUpdateService> component_updater_;
-#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
- std::unique_ptr<component_updater::SupervisedUserWhitelistInstaller>
- supervised_user_whitelist_installer_;
-#endif
-
#if BUILDFLAG(ENABLE_PLUGINS)
std::unique_ptr<PluginsResourceService> plugins_resource_service_;
#endif
diff --git a/chrome/browser/component_updater/component_updater_prefs.cc b/chrome/browser/component_updater/component_updater_prefs.cc
index e8ee2b9..b26e1ff 100644
--- a/chrome/browser/component_updater/component_updater_prefs.cc
+++ b/chrome/browser/component_updater/component_updater_prefs.cc
@@ -9,10 +9,6 @@
#include "chrome/browser/component_updater/recovery_component_installer.h"
#include "chrome/common/buildflags.h"
-#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
-#include "chrome/browser/component_updater/supervised_user_whitelist_installer.h"
-#endif
-
#if !defined(OS_ANDROID)
#include "chrome/browser/component_updater/soda_component_installer.h"
#endif
@@ -23,10 +19,6 @@
RegisterPrefsForChromeComponentUpdaterConfigurator(registry);
RegisterPrefsForRecoveryComponent(registry);
-#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
- SupervisedUserWhitelistInstaller::RegisterPrefs(registry);
-#endif
-
#if !defined(OS_ANDROID)
RegisterPrefsForSodaComponent(registry);
#endif
diff --git a/chrome/browser/component_updater/registration.cc b/chrome/browser/component_updater/registration.cc
index 565d78c3..8bec7e3 100644
--- a/chrome/browser/component_updater/registration.cc
+++ b/chrome/browser/component_updater/registration.cc
@@ -79,10 +79,6 @@
#include "ui/aura/env.h"
#endif
-#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
-#include "chrome/browser/component_updater/supervised_user_whitelist_installer.h"
-#endif
-
namespace component_updater {
void RegisterComponentsForUpdate(bool is_off_the_record_profile,
@@ -113,12 +109,6 @@
RegisterPnaclComponent(cus);
#endif // BUILDFLAG(ENABLE_NACL) && !defined(OS_ANDROID)
-#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
- component_updater::SupervisedUserWhitelistInstaller* whitelist_installer =
- g_browser_process->supervised_user_whitelist_installer();
- whitelist_installer->RegisterComponents();
-#endif
-
RegisterSubresourceFilterComponent(cus);
RegisterFlocComponent(cus,
g_browser_process->floc_sorting_lsh_clusters_service());
diff --git a/chrome/browser/component_updater/supervised_user_whitelist_installer.cc b/chrome/browser/component_updater/supervised_user_whitelist_installer.cc
deleted file mode 100644
index c05e40e..0000000
--- a/chrome/browser/component_updater/supervised_user_whitelist_installer.cc
+++ /dev/null
@@ -1,674 +0,0 @@
-// Copyright 2014 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/component_updater/supervised_user_whitelist_installer.h"
-
-#include <stddef.h>
-
-#include <map>
-#include <utility>
-
-#include "base/bind.h"
-#include "base/callback.h"
-#include "base/files/file_enumerator.h"
-#include "base/files/file_path.h"
-#include "base/files/file_util.h"
-#include "base/files/important_file_writer.h"
-#include "base/location.h"
-#include "base/macros.h"
-#include "base/memory/ref_counted.h"
-#include "base/memory/weak_ptr.h"
-#include "base/metrics/user_metrics.h"
-#include "base/metrics/user_metrics_action.h"
-#include "base/path_service.h"
-#include "base/scoped_observer.h"
-#include "base/sequenced_task_runner.h"
-#include "base/stl_util.h"
-#include "base/strings/string_util.h"
-#include "base/task/task_traits.h"
-#include "base/task/thread_pool.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "base/util/values/values_util.h"
-#include "base/values.h"
-#include "chrome/browser/profiles/profile_attributes_storage.h"
-#include "chrome/browser/supervised_user/supervised_user_allowlist_service.h"
-#include "chrome/common/chrome_paths.h"
-#include "chrome/common/pref_names.h"
-#include "components/component_updater/component_installer.h"
-#include "components/component_updater/component_updater_paths.h"
-#include "components/component_updater/component_updater_service.h"
-#include "components/crx_file/id_util.h"
-#include "components/prefs/pref_registry_simple.h"
-#include "components/prefs/pref_service.h"
-#include "components/prefs/scoped_user_pref_update.h"
-#include "content/public/browser/browser_task_traits.h"
-#include "content/public/browser/browser_thread.h"
-#include "services/data_decoder/public/cpp/json_sanitizer.h"
-
-namespace component_updater {
-
-namespace {
-
-const char kSanitizedWhitelistExtension[] = ".json";
-
-const char kWhitelistedContent[] = "whitelisted_content";
-const char kSites[] = "sites";
-
-const char kClients[] = "clients";
-const char kName[] = "name";
-
-// These are copies of extensions::manifest_keys::kName and kShortName. They
-// are duplicated here because we mustn't depend on code from extensions/
-// (since it's not built on Android).
-const char kExtensionName[] = "name";
-const char kExtensionShortName[] = "short_name";
-const char kExtensionIcons[] = "icons";
-const char kExtensionLargeIcon[] = "128";
-
-constexpr base::TaskTraits kThreadPoolTaskTraits = {
- base::MayBlock(), base::TaskPriority::BEST_EFFORT,
- base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN};
-
-base::string16 GetWhitelistTitle(const base::DictionaryValue& manifest) {
- base::string16 title;
- if (!manifest.GetString(kExtensionShortName, &title))
- manifest.GetString(kExtensionName, &title);
- return title;
-}
-
-base::FilePath GetSafeFilePath(const base::DictionaryValue& dictionary,
- const std::string& key,
- const base::FilePath& install_dir) {
- const base::Value* path_value = nullptr;
- if (!dictionary.Get(key, &path_value))
- return base::FilePath();
- base::Optional<base::FilePath> path = util::ValueToFilePath(*path_value);
- if (!path)
- return base::FilePath();
- // Path components ("..") are not allowed.
- if (path->ReferencesParent())
- return base::FilePath();
-
- return install_dir.Append(*path);
-}
-
-base::FilePath GetLargeIconPath(const base::DictionaryValue& manifest,
- const base::FilePath& install_dir) {
- const base::DictionaryValue* icons = nullptr;
- if (!manifest.GetDictionary(kExtensionIcons, &icons))
- return base::FilePath();
-
- return GetSafeFilePath(*icons, kExtensionLargeIcon, install_dir);
-}
-
-base::FilePath GetRawWhitelistPath(const base::DictionaryValue& manifest,
- const base::FilePath& install_dir) {
- const base::DictionaryValue* whitelist_dict = nullptr;
- if (!manifest.GetDictionary(kWhitelistedContent, &whitelist_dict))
- return base::FilePath();
-
- return GetSafeFilePath(*whitelist_dict, kSites, install_dir);
-}
-
-base::FilePath GetSanitizedWhitelistPath(const std::string& crx_id) {
- base::FilePath base_dir;
- base::PathService::Get(chrome::DIR_SUPERVISED_USER_INSTALLED_WHITELISTS,
- &base_dir);
- return base_dir.empty()
- ? base::FilePath()
- : base_dir.AppendASCII(crx_id + kSanitizedWhitelistExtension);
-}
-
-void RecordUncleanUninstall() {
- content::GetUIThreadTaskRunner({})->PostTask(
- FROM_HERE,
- base::BindOnce(
- &base::RecordAction,
- base::UserMetricsAction("ManagedUsers_Whitelist_UncleanUninstall")));
-}
-
-void DeleteFileOnTaskRunner(const base::FilePath& path) {
- if (!base::DeletePathRecursively(path))
- DPLOG(ERROR) << "Couldn't delete " << path.value();
-}
-
-void OnWhitelistSanitizationResult(
- const base::FilePath& whitelist_path,
- const std::string& crx_id,
- scoped_refptr<base::SequencedTaskRunner> task_runner,
- base::OnceClosure callback,
- data_decoder::JsonSanitizer::Result result) {
- if (!result.value) {
- LOG(WARNING) << "Invalid whitelist " << whitelist_path.value() << ": "
- << *result.error;
- return;
- }
-
- const base::FilePath sanitized_whitelist_path =
- GetSanitizedWhitelistPath(crx_id);
- const base::FilePath install_directory = sanitized_whitelist_path.DirName();
- if (!base::DirectoryExists(install_directory)) {
- if (!base::CreateDirectory(install_directory)) {
- PLOG(ERROR) << "Could't create directory " << install_directory.value();
- return;
- }
- }
-
- const int size = result.value->size();
- if (base::WriteFile(sanitized_whitelist_path, result.value->data(), size) !=
- size) {
- PLOG(ERROR) << "Couldn't write file " << sanitized_whitelist_path.value();
- return;
- }
- task_runner->PostTask(FROM_HERE, std::move(callback));
-}
-
-void CheckForSanitizedWhitelistOnTaskRunner(
- const std::string& crx_id,
- const base::FilePath& whitelist_path,
- scoped_refptr<base::SequencedTaskRunner> task_runner,
- base::OnceClosure callback) {
- if (base::PathExists(GetSanitizedWhitelistPath(crx_id))) {
- task_runner->PostTask(FROM_HERE, std::move(callback));
- return;
- }
-
- std::string unsafe_json;
- if (!base::ReadFileToString(whitelist_path, &unsafe_json)) {
- PLOG(ERROR) << "Couldn't read file " << whitelist_path.value();
- return;
- }
-
- data_decoder::JsonSanitizer::Sanitize(
- unsafe_json,
- base::BindOnce(&OnWhitelistSanitizationResult, whitelist_path, crx_id,
- task_runner, std::move(callback)));
-}
-
-void RemoveUnregisteredWhitelistsOnTaskRunner(
- const std::set<std::string>& registered_whitelists) {
- base::FilePath base_dir;
- base::PathService::Get(DIR_SUPERVISED_USER_ALLOWLISTS, &base_dir);
- if (!base_dir.empty()) {
- base::FileEnumerator file_enumerator(base_dir, false,
- base::FileEnumerator::DIRECTORIES);
- for (base::FilePath path = file_enumerator.Next(); !path.value().empty();
- path = file_enumerator.Next()) {
- const std::string crx_id = path.BaseName().MaybeAsASCII();
-
- // Ignore folders that don't have valid CRX ID names. These folders are
- // not managed by the component installer, so do not try to remove them.
- if (!crx_file::id_util::IdIsValid(crx_id))
- continue;
-
- // Ignore folders that correspond to registered whitelists.
- if (base::Contains(registered_whitelists, crx_id))
- continue;
-
- RecordUncleanUninstall();
-
- DeleteFileOnTaskRunner(path);
- }
- }
-
- base::PathService::Get(chrome::DIR_SUPERVISED_USER_INSTALLED_WHITELISTS,
- &base_dir);
- if (!base_dir.empty()) {
- base::FilePath pattern(FILE_PATH_LITERAL("*"));
- pattern = pattern.AppendASCII(kSanitizedWhitelistExtension);
- base::FileEnumerator file_enumerator(
- base_dir, false, base::FileEnumerator::FILES, pattern.value());
- for (base::FilePath path = file_enumerator.Next(); !path.value().empty();
- path = file_enumerator.Next()) {
- // Ignore files that don't have valid CRX ID names. These files are not
- // managed by the component installer, so do not try to remove them.
- const std::string filename = path.BaseName().MaybeAsASCII();
- DCHECK(base::EndsWith(filename, kSanitizedWhitelistExtension,
- base::CompareCase::SENSITIVE));
-
- const std::string crx_id = filename.substr(
- filename.size() - strlen(kSanitizedWhitelistExtension));
-
- if (!crx_file::id_util::IdIsValid(crx_id))
- continue;
-
- // Ignore files that correspond to registered whitelists.
- if (base::Contains(registered_whitelists, crx_id))
- continue;
-
- RecordUncleanUninstall();
-
- DeleteFileOnTaskRunner(path);
- }
- }
-}
-
-class SupervisedUserWhitelistComponentInstallerPolicy
- : public ComponentInstallerPolicy {
- public:
- using RawWhitelistReadyCallback =
- base::RepeatingCallback<void(const base::string16&, /* title */
- const base::FilePath&, /* icon_path */
- const base::FilePath& /* whitelist_path */)>;
-
- SupervisedUserWhitelistComponentInstallerPolicy(
- const std::string& crx_id,
- const std::string& name,
- RawWhitelistReadyCallback callback)
- : crx_id_(crx_id), name_(name), callback_(callback) {}
- ~SupervisedUserWhitelistComponentInstallerPolicy() override = default;
-
- private:
- // ComponentInstallerPolicy overrides:
- bool VerifyInstallation(const base::DictionaryValue& manifest,
- const base::FilePath& install_dir) const override;
- bool SupportsGroupPolicyEnabledComponentUpdates() const override;
- bool RequiresNetworkEncryption() const override;
- update_client::CrxInstaller::Result OnCustomInstall(
- const base::DictionaryValue& manifest,
- const base::FilePath& install_dir) override;
- void OnCustomUninstall() override;
- void ComponentReady(const base::Version& version,
- const base::FilePath& install_dir,
- std::unique_ptr<base::DictionaryValue> manifest) override;
- base::FilePath GetRelativeInstallDir() const override;
- void GetHash(std::vector<uint8_t>* hash) const override;
- std::string GetName() const override;
- update_client::InstallerAttributes GetInstallerAttributes() const override;
- std::vector<std::string> GetMimeTypes() const override;
-
- std::string crx_id_;
- std::string name_;
- RawWhitelistReadyCallback callback_;
-
- DISALLOW_COPY_AND_ASSIGN(SupervisedUserWhitelistComponentInstallerPolicy);
-};
-
-bool SupervisedUserWhitelistComponentInstallerPolicy::VerifyInstallation(
- const base::DictionaryValue& manifest,
- const base::FilePath& install_dir) const {
- // Check whether the whitelist exists at the path specified by the manifest.
- // This does not check whether the whitelist is wellformed.
- return base::PathExists(GetRawWhitelistPath(manifest, install_dir));
-}
-
-bool SupervisedUserWhitelistComponentInstallerPolicy::
- SupportsGroupPolicyEnabledComponentUpdates() const {
- return false;
-}
-
-bool SupervisedUserWhitelistComponentInstallerPolicy::
- RequiresNetworkEncryption() const {
- return true;
-}
-
-update_client::CrxInstaller::Result
-SupervisedUserWhitelistComponentInstallerPolicy::OnCustomInstall(
- const base::DictionaryValue& manifest,
- const base::FilePath& install_dir) {
- // Delete the existing sanitized whitelist.
- const bool success = base::DeleteFile(GetSanitizedWhitelistPath(crx_id_));
- return update_client::CrxInstaller::Result(
- success ? update_client::InstallError::NONE
- : update_client::InstallError::GENERIC_ERROR);
-}
-
-void SupervisedUserWhitelistComponentInstallerPolicy::OnCustomUninstall() {}
-
-void SupervisedUserWhitelistComponentInstallerPolicy::ComponentReady(
- const base::Version& version,
- const base::FilePath& install_dir,
- std::unique_ptr<base::DictionaryValue> manifest) {
- // TODO(crbug.com/558387): Before getting the title, we should localize the
- // manifest using extension_l10n_util::LocalizeExtension, but that doesn't
- // exist on Android.
- callback_.Run(GetWhitelistTitle(*manifest),
- GetLargeIconPath(*manifest, install_dir),
- GetRawWhitelistPath(*manifest, install_dir));
-}
-
-base::FilePath
-SupervisedUserWhitelistComponentInstallerPolicy::GetRelativeInstallDir() const {
- return base::FilePath(component_updater::kSupervisedUserWhitelistDirName)
- .AppendASCII(crx_id_);
-}
-
-void SupervisedUserWhitelistComponentInstallerPolicy::GetHash(
- std::vector<uint8_t>* hash) const {
- *hash = SupervisedUserWhitelistInstaller::GetHashFromCrxId(crx_id_);
-}
-
-std::string SupervisedUserWhitelistComponentInstallerPolicy::GetName() const {
- return name_;
-}
-
-update_client::InstallerAttributes
-SupervisedUserWhitelistComponentInstallerPolicy::GetInstallerAttributes()
- const {
- return update_client::InstallerAttributes();
-}
-
-std::vector<std::string>
-SupervisedUserWhitelistComponentInstallerPolicy::GetMimeTypes() const {
- return std::vector<std::string>();
-}
-
-class SupervisedUserWhitelistInstallerImpl
- : public SupervisedUserWhitelistInstaller,
- public ProfileAttributesStorage::Observer {
- public:
- SupervisedUserWhitelistInstallerImpl(
- ComponentUpdateService* cus,
- ProfileAttributesStorage* profile_attributes_storage,
- PrefService* local_state);
- ~SupervisedUserWhitelistInstallerImpl() override = default;
-
- private:
- void RegisterComponent(const std::string& crx_id,
- const std::string& name,
- base::OnceClosure callback);
- void RegisterNewComponent(const std::string& crx_id, const std::string& name);
- bool UnregisterWhitelistInternal(base::DictionaryValue* pref_dict,
- const std::string& client_id,
- const std::string& crx_id);
-
- void OnRawWhitelistReady(const std::string& crx_id,
- const base::string16& title,
- const base::FilePath& large_icon_path,
- const base::FilePath& whitelist_path);
- void OnSanitizedWhitelistReady(const std::string& crx_id,
- const base::string16& title,
- const base::FilePath& large_icon_path);
-
- // SupervisedUserWhitelistInstaller overrides:
- void RegisterComponents() override;
- void Subscribe(WhitelistReadyCallback callback) override;
- void RegisterWhitelist(const std::string& client_id,
- const std::string& crx_id,
- const std::string& name) override;
- void UnregisterWhitelist(const std::string& client_id,
- const std::string& crx_id) override;
-
- // ProfileAttributesStorage::Observer overrides:
- void OnProfileWillBeRemoved(const base::FilePath& profile_path) override;
-
- ComponentUpdateService* cus_ = nullptr;
- PrefService* local_state_ = nullptr;
-
- std::vector<WhitelistReadyCallback> callbacks_;
-
- ScopedObserver<ProfileAttributesStorage, ProfileAttributesStorage::Observer>
- observer_;
-
- scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_ =
- base::ThreadPool::CreateSequencedTaskRunner(kThreadPoolTaskTraits);
-
- base::WeakPtrFactory<SupervisedUserWhitelistInstallerImpl> weak_ptr_factory_{
- this};
-
- DISALLOW_COPY_AND_ASSIGN(SupervisedUserWhitelistInstallerImpl);
-};
-
-SupervisedUserWhitelistInstallerImpl::SupervisedUserWhitelistInstallerImpl(
- ComponentUpdateService* cus,
- ProfileAttributesStorage* profile_attributes_storage,
- PrefService* local_state)
- : cus_(cus), local_state_(local_state), observer_(this) {
- DCHECK(cus);
- DCHECK(local_state);
- observer_.Add(profile_attributes_storage);
-}
-
-void SupervisedUserWhitelistInstallerImpl::RegisterComponent(
- const std::string& crx_id,
- const std::string& name,
- base::OnceClosure callback) {
- std::unique_ptr<ComponentInstallerPolicy> policy =
- std::make_unique<SupervisedUserWhitelistComponentInstallerPolicy>(
- crx_id, name,
- base::Bind(&SupervisedUserWhitelistInstallerImpl::OnRawWhitelistReady,
- weak_ptr_factory_.GetWeakPtr(), crx_id));
- scoped_refptr<ComponentInstaller> installer =
- base::MakeRefCounted<ComponentInstaller>(std::move(policy));
- installer->Register(cus_, std::move(callback));
-}
-
-void SupervisedUserWhitelistInstallerImpl::RegisterNewComponent(
- const std::string& crx_id,
- const std::string& name) {
- RegisterComponent(
- crx_id, name,
- base::BindOnce(&SupervisedUserWhitelistInstaller::TriggerComponentUpdate,
- &cus_->GetOnDemandUpdater(), crx_id));
-}
-
-bool SupervisedUserWhitelistInstallerImpl::UnregisterWhitelistInternal(
- base::DictionaryValue* pref_dict,
- const std::string& client_id,
- const std::string& crx_id) {
- base::DictionaryValue* whitelist_dict = nullptr;
- bool success =
- pref_dict->GetDictionaryWithoutPathExpansion(crx_id, &whitelist_dict);
- DCHECK(success);
- base::ListValue* clients = nullptr;
- success = whitelist_dict->GetList(kClients, &clients);
-
- const bool removed = clients->Remove(base::Value(client_id), nullptr);
-
- if (!clients->empty())
- return removed;
-
- pref_dict->RemoveKey(crx_id);
- const bool result = cus_->UnregisterComponent(crx_id);
- DCHECK(result);
-
- sequenced_task_runner_->PostTask(
- FROM_HERE, base::BindOnce(&DeleteFileOnTaskRunner,
- GetSanitizedWhitelistPath(crx_id)));
- return removed;
-}
-
-void SupervisedUserWhitelistInstallerImpl::OnRawWhitelistReady(
- const std::string& crx_id,
- const base::string16& title,
- const base::FilePath& large_icon_path,
- const base::FilePath& whitelist_path) {
- // TODO(sorin): avoid using a single thread task runner crbug.com/744718.
- auto task_runner = base::ThreadPool::CreateSingleThreadTaskRunner(
- kThreadPoolTaskTraits, base::SingleThreadTaskRunnerThreadMode::SHARED);
- task_runner->PostTask(
- FROM_HERE,
- base::BindOnce(
- &CheckForSanitizedWhitelistOnTaskRunner, crx_id, whitelist_path,
- base::ThreadTaskRunnerHandle::Get(),
- base::BindOnce(
- &SupervisedUserWhitelistInstallerImpl::OnSanitizedWhitelistReady,
- weak_ptr_factory_.GetWeakPtr(), crx_id, title, large_icon_path)));
-}
-
-void SupervisedUserWhitelistInstallerImpl::OnSanitizedWhitelistReady(
- const std::string& crx_id,
- const base::string16& title,
- const base::FilePath& large_icon_path) {
- for (WhitelistReadyCallback callback : callbacks_)
- callback.Run(crx_id, title, large_icon_path,
- GetSanitizedWhitelistPath(crx_id));
-}
-
-void SupervisedUserWhitelistInstallerImpl::RegisterComponents() {
- const std::map<std::string, std::string> command_line_whitelists =
- SupervisedUserAllowlistService::GetAllowlistsFromCommandLine();
-
- std::set<std::string> registered_whitelists;
- std::set<std::string> stale_whitelists;
- DictionaryPrefUpdate update(local_state_,
- prefs::kRegisteredSupervisedUserWhitelists);
- base::DictionaryValue* whitelists = update.Get();
- for (base::DictionaryValue::Iterator it(*whitelists); !it.IsAtEnd();
- it.Advance()) {
- const base::DictionaryValue* dict = nullptr;
- it.value().GetAsDictionary(&dict);
-
- const std::string& id = it.key();
-
- // Skip whitelists with no clients. This can happen when a whitelist was
- // previously registered on the command line but isn't anymore.
- const base::ListValue* clients = nullptr;
- if ((!dict->GetList(kClients, &clients) || clients->empty()) &&
- !base::Contains(command_line_whitelists, id)) {
- stale_whitelists.insert(id);
- continue;
- }
-
- std::string name;
- const bool result = dict->GetString(kName, &name);
- DCHECK(result);
- RegisterComponent(id, name, base::OnceClosure());
-
- registered_whitelists.insert(id);
- }
-
- // Clean up stale whitelists as determined above.
- for (const std::string& id : stale_whitelists)
- whitelists->RemoveKey(id);
-
- sequenced_task_runner_->PostTask(
- FROM_HERE, base::BindOnce(&RemoveUnregisteredWhitelistsOnTaskRunner,
- registered_whitelists));
-}
-
-void SupervisedUserWhitelistInstallerImpl::Subscribe(
- WhitelistReadyCallback callback) {
- return callbacks_.push_back(callback);
-}
-
-void SupervisedUserWhitelistInstallerImpl::RegisterWhitelist(
- const std::string& client_id,
- const std::string& crx_id,
- const std::string& name) {
- DictionaryPrefUpdate update(local_state_,
- prefs::kRegisteredSupervisedUserWhitelists);
- base::Value* pref_dict = update.Get();
- base::Value* whitelist_dict =
- pref_dict->FindKeyOfType(crx_id, base::Value::Type::DICTIONARY);
- const bool newly_added = !whitelist_dict;
- if (newly_added) {
- whitelist_dict =
- pref_dict->SetKey(crx_id, base::Value(base::Value::Type::DICTIONARY));
- whitelist_dict->SetKey(kName, base::Value(name));
- }
-
- if (!client_id.empty()) {
- base::Value* clients =
- whitelist_dict->FindKeyOfType(kClients, base::Value::Type::LIST);
- if (!clients) {
- DCHECK(newly_added);
- clients = whitelist_dict->SetKey(kClients,
- base::Value(base::Value::Type::LIST));
- }
-
- base::Value client(client_id);
- DCHECK(!base::Contains(clients->GetList(), client));
- clients->Append(std::move(client));
- }
-
- if (!newly_added) {
- // Sanity-check that the stored name is equal to the name passed in.
- // In release builds this is a no-op.
- DCHECK_EQ(name, whitelist_dict->FindKey(kName)->GetString());
- return;
- }
-
- RegisterNewComponent(crx_id, name);
-}
-
-void SupervisedUserWhitelistInstallerImpl::UnregisterWhitelist(
- const std::string& client_id,
- const std::string& crx_id) {
- DictionaryPrefUpdate update(local_state_,
- prefs::kRegisteredSupervisedUserWhitelists);
- bool removed = UnregisterWhitelistInternal(update.Get(), client_id, crx_id);
- DCHECK(removed);
-}
-
-void SupervisedUserWhitelistInstallerImpl::OnProfileWillBeRemoved(
- const base::FilePath& profile_path) {
- std::string client_id = ClientIdForProfilePath(profile_path);
-
- // Go through all registered whitelists and possibly unregister them for this
- // client. Because unregistering a whitelist might completely uninstall it, we
- // need to make a copy of all the IDs before iterating over them.
- DictionaryPrefUpdate update(local_state_,
- prefs::kRegisteredSupervisedUserWhitelists);
- base::DictionaryValue* pref_dict = update.Get();
-
- std::vector<std::string> crx_ids;
- for (base::DictionaryValue::Iterator it(*pref_dict); !it.IsAtEnd();
- it.Advance()) {
- crx_ids.push_back(it.key());
- }
-
- for (const std::string& crx_id : crx_ids)
- UnregisterWhitelistInternal(pref_dict, client_id, crx_id);
-}
-
-} // namespace
-
-// static
-std::unique_ptr<SupervisedUserWhitelistInstaller>
-SupervisedUserWhitelistInstaller::Create(
- ComponentUpdateService* cus,
- ProfileAttributesStorage* profile_attributes_storage,
- PrefService* local_state) {
- return std::make_unique<SupervisedUserWhitelistInstallerImpl>(
- cus, profile_attributes_storage, local_state);
-}
-
-// static
-void SupervisedUserWhitelistInstaller::RegisterPrefs(
- PrefRegistrySimple* registry) {
- registry->RegisterDictionaryPref(prefs::kRegisteredSupervisedUserWhitelists);
-}
-
-// static
-std::string SupervisedUserWhitelistInstaller::ClientIdForProfilePath(
- const base::FilePath& profile_path) {
- // See ProfileInfoCache::CacheKeyFromProfilePath().
- // TODO(anthonyvd): update comment when the refactoring of ProfileInfoCache
- // is completed.
- return profile_path.BaseName().MaybeAsASCII();
-}
-
-// static
-std::vector<uint8_t> SupervisedUserWhitelistInstaller::GetHashFromCrxId(
- const std::string& crx_id) {
- DCHECK(crx_file::id_util::IdIsValid(crx_id));
-
- std::vector<uint8_t> hash;
- uint8_t byte = 0;
- for (size_t i = 0; i < crx_id.size(); ++i) {
- // Uppercase characters in IDs are technically legal.
- int val = base::ToLowerASCII(crx_id[i]) - 'a';
- DCHECK_GE(val, 0);
- DCHECK_LT(val, 16);
- if (i % 2 == 0) {
- byte = val;
- } else {
- hash.push_back(16 * byte + val);
- byte = 0;
- }
- }
- return hash;
-}
-
-// static
-void SupervisedUserWhitelistInstaller::TriggerComponentUpdate(
- OnDemandUpdater* updater,
- const std::string& crx_id) {
- // TODO(sorin): use a callback to check the result (crbug.com/639189).
- updater->OnDemandUpdate(crx_id, OnDemandUpdater::Priority::FOREGROUND,
- component_updater::Callback());
-}
-
-} // namespace component_updater
diff --git a/chrome/browser/component_updater/supervised_user_whitelist_installer.h b/chrome/browser/component_updater/supervised_user_whitelist_installer.h
deleted file mode 100644
index 7134062..0000000
--- a/chrome/browser/component_updater/supervised_user_whitelist_installer.h
+++ /dev/null
@@ -1,93 +0,0 @@
-// Copyright 2014 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_COMPONENT_UPDATER_SUPERVISED_USER_WHITELIST_INSTALLER_H_
-#define CHROME_BROWSER_COMPONENT_UPDATER_SUPERVISED_USER_WHITELIST_INSTALLER_H_
-
-#include <stdint.h>
-
-#include <memory>
-#include <set>
-#include <string>
-#include <vector>
-
-#include "base/callback_forward.h"
-#include "base/strings/string16.h"
-
-namespace base {
-class FilePath;
-}
-
-class PrefRegistrySimple;
-class PrefService;
-class ProfileAttributesStorage;
-
-namespace component_updater {
-
-class ComponentUpdateService;
-class OnDemandUpdater;
-
-class SupervisedUserWhitelistInstaller {
- public:
- using WhitelistReadyCallback =
- base::RepeatingCallback<void(const std::string& crx_id,
- const base::string16& title,
- const base::FilePath& large_icon_path,
- const base::FilePath& whitelist_path)>;
-
- virtual ~SupervisedUserWhitelistInstaller() = default;
-
- static std::unique_ptr<SupervisedUserWhitelistInstaller> Create(
- ComponentUpdateService* cus,
- ProfileAttributesStorage* profile_attributes_storage,
- PrefService* local_state);
-
- static void RegisterPrefs(PrefRegistrySimple* registry);
-
- // Generates a client ID suitable for RegisterWhitelist() and
- // UnregisterWhitelist() below from a profile path.
- static std::string ClientIdForProfilePath(const base::FilePath& profile_path);
-
- // Turns a CRX ID (which is derived from a hash) back into a hash.
- // Note that the resulting hash will be only 16 bytes long instead of the
- // usual 32 bytes, as the CRX ID is created from the first half of the
- // original hash, but the component installer will still accept this.
- // Public for testing.
- static std::vector<uint8_t> GetHashFromCrxId(const std::string& crx_id);
-
- // Starts registering all components with the ComponentUpdaterService.
- // Also removes unregistered components on disk (which are most likely left
- // over from a previous uninstallation that was interrupted, e.g. during
- // shutdown or a crash).
- virtual void RegisterComponents() = 0;
-
- // Subscribes for notifications about available whitelists. Clients should
- // filter out the whitelists they are interested in via the |crx_id|
- // parameter.
- virtual void Subscribe(WhitelistReadyCallback callback) = 0;
-
- // Registers a new whitelist with the given |crx_id|.
- // The |client_id| should be a unique identifier for the client that is stable
- // across restarts. If it is empty, the registration will not be persisted in
- // Local State.
- virtual void RegisterWhitelist(const std::string& client_id,
- const std::string& crx_id,
- const std::string& name) = 0;
-
- // Unregisters a whitelist.
- virtual void UnregisterWhitelist(const std::string& client_id,
- const std::string& crx_id) = 0;
-
- protected:
- // Triggers an update for a whitelist to be installed. Protected so it can be
- // called from the implementation subclass, and declared here so that the
- // OnDemandUpdater can friend this class and the implementation subclass can
- // live in an anonymous namespace.
- static void TriggerComponentUpdate(OnDemandUpdater* updater,
- const std::string& crx_id);
-};
-
-} // namespace component_updater
-
-#endif // CHROME_BROWSER_COMPONENT_UPDATER_SUPERVISED_USER_WHITELIST_INSTALLER_H_
diff --git a/chrome/browser/component_updater/supervised_user_whitelist_installer_unittest.cc b/chrome/browser/component_updater/supervised_user_whitelist_installer_unittest.cc
deleted file mode 100644
index 697d59fc..0000000
--- a/chrome/browser/component_updater/supervised_user_whitelist_installer_unittest.cc
+++ /dev/null
@@ -1,457 +0,0 @@
-// Copyright 2014 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 <stddef.h>
-
-#include <memory>
-#include <utility>
-
-#include "base/bind.h"
-#include "base/callback.h"
-#include "base/callback_helpers.h"
-#include "base/files/file_path.h"
-#include "base/files/file_util.h"
-#include "base/files/scoped_temp_dir.h"
-#include "base/json/json_file_value_serializer.h"
-#include "base/json/json_reader.h"
-#include "base/json/json_writer.h"
-#include "base/path_service.h"
-#include "base/run_loop.h"
-#include "base/sequenced_task_runner.h"
-#include "base/strings/string_util.h"
-#include "base/strings/utf_string_conversions.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "base/values.h"
-#include "chrome/browser/component_updater/supervised_user_whitelist_installer.h"
-#include "chrome/browser/profiles/profile_attributes_storage.h"
-#include "chrome/common/chrome_paths.h"
-#include "chrome/common/pref_names.h"
-#include "chrome/test/base/testing_browser_process.h"
-#include "chrome/test/base/testing_profile_manager.h"
-#include "components/account_id/account_id.h"
-#include "components/component_updater/component_updater_paths.h"
-#include "components/component_updater/component_updater_service.h"
-#include "components/crx_file/id_util.h"
-#include "components/prefs/testing_pref_service.h"
-#include "components/update_client/crx_update_item.h"
-#include "components/update_client/update_client.h"
-#include "components/update_client/utils.h"
-#include "content/public/test/browser_task_environment.h"
-#include "content/public/test/test_utils.h"
-#include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-using update_client::CrxComponent;
-using update_client::CrxUpdateItem;
-
-namespace component_updater {
-
-namespace {
-
-const char kClientId[] = "client-id";
-const char kCrxId[] = "abcdefghijklmnopponmlkjihgfedcba";
-const char kName[] = "Some Whitelist";
-const char kOtherClientId[] = "other-client-id";
-const char kVersion[] = "1.2.3.4";
-const char kWhitelistContents[] = "{\"foo\": \"bar\"}";
-const char kWhitelistFile[] = "whitelist.json";
-const char kLargeIconFile[] = "icon.png";
-
-std::string CrxIdToHashToCrxId(const std::string& kCrxId) {
- CrxComponent component;
- component.pk_hash =
- SupervisedUserWhitelistInstaller::GetHashFromCrxId(kCrxId);
- EXPECT_EQ(16u, component.pk_hash.size());
- return GetCrxComponentID(component);
-}
-
-std::string JsonToString(const base::DictionaryValue& dict) {
- std::string json;
- base::JSONWriter::Write(dict, &json);
- return json;
-}
-
-class MockComponentUpdateService : public ComponentUpdateService,
- public OnDemandUpdater {
- public:
- ~MockComponentUpdateService() override = default;
-
- bool on_demand_update_called() const { return on_demand_update_called_; }
-
- const CrxComponent* registered_component() { return component_.get(); }
-
- void set_registration_callback(base::OnceClosure registration_callback) {
- registration_callback_ = std::move(registration_callback);
- }
-
- // ComponentUpdateService implementation:
- void AddObserver(Observer* observer) override { ADD_FAILURE(); }
- void RemoveObserver(Observer* observer) override { ADD_FAILURE(); }
-
- std::vector<std::string> GetComponentIDs() const override {
- ADD_FAILURE();
- return std::vector<std::string>();
- }
-
- bool RegisterComponent(const CrxComponent& component) override {
- EXPECT_EQ(nullptr, component_.get());
- component_ = std::make_unique<CrxComponent>(component);
- if (!registration_callback_.is_null())
- std::move(registration_callback_).Run();
-
- return true;
- }
-
- bool UnregisterComponent(const std::string& crx_id) override {
- if (!component_) {
- ADD_FAILURE();
- return false;
- }
-
- EXPECT_EQ(GetCrxComponentID(*component_), crx_id);
- if (!component_->installer->Uninstall()) {
- ADD_FAILURE();
- return false;
- }
-
- component_.reset();
- return true;
- }
-
- OnDemandUpdater& GetOnDemandUpdater() override { return *this; }
-
- void MaybeThrottle(const std::string& kCrxId,
- const base::OnceClosure callback) override {
- ADD_FAILURE();
- }
-
- bool GetComponentDetails(const std::string& component_id,
- CrxUpdateItem* item) const override {
- ADD_FAILURE();
- return false;
- }
-
- std::unique_ptr<ComponentInfo> GetComponentForMimeType(
- const std::string& mime_type) const override {
- return nullptr;
- }
-
- std::vector<ComponentInfo> GetComponents() const override {
- return std::vector<ComponentInfo>();
- }
-
- // OnDemandUpdater implementation:
- void OnDemandUpdate(const std::string& crx_id,
- Priority priority,
- Callback callback) override {
- on_demand_update_called_ = true;
-
- if (!component_) {
- ADD_FAILURE() << "Trying to update unregistered component " << crx_id;
- return;
- }
-
- EXPECT_EQ(OnDemandUpdater::Priority::FOREGROUND, priority);
- EXPECT_EQ(GetCrxComponentID(*component_), crx_id);
- }
-
- private:
- std::unique_ptr<CrxComponent> component_;
- base::OnceClosure registration_callback_;
- bool on_demand_update_called_ = false;
-};
-
-class WhitelistLoadObserver {
- public:
- explicit WhitelistLoadObserver(SupervisedUserWhitelistInstaller* installer) {
- installer->Subscribe(
- base::BindRepeating(&WhitelistLoadObserver::OnWhitelistReady,
- weak_ptr_factory_.GetWeakPtr()));
- }
-
- void Wait() { run_loop_.Run(); }
- void Quit() { run_loop_.Quit(); }
-
- const base::FilePath& large_icon_path() const { return large_icon_path_; }
- const base::FilePath& whitelist_path() const { return whitelist_path_; }
-
- private:
- void OnWhitelistReady(const std::string& crx_id,
- const base::string16& title,
- const base::FilePath& large_icon_path,
- const base::FilePath& whitelist_path) {
- EXPECT_EQ(base::FilePath::StringType(), large_icon_path_.value());
- EXPECT_EQ(base::FilePath::StringType(), whitelist_path_.value());
- whitelist_path_ = whitelist_path;
- large_icon_path_ = large_icon_path;
- Quit();
- }
-
- base::FilePath large_icon_path_;
- base::FilePath whitelist_path_;
-
- base::RunLoop run_loop_;
- base::WeakPtrFactory<WhitelistLoadObserver> weak_ptr_factory_{this};
-};
-
-} // namespace
-
-class SupervisedUserWhitelistInstallerTest : public testing::Test {
- public:
- SupervisedUserWhitelistInstallerTest()
- : testing_profile_manager_(TestingBrowserProcess::GetGlobal()) {}
-
- ~SupervisedUserWhitelistInstallerTest() override = default;
-
- void SetUp() override {
- SupervisedUserWhitelistInstaller::RegisterPrefs(local_state_.registry());
-
- ASSERT_TRUE(testing_profile_manager_.SetUp());
-
- profile_attributes_storage()->AddProfile(
- GetProfilePath(kClientId), base::ASCIIToUTF16("A Profile"),
- std::string(), base::string16(), false, 0, std::string(),
- EmptyAccountId());
- profile_attributes_storage()->AddProfile(
- GetProfilePath(kOtherClientId), base::ASCIIToUTF16("Another Profile"),
- std::string(), base::string16(), false, 0, std::string(),
- EmptyAccountId());
-
- installer_ = SupervisedUserWhitelistInstaller::Create(
- &component_update_service_,
- profile_attributes_storage(),
- &local_state_);
-
- ASSERT_TRUE(base::PathService::Get(DIR_SUPERVISED_USER_ALLOWLISTS,
- &whitelist_base_directory_));
- whitelist_directory_ = whitelist_base_directory_.AppendASCII(kCrxId);
- whitelist_version_directory_ = whitelist_directory_.AppendASCII(kVersion);
-
- ASSERT_TRUE(
- base::PathService::Get(chrome::DIR_SUPERVISED_USER_INSTALLED_WHITELISTS,
- &installed_whitelist_directory_));
- std::string crx_id(kCrxId);
- whitelist_path_ =
- installed_whitelist_directory_.AppendASCII(crx_id + ".json");
- large_icon_path_ = whitelist_version_directory_.AppendASCII(kLargeIconFile);
-
- auto crx_dict = std::make_unique<base::DictionaryValue>();
- crx_dict->SetString("name", kName);
- std::unique_ptr<base::ListValue> clients =
- std::make_unique<base::ListValue>();
- clients->AppendString(kClientId);
- clients->AppendString(kOtherClientId);
- crx_dict->Set("clients", std::move(clients));
- pref_.Set(kCrxId, std::move(crx_dict));
- }
-
- protected:
- ProfileAttributesStorage* profile_attributes_storage() {
- return testing_profile_manager_.profile_attributes_storage();
- }
-
- base::FilePath GetProfilePath(const std::string& profile_name) {
- return testing_profile_manager_.profiles_dir().AppendASCII(profile_name);
- }
-
- void PrepareWhitelistFile(const base::FilePath& whitelist_path) {
- size_t whitelist_contents_length = sizeof(kWhitelistContents) - 1;
- ASSERT_EQ(static_cast<int>(whitelist_contents_length),
- base::WriteFile(whitelist_path, kWhitelistContents,
- whitelist_contents_length));
- }
-
- void PrepareWhitelistDirectory(const base::FilePath& whitelist_directory) {
- PrepareWhitelistFile(whitelist_directory.AppendASCII(kWhitelistFile));
- base::FilePath manifest_file =
- whitelist_directory.AppendASCII("manifest.json");
-
- base::DictionaryValue manifest;
-
- auto whitelist_dict = std::make_unique<base::DictionaryValue>();
- whitelist_dict->SetString("sites", kWhitelistFile);
- manifest.Set("whitelisted_content", std::move(whitelist_dict));
-
- auto icons_dict = std::make_unique<base::DictionaryValue>();
- icons_dict->SetString("128", kLargeIconFile);
- manifest.Set("icons", std::move(icons_dict));
-
- manifest.SetString("version", kVersion);
-
- ASSERT_TRUE(JSONFileValueSerializer(manifest_file).Serialize(manifest));
- }
-
- void RegisterExistingComponents() {
- local_state_.Set(prefs::kRegisteredSupervisedUserWhitelists, pref_);
- installer_->RegisterComponents();
- content::RunAllTasksUntilIdle();
- base::RunLoop().RunUntilIdle();
- }
-
- void CheckRegisteredComponent(const char* version) {
- const CrxComponent* component =
- component_update_service_.registered_component();
- ASSERT_TRUE(component);
- EXPECT_EQ(kName, component->name);
- EXPECT_EQ(kCrxId, GetCrxComponentID(*component));
- EXPECT_EQ(version, component->version.GetString());
- }
-
- content::BrowserTaskEnvironment task_environment_;
- TestingProfileManager testing_profile_manager_;
- data_decoder::test::InProcessDataDecoder in_process_data_decoder_;
- TestingPrefServiceSimple local_state_;
- std::unique_ptr<SupervisedUserWhitelistInstaller> installer_;
- base::FilePath whitelist_base_directory_;
- base::FilePath whitelist_directory_;
- base::FilePath whitelist_version_directory_;
- base::FilePath installed_whitelist_directory_;
- base::FilePath whitelist_path_;
- base::FilePath large_icon_path_;
- base::DictionaryValue pref_;
- MockComponentUpdateService component_update_service_;
-};
-
-TEST_F(SupervisedUserWhitelistInstallerTest, GetHashFromCrxId) {
- {
- std::string extension_id = "abcdefghijklmnopponmlkjihgfedcba";
- ASSERT_EQ(extension_id, CrxIdToHashToCrxId(extension_id));
- }
-
- {
- std::string extension_id = "aBcDeFgHiJkLmNoPpOnMlKjIhGfEdCbA";
- ASSERT_EQ(base::ToLowerASCII(extension_id),
- CrxIdToHashToCrxId(extension_id));
- }
-
- {
- std::string extension_id = crx_file::id_util::GenerateId("Moose");
- ASSERT_EQ(extension_id, CrxIdToHashToCrxId(extension_id));
- }
-}
-
-TEST_F(SupervisedUserWhitelistInstallerTest, InstallNewWhitelist) {
- base::RunLoop registration_run_loop;
- component_update_service_.set_registration_callback(
- registration_run_loop.QuitClosure());
-
- WhitelistLoadObserver observer(installer_.get());
- installer_->RegisterWhitelist(kClientId, kCrxId, kName);
- registration_run_loop.Run();
-
- ASSERT_NO_FATAL_FAILURE(CheckRegisteredComponent("0.0.0.0"));
- EXPECT_TRUE(component_update_service_.on_demand_update_called());
-
- // Registering the same whitelist for another client should not do anything.
- installer_->RegisterWhitelist(kOtherClientId, kCrxId, kName);
-
- base::ScopedTempDir temp_dir;
- ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
- base::FilePath unpacked_path = temp_dir.GetPath();
- ASSERT_NO_FATAL_FAILURE(PrepareWhitelistDirectory(unpacked_path));
-
- const CrxComponent* component =
- component_update_service_.registered_component();
- ASSERT_TRUE(component);
-
- // The lambda function argument below is called by the ComponentInstaller
- // implementation of the SupervisedUserWhitelistInstaller. Quit the observer
- // in case of errors to allow the test to continue, since the component
- // installer only calls |ComponentReady| if the install of the component
- // has succeeded.
- component->installer->Install(
- unpacked_path, std::string(), nullptr, base::DoNothing(),
- base::BindOnce(
- [](WhitelistLoadObserver* observer,
- const update_client::CrxInstaller::Result& result) {
- EXPECT_EQ(0, result.error);
- EXPECT_EQ(0, result.extended_error);
- if (result.error)
- observer->Quit();
- },
- &observer));
-
- content::RunAllTasksUntilIdle();
-
- observer.Wait();
- EXPECT_EQ(whitelist_path_.value(), observer.whitelist_path().value());
- EXPECT_EQ(large_icon_path_.value(), observer.large_icon_path().value());
-
- std::string whitelist_contents;
- ASSERT_TRUE(base::ReadFileToString(whitelist_path_, &whitelist_contents));
-
- // The actual file contents don't have to be equal, but the parsed values
- // should be.
- EXPECT_TRUE(
- base::JSONReader::ReadDeprecated(kWhitelistContents)
- ->Equals(base::JSONReader::ReadDeprecated(whitelist_contents).get()))
- << kWhitelistContents << " vs. " << whitelist_contents;
-
- EXPECT_EQ(JsonToString(pref_),
- JsonToString(*local_state_.GetDictionary(
- prefs::kRegisteredSupervisedUserWhitelists)));
-}
-
-TEST_F(SupervisedUserWhitelistInstallerTest,
- RegisterAndUninstallExistingWhitelist) {
- ASSERT_TRUE(base::CreateDirectory(whitelist_version_directory_));
- ASSERT_NO_FATAL_FAILURE(
- PrepareWhitelistDirectory(whitelist_version_directory_));
- ASSERT_TRUE(base::CreateDirectory(installed_whitelist_directory_));
- ASSERT_NO_FATAL_FAILURE(PrepareWhitelistFile(whitelist_path_));
-
- // Create another whitelist directory, with an ID that is not registered.
- base::FilePath other_directory =
- whitelist_base_directory_.AppendASCII("paobncmdlekfjgihhigjfkeldmcnboap");
- ASSERT_TRUE(base::CreateDirectory(other_directory));
- ASSERT_NO_FATAL_FAILURE(PrepareWhitelistDirectory(other_directory));
-
- // Create a directory that is not a valid whitelist directory.
- base::FilePath non_whitelist_directory =
- whitelist_base_directory_.AppendASCII("Not a whitelist");
- ASSERT_TRUE(base::CreateDirectory(non_whitelist_directory));
-
- RegisterExistingComponents();
-
- ASSERT_NO_FATAL_FAILURE(CheckRegisteredComponent(kVersion));
- EXPECT_FALSE(component_update_service_.on_demand_update_called());
-
- // Check that unregistered whitelists have been removed:
- // The registered whitelist directory should still exist.
- EXPECT_TRUE(base::DirectoryExists(whitelist_directory_));
-
- // The other directory should be gone.
- EXPECT_FALSE(base::DirectoryExists(other_directory));
-
- // The non-whitelist directory should still exist as well.
- EXPECT_TRUE(base::DirectoryExists(non_whitelist_directory));
-
- // Unregistering for the first client should do nothing.
- {
- base::RunLoop run_loop;
- installer_->UnregisterWhitelist(kClientId, kCrxId);
- content::RunAllTasksUntilIdle();
- run_loop.RunUntilIdle();
- }
- EXPECT_TRUE(component_update_service_.registered_component());
- EXPECT_TRUE(base::DirectoryExists(whitelist_version_directory_));
- EXPECT_TRUE(base::PathExists(whitelist_path_));
-
- // Unregistering for the second client should uninstall the whitelist.
- {
- base::RunLoop run_loop;
-
- // This does the same thing in our case as calling UnregisterWhitelist(),
- // but it exercises a different code path.
- profile_attributes_storage()->RemoveProfile(GetProfilePath(kOtherClientId));
- content::RunAllTasksUntilIdle();
- run_loop.RunUntilIdle();
- }
- EXPECT_FALSE(component_update_service_.registered_component());
- EXPECT_FALSE(base::DirectoryExists(whitelist_directory_));
- EXPECT_FALSE(base::PathExists(whitelist_path_));
-}
-
-} // namespace component_updater
diff --git a/chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.cc b/chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.cc
index d872e46..8348dfb 100644
--- a/chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.cc
+++ b/chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.cc
@@ -93,17 +93,8 @@
std::vector<ntp_tiles::MostVisitedSitesSupervisor::Allowlist>
SupervisorBridge::GetAllowlists() {
- std::vector<MostVisitedSitesSupervisor::Allowlist> results;
- SupervisedUserService* supervised_user_service =
- SupervisedUserServiceFactory::GetForProfile(profile_);
- for (const auto& allowlist : supervised_user_service->allowlists()) {
- results.emplace_back(Allowlist{
- allowlist->title(),
- allowlist->entry_point(),
- allowlist->large_icon_path(),
- });
- }
- return results;
+ // TODO(crbug.com/1149782): Remove allowlists from New Tab Page.
+ return {};
}
bool SupervisorBridge::IsChildProfile() {
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 1a181d49..58a0fba 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -200,7 +200,6 @@
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
#include "chrome/browser/supervised_user/child_accounts/child_account_service.h"
-#include "chrome/browser/supervised_user/supervised_user_allowlist_service.h"
#include "chrome/browser/supervised_user/supervised_user_service.h"
#endif
@@ -458,6 +457,13 @@
#if BUILDFLAG(IS_CHROMEOS_ASH)
// Deprecated 4/2020
const char kSupervisedUsersNextId[] = "LocallyManagedUsersNextId";
+
+// Deprecated 11/2020
+const char kRegisteredSupervisedUserAllowlists[] =
+ "supervised_users.whitelists";
+
+// Deprecated 11/2020
+const char kSupervisedUserAllowlists[] = "profile.managed.whitelists";
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
// Deprecated 6/2020
@@ -509,6 +515,7 @@
registry->RegisterStringPref(kInvalidatorClientId, std::string());
#if BUILDFLAG(IS_CHROMEOS_ASH)
+ registry->RegisterDictionaryPref(kRegisteredSupervisedUserAllowlists);
registry->RegisterIntegerPref(kSupervisedUsersNextId, 0);
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
}
@@ -525,6 +532,7 @@
#if BUILDFLAG(IS_CHROMEOS_ASH)
registry->RegisterBooleanPref(
kDisplayRotationAcceleratorDialogHasBeenAccepted, false);
+ registry->RegisterDictionaryPref(kSupervisedUserAllowlists);
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
registry->RegisterBooleanPref(kBlacklistedCredentialsNormalized, false);
@@ -893,7 +901,6 @@
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
ChildAccountService::RegisterProfilePrefs(registry);
SupervisedUserService::RegisterProfilePrefs(registry);
- SupervisedUserAllowlistService::RegisterProfilePrefs(registry);
#endif
#if defined(OS_ANDROID)
@@ -1096,6 +1103,9 @@
#if BUILDFLAG(IS_CHROMEOS_ASH)
// Added 4/2020.
local_state->ClearPref(kSupervisedUsersNextId);
+
+ // Added 11/2020.
+ local_state->ClearPref(kRegisteredSupervisedUserAllowlists);
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
// Please don't delete the following line. It is used by PRESUBMIT.py.
@@ -1198,6 +1208,11 @@
// Added 11/2020
profile_prefs->ClearPref(kDRMSalt);
+#if BUILDFLAG(IS_CHROMEOS_ASH)
+ // Added 11/2020.
+ profile_prefs->ClearPref(kSupervisedUserAllowlists);
+#endif // BUILDFLAG(IS_CHROMEOS_ASH)
+
// Please don't delete the following line. It is used by PRESUBMIT.py.
// END_MIGRATE_OBSOLETE_PROFILE_PREFS
}
diff --git a/chrome/browser/supervised_user/supervised_user_allowlist_service.cc b/chrome/browser/supervised_user/supervised_user_allowlist_service.cc
deleted file mode 100644
index d0dcd25e..0000000
--- a/chrome/browser/supervised_user/supervised_user_allowlist_service.cc
+++ /dev/null
@@ -1,356 +0,0 @@
-// Copyright 2014 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/supervised_user/supervised_user_allowlist_service.h"
-
-#include <stddef.h>
-
-#include <string>
-#include <utility>
-
-#include "base/bind.h"
-#include "base/command_line.h"
-#include "base/files/file_path.h"
-#include "base/logging.h"
-#include "base/metrics/histogram_macros.h"
-#include "base/metrics/user_metrics.h"
-#include "base/metrics/user_metrics_action.h"
-#include "base/strings/string_split.h"
-#include "base/values.h"
-#include "chrome/browser/component_updater/supervised_user_whitelist_installer.h"
-#include "chrome/browser/supervised_user/supervised_user_site_list.h"
-#include "chrome/common/chrome_switches.h"
-#include "chrome/common/pref_names.h"
-#include "components/pref_registry/pref_registry_syncable.h"
-#include "components/prefs/pref_service.h"
-#include "components/prefs/scoped_user_pref_update.h"
-#include "components/sync/model/sync_change.h"
-#include "components/sync/model/sync_change_processor.h"
-#include "components/sync/model/sync_data.h"
-#include "components/sync/model/sync_error.h"
-#include "components/sync/model/sync_error_factory.h"
-#include "components/sync/protocol/sync.pb.h"
-
-const char kName[] = "name";
-
-SupervisedUserAllowlistService::SupervisedUserAllowlistService(
- PrefService* prefs,
- component_updater::SupervisedUserWhitelistInstaller* installer,
- const std::string& client_id)
- : prefs_(prefs), installer_(installer), client_id_(client_id) {
- DCHECK(prefs);
-}
-
-SupervisedUserAllowlistService::~SupervisedUserAllowlistService() {}
-
-// static
-void SupervisedUserAllowlistService::RegisterProfilePrefs(
- user_prefs::PrefRegistrySyncable* registry) {
- registry->RegisterDictionaryPref(prefs::kSupervisedUserAllowlists);
-}
-
-void SupervisedUserAllowlistService::Init() {
- const base::DictionaryValue* allowlists =
- prefs_->GetDictionary(prefs::kSupervisedUserAllowlists);
- for (base::DictionaryValue::Iterator it(*allowlists); !it.IsAtEnd();
- it.Advance()) {
- registered_allowlists_.insert(it.key());
- }
- UMA_HISTOGRAM_COUNTS_100("ManagedUsers.Whitelist.Count", allowlists->size());
-
- // The installer can be null in some unit tests.
- if (!installer_)
- return;
-
- installer_->Subscribe(
- base::BindRepeating(&SupervisedUserAllowlistService::OnAllowlistReady,
- weak_ptr_factory_.GetWeakPtr()));
-
- // Register allowlists specified on the command line.
- for (const auto& allowlist : GetAllowlistsFromCommandLine())
- RegisterAllowlist(allowlist.first, allowlist.second, FROM_COMMAND_LINE);
-}
-
-void SupervisedUserAllowlistService::AddSiteListsChangedCallback(
- const SiteListsChangedCallback& callback) {
- site_lists_changed_callbacks_.push_back(callback);
-
- std::vector<scoped_refptr<SupervisedUserSiteList>> allowlists;
- GetLoadedAllowlists(&allowlists);
- callback.Run(allowlists);
-}
-
-// static
-std::map<std::string, std::string>
-SupervisedUserAllowlistService::GetAllowlistsFromCommandLine() {
- std::map<std::string, std::string> allowlists;
- const base::CommandLine* command_line =
- base::CommandLine::ForCurrentProcess();
- std::string command_line_allowlists = command_line->GetSwitchValueASCII(
- switches::kInstallSupervisedUserAllowlists);
- std::vector<base::StringPiece> string_pieces =
- base::SplitStringPiece(command_line_allowlists, ",",
- base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
- for (const base::StringPiece& allowlist : string_pieces) {
- std::string id;
- std::string name;
- size_t separator = allowlist.find(':');
- if (separator != base::StringPiece::npos) {
- id = std::string(allowlist.substr(0, separator));
- name = std::string(allowlist.substr(separator + 1));
- } else {
- id = std::string(allowlist);
- }
-
- const bool result = allowlists.insert(std::make_pair(id, name)).second;
- DCHECK(result);
- }
-
- return allowlists;
-}
-
-void SupervisedUserAllowlistService::LoadAllowlistForTesting(
- const std::string& id,
- const base::string16& title,
- const base::FilePath& path) {
- bool result = registered_allowlists_.insert(id).second;
- DCHECK(result);
- OnAllowlistReady(id, title, base::FilePath(), path);
-}
-
-void SupervisedUserAllowlistService::UnloadAllowlist(const std::string& id) {
- bool result = registered_allowlists_.erase(id) > 0u;
- DCHECK(result);
- loaded_allowlists_.erase(id);
- NotifyAllowlistsChanged();
-}
-
-// static
-syncer::SyncData SupervisedUserAllowlistService::CreateAllowlistSyncData(
- const std::string& id,
- const std::string& name) {
- sync_pb::EntitySpecifics specifics;
- sync_pb::ManagedUserWhitelistSpecifics* allowlist =
- specifics.mutable_managed_user_whitelist();
- allowlist->set_id(id);
- allowlist->set_name(name);
-
- return syncer::SyncData::CreateLocalData(id, name, specifics);
-}
-
-void SupervisedUserAllowlistService::WaitUntilReadyToSync(
- base::OnceClosure done) {
- // This service handles sync events at any time.
- std::move(done).Run();
-}
-
-base::Optional<syncer::ModelError>
-SupervisedUserAllowlistService::MergeDataAndStartSyncing(
- syncer::ModelType type,
- const syncer::SyncDataList& initial_sync_data,
- std::unique_ptr<syncer::SyncChangeProcessor> sync_processor,
- std::unique_ptr<syncer::SyncErrorFactory> error_handler) {
- DCHECK_EQ(syncer::DEPRECATED_SUPERVISED_USER_ALLOWLISTS, type);
-
- syncer::SyncChangeList change_list;
-
- DictionaryPrefUpdate update(prefs_, prefs::kSupervisedUserAllowlists);
- base::DictionaryValue* pref_dict = update.Get();
- std::set<std::string> seen_ids;
-
- for (const syncer::SyncData& sync_data : initial_sync_data) {
- DCHECK_EQ(syncer::DEPRECATED_SUPERVISED_USER_ALLOWLISTS,
- sync_data.GetDataType());
- const sync_pb::ManagedUserWhitelistSpecifics& allowlist =
- sync_data.GetSpecifics().managed_user_whitelist();
- std::string id = allowlist.id();
- std::string name = allowlist.name();
- seen_ids.insert(id);
- base::DictionaryValue* dict = nullptr;
- if (pref_dict->GetDictionary(id, &dict)) {
- std::string old_name;
- bool result = dict->GetString(kName, &old_name);
- DCHECK(result);
- if (name != old_name) {
- SetAllowlistProperties(dict, allowlist);
- }
- } else {
- AddNewAllowlist(pref_dict, allowlist);
- }
- }
-
- std::set<std::string> ids_to_remove;
- for (base::DictionaryValue::Iterator it(*pref_dict); !it.IsAtEnd();
- it.Advance()) {
- if (seen_ids.find(it.key()) == seen_ids.end())
- ids_to_remove.insert(it.key());
- }
-
- for (const std::string& id : ids_to_remove)
- RemoveAllowlist(pref_dict, id);
-
- // Notify if allowlists have been uninstalled. We will notify about newly
- // added allowlists later, when they are actually available
- // (in OnAllowlistLoaded).
- if (!ids_to_remove.empty())
- NotifyAllowlistsChanged();
-
- // The function does not generate any errors, so it can always return
- // base::nullopt.
- return base::nullopt;
-}
-
-void SupervisedUserAllowlistService::StopSyncing(syncer::ModelType type) {
- DCHECK_EQ(syncer::DEPRECATED_SUPERVISED_USER_ALLOWLISTS, type);
-}
-
-syncer::SyncDataList SupervisedUserAllowlistService::GetAllSyncDataForTesting(
- syncer::ModelType type) const {
- syncer::SyncDataList sync_data;
- const base::DictionaryValue* allowlists =
- prefs_->GetDictionary(prefs::kSupervisedUserAllowlists);
- for (base::DictionaryValue::Iterator it(*allowlists); !it.IsAtEnd();
- it.Advance()) {
- const std::string& id = it.key();
- const base::DictionaryValue* dict = nullptr;
- it.value().GetAsDictionary(&dict);
- std::string name;
- bool result = dict->GetString(kName, &name);
- DCHECK(result);
- sync_pb::EntitySpecifics specifics;
- sync_pb::ManagedUserWhitelistSpecifics* allowlist =
- specifics.mutable_managed_user_whitelist();
- allowlist->set_id(id);
- allowlist->set_name(name);
- sync_data.push_back(syncer::SyncData::CreateLocalData(id, name, specifics));
- }
- return sync_data;
-}
-
-base::Optional<syncer::ModelError>
-SupervisedUserAllowlistService::ProcessSyncChanges(
- const base::Location& from_here,
- const syncer::SyncChangeList& change_list) {
- bool allowlists_removed = false;
- DictionaryPrefUpdate update(prefs_, prefs::kSupervisedUserAllowlists);
- base::DictionaryValue* pref_dict = update.Get();
- for (const syncer::SyncChange& sync_change : change_list) {
- syncer::SyncData data = sync_change.sync_data();
- DCHECK_EQ(syncer::DEPRECATED_SUPERVISED_USER_ALLOWLISTS,
- data.GetDataType());
- const sync_pb::ManagedUserWhitelistSpecifics& allowlist =
- data.GetSpecifics().managed_user_whitelist();
- std::string id = allowlist.id();
- switch (sync_change.change_type()) {
- case syncer::SyncChange::ACTION_ADD: {
- DCHECK(!pref_dict->HasKey(id)) << id;
- AddNewAllowlist(pref_dict, allowlist);
- break;
- }
- case syncer::SyncChange::ACTION_UPDATE: {
- base::DictionaryValue* dict = nullptr;
- pref_dict->GetDictionaryWithoutPathExpansion(id, &dict);
- SetAllowlistProperties(dict, allowlist);
- break;
- }
- case syncer::SyncChange::ACTION_DELETE: {
- DCHECK(pref_dict->HasKey(id)) << id;
- RemoveAllowlist(pref_dict, id);
- allowlists_removed = true;
- break;
- }
- }
- }
-
- if (allowlists_removed)
- NotifyAllowlistsChanged();
-
- return base::nullopt;
-}
-
-void SupervisedUserAllowlistService::AddNewAllowlist(
- base::DictionaryValue* pref_dict,
- const sync_pb::ManagedUserWhitelistSpecifics& allowlist) {
- base::RecordAction(base::UserMetricsAction("ManagedUsers_Whitelist_Added"));
-
- RegisterAllowlist(allowlist.id(), allowlist.name(), FROM_SYNC);
- std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
- SetAllowlistProperties(dict.get(), allowlist);
- pref_dict->SetWithoutPathExpansion(allowlist.id(), std::move(dict));
-}
-
-void SupervisedUserAllowlistService::SetAllowlistProperties(
- base::DictionaryValue* dict,
- const sync_pb::ManagedUserWhitelistSpecifics& allowlist) {
- dict->SetString(kName, allowlist.name());
-}
-
-void SupervisedUserAllowlistService::RemoveAllowlist(
- base::DictionaryValue* pref_dict,
- const std::string& id) {
- base::RecordAction(base::UserMetricsAction("ManagedUsers_Whitelist_Removed"));
-
- pref_dict->RemoveKey(id);
- installer_->UnregisterWhitelist(client_id_, id);
- UnloadAllowlist(id);
-}
-
-void SupervisedUserAllowlistService::RegisterAllowlist(const std::string& id,
- const std::string& name,
- AllowlistSource source) {
- bool result = registered_allowlists_.insert(id).second;
- DCHECK(result);
-
- // Using an empty client ID for allowlists installed from the command line
- // causes the installer to not persist the installation, so the allowlist will
- // be removed the next time the browser is started without the command line
- // flag.
- installer_->RegisterWhitelist(
- source == FROM_COMMAND_LINE ? std::string() : client_id_, id, name);
-}
-
-void SupervisedUserAllowlistService::GetLoadedAllowlists(
- std::vector<scoped_refptr<SupervisedUserSiteList>>* allowlists) {
- for (const auto& allowlist : loaded_allowlists_)
- allowlists->push_back(allowlist.second);
-}
-
-void SupervisedUserAllowlistService::NotifyAllowlistsChanged() {
- std::vector<scoped_refptr<SupervisedUserSiteList>> allowlists;
- GetLoadedAllowlists(&allowlists);
-
- for (const auto& callback : site_lists_changed_callbacks_)
- callback.Run(allowlists);
-}
-
-void SupervisedUserAllowlistService::OnAllowlistReady(
- const std::string& id,
- const base::string16& title,
- const base::FilePath& large_icon_path,
- const base::FilePath& allowlist_path) {
- // If we did not register the allowlist or it has been unregistered in the
- // mean time, ignore it.
- if (registered_allowlists_.count(id) == 0u)
- return;
-
- SupervisedUserSiteList::Load(
- id, title, large_icon_path, allowlist_path,
- base::Bind(&SupervisedUserAllowlistService::OnAllowlistLoaded,
- weak_ptr_factory_.GetWeakPtr(), id));
-}
-
-void SupervisedUserAllowlistService::OnAllowlistLoaded(
- const std::string& id,
- const scoped_refptr<SupervisedUserSiteList>& allowlist) {
- if (!allowlist) {
- LOG(WARNING) << "Couldn't load allowlist " << id;
- return;
- }
- // If the allowlist has been unregistered in the mean time, ignore it.
- if (registered_allowlists_.count(id) == 0u)
- return;
-
- loaded_allowlists_[id] = allowlist;
- NotifyAllowlistsChanged();
-}
diff --git a/chrome/browser/supervised_user/supervised_user_allowlist_service.h b/chrome/browser/supervised_user/supervised_user_allowlist_service.h
deleted file mode 100644
index 3be917c..0000000
--- a/chrome/browser/supervised_user/supervised_user_allowlist_service.h
+++ /dev/null
@@ -1,144 +0,0 @@
-// Copyright 2014 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_SUPERVISED_USER_SUPERVISED_USER_ALLOWLIST_SERVICE_H_
-#define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_ALLOWLIST_SERVICE_H_
-
-#include <map>
-#include <memory>
-#include <set>
-#include <string>
-#include <vector>
-
-#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
-#include "base/strings/string16.h"
-#include "chrome/browser/supervised_user/supervised_users.h"
-#include "components/sync/model/syncable_service.h"
-
-class PrefService;
-class SupervisedUserSiteList;
-
-namespace base {
-class DictionaryValue;
-class FilePath;
-} // namespace base
-
-namespace component_updater {
-class SupervisedUserWhitelistInstaller;
-}
-
-namespace user_prefs {
-class PrefRegistrySyncable;
-}
-
-namespace sync_pb {
-class ManagedUserWhitelistSpecifics;
-}
-
-class SupervisedUserAllowlistService : public syncer::SyncableService {
- public:
- typedef base::Callback<void(
- const std::vector<scoped_refptr<SupervisedUserSiteList>>&)>
- SiteListsChangedCallback;
-
- SupervisedUserAllowlistService(
- PrefService* prefs,
- component_updater::SupervisedUserWhitelistInstaller* installer,
- const std::string& client_id);
- ~SupervisedUserAllowlistService() override;
-
- static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
-
- void Init();
-
- // Adds a callback to be called when the list of loaded site lists changes.
- // The callback will also be called immediately, to get the current
- // site lists.
- void AddSiteListsChangedCallback(const SiteListsChangedCallback& callback);
-
- // Returns a map (from CRX ID to name) of allowlists to be installed,
- // specified on the command line.
- static std::map<std::string, std::string> GetAllowlistsFromCommandLine();
-
- // Loads an already existing allowlist on disk (i.e. without downloading it as
- // a component).
- void LoadAllowlistForTesting(const std::string& id,
- const base::string16& title,
- const base::FilePath& path);
-
- // Unloads a allowlist. Public for testing.
- void UnloadAllowlist(const std::string& id);
-
- // Creates Sync data for a allowlist with the given |id| and |name|.
- // Public for testing.
- static syncer::SyncData CreateAllowlistSyncData(const std::string& id,
- const std::string& name);
-
- // SyncableService implementation:
- void WaitUntilReadyToSync(base::OnceClosure done) override;
- base::Optional<syncer::ModelError> MergeDataAndStartSyncing(
- syncer::ModelType type,
- const syncer::SyncDataList& initial_sync_data,
- std::unique_ptr<syncer::SyncChangeProcessor> sync_processor,
- std::unique_ptr<syncer::SyncErrorFactory> error_handler) override;
- void StopSyncing(syncer::ModelType type) override;
- base::Optional<syncer::ModelError> ProcessSyncChanges(
- const base::Location& from_here,
- const syncer::SyncChangeList& change_list) override;
-
- syncer::SyncDataList GetAllSyncDataForTesting(syncer::ModelType type) const;
-
- private:
- // The following methods handle allowlist additions, updates and removals,
- // usually coming from Sync.
- void AddNewAllowlist(base::DictionaryValue* pref_dict,
- const sync_pb::ManagedUserWhitelistSpecifics& allowlist);
- void SetAllowlistProperties(
- base::DictionaryValue* pref_dict,
- const sync_pb::ManagedUserWhitelistSpecifics& allowlist);
- void RemoveAllowlist(base::DictionaryValue* pref_dict, const std::string& id);
-
- enum AllowlistSource {
- FROM_SYNC,
- FROM_COMMAND_LINE,
- };
-
- // Registers a new or existing allowlist.
- void RegisterAllowlist(const std::string& id,
- const std::string& name,
- AllowlistSource source);
-
- void GetLoadedAllowlists(
- std::vector<scoped_refptr<SupervisedUserSiteList>>* allowlists);
-
- void NotifyAllowlistsChanged();
-
- void OnAllowlistReady(const std::string& id,
- const base::string16& title,
- const base::FilePath& large_icon_path,
- const base::FilePath& allowlist_path);
- void OnAllowlistLoaded(
- const std::string& id,
- const scoped_refptr<SupervisedUserSiteList>& allowlist);
-
- PrefService* prefs_;
- component_updater::SupervisedUserWhitelistInstaller* installer_;
-
- std::string client_id_;
- std::vector<SiteListsChangedCallback> site_lists_changed_callbacks_;
-
- // The set of registered allowlists. A allowlist might be registered but not
- // loaded yet, in which case it will not be in |loaded_allowlists_| yet.
- // On the other hand, every loaded allowlist has to be registered.
- std::set<std::string> registered_allowlists_;
- std::map<std::string, scoped_refptr<SupervisedUserSiteList>>
- loaded_allowlists_;
-
- base::WeakPtrFactory<SupervisedUserAllowlistService> weak_ptr_factory_{this};
-
- DISALLOW_COPY_AND_ASSIGN(SupervisedUserAllowlistService);
-};
-
-#endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_ALLOWLIST_SERVICE_H_
diff --git a/chrome/browser/supervised_user/supervised_user_allowlist_service_unittest.cc b/chrome/browser/supervised_user/supervised_user_allowlist_service_unittest.cc
deleted file mode 100644
index 0201aea..0000000
--- a/chrome/browser/supervised_user/supervised_user_allowlist_service_unittest.cc
+++ /dev/null
@@ -1,273 +0,0 @@
-// Copyright 2014 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/supervised_user/supervised_user_allowlist_service.h"
-
-#include <map>
-#include <memory>
-#include <set>
-#include <string>
-#include <utility>
-
-#include "base/bind.h"
-#include "base/callback.h"
-#include "base/path_service.h"
-#include "base/run_loop.h"
-#include "base/strings/string_util.h"
-#include "base/strings/utf_string_conversions.h"
-#include "build/build_config.h"
-#include "chrome/browser/component_updater/supervised_user_whitelist_installer.h"
-#include "chrome/browser/supervised_user/supervised_user_site_list.h"
-#include "chrome/common/chrome_paths.h"
-#include "chrome/common/pref_names.h"
-#include "chrome/test/base/testing_profile.h"
-#include "components/prefs/scoped_user_pref_update.h"
-#include "components/sync/model/sync_change.h"
-#include "components/sync/model/sync_change_processor.h"
-#include "components/sync/model/sync_error_factory.h"
-#include "components/sync/protocol/sync.pb.h"
-#include "content/public/test/browser_task_environment.h"
-#include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace {
-
-const char kClientId[] = "client-id";
-
-class MockSupervisedUserWhitelistInstaller
- : public component_updater::SupervisedUserWhitelistInstaller {
- public:
- MockSupervisedUserWhitelistInstaller() {}
- ~MockSupervisedUserWhitelistInstaller() override {}
-
- const std::set<std::string>& registered_allowlists() {
- return registered_allowlists_;
- }
-
- void NotifyAllowlistReady(const std::string& crx_id,
- const base::string16& title,
- const base::FilePath& large_icon_path,
- const base::FilePath& allowlist_path) {
- for (const auto& callback : ready_callbacks_)
- callback.Run(crx_id, title, large_icon_path, allowlist_path);
- }
-
- // SupervisedUserWhitelistInstaller implementation:
- void RegisterComponents() override {}
-
- void Subscribe(WhitelistReadyCallback callback) override {
- ready_callbacks_.push_back(callback);
- }
-
- void RegisterWhitelist(const std::string& client_id,
- const std::string& crx_id,
- const std::string& name) override {
- EXPECT_EQ(kClientId, client_id);
- EXPECT_FALSE(AllowlistIsRegistered(crx_id)) << crx_id;
- registered_allowlists_.insert(crx_id);
- }
-
- void UnregisterWhitelist(const std::string& client_id,
- const std::string& crx_id) override {
- EXPECT_EQ(kClientId, client_id);
- EXPECT_TRUE(AllowlistIsRegistered(crx_id)) << crx_id;
- registered_allowlists_.erase(crx_id);
- }
-
- private:
- bool AllowlistIsRegistered(const std::string& crx_id) {
- return registered_allowlists_.count(crx_id) > 0;
- }
-
- std::set<std::string> registered_allowlists_;
- std::vector<WhitelistReadyCallback> ready_callbacks_;
-};
-
-} // namespace
-
-class SupervisedUserAllowlistServiceTest : public testing::Test {
- public:
- SupervisedUserAllowlistServiceTest()
- : installer_(new MockSupervisedUserWhitelistInstaller),
- service_(new SupervisedUserAllowlistService(profile_.GetPrefs(),
- installer_.get(),
- kClientId)) {
- service_->AddSiteListsChangedCallback(
- base::Bind(&SupervisedUserAllowlistServiceTest::OnSiteListsChanged,
- base::Unretained(this)));
- }
-
- protected:
- void PrepareInitialStateAndPreferences() {
- // Create two allowlists.
- DictionaryPrefUpdate update(profile_.GetPrefs(),
- prefs::kSupervisedUserAllowlists);
- base::DictionaryValue* dict = update.Get();
-
- std::unique_ptr<base::DictionaryValue> allowlist_dict(
- new base::DictionaryValue);
- allowlist_dict->SetString("name", "Allowlist A");
- dict->Set("aaaa", std::move(allowlist_dict));
-
- allowlist_dict.reset(new base::DictionaryValue);
- allowlist_dict->SetString("name", "Allowlist B");
- dict->Set("bbbb", std::move(allowlist_dict));
-
- installer_->RegisterWhitelist(kClientId, "aaaa", "Allowlist A");
- installer_->RegisterWhitelist(kClientId, "bbbb", "Allowlist B");
- }
-
- void CheckFinalStateAndPreferences() {
- EXPECT_EQ(2u, installer_->registered_allowlists().size());
- EXPECT_EQ(1u, installer_->registered_allowlists().count("bbbb"));
- EXPECT_EQ(1u, installer_->registered_allowlists().count("cccc"));
-
- const base::DictionaryValue* dict =
- profile_.GetPrefs()->GetDictionary(prefs::kSupervisedUserAllowlists);
- EXPECT_EQ(2u, dict->size());
- const base::DictionaryValue* allowlist_dict = nullptr;
- ASSERT_TRUE(dict->GetDictionary("bbbb", &allowlist_dict));
- std::string name;
- ASSERT_TRUE(allowlist_dict->GetString("name", &name));
- EXPECT_EQ("Allowlist B New", name);
- ASSERT_TRUE(dict->GetDictionary("cccc", &allowlist_dict));
- ASSERT_TRUE(allowlist_dict->GetString("name", &name));
- EXPECT_EQ("Allowlist C", name);
- }
-
- const sync_pb::ManagedUserWhitelistSpecifics* FindAllowlist(
- const syncer::SyncDataList& data_list,
- const std::string& id) {
- for (const syncer::SyncData& data : data_list) {
- const sync_pb::ManagedUserWhitelistSpecifics& allowlist =
- data.GetSpecifics().managed_user_whitelist();
- if (allowlist.id() == id)
- return &allowlist;
- }
- return nullptr;
- }
-
- void OnSiteListsChanged(
- const std::vector<scoped_refptr<SupervisedUserSiteList>>& site_lists) {
- site_lists_ = site_lists;
- if (!site_lists_changed_callback_.is_null())
- site_lists_changed_callback_.Run();
- }
-
- content::BrowserTaskEnvironment task_environment_;
- TestingProfile profile_;
- data_decoder::test::InProcessDataDecoder in_process_data_decoder_;
-
- std::unique_ptr<MockSupervisedUserWhitelistInstaller> installer_;
- std::unique_ptr<SupervisedUserAllowlistService> service_;
-
- std::vector<scoped_refptr<SupervisedUserSiteList>> site_lists_;
- base::Closure site_lists_changed_callback_;
-};
-
-TEST_F(SupervisedUserAllowlistServiceTest, MergeEmpty) {
- service_->Init();
-
- ASSERT_TRUE(service_
- ->GetAllSyncDataForTesting(
- syncer::DEPRECATED_SUPERVISED_USER_ALLOWLISTS)
- .empty());
- base::Optional<syncer::ModelError> error = service_->MergeDataAndStartSyncing(
- syncer::DEPRECATED_SUPERVISED_USER_ALLOWLISTS, syncer::SyncDataList(),
- std::unique_ptr<syncer::SyncChangeProcessor>(),
- std::unique_ptr<syncer::SyncErrorFactory>());
- EXPECT_TRUE(service_
- ->GetAllSyncDataForTesting(
- syncer::DEPRECATED_SUPERVISED_USER_ALLOWLISTS)
- .empty());
- EXPECT_FALSE(error.has_value());
-
- EXPECT_EQ(0u, installer_->registered_allowlists().size());
-}
-
-TEST_F(SupervisedUserAllowlistServiceTest, MergeExisting) {
- PrepareInitialStateAndPreferences();
-
- // Initialize the service. The allowlists should not be ready yet.
- service_->Init();
- EXPECT_EQ(0u, site_lists_.size());
-
- // Notify that allowlist A is ready.
- base::RunLoop run_loop;
- site_lists_changed_callback_ = run_loop.QuitClosure();
- base::FilePath test_data_dir;
- ASSERT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));
- base::FilePath allowlist_path =
- test_data_dir.AppendASCII("allowlists/content_pack/site_list.json");
- installer_->NotifyAllowlistReady("aaaa", base::ASCIIToUTF16("Title"),
- base::FilePath(), allowlist_path);
- run_loop.Run();
-
- ASSERT_EQ(1u, site_lists_.size());
- EXPECT_EQ(base::ASCIIToUTF16("Title"), site_lists_[0]->title());
- EXPECT_EQ(4u, site_lists_[0]->patterns().size());
-
- // Do the initial merge. One item should be added (allowlist C), one should be
- // modified (allowlist B), and one item should be removed (allowlist A).
- syncer::SyncDataList initial_data;
- initial_data.push_back(
- SupervisedUserAllowlistService::CreateAllowlistSyncData(
- "bbbb", "Allowlist B New"));
- initial_data.push_back(
- SupervisedUserAllowlistService::CreateAllowlistSyncData("cccc",
- "Allowlist C"));
- ASSERT_EQ(2u, service_
- ->GetAllSyncDataForTesting(
- syncer::DEPRECATED_SUPERVISED_USER_ALLOWLISTS)
- .size());
- base::Optional<syncer::ModelError> error = service_->MergeDataAndStartSyncing(
- syncer::DEPRECATED_SUPERVISED_USER_ALLOWLISTS, initial_data,
- std::unique_ptr<syncer::SyncChangeProcessor>(),
- std::unique_ptr<syncer::SyncErrorFactory>());
- EXPECT_EQ(2u, service_
- ->GetAllSyncDataForTesting(
- syncer::DEPRECATED_SUPERVISED_USER_ALLOWLISTS)
- .size());
- EXPECT_FALSE(error.has_value());
-
- // Allowlist A (which was previously ready) should be removed now, and
- // allowlist B was never ready.
- EXPECT_EQ(0u, site_lists_.size());
-
- CheckFinalStateAndPreferences();
-}
-
-TEST_F(SupervisedUserAllowlistServiceTest, ApplyChanges) {
- PrepareInitialStateAndPreferences();
-
- service_->Init();
-
- // Process some changes.
- syncer::SyncChangeList changes;
- changes.push_back(syncer::SyncChange(
- FROM_HERE, syncer::SyncChange::ACTION_ADD,
- SupervisedUserAllowlistService::CreateAllowlistSyncData("cccc",
- "Allowlist C")));
- changes.push_back(syncer::SyncChange(
- FROM_HERE, syncer::SyncChange::ACTION_UPDATE,
- SupervisedUserAllowlistService::CreateAllowlistSyncData(
- "bbbb", "Allowlist B New")));
- changes.push_back(syncer::SyncChange(
- FROM_HERE, syncer::SyncChange::ACTION_DELETE,
- SupervisedUserAllowlistService::CreateAllowlistSyncData("aaaa",
- "Ignored")));
- base::Optional<syncer::ModelError> error =
- service_->ProcessSyncChanges(FROM_HERE, changes);
- EXPECT_FALSE(error.has_value());
-
- EXPECT_EQ(0u, site_lists_.size());
-
- // If allowlist A now becomes ready, it should be ignored.
- installer_->NotifyAllowlistReady(
- "aaaa", base::ASCIIToUTF16("Title"), base::FilePath(),
- base::FilePath(FILE_PATH_LITERAL("/path/to/aaaa")));
- EXPECT_EQ(0u, site_lists_.size());
-
- CheckFinalStateAndPreferences();
-}
diff --git a/chrome/browser/supervised_user/supervised_user_service.cc b/chrome/browser/supervised_user/supervised_user_service.cc
index 6c42234..cfe0f03 100644
--- a/chrome/browser/supervised_user/supervised_user_service.cc
+++ b/chrome/browser/supervised_user/supervised_user_service.cc
@@ -25,11 +25,9 @@
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/component_updater/supervised_user_whitelist_installer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_key.h"
#include "chrome/browser/supervised_user/permission_request_creator.h"
-#include "chrome/browser/supervised_user/supervised_user_allowlist_service.h"
#include "chrome/browser/supervised_user/supervised_user_constants.h"
#include "chrome/browser/supervised_user/supervised_user_features.h"
#include "chrome/browser/supervised_user/supervised_user_filtering_switches.h"
@@ -163,10 +161,6 @@
base::Bind(&SupervisedUserService::OnSupervisedUserIdChanged,
base::Unretained(this)));
- allowlist_service_->AddSiteListsChangedCallback(
- base::Bind(&SupervisedUserService::OnSiteListsChanged,
- weak_ptr_factory_.GetWeakPtr()));
-
SetActive(IsChild());
}
@@ -186,9 +180,6 @@
return &url_filter_;
}
-SupervisedUserAllowlistService* SupervisedUserService::GetAllowlistService() {
- return allowlist_service_.get();
-}
bool SupervisedUserService::AccessRequestsEnabled() {
return FindEnabledPermissionRequestCreator(0) < permissions_creators_.size();
@@ -327,12 +318,6 @@
#if BUILDFLAG(ENABLE_EXTENSIONS)
registry_observer_.Add(extensions::ExtensionRegistry::Get(profile));
#endif
-
- std::string client_id = component_updater::SupervisedUserWhitelistInstaller::
- ClientIdForProfilePath(profile_->GetPath());
- allowlist_service_ = std::make_unique<SupervisedUserAllowlistService>(
- profile_->GetPrefs(),
- g_browser_process->supervised_user_whitelist_installer(), client_id);
}
void SupervisedUserService::SetPrimaryPermissionCreatorForTest(
@@ -487,7 +472,6 @@
// Initialize the filter.
OnDefaultFilteringBehaviorChanged();
OnSafeSitesSettingChanged();
- allowlist_service_->Init();
UpdateManualHosts();
UpdateManualURLs();
@@ -636,12 +620,6 @@
}
}
-void SupervisedUserService::OnSiteListsChanged(
- const std::vector<scoped_refptr<SupervisedUserSiteList> >& site_lists) {
- allowlists_ = site_lists;
- url_filter_.LoadAllowlists(site_lists);
-}
-
void SupervisedUserService::LoadDenylist(const base::FilePath& path,
const GURL& url) {
DCHECK(denylist_state_ == DenylistLoadState::NOT_LOADED);
diff --git a/chrome/browser/supervised_user/supervised_user_service.h b/chrome/browser/supervised_user/supervised_user_service.h
index 38672ab..69316ad 100644
--- a/chrome/browser/supervised_user/supervised_user_service.h
+++ b/chrome/browser/supervised_user/supervised_user_service.h
@@ -45,9 +45,7 @@
class Profile;
class SupervisedUserServiceObserver;
class SupervisedUserSettingsService;
-class SupervisedUserSiteList;
class SupervisedUserURLFilter;
-class SupervisedUserAllowlistService;
namespace base {
class FilePath;
@@ -69,8 +67,8 @@
#endif // !defined(OS_ANDROID)
// This class handles all the information related to a given supervised profile
-// (e.g. the installed content packs, the default URL filtering behavior, or
-// manual allowlist/denylist overrides).
+// (e.g. the default URL filtering behavior, or manual allowlist/denylist
+// overrides).
class SupervisedUserService : public KeyedService,
#if BUILDFLAG(ENABLE_EXTENSIONS)
public extensions::ExtensionRegistryObserver,
@@ -118,13 +116,6 @@
// on the UI thread.
SupervisedUserURLFilter* GetURLFilter();
- // Returns the allowlist service.
- SupervisedUserAllowlistService* GetAllowlistService();
-
- const std::vector<scoped_refptr<SupervisedUserSiteList>>& allowlists() const {
- return allowlists_;
- }
-
// Whether the user can request to get access to blocked URLs or to new
// extensions.
bool AccessRequestsEnabled();
@@ -343,9 +334,6 @@
void UpdateAsyncUrlChecker();
- void OnSiteListsChanged(
- const std::vector<scoped_refptr<SupervisedUserSiteList>>& site_lists);
-
// Asynchronously loads a denylist from a binary file at |path| and applies
// it to the URL filters. If no file exists at |path| yet, downloads a file
// from |url| and stores it at |path| first.
@@ -406,10 +394,6 @@
SupervisedUserDenylist denylist_;
std::unique_ptr<FileDownloader> denylist_downloader_;
- std::unique_ptr<SupervisedUserAllowlistService> allowlist_service_;
-
- std::vector<scoped_refptr<SupervisedUserSiteList>> allowlists_;
-
// Used to create permission requests.
std::vector<std::unique_ptr<PermissionRequestCreator>> permissions_creators_;
diff --git a/chrome/browser/supervised_user/supervised_user_service_unittest.cc b/chrome/browser/supervised_user/supervised_user_service_unittest.cc
index 74ae409..739091c 100644
--- a/chrome/browser/supervised_user/supervised_user_service_unittest.cc
+++ b/chrome/browser/supervised_user/supervised_user_service_unittest.cc
@@ -23,14 +23,10 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_test_environment_profile_adaptor.h"
#include "chrome/browser/supervised_user/permission_request_creator.h"
-#include "chrome/browser/supervised_user/supervised_user_allowlist_service.h"
#include "chrome/browser/supervised_user/supervised_user_features.h"
#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
-#include "chrome/common/chrome_paths.h"
-#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
#include "components/prefs/pref_service.h"
-#include "components/prefs/scoped_user_pref_update.h"
#include "components/version_info/version_info.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_utils.h"
@@ -116,37 +112,6 @@
DISALLOW_COPY_AND_ASSIGN(SupervisedUserURLFilterObserver);
};
-class SiteListObserver : public AsyncTestHelper {
- public:
- SiteListObserver() {}
- ~SiteListObserver() {}
-
- void Init(SupervisedUserAllowlistService* service) {
- service->AddSiteListsChangedCallback(base::Bind(
- &SiteListObserver::OnSiteListsChanged, base::Unretained(this)));
-
- // The initial call to AddSiteListsChangedCallback will call
- // OnSiteListsChanged(), so we balance it out by calling Wait().
- Wait();
- }
-
- const std::vector<scoped_refptr<SupervisedUserSiteList>>& site_lists() {
- return site_lists_;
- }
-
- private:
- void OnSiteListsChanged(
- const std::vector<scoped_refptr<SupervisedUserSiteList>>& site_lists) {
- site_lists_ = site_lists;
-
- QuitRunLoop();
- }
-
- std::vector<scoped_refptr<SupervisedUserSiteList>> site_lists_;
-
- DISALLOW_COPY_AND_ASSIGN(SiteListObserver);
-};
-
class AsyncResultHolder {
public:
AsyncResultHolder() : result_(false) {}
@@ -351,15 +316,11 @@
SupervisedUserService* service =
SupervisedUserServiceFactory::GetForProfile(profile_.get());
service->Init();
- site_list_observer_.Init(service->GetAllowlistService());
SupervisedUserURLFilter* url_filter = service->GetURLFilter();
url_filter->SetBlockingTaskRunnerForTesting(
base::ThreadTaskRunnerHandle::Get());
url_filter_observer_.Init(url_filter);
-
- // Wait for the initial update to finish.
- url_filter_observer_.Wait();
}
void TearDown() override {
@@ -395,7 +356,6 @@
bool is_supervised_;
extensions::ScopedCurrentChannel channel_;
- SiteListObserver site_list_observer_;
SupervisedUserURLFilterObserver url_filter_observer_;
base::test::ScopedFeatureList scoped_feature_list_;
};
@@ -520,106 +480,4 @@
EXPECT_FALSE(supervised_user_service->GetDebugPolicyProviderName().empty());
#endif
}
-
-TEST_F(SupervisedUserServiceExtensionTest, NoContentPacks) {
- InitSupervisedUserInitiatedExtensionInstallFeature(true);
-
- SupervisedUserService* supervised_user_service =
- SupervisedUserServiceFactory::GetForProfile(profile_.get());
- SupervisedUserURLFilter* url_filter = supervised_user_service->GetURLFilter();
-
- // ASSERT_EQ instead of ASSERT_TRUE([...].empty()) so that the error
- // message contains the size in case of failure.
- ASSERT_EQ(0u, site_list_observer_.site_lists().size());
-
- GURL url("http://youtube.com");
- EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
- url_filter->GetFilteringBehaviorForURL(url));
-}
-
-TEST_F(SupervisedUserServiceExtensionTest, InstallContentPacks) {
- InitSupervisedUserInitiatedExtensionInstallFeature(true);
-
- SupervisedUserService* supervised_user_service =
- SupervisedUserServiceFactory::GetForProfile(profile_.get());
- SupervisedUserURLFilter* url_filter = supervised_user_service->GetURLFilter();
-
- const std::string id1 = "ID 1";
- const base::string16 title1 = base::ASCIIToUTF16("Title 1");
- const std::string id2 = "ID 2";
- const base::string16 title2 = base::ASCIIToUTF16("Title 2");
-
- GURL youtube_url("http://www.youtube.com");
- GURL moose_url("http://moose.org");
- EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
- url_filter->GetFilteringBehaviorForURL(youtube_url));
-
- profile_->GetPrefs()->SetInteger(
- prefs::kDefaultSupervisedUserFilteringBehavior,
- SupervisedUserURLFilter::BLOCK);
- EXPECT_EQ(SupervisedUserURLFilter::BLOCK,
- url_filter->GetFilteringBehaviorForURL(youtube_url));
-
- profile_->GetPrefs()->SetInteger(
- prefs::kDefaultSupervisedUserFilteringBehavior,
- SupervisedUserURLFilter::WARN);
- EXPECT_EQ(SupervisedUserURLFilter::WARN,
- url_filter->GetFilteringBehaviorForURL(youtube_url));
-
- // Load a allowlist.
- base::FilePath test_data_dir;
- ASSERT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));
- SupervisedUserAllowlistService* allowlist_service =
- supervised_user_service->GetAllowlistService();
- base::FilePath allowlist_path =
- test_data_dir.AppendASCII("allowlists/content_pack/site_list.json");
- allowlist_service->LoadAllowlistForTesting(id1, title1, allowlist_path);
- site_list_observer_.Wait();
-
- ASSERT_EQ(1u, site_list_observer_.site_lists().size());
- EXPECT_EQ(id1, site_list_observer_.site_lists()[0]->id());
- EXPECT_EQ(title1, site_list_observer_.site_lists()[0]->title());
- EXPECT_EQ(youtube_url, site_list_observer_.site_lists()[0]->entry_point());
-
- url_filter_observer_.Wait();
- EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
- url_filter->GetFilteringBehaviorForURL(youtube_url));
- EXPECT_EQ(SupervisedUserURLFilter::WARN,
- url_filter->GetFilteringBehaviorForURL(moose_url));
-
- // Load a second allowlist.
- allowlist_path =
- test_data_dir.AppendASCII("allowlists/content_pack_2/site_list.json");
- allowlist_service->LoadAllowlistForTesting(id2, title2, allowlist_path);
- site_list_observer_.Wait();
-
- ASSERT_EQ(2u, site_list_observer_.site_lists().size());
- EXPECT_EQ(id1, site_list_observer_.site_lists()[0]->id());
- EXPECT_EQ(title1, site_list_observer_.site_lists()[0]->title());
- EXPECT_EQ(youtube_url, site_list_observer_.site_lists()[0]->entry_point());
- EXPECT_EQ(id2, site_list_observer_.site_lists()[1]->id());
- EXPECT_EQ(title2, site_list_observer_.site_lists()[1]->title());
- EXPECT_TRUE(site_list_observer_.site_lists()[1]->entry_point().is_empty());
-
- url_filter_observer_.Wait();
- EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
- url_filter->GetFilteringBehaviorForURL(youtube_url));
- EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
- url_filter->GetFilteringBehaviorForURL(moose_url));
-
- // Unload the first allowlist.
- allowlist_service->UnloadAllowlist(id1);
- site_list_observer_.Wait();
-
- ASSERT_EQ(1u, site_list_observer_.site_lists().size());
- EXPECT_EQ(id2, site_list_observer_.site_lists()[0]->id());
- EXPECT_EQ(title2, site_list_observer_.site_lists()[0]->title());
- EXPECT_TRUE(site_list_observer_.site_lists()[0]->entry_point().is_empty());
-
- url_filter_observer_.Wait();
- EXPECT_EQ(SupervisedUserURLFilter::WARN,
- url_filter->GetFilteringBehaviorForURL(youtube_url));
- EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
- url_filter->GetFilteringBehaviorForURL(moose_url));
-}
#endif // BUILDFLAG(ENABLE_EXTENSIONS)
diff --git a/chrome/browser/sync/chrome_sync_client.cc b/chrome/browser/sync/chrome_sync_client.cc
index ba24ff2..6e4cd8a 100644
--- a/chrome/browser/sync/chrome_sync_client.cc
+++ b/chrome/browser/sync/chrome_sync_client.cc
@@ -105,7 +105,6 @@
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
#include "chrome/browser/profiles/profile_key.h"
-#include "chrome/browser/supervised_user/supervised_user_allowlist_service.h"
#include "chrome/browser/supervised_user/supervised_user_service.h"
#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#include "chrome/browser/supervised_user/supervised_user_settings_service.h"
@@ -382,11 +381,6 @@
syncer::SUPERVISED_USER_SETTINGS, profile_, dump_stack,
model_type_store_factory,
GetSyncableServiceForType(syncer::SUPERVISED_USER_SETTINGS)));
- controllers.push_back(std::make_unique<SupervisedUserSyncModelTypeController>(
- syncer::DEPRECATED_SUPERVISED_USER_ALLOWLISTS, profile_, dump_stack,
- model_type_store_factory,
- GetSyncableServiceForType(
- syncer::DEPRECATED_SUPERVISED_USER_ALLOWLISTS)));
#endif // BUILDFLAG(ENABLE_SUPERVISED_USERS)
#if BUILDFLAG(ENABLE_EXTENSIONS)
@@ -611,10 +605,6 @@
return SupervisedUserSettingsServiceFactory::GetForKey(
profile_->GetProfileKey())
->AsWeakPtr();
- case syncer::DEPRECATED_SUPERVISED_USER_ALLOWLISTS:
- return SupervisedUserServiceFactory::GetForProfile(profile_)
- ->GetAllowlistService()
- ->AsWeakPtr();
#endif // BUILDFLAG(ENABLE_SUPERVISED_USERS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
case syncer::ARC_PACKAGE:
diff --git a/chrome/browser/sync/profile_sync_service_factory_unittest.cc b/chrome/browser/sync/profile_sync_service_factory_unittest.cc
index 3925844..9f0d624 100644
--- a/chrome/browser/sync/profile_sync_service_factory_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_factory_unittest.cc
@@ -92,7 +92,6 @@
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
datatypes.push_back(syncer::SUPERVISED_USER_SETTINGS);
- datatypes.push_back(syncer::DEPRECATED_SUPERVISED_USER_ALLOWLISTS);
#endif // BUILDFLAG(ENABLE_SUPERVISED_USERS)
#if BUILDFLAG(ENABLE_EXTENSIONS)