Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4829)

Unified Diff: chrome/browser/privacy_blacklist/blacklist_manager.cc

Issue 371063: Integrate BlacklistManager with Profile. (Closed)
Patch Set: trybot fixes Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/privacy_blacklist/blacklist_manager.cc
diff --git a/chrome/browser/privacy_blacklist/blacklist_manager.cc b/chrome/browser/privacy_blacklist/blacklist_manager.cc
index 2a9f4c7bd2bda4f364a44c44a1a177d808c30424..ca8dc0b0d01ea172f77398533b74500e5cbf6cb9 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));
}

Powered by Google App Engine
This is Rietveld 408576698