Commit edf34524 authored by Michael Giuffrida's avatar Michael Giuffrida Committed by Commit Bot

Remove unused policy blacklist code

The URLBlacklistManager used to take a callback for overriding the
blacklist. This was used for limited guest sessions in OOBE, but all
code paths that actually triggered this code have been removed, and
these limited guest sessions will no longer be supported.

Bug: 850213
Change-Id: I299ccace10529696ba2b581ed861e8c6a6cd769b
Reviewed-on: https://chromium-review.googlesource.com/1119073
Commit-Queue: Michael Giuffrida <michaelpg@chromium.org>
Reviewed-by: default avatarPavol Marko <pmarko@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575146}
parent ab546e70
...@@ -7,61 +7,9 @@ ...@@ -7,61 +7,9 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
#include "extensions/buildflags/buildflags.h"
#include "net/base/net_errors.h"
#include "url/gurl.h"
#if defined(OS_CHROMEOS)
#include "base/command_line.h"
#include "chromeos/chromeos_switches.h"
#endif
#if !defined(OS_CHROMEOS)
#include "google_apis/gaia/gaia_urls.h"
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "extensions/common/constants.h"
#endif
namespace policy { namespace policy {
bool OverrideBlacklistForURL(const GURL& url, bool* block, int* reason) {
#if defined(OS_CHROMEOS)
// Don't block if OOBE has completed.
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kOobeGuestSession)) {
return false;
}
#if BUILDFLAG(ENABLE_EXTENSIONS)
// Don't block internal pages and extensions.
if (url.SchemeIs("chrome") || url.SchemeIs(extensions::kExtensionScheme)) {
return false;
}
#endif
// Don't block Google's support web site.
if (url.SchemeIs(url::kHttpsScheme) && url.DomainIs("support.google.com")) {
return false;
}
// Block the rest.
*reason = net::ERR_BLOCKED_ENROLLMENT_CHECK_PENDING;
*block = true;
return true;
#else
static const char kServiceLoginAuth[] = "/ServiceLoginAuth";
*block = false;
// Additionally whitelist /ServiceLoginAuth.
if (url.GetOrigin() != GaiaUrls::GetInstance()->gaia_url().GetOrigin())
return false;
return url.path_piece() == kServiceLoginAuth;
#endif
}
void RegisterPrefs(PrefRegistrySimple* registry) { void RegisterPrefs(PrefRegistrySimple* registry) {
#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
registry->RegisterBooleanPref(prefs::kCloudPolicyOverridesMachinePolicy, registry->RegisterBooleanPref(prefs::kCloudPolicyOverridesMachinePolicy,
......
...@@ -5,14 +5,10 @@ ...@@ -5,14 +5,10 @@
#ifndef CHROME_BROWSER_POLICY_POLICY_HELPERS_H_ #ifndef CHROME_BROWSER_POLICY_POLICY_HELPERS_H_
#define CHROME_BROWSER_POLICY_POLICY_HELPERS_H_ #define CHROME_BROWSER_POLICY_POLICY_HELPERS_H_
class GURL;
class PrefRegistrySimple; class PrefRegistrySimple;
namespace policy { namespace policy {
// Returns true if |url| should never be blacklisted by policy.
bool OverrideBlacklistForURL(const GURL& url, bool* block, int* reason);
// Register policy related preferences in Local State. // Register policy related preferences in Local State.
void RegisterPrefs(PrefRegistrySimple* registry); void RegisterPrefs(PrefRegistrySimple* registry);
......
...@@ -86,7 +86,6 @@ ...@@ -86,7 +86,6 @@
#include "chrome/browser/web_data_service_factory.h" #include "chrome/browser/web_data_service_factory.h"
#include "chrome/common/buildflags.h" #include "chrome/common/buildflags.h"
#include "components/feature_engagement/buildflags.h" #include "components/feature_engagement/buildflags.h"
#include "components/policy/content/policy_blacklist_navigation_throttle.h"
#include "components/spellcheck/spellcheck_buildflags.h" #include "components/spellcheck/spellcheck_buildflags.h"
#include "extensions/buildflags/buildflags.h" #include "extensions/buildflags/buildflags.h"
#include "ppapi/buildflags/buildflags.h" #include "ppapi/buildflags/buildflags.h"
...@@ -346,8 +345,6 @@ void ChromeBrowserMainExtraPartsProfiles:: ...@@ -346,8 +345,6 @@ void ChromeBrowserMainExtraPartsProfiles::
prerender::PrerenderMessageFilter::EnsureShutdownNotifierFactoryBuilt(); prerender::PrerenderMessageFilter::EnsureShutdownNotifierFactoryBuilt();
ProfileSyncServiceFactory::GetInstance(); ProfileSyncServiceFactory::GetInstance();
ProtocolHandlerRegistryFactory::GetInstance(); ProtocolHandlerRegistryFactory::GetInstance();
PolicyBlacklistFactory::GetInstance()->SetBlacklistOverride(
base::BindRepeating(policy::OverrideBlacklistForURL));
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
resource_coordinator::LocalSiteCharacteristicsDataStoreFactory::GetInstance(); resource_coordinator::LocalSiteCharacteristicsDataStoreFactory::GetInstance();
#endif #endif
......
...@@ -43,16 +43,11 @@ PolicyBlacklistFactory::PolicyBlacklistFactory() ...@@ -43,16 +43,11 @@ PolicyBlacklistFactory::PolicyBlacklistFactory()
PolicyBlacklistFactory::~PolicyBlacklistFactory() {} PolicyBlacklistFactory::~PolicyBlacklistFactory() {}
void PolicyBlacklistFactory::SetBlacklistOverride(
policy::URLBlacklistManager::OverrideBlacklistCallback callback) {
override_blacklist_ = callback;
}
KeyedService* PolicyBlacklistFactory::BuildServiceInstanceFor( KeyedService* PolicyBlacklistFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const { content::BrowserContext* context) const {
PrefService* pref_service = user_prefs::UserPrefs::Get(context); PrefService* pref_service = user_prefs::UserPrefs::Get(context);
auto url_blacklist_manager = std::make_unique<policy::URLBlacklistManager>( auto url_blacklist_manager =
pref_service, override_blacklist_); std::make_unique<policy::URLBlacklistManager>(pref_service);
return new PolicyBlacklistService(std::move(url_blacklist_manager)); return new PolicyBlacklistService(std::move(url_blacklist_manager));
} }
......
...@@ -38,11 +38,6 @@ class PolicyBlacklistFactory : public BrowserContextKeyedServiceFactory { ...@@ -38,11 +38,6 @@ class PolicyBlacklistFactory : public BrowserContextKeyedServiceFactory {
static PolicyBlacklistService* GetForProfile( static PolicyBlacklistService* GetForProfile(
content::BrowserContext* context); content::BrowserContext* context);
// Sets the OverrideBlacklistCallback for the underlying URLBlacklistManager.
// Must be called before BuildServiceInstanceFor().
void SetBlacklistOverride(
policy::URLBlacklistManager::OverrideBlacklistCallback);
private: private:
PolicyBlacklistFactory(); PolicyBlacklistFactory();
~PolicyBlacklistFactory() override; ~PolicyBlacklistFactory() override;
...@@ -56,8 +51,6 @@ class PolicyBlacklistFactory : public BrowserContextKeyedServiceFactory { ...@@ -56,8 +51,6 @@ class PolicyBlacklistFactory : public BrowserContextKeyedServiceFactory {
content::BrowserContext* GetBrowserContextToUse( content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override; content::BrowserContext* context) const override;
policy::URLBlacklistManager::OverrideBlacklistCallback override_blacklist_;
DISALLOW_COPY_AND_ASSIGN(PolicyBlacklistFactory); DISALLOW_COPY_AND_ASSIGN(PolicyBlacklistFactory);
}; };
......
...@@ -428,11 +428,8 @@ bool URLBlacklist::FilterTakesPrecedence(const FilterComponents& lhs, ...@@ -428,11 +428,8 @@ bool URLBlacklist::FilterTakesPrecedence(const FilterComponents& lhs,
return false; return false;
} }
URLBlacklistManager::URLBlacklistManager( URLBlacklistManager::URLBlacklistManager(PrefService* pref_service)
PrefService* pref_service,
OverrideBlacklistCallback override_blacklist)
: pref_service_(pref_service), : pref_service_(pref_service),
override_blacklist_(override_blacklist),
blacklist_(new URLBlacklist), blacklist_(new URLBlacklist),
ui_weak_ptr_factory_(this) { ui_weak_ptr_factory_(this) {
// This class assumes that it is created on the same thread that // This class assumes that it is created on the same thread that
...@@ -512,18 +509,6 @@ URLBlacklist::URLBlacklistState URLBlacklistManager::GetURLBlacklistState( ...@@ -512,18 +509,6 @@ URLBlacklist::URLBlacklistState URLBlacklistManager::GetURLBlacklistState(
return blacklist_->GetURLBlacklistState(url); return blacklist_->GetURLBlacklistState(url);
} }
bool URLBlacklistManager::ShouldBlockRequestForFrame(const GURL& url,
int* reason) const {
DCHECK(ui_task_runner_->RunsTasksInCurrentSequence());
bool block = false;
if (override_blacklist_.Run(url, &block, reason))
return block;
*reason = net::ERR_BLOCKED_BY_ADMINISTRATOR;
return IsURLBlocked(url);
}
// static // static
void URLBlacklistManager::RegisterProfilePrefs( void URLBlacklistManager::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) { user_prefs::PrefRegistrySyncable* registry) {
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "base/callback_forward.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/containers/hash_tables.h" #include "base/containers/hash_tables.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -125,15 +124,8 @@ class POLICY_EXPORT URLBlacklist { ...@@ -125,15 +124,8 @@ class POLICY_EXPORT URLBlacklist {
// Tracks the blacklist policies for a given profile, and updates it on changes. // Tracks the blacklist policies for a given profile, and updates it on changes.
class POLICY_EXPORT URLBlacklistManager { class POLICY_EXPORT URLBlacklistManager {
public: public:
// Returns true if the blacklist should be overridden for |url| and sets
// |block| to true if it should be blocked and false otherwise.
// |reason| is set to the exact reason for blocking |url| iff |block| is true.
typedef base::Callback<bool(const GURL& url, bool* block, int* reason)>
OverrideBlacklistCallback;
// Must be constructed on the UI thread. // Must be constructed on the UI thread.
URLBlacklistManager(PrefService* pref_service, explicit URLBlacklistManager(PrefService* pref_service);
OverrideBlacklistCallback override_blacklist);
virtual ~URLBlacklistManager(); virtual ~URLBlacklistManager();
// Returns true if |url| is blocked by the current blacklist. // Returns true if |url| is blocked by the current blacklist.
...@@ -176,9 +168,6 @@ class POLICY_EXPORT URLBlacklistManager { ...@@ -176,9 +168,6 @@ class POLICY_EXPORT URLBlacklistManager {
// Used to post tasks to a background thread. // Used to post tasks to a background thread.
scoped_refptr<base::SequencedTaskRunner> background_task_runner_; scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
// Used to optionally skip blacklisting for some URLs.
OverrideBlacklistCallback override_blacklist_;
// Used to schedule tasks on the main loop to avoid rebuilding the blocklist // Used to schedule tasks on the main loop to avoid rebuilding the blocklist
// multiple times during a message loop process. This can happen if two // multiple times during a message loop process. This can happen if two
// preferences that change the blacklist are updated in one message loop // preferences that change the blacklist are updated in one message loop
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include "components/url_formatter/url_fixer.h" #include "components/url_formatter/url_fixer.h"
#include "google_apis/gaia/gaia_urls.h" #include "google_apis/gaia/gaia_urls.h"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
#include "net/base/net_errors.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -30,15 +29,10 @@ namespace policy { ...@@ -30,15 +29,10 @@ namespace policy {
namespace { namespace {
bool OverrideBlacklistForURL(const GURL& url, bool* block, int* reason) {
return false;
}
class TestingURLBlacklistManager : public URLBlacklistManager { class TestingURLBlacklistManager : public URLBlacklistManager {
public: public:
explicit TestingURLBlacklistManager(PrefService* pref_service) explicit TestingURLBlacklistManager(PrefService* pref_service)
: URLBlacklistManager(pref_service, : URLBlacklistManager(pref_service),
base::Bind(OverrideBlacklistForURL)),
update_called_(0), update_called_(0),
set_blacklist_called_(false) {} set_blacklist_called_(false) {}
...@@ -214,8 +208,7 @@ TEST_F(URLBlacklistManagerTest, LoadBlacklistOnCreate) { ...@@ -214,8 +208,7 @@ TEST_F(URLBlacklistManagerTest, LoadBlacklistOnCreate) {
auto list = std::make_unique<base::ListValue>(); auto list = std::make_unique<base::ListValue>();
list->AppendString("example.com"); list->AppendString("example.com");
pref_service_.SetManagedPref(policy_prefs::kUrlBlacklist, std::move(list)); pref_service_.SetManagedPref(policy_prefs::kUrlBlacklist, std::move(list));
auto manager = std::make_unique<URLBlacklistManager>( auto manager = std::make_unique<URLBlacklistManager>(&pref_service_);
&pref_service_, URLBlacklistManager::OverrideBlacklistCallback());
scoped_task_environment_.RunUntilIdle(); scoped_task_environment_.RunUntilIdle();
EXPECT_EQ(URLBlacklist::URL_IN_BLACKLIST, EXPECT_EQ(URLBlacklist::URL_IN_BLACKLIST,
manager->GetURLBlacklistState(GURL("http://example.com"))); manager->GetURLBlacklistState(GURL("http://example.com")));
...@@ -225,8 +218,7 @@ TEST_F(URLBlacklistManagerTest, LoadWhitelistOnCreate) { ...@@ -225,8 +218,7 @@ TEST_F(URLBlacklistManagerTest, LoadWhitelistOnCreate) {
auto list = std::make_unique<base::ListValue>(); auto list = std::make_unique<base::ListValue>();
list->AppendString("example.com"); list->AppendString("example.com");
pref_service_.SetManagedPref(policy_prefs::kUrlWhitelist, std::move(list)); pref_service_.SetManagedPref(policy_prefs::kUrlWhitelist, std::move(list));
auto manager = std::make_unique<URLBlacklistManager>( auto manager = std::make_unique<URLBlacklistManager>(&pref_service_);
&pref_service_, URLBlacklistManager::OverrideBlacklistCallback());
scoped_task_environment_.RunUntilIdle(); scoped_task_environment_.RunUntilIdle();
EXPECT_EQ(URLBlacklist::URL_IN_WHITELIST, EXPECT_EQ(URLBlacklist::URL_IN_WHITELIST,
manager->GetURLBlacklistState(GURL("http://example.com"))); manager->GetURLBlacklistState(GURL("http://example.com")));
...@@ -627,21 +619,6 @@ TEST_F(URLBlacklistManagerTest, BlockAllWithExceptions) { ...@@ -627,21 +619,6 @@ TEST_F(URLBlacklistManagerTest, BlockAllWithExceptions) {
EXPECT_FALSE(blacklist.IsURLBlocked(GURL("https://very.safe/path"))); EXPECT_FALSE(blacklist.IsURLBlocked(GURL("https://very.safe/path")));
} }
TEST_F(URLBlacklistManagerTest, DontBlockResources) {
std::unique_ptr<URLBlacklist>
blacklist(new URLBlacklist);
std::unique_ptr<base::ListValue> blocked(new base::ListValue);
blocked->AppendString("google.com");
blacklist->Block(blocked.get());
blacklist_manager_->SetBlacklist(std::move(blacklist));
EXPECT_TRUE(blacklist_manager_->IsURLBlocked(GURL("http://google.com")));
int reason = net::ERR_UNEXPECTED;
EXPECT_TRUE(blacklist_manager_->ShouldBlockRequestForFrame(
GURL("http://google.com"), &reason));
EXPECT_EQ(net::ERR_BLOCKED_BY_ADMINISTRATOR, reason);
}
TEST_F(URLBlacklistManagerTest, DefaultBlacklistExceptions) { TEST_F(URLBlacklistManagerTest, DefaultBlacklistExceptions) {
URLBlacklist blacklist; URLBlacklist blacklist;
std::unique_ptr<base::ListValue> blocked(new base::ListValue); std::unique_ptr<base::ListValue> blocked(new base::ListValue);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment