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

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

Issue 501082: Implement delaying resource requests until privacy blacklists are ready. (Closed)
Patch Set: don't get stuck on errors Created 10 years, 12 months 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 ca8dc0b0d01ea172f77398533b74500e5cbf6cb9..c2253ef42ab2092a95aec4019103a4a5b03a6005 100644
--- a/chrome/browser/privacy_blacklist/blacklist_manager.cc
+++ b/chrome/browser/privacy_blacklist/blacklist_manager.cc
@@ -8,6 +8,7 @@
#include "base/string_util.h"
#include "base/task.h"
#include "base/thread.h"
+#include "base/utf_string_conversions.h"
#include "chrome/browser/privacy_blacklist/blacklist.h"
#include "chrome/browser/privacy_blacklist/blacklist_io.h"
#include "chrome/browser/profile.h"
@@ -89,6 +90,14 @@ void BlacklistManager::CompileBlacklist() {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
DCHECK(path_provider_->AreBlacklistPathsReady());
+ // The compiled blacklist is going to change. Make sure our clients don't use
+ // the old one and wait for the update instead by indicating that the compiled
+ // blacklist is not ready.
+ ChromeThread::PostTask(ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(this,
+ &BlacklistManager::ResetPublishedCompiledBlacklist));
+
+ // Schedule actual compilation on the background thread.
ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE,
NewRunnableMethod(this, &BlacklistManager::DoCompileBlacklist,
path_provider_->GetPersistentBlacklistPaths()));
@@ -98,22 +107,28 @@ void BlacklistManager::DoCompileBlacklist(
const std::vector<FilePath>& source_blacklists) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
- bool success = true;
Blacklist blacklist;
std::string error_string;
+ std::vector<string16> errors;
for (std::vector<FilePath>::const_iterator i = source_blacklists.begin();
i != source_blacklists.end(); ++i) {
+ std::string error_string;
if (!BlacklistIO::ReadText(&blacklist, *i, &error_string)) {
- success = false;
- break;
+ string16 path = WideToUTF16(i->ToWStringHack());
+ errors.push_back(path + ASCIIToUTF16(": " + error_string));
}
}
- // Only overwrite the current compiled blacklist if we read all source
- // files successfully.
- if (success)
- success = BlacklistIO::WriteBinary(&blacklist, compiled_blacklist_path_);
+ if (!errors.empty()) {
+ ChromeThread::PostTask(ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(this,
+ &BlacklistManager::OnBlacklistCompilationReadErrors,
+ errors));
+ }
+ // Write the new compiled blacklist based on the data we could read
+ // successfully.
+ bool success = BlacklistIO::WriteBinary(&blacklist, compiled_blacklist_path_);
ChromeThread::PostTask(ChromeThread::UI, FROM_HERE,
NewRunnableMethod(this, &BlacklistManager::OnBlacklistCompilationFinished,
success));
@@ -133,6 +148,21 @@ void BlacklistManager::OnBlacklistCompilationFinished(bool success) {
}
}
+void BlacklistManager::OnBlacklistCompilationReadErrors(
+ const std::vector<string16>& errors) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+
+ string16 error_message(ASCIIToUTF16("Blacklist compilation failed.\n"));
+ for (std::vector<string16>::const_iterator i = errors.begin();
+ i != errors.end(); ++i) {
+ error_message += *i + ASCIIToUTF16("\n");
+ }
+ NotificationService::current()->Notify(
+ NotificationType::BLACKLIST_MANAGER_ERROR,
+ Source<Profile>(profile_),
+ Details<string16>(&error_message));
+}
+
void BlacklistManager::ReadBlacklist() {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
DCHECK(path_provider_->AreBlacklistPathsReady());
@@ -197,3 +227,8 @@ void BlacklistManager::OnBlacklistReadFinished(bool success) {
}
first_read_finished_ = true;
}
+
+void BlacklistManager::ResetPublishedCompiledBlacklist() {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ compiled_blacklist_.reset();
+}

Powered by Google App Engine
This is Rietveld 408576698