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

Unified Diff: chrome/browser/policy/host_blacklist_manager.h

Issue 7747018: Introduced the URLBlacklistManager, and wired it to various places. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reviewed, rebased Created 9 years, 4 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/policy/host_blacklist_manager.h
diff --git a/chrome/browser/policy/host_blacklist_manager.h b/chrome/browser/policy/host_blacklist_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..db6f6e04ea2d756d64ee9c17a6921ccea4707bcc
--- /dev/null
+++ b/chrome/browser/policy/host_blacklist_manager.h
@@ -0,0 +1,97 @@
+// Copyright (c) 2011 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_POLICY_HOST_BLACKLIST_MANAGER_H_
+#define CHROME_BROWSER_POLICY_HOST_BLACKLIST_MANAGER_H_
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/prefs/pref_change_registrar.h"
+#include "content/common/notification_observer.h"
+
+class CancelableTask;
+class GURL;
+class NotificationDetails;
+class NotificationSource;
+class PrefService;
+class Profile;
+
+namespace base {
+class ListValue;
+}
+
+namespace policy {
+
+// Tracks the blacklist policies for a given profile, and updates it on changes.
willchan no longer on Chromium 2011/08/26 11:40:21 The ownership of this object should be explained i
Joao da Silva 2011/08/29 11:24:25 Done. It took a while to figure how to do this, an
+class HostBlacklistManager
+ : public base::RefCountedThreadSafe<HostBlacklistManager>,
+ public NotificationObserver {
+ public:
+ explicit HostBlacklistManager(Profile* profile);
+
+ // Call once to initialize the service on the UI thread.
+ // This is a separate method because it involves adding a ref to |this|
+ // (through NewRunnableMethod), which isn't allowed in the ctor.
+ void Initialize();
+
+ // Called on shutdown or destruction of the profile. The
+ // ChromeNetworkDelegate can still hold a reference to |this| on the IO thread
+ // but the PrefChangeRegistrar must clean up on the UI thread.
+ // After calling ShutdownOnUIThread(), the blacklist will still be enforced
+ // but it won't react to updates of the policies.
+ void ShutdownOnUIThread();
+
+ // Returns true if |url| is blocked by the current blacklist. This must only
+ // be invoked from the IO thread.
+ bool ShouldBlockRequest(const GURL& url) const;
+
+ // Registers the preferences related to blacklisting in the given PrefService.
+ static void RegisterPrefs(PrefService* pref_service);
+
+ private:
+ friend class base::RefCountedThreadSafe<HostBlacklistManager>;
+ friend class BuildBlacklistTask;
willchan no longer on Chromium 2011/08/26 11:40:21 Why are these friends? Why don't you just make the
Joao da Silva 2011/08/29 11:24:25 Done.
+ friend class SetBlacklistTask;
+ friend class TestingHostBlacklistManager;
+
+ class Blacklist;
+
+ virtual ~HostBlacklistManager();
+
+ virtual void Observe(int type,
+ const NotificationSource& source,
+ const NotificationDetails& details) OVERRIDE;
+
+ void ScheduleUpdate();
+ virtual void PostUpdateTask(); // Virtual for testing.
+ virtual void Update(); // Virtual for testing.
+
+ void BuildBlacklist(const std::vector<std::string>* blacklist,
+ const std::vector<std::string>* whitelist);
+ void SetBlacklist(Blacklist* blacklist);
+
+ // Non NULL when a pending update task exists. This is only modified on
+ // the UI thread, and is used to avoid duplicate updates when both policies
+ // change at the same time.
+ CancelableTask* update_task_;
+
+ // Used to track the policies and update the blacklist on changes.
+ PrefChangeRegistrar pref_change_registrar_;
+ PrefService* pref_service_; // Weak.
+
+ // The current blacklist. Lives in the IO thread.
+ scoped_ptr<Blacklist> blacklist_;
+
+ DISALLOW_COPY_AND_ASSIGN(HostBlacklistManager);
+};
+
+} // namespace policy
+
+#endif // CHROME_BROWSER_POLICY_HOST_BLACKLIST_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698