| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_POLICY_HOST_BLACKLIST_MANAGER_H_ |
| 6 #define CHROME_BROWSER_POLICY_HOST_BLACKLIST_MANAGER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 17 #include "content/common/notification_observer.h" |
| 18 |
| 19 class CancelableTask; |
| 20 class GURL; |
| 21 class NotificationDetails; |
| 22 class NotificationSource; |
| 23 class PrefService; |
| 24 class Profile; |
| 25 |
| 26 namespace base { |
| 27 class ListValue; |
| 28 } |
| 29 |
| 30 namespace policy { |
| 31 |
| 32 // Tracks the blacklist policies for a given profile, and updates it on changes. |
| 33 class HostBlacklistManager |
| 34 : public base::RefCountedThreadSafe<HostBlacklistManager>, |
| 35 public NotificationObserver { |
| 36 public: |
| 37 explicit HostBlacklistManager(Profile* profile); |
| 38 |
| 39 // Call once to initialize the service on the UI thread. |
| 40 // This is a separate method because it involves adding a ref to |this| |
| 41 // (through NewRunnableMethod), which isn't allowed in the ctor. |
| 42 void Initialize(); |
| 43 |
| 44 // Called on shutdown or destruction of the profile. The |
| 45 // ChromeNetworkDelegate can still hold a reference to |this| on the IO thread |
| 46 // but the PrefChangeRegistrar must clean up on the UI thread. |
| 47 // After calling ShutdownOnUIThread(), the blacklist will still be enforced |
| 48 // but it won't react to updates of the policies. |
| 49 void ShutdownOnUIThread(); |
| 50 |
| 51 // Returns true if |url| is blocked by the current blacklist. This must only |
| 52 // be invoked from the IO thread. |
| 53 bool ShouldBlockRequest(const GURL& url) const; |
| 54 |
| 55 // Registers the preferences related to blacklisting in the given PrefService. |
| 56 static void RegisterPrefs(PrefService* pref_service); |
| 57 |
| 58 private: |
| 59 friend class base::RefCountedThreadSafe<HostBlacklistManager>; |
| 60 friend class BuildBlacklistTask; |
| 61 friend class SetBlacklistTask; |
| 62 friend class TestingHostBlacklistManager; |
| 63 |
| 64 class Blacklist; |
| 65 |
| 66 virtual ~HostBlacklistManager(); |
| 67 |
| 68 virtual void Observe(int type, |
| 69 const NotificationSource& source, |
| 70 const NotificationDetails& details) OVERRIDE; |
| 71 |
| 72 void ScheduleUpdate(); |
| 73 virtual void PostUpdateTask(); // Virtual for testing. |
| 74 virtual void Update(); // Virtual for testing. |
| 75 |
| 76 void BuildBlacklist(const std::vector<std::string>* blacklist, |
| 77 const std::vector<std::string>* whitelist); |
| 78 void SetBlacklist(Blacklist* blacklist); |
| 79 |
| 80 // Non NULL when a pending update task exists. This is only modified on |
| 81 // the UI thread, and is used to avoid duplicate updates when both policies |
| 82 // change at the same time. |
| 83 CancelableTask* update_task_; |
| 84 |
| 85 // Used to track the policies and update the blacklist on changes. |
| 86 PrefChangeRegistrar pref_change_registrar_; |
| 87 PrefService* pref_service_; // Weak. |
| 88 |
| 89 // The current blacklist. Lives in the IO thread. |
| 90 scoped_ptr<Blacklist> blacklist_; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(HostBlacklistManager); |
| 93 }; |
| 94 |
| 95 } // namespace policy |
| 96 |
| 97 #endif // CHROME_BROWSER_POLICY_HOST_BLACKLIST_MANAGER_H_ |
| OLD | NEW |