summaryrefslogtreecommitdiffstats
path: root/chrome/browser/privacy_blacklist
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-30 16:11:27 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-30 16:11:27 +0000
commita307e31e82d2b9006802d4381dc5f3da2b993a8d (patch)
treee46d5b0b6ea59aa1fb7d47f917bc837b37dd88b8 /chrome/browser/privacy_blacklist
parent48a74f65c7775737ccee06a34eb5f73a5172172f (diff)
downloadchromium_src-a307e31e82d2b9006802d4381dc5f3da2b993a8d.zip
chromium_src-a307e31e82d2b9006802d4381dc5f3da2b993a8d.tar.gz
chromium_src-a307e31e82d2b9006802d4381dc5f3da2b993a8d.tar.bz2
Integrate BlacklistManager with Profile.
Now each Profile has a BlacklistManager that maintains a compiled Blacklist for that Profile. The system does not yet pause user-initiated web requests until the blacklist system is ready. However, the code is not supposed to be ready, and is hidden behind a --enable-privacy-blacklists command-line flag. TEST=Covered by browser_test. BUG=21541 Review URL: http://codereview.chromium.org/371063 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33290 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/privacy_blacklist')
-rw-r--r--chrome/browser/privacy_blacklist/blacklist_manager.cc120
-rw-r--r--chrome/browser/privacy_blacklist/blacklist_manager.h36
-rw-r--r--chrome/browser/privacy_blacklist/blacklist_manager_browsertest.cc102
-rw-r--r--chrome/browser/privacy_blacklist/blacklist_manager_unittest.cc52
-rw-r--r--chrome/browser/privacy_blacklist/blacklist_observer.h16
-rw-r--r--chrome/browser/privacy_blacklist/blacklist_ui.cc (renamed from chrome/browser/privacy_blacklist/blacklist_observer.cc)47
-rw-r--r--chrome/browser/privacy_blacklist/blacklist_ui.h18
7 files changed, 236 insertions, 155 deletions
diff --git a/chrome/browser/privacy_blacklist/blacklist_manager.cc b/chrome/browser/privacy_blacklist/blacklist_manager.cc
index 2a9f4c7..ca8dc0b 100644
--- a/chrome/browser/privacy_blacklist/blacklist_manager.cc
+++ b/chrome/browser/privacy_blacklist/blacklist_manager.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/privacy_blacklist/blacklist_io.h"
#include "chrome/browser/profile.h"
#include "chrome/common/chrome_constants.h"
+#include "chrome/common/extensions/extension.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/notification_source.h"
#include "chrome/common/notification_type.h"
@@ -19,27 +20,35 @@
BlacklistPathProvider::~BlacklistPathProvider() {
}
-BlacklistManager::BlacklistManager()
+BlacklistManager::BlacklistManager(Profile* profile,
+ BlacklistPathProvider* path_provider)
: first_read_finished_(false),
- profile_(NULL),
- path_provider_(NULL) {
+ profile_(profile),
+ compiled_blacklist_path_(
+ profile->GetPath().Append(chrome::kPrivacyBlacklistFileName)),
+ path_provider_(path_provider) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
-}
-
-void BlacklistManager::Initialize(Profile* profile,
- BlacklistPathProvider* path_provider) {
- profile_ = profile;
- compiled_blacklist_path_ =
- profile->GetPath().Append(chrome::kPrivacyBlacklistFileName);
- path_provider_ = path_provider;
+ DCHECK(path_provider_);
registrar_.Add(this,
+ NotificationType::EXTENSIONS_READY,
+ Source<Profile>(profile));
+ registrar_.Add(this,
NotificationType::EXTENSION_LOADED,
Source<Profile>(profile));
registrar_.Add(this,
NotificationType::EXTENSION_UNLOADED,
Source<Profile>(profile));
- ReadBlacklist();
+}
+
+void BlacklistManager::Initialize() {
+ if (path_provider_->AreBlacklistPathsReady())
+ ReadBlacklist();
+}
+
+const Blacklist* BlacklistManager::GetCompiledBlacklist() const {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ return compiled_blacklist_.get();
}
void BlacklistManager::Observe(NotificationType type,
@@ -48,8 +57,23 @@ void BlacklistManager::Observe(NotificationType type,
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
switch (type.value) {
+ case NotificationType::EXTENSIONS_READY:
+ ReadBlacklist();
+ break;
case NotificationType::EXTENSION_LOADED:
case NotificationType::EXTENSION_UNLOADED:
+ // Don't do anything if the path provider isn't ready. We're going to get
+ // the paths when it becomes ready.
+ // This makes an assumption that it isn't possible to install an extension
+ // before ExtensionsService becomes ready.
+ if (!path_provider_->AreBlacklistPathsReady())
+ break;
+
+ // We don't need to recompile the on-disk blacklist when the extension
+ // doesn't have any blacklist.
+ if (Details<Extension>(details).ptr()->privacy_blacklists().empty())
+ break;
+
CompileBlacklist();
break;
default:
@@ -58,8 +82,12 @@ void BlacklistManager::Observe(NotificationType type,
}
}
+BlacklistManager::~BlacklistManager() {
+}
+
void BlacklistManager::CompileBlacklist() {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+ DCHECK(path_provider_->AreBlacklistPathsReady());
ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE,
NewRunnableMethod(this, &BlacklistManager::DoCompileBlacklist,
@@ -71,10 +99,8 @@ void BlacklistManager::DoCompileBlacklist(
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
bool success = true;
-
Blacklist blacklist;
std::string error_string;
-
for (std::vector<FilePath>::const_iterator i = source_blacklists.begin();
i != source_blacklists.end(); ++i) {
if (!BlacklistIO::ReadText(&blacklist, *i, &error_string)) {
@@ -109,6 +135,7 @@ void BlacklistManager::OnBlacklistCompilationFinished(bool success) {
void BlacklistManager::ReadBlacklist() {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+ DCHECK(path_provider_->AreBlacklistPathsReady());
ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE,
NewRunnableMethod(this, &BlacklistManager::DoReadBlacklist,
@@ -120,54 +147,53 @@ void BlacklistManager::DoReadBlacklist(
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
scoped_ptr<Blacklist> blacklist(new Blacklist);
- if (!BlacklistIO::ReadBinary(blacklist.get(), compiled_blacklist_path_)) {
- ReportBlacklistReadResult(NULL);
- return;
- }
-
- std::string error_string;
- std::vector<FilePath>::const_iterator i;
- for (i = transient_blacklists.begin();
- i != transient_blacklists.end(); ++i) {
- if (!BlacklistIO::ReadText(blacklist.get(), *i, &error_string)) {
- ReportBlacklistReadResult(NULL);
- return;
+ if (BlacklistIO::ReadBinary(blacklist.get(), compiled_blacklist_path_)) {
+ std::string error_string;
+ std::vector<FilePath>::const_iterator i;
+ for (i = transient_blacklists.begin();
+ i != transient_blacklists.end(); ++i) {
+ if (!BlacklistIO::ReadText(blacklist.get(), *i, &error_string)) {
+ blacklist.reset();
+ break;
+ }
}
+ } else {
+ blacklist.reset();
}
-
- ReportBlacklistReadResult(blacklist.release());
+ ChromeThread::PostTask(ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(this,
+ &BlacklistManager::UpdatePublishedCompiledBlacklist,
+ blacklist.release()));
}
-void BlacklistManager::ReportBlacklistReadResult(Blacklist* blacklist) {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
+void BlacklistManager::UpdatePublishedCompiledBlacklist(Blacklist* blacklist) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ if (blacklist)
+ compiled_blacklist_.reset(blacklist);
ChromeThread::PostTask(ChromeThread::UI, FROM_HERE,
NewRunnableMethod(this, &BlacklistManager::OnBlacklistReadFinished,
- blacklist));
+ blacklist != NULL));
}
-void BlacklistManager::OnBlacklistReadFinished(Blacklist* blacklist) {
+void BlacklistManager::OnBlacklistReadFinished(bool success) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
- if (!blacklist) {
+ if (success) {
+ NotificationService::current()->Notify(
+ NotificationType::BLACKLIST_MANAGER_BLACKLIST_READ_FINISHED,
+ Source<Profile>(profile_),
+ NotificationService::NoDetails());
+ } else {
+ string16 error_message(ASCIIToUTF16("Blacklist read failed."));
+ NotificationService::current()->Notify(
+ NotificationType::BLACKLIST_MANAGER_ERROR,
+ Source<Profile>(profile_),
+ Details<string16>(&error_message));
if (!first_read_finished_) {
// If we're loading for the first time, the compiled blacklist could
// just not exist. Try compiling it once.
- first_read_finished_ = true;
CompileBlacklist();
- } else {
- string16 error_message(ASCIIToUTF16("Blacklist read failed."));
- NotificationService::current()->Notify(
- NotificationType::BLACKLIST_MANAGER_ERROR,
- Source<Profile>(profile_),
- Details<string16>(&error_message));
}
- return;
}
first_read_finished_ = true;
- compiled_blacklist_.reset(blacklist);
-
- NotificationService::current()->Notify(
- NotificationType::BLACKLIST_MANAGER_BLACKLIST_READ_FINISHED,
- Source<Profile>(profile_),
- Details<Blacklist>(blacklist));
}
diff --git a/chrome/browser/privacy_blacklist/blacklist_manager.h b/chrome/browser/privacy_blacklist/blacklist_manager.h
index ad401f7..5d6e97b 100644
--- a/chrome/browser/privacy_blacklist/blacklist_manager.h
+++ b/chrome/browser/privacy_blacklist/blacklist_manager.h
@@ -19,11 +19,20 @@ class Profile;
class BlacklistPathProvider {
public:
- virtual ~BlacklistPathProvider();
+ // Returns true if the provider is ready (has loaded the blacklist paths
+ // and we can query them). Called on UI thread.
+ virtual bool AreBlacklistPathsReady() const = 0;
- // The methods below will be invoked on the UI thread.
+ // Returns paths that will still be there after browser shutdown
+ // (installed extensions). Called on UI thread.
virtual std::vector<FilePath> GetPersistentBlacklistPaths() = 0;
+
+ // Returns paths that will disappear after browser shutdown
+ // (unpacked extensions). Called on UI thread.
virtual std::vector<FilePath> GetTransientBlacklistPaths() = 0;
+
+ protected:
+ virtual ~BlacklistPathProvider();
};
// Updates one compiled binary blacklist based on a list of plaintext
@@ -33,13 +42,15 @@ class BlacklistManager
public base::RefCountedThreadSafe<BlacklistManager,
ChromeThread::DeleteOnUIThread> {
public:
- BlacklistManager();
- void Initialize(Profile* profile, BlacklistPathProvider* path_provider);
+ // Create BlacklistManager (must be done on UI thread).
+ BlacklistManager(Profile* profile, BlacklistPathProvider* path_provider);
+
+ // Initialize the BlacklistManager (on UI thread).
+ void Initialize();
- const Blacklist* GetCompiledBlacklist() const {
- // TODO(phajdan.jr): Determine on which thread this should be invoked (IO?).
- return compiled_blacklist_.get();
- }
+ // Returns compiled blacklist, or NULL if not ready. Only valid to call on IO
+ // thread.
+ const Blacklist* GetCompiledBlacklist() const;
// NotificationObserver
virtual void Observe(NotificationType type,
@@ -54,7 +65,7 @@ class BlacklistManager
friend class ChromeThread;
friend class DeleteTask<BlacklistManager>;
- ~BlacklistManager() {}
+ virtual ~BlacklistManager();
// Compile all persistent blacklists to one binary blacklist stored on disk.
void CompileBlacklist();
@@ -62,11 +73,12 @@ class BlacklistManager
void OnBlacklistCompilationFinished(bool success);
// Read all blacklists from disk (the compiled one and also the transient
- // blacklists).
+ // blacklists). In case of failure, if we haven't loaded any blacklist yet,
+ // we'll compile the blacklist and try to read it again.
void ReadBlacklist();
void DoReadBlacklist(const std::vector<FilePath>& transient_blacklists);
- void ReportBlacklistReadResult(Blacklist* blacklist);
- void OnBlacklistReadFinished(Blacklist* blacklist);
+ void UpdatePublishedCompiledBlacklist(Blacklist* blacklist);
+ void OnBlacklistReadFinished(bool success);
// True after the first blacklist read has finished (regardless of success).
// Used to avoid an infinite loop.
diff --git a/chrome/browser/privacy_blacklist/blacklist_manager_browsertest.cc b/chrome/browser/privacy_blacklist/blacklist_manager_browsertest.cc
index b5d5316..a235df3 100644
--- a/chrome/browser/privacy_blacklist/blacklist_manager_browsertest.cc
+++ b/chrome/browser/privacy_blacklist/blacklist_manager_browsertest.cc
@@ -4,10 +4,12 @@
#include "chrome/browser/privacy_blacklist/blacklist_manager.h"
+#include "base/command_line.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/profile.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/common/notification_registrar.h"
#include "chrome/common/notification_source.h"
#include "chrome/test/in_process_browser_test.h"
@@ -16,31 +18,32 @@
namespace {
-// Returns true if |blacklist| contains a match for |url|.
-bool BlacklistHasMatch(const Blacklist* blacklist, const char* url) {
- Blacklist::Match* match = blacklist->findMatch(GURL(url));
-
- if (!match)
- return false;
-
- delete match;
- return true;
+void GetBlacklistHasMatchOnIOThread(const BlacklistManager* manager,
+ const GURL& url,
+ bool *has_match) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ const Blacklist* blacklist = manager->GetCompiledBlacklist();
+ scoped_ptr<Blacklist::Match> match(blacklist->findMatch(url));
+ *has_match = (match.get() != NULL);
+ ChromeThread::PostTask(ChromeThread::UI, FROM_HERE,
+ new MessageLoop::QuitTask());
}
} // namespace
class BlacklistManagerBrowserTest : public ExtensionBrowserTest {
public:
- void InitializeBlacklistManager() {
- Profile* profile = browser()->profile();
- blacklist_manager_ = new BlacklistManager();
- blacklist_manager_->Initialize(profile, profile->GetExtensionsService());
- WaitForBlacklistUpdate();
+ virtual void SetUp() {
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnablePrivacyBlacklists);
+ ExtensionBrowserTest::SetUp();
}
- virtual void CleanUpOnMainThread() {
- blacklist_manager_ = NULL;
- ExtensionBrowserTest::CleanUpOnMainThread();
+ virtual void SetUpInProcessBrowserTestFixture() {
+ ExtensionBrowserTest::SetUpInProcessBrowserTestFixture();
+
+ received_blacklist_notification_ = false;
+ host_resolver()->AddSimulatedFailure("www.example.com");
}
// NotificationObserver
@@ -52,48 +55,55 @@ class BlacklistManagerBrowserTest : public ExtensionBrowserTest {
ExtensionBrowserTest::Observe(type, source, details);
return;
}
+ received_blacklist_notification_ = true;
MessageLoop::current()->Quit();
}
protected:
- void WaitForBlacklistUpdate() {
- NotificationRegistrar registrar;
- registrar.Add(this,
- NotificationType::BLACKLIST_MANAGER_BLACKLIST_READ_FINISHED,
- Source<Profile>(browser()->profile()));
+ BlacklistManager* GetBlacklistManager() {
+ return browser()->profile()->GetBlacklistManager();
+ }
+
+ bool GetAndResetReceivedBlacklistNotification() {
+ bool result = received_blacklist_notification_;
+ received_blacklist_notification_ = false;
+ return result;
+ }
+
+ bool BlacklistHasMatch(const std::string& url) {
+ bool has_match = false;
+ ChromeThread::PostTask(ChromeThread::IO, FROM_HERE,
+ NewRunnableFunction(GetBlacklistHasMatchOnIOThread,
+ GetBlacklistManager(),
+ GURL(url),
+ &has_match));
ui_test_utils::RunMessageLoop();
+ return has_match;
}
- scoped_refptr<BlacklistManager> blacklist_manager_;
+ private:
+ bool received_blacklist_notification_;
};
IN_PROC_BROWSER_TEST_F(BlacklistManagerBrowserTest, Basic) {
- static const char kTestUrl[] = "http://host/annoying_ads/ad.jpg";
+ static const char kTestUrl[] = "http://www.example.com/annoying_ads/ad.jpg";
- InitializeBlacklistManager();
- ASSERT_TRUE(blacklist_manager_->GetCompiledBlacklist());
- EXPECT_FALSE(BlacklistHasMatch(blacklist_manager_->GetCompiledBlacklist(),
- kTestUrl));
+ NotificationRegistrar registrar;
+ registrar.Add(this,
+ NotificationType::BLACKLIST_MANAGER_BLACKLIST_READ_FINISHED,
+ Source<Profile>(browser()->profile()));
// Test loading an extension with blacklist.
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("common").AppendASCII("privacy_blacklist")));
- if (!BlacklistHasMatch(blacklist_manager_->GetCompiledBlacklist(),
- kTestUrl)) {
- WaitForBlacklistUpdate();
- }
- EXPECT_TRUE(BlacklistHasMatch(blacklist_manager_->GetCompiledBlacklist(),
- kTestUrl));
-
- // Make sure that after unloading the extension we update the blacklist.
- ExtensionsService* extensions_service =
- browser()->profile()->GetExtensionsService();
- ASSERT_EQ(1U, extensions_service->extensions()->size());
- UnloadExtension(extensions_service->extensions()->front()->id());
- if (BlacklistHasMatch(blacklist_manager_->GetCompiledBlacklist(),
- kTestUrl)) {
- WaitForBlacklistUpdate();
- }
- EXPECT_FALSE(BlacklistHasMatch(blacklist_manager_->GetCompiledBlacklist(),
- kTestUrl));
+
+ // Wait until the blacklist is loaded and ready.
+ if (!GetAndResetReceivedBlacklistNotification())
+ ui_test_utils::RunMessageLoop();
+
+ // The blacklist should block our test URL.
+ EXPECT_TRUE(BlacklistHasMatch(kTestUrl));
+
+ // TODO(phajdan.jr): Verify that we really blocked the request etc.
+ ui_test_utils::NavigateToURL(browser(), GURL(kTestUrl));
}
diff --git a/chrome/browser/privacy_blacklist/blacklist_manager_unittest.cc b/chrome/browser/privacy_blacklist/blacklist_manager_unittest.cc
index 42ed8e53..2b48b5c 100644
--- a/chrome/browser/privacy_blacklist/blacklist_manager_unittest.cc
+++ b/chrome/browser/privacy_blacklist/blacklist_manager_unittest.cc
@@ -8,9 +8,11 @@
#include "base/path_service.h"
#include "base/scoped_temp_dir.h"
#include "base/thread.h"
+#include "base/values.h"
#include "chrome/browser/privacy_blacklist/blacklist.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension.h"
+#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/notification_service.h"
#include "chrome/test/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -35,6 +37,10 @@ class TestBlacklistPathProvider : public BlacklistPathProvider {
explicit TestBlacklistPathProvider(Profile* profile) : profile_(profile) {
}
+ virtual bool AreBlacklistPathsReady() const {
+ return true;
+ }
+
virtual std::vector<FilePath> GetPersistentBlacklistPaths() {
return persistent_paths_;
}
@@ -61,12 +67,25 @@ class TestBlacklistPathProvider : public BlacklistPathProvider {
private:
void SendUpdateNotification() {
+ ListValue* privacy_blacklists = new ListValue;
+ privacy_blacklists->Append(new StringValue("dummy.pbl"));
+
+ DictionaryValue manifest;
+ manifest.SetString(extension_manifest_keys::kVersion, "1.0");
+ manifest.SetString(extension_manifest_keys::kName, "test");
+ manifest.Set(extension_manifest_keys::kPrivacyBlacklists,
+ privacy_blacklists);
+
#if defined(OS_WIN)
FilePath path(FILE_PATH_LITERAL("c:\\foo"));
#elif defined(OS_POSIX)
FilePath path(FILE_PATH_LITERAL("/foo"));
#endif
Extension extension(path);
+ std::string error;
+ ASSERT_TRUE(extension.InitFromValue(manifest, false, &error));
+ ASSERT_TRUE(error.empty());
+
NotificationService::current()->Notify(
NotificationType::EXTENSION_LOADED,
Source<Profile>(profile_),
@@ -86,7 +105,8 @@ class BlacklistManagerTest : public testing::Test, public NotificationObserver {
BlacklistManagerTest()
: path_provider_(&profile_),
mock_ui_thread_(ChromeThread::UI, MessageLoop::current()),
- mock_file_thread_(ChromeThread::FILE) {
+ mock_file_thread_(ChromeThread::FILE),
+ mock_io_thread_(ChromeThread::IO, MessageLoop::current()) {
}
virtual void SetUp() {
@@ -135,6 +155,7 @@ class BlacklistManagerTest : public testing::Test, public NotificationObserver {
ChromeThread mock_ui_thread_;
ChromeThread mock_file_thread_;
+ ChromeThread mock_io_thread_;
};
// Returns true if |blacklist| contains a match for |url|.
@@ -149,8 +170,9 @@ bool BlacklistHasMatch(const Blacklist* blacklist, const char* url) {
}
TEST_F(BlacklistManagerTest, Basic) {
- scoped_refptr<BlacklistManager> manager(new BlacklistManager());
- manager->Initialize(&profile_, &path_provider_);
+ scoped_refptr<BlacklistManager> manager(
+ new BlacklistManager(&profile_, &path_provider_));
+ manager->Initialize();
WaitForBlacklistUpdate();
const Blacklist* blacklist = manager->GetCompiledBlacklist();
@@ -161,8 +183,9 @@ TEST_F(BlacklistManagerTest, Basic) {
}
TEST_F(BlacklistManagerTest, BlacklistPathProvider) {
- scoped_refptr<BlacklistManager> manager(new BlacklistManager());
- manager->Initialize(&profile_, &path_provider_);
+ scoped_refptr<BlacklistManager> manager(
+ new BlacklistManager(&profile_, &path_provider_));
+ manager->Initialize();
WaitForBlacklistUpdate();
const Blacklist* blacklist1 = manager->GetCompiledBlacklist();
@@ -196,8 +219,8 @@ TEST_F(BlacklistManagerTest, BlacklistPathProvider) {
path_provider_.clear();
path_provider_.AddPersistentPath(
test_data_dir_.AppendASCII("annoying_ads.pbl"));
- manager = new BlacklistManager();
- manager->Initialize(&profile_, &path_provider_);
+ manager = new BlacklistManager(&profile_, &path_provider_);
+ manager->Initialize();
WaitForBlacklistUpdate();
const Blacklist* blacklist4 = manager->GetCompiledBlacklist();
@@ -207,8 +230,9 @@ TEST_F(BlacklistManagerTest, BlacklistPathProvider) {
}
TEST_F(BlacklistManagerTest, BlacklistPathReadError) {
- scoped_refptr<BlacklistManager> manager(new BlacklistManager());
- manager->Initialize(&profile_, &path_provider_);
+ scoped_refptr<BlacklistManager> manager(
+ new BlacklistManager(&profile_, &path_provider_));
+ manager->Initialize();
WaitForBlacklistUpdate();
FilePath bogus_path(test_data_dir_.AppendASCII("does_not_exist_randomness"));
@@ -224,8 +248,9 @@ TEST_F(BlacklistManagerTest, CompiledBlacklistReadError) {
FilePath compiled_blacklist_path;
{
- scoped_refptr<BlacklistManager> manager(new BlacklistManager());
- manager->Initialize(&profile_, &path_provider_);
+ scoped_refptr<BlacklistManager> manager(
+ new BlacklistManager(&profile_, &path_provider_));
+ manager->Initialize();
WaitForBlacklistUpdate();
path_provider_.AddPersistentPath(
@@ -242,8 +267,9 @@ TEST_F(BlacklistManagerTest, CompiledBlacklistReadError) {
ASSERT_TRUE(file_util::Delete(compiled_blacklist_path, false));
{
- scoped_refptr<BlacklistManager> manager(new BlacklistManager());
- manager->Initialize(&profile_, &path_provider_);
+ scoped_refptr<BlacklistManager> manager(
+ new BlacklistManager(&profile_, &path_provider_));
+ manager->Initialize();
WaitForBlacklistUpdate();
// The manager should recompile the blacklist.
diff --git a/chrome/browser/privacy_blacklist/blacklist_observer.h b/chrome/browser/privacy_blacklist/blacklist_observer.h
deleted file mode 100644
index a545ac8..0000000
--- a/chrome/browser/privacy_blacklist/blacklist_observer.h
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright (c) 2009 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_PRIVACY_BLACKLIST_BLACKLIST_OBSERVER_H_
-#define CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_OBSERVER_H_
-
-class URLRequest;
-
-class BlacklistObserver {
- public:
- // Called when non-visual content is blocked by the privacy blacklist.
- static void ContentBlocked(const URLRequest* request);
-};
-
-#endif // CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_OBSERVER_H_
diff --git a/chrome/browser/privacy_blacklist/blacklist_observer.cc b/chrome/browser/privacy_blacklist/blacklist_ui.cc
index b62d0c8..6d2327e 100644
--- a/chrome/browser/privacy_blacklist/blacklist_observer.cc
+++ b/chrome/browser/privacy_blacklist/blacklist_ui.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/privacy_blacklist/blacklist_observer.h"
+#include "chrome/browser/privacy_blacklist/blacklist_ui.h"
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
@@ -14,38 +14,40 @@
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h"
#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/common/notification_details.h"
-#include "chrome/common/notification_service.h"
-#include "chrome/common/notification_type.h"
#include "grit/generated_resources.h"
-class BlockedContentNotice : public Task {
+// Displays more info why some content has been blocked.
+class DisplayBlockedContentNoticeTask : public Task {
public:
- BlockedContentNotice(const GURL& gurl,
- const Blacklist::Match* match,
- const ResourceDispatcherHostRequestInfo* info)
+ DisplayBlockedContentNoticeTask(const GURL& gurl,
+ const Blacklist::Match* match,
+ const ResourceDispatcherHostRequestInfo* info)
: gurl_(gurl),
match_(match),
child_id_(info->child_id()),
route_id_(info->route_id()) {
+ }
+
+ virtual void Run() {
+ RenderViewHost* view = RenderViewHost::FromID(child_id_, route_id_);
+ if (!view)
+ return; // The view may be gone by the time we get here.
+
+ string16 reason;
if (match_->attributes() & Blacklist::kDontStoreCookies) {
// No cookies stored.
- reason_ = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_COOKIES);
+ reason = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_COOKIES);
} else if (match_->attributes() & Blacklist::kDontSendCookies) {
// No cookies sent.
- reason_ = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_COOKIES);
+ reason = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_COOKIES);
} else if (match_->attributes() & Blacklist::kDontSendReferrer) {
// No referrer sent.
- reason_ = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_REFERRER);
+ reason = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_REFERRER);
+ } else {
+ NOTREACHED();
}
- }
- virtual void Run() {
- RenderViewHost* view = RenderViewHost::FromID(child_id_, route_id_);
- if (!view)
- return; // The view may be gone by the time we get here.
-
- view->delegate()->AddBlockedNotice(gurl_, reason_);
+ view->delegate()->AddBlockedNotice(gurl_, reason);
}
private:
@@ -54,10 +56,13 @@ class BlockedContentNotice : public Task {
const int child_id_;
const int route_id_;
- string16 reason_;
+ DISALLOW_COPY_AND_ASSIGN(DisplayBlockedContentNoticeTask);
};
-void BlacklistObserver::ContentBlocked(const URLRequest* request) {
+// static
+void BlacklistUI::OnNonvisualContentBlocked(const URLRequest* request) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+
const URLRequest::UserData* d =
request->GetUserData(&Blacklist::kRequestDataKey);
const Blacklist::Match* match = static_cast<const Blacklist::Match*>(d);
@@ -68,5 +73,5 @@ void BlacklistObserver::ContentBlocked(const URLRequest* request) {
// Notify the UI that something non-visual has been blocked.
ChromeThread::PostTask(
ChromeThread::UI, FROM_HERE,
- new BlockedContentNotice(gurl, match, info));
+ new DisplayBlockedContentNoticeTask(gurl, match, info));
}
diff --git a/chrome/browser/privacy_blacklist/blacklist_ui.h b/chrome/browser/privacy_blacklist/blacklist_ui.h
new file mode 100644
index 0000000..ce76ad8
--- /dev/null
+++ b/chrome/browser/privacy_blacklist/blacklist_ui.h
@@ -0,0 +1,18 @@
+// Copyright (c) 2009 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_PRIVACY_BLACKLIST_BLACKLIST_UI_H_
+#define CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_UI_H_
+
+class URLRequest;
+
+// Set of routines to display blacklist-related UI.
+class BlacklistUI {
+ public:
+ // Called on IO thread when non-visual content is blocked by a privacy
+ // blacklist.
+ static void OnNonvisualContentBlocked(const URLRequest* request);
+};
+
+#endif // CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_UI_H_