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_URL_BLACKLIST_MANAGER_H_ | |
6 #define CHROME_BROWSER_POLICY_URL_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/linked_ptr.h" | |
15 #include "base/memory/weak_ptr.h" | |
16 #include "base/task.h" | |
17 #include "chrome/browser/prefs/pref_change_registrar.h" | |
18 #include "content/common/notification_observer.h" | |
19 | |
20 class GURL; | |
21 class NotificationDetails; | |
22 class NotificationSource; | |
23 class PrefService; | |
24 | |
25 namespace base { | |
26 class ListValue; | |
27 } | |
28 | |
29 namespace policy { | |
30 | |
31 // TODO(joaodasilva): this is a work in progress. http://crbug.com/49612 | |
32 class Blacklist { | |
33 public: | |
34 Blacklist() { | |
willchan no longer on Chromium
2011/09/02 16:39:26
This is totally fine now and you were probably alr
Joao da Silva
2011/09/02 17:35:20
I've moved it to the .cc. Thanks for the info.
| |
35 } | |
36 | |
37 private: | |
38 DISALLOW_COPY_AND_ASSIGN(Blacklist); | |
39 }; | |
40 | |
41 // Tracks the blacklist policies for a given profile, and updates it on changes. | |
42 // | |
43 // This class interacts with both the UI thread, where notifications of pref | |
44 // changes are received from, and the IO thread, which owns it (in the | |
45 // ProfileIOData) and checks for blacklisted URLs (from ChromeNetworkDelegate). | |
46 // | |
47 // It must be constructed on the UI thread, to set up |ui_method_factory_| and | |
48 // the prefs listeners. | |
49 // | |
50 // ShutdownOnUIThread must be called from UI before destruction, to release | |
51 // the prefs listeners on the UI thread. This is done from ProfileIOData. | |
52 // | |
53 // Update tasks from the UI thread can post safely to the IO thread, since the | |
54 // destruction order of Profile and ProfileIOData guarantees that if this | |
55 // exists in UI, then a potential destruction on IO will come after any task | |
56 // posted to IO from that method on UI. This is used to go through IO before | |
57 // the actual update starts, and grab a WeakPtr. | |
58 class URLBlacklistManager : public NotificationObserver { | |
59 public: | |
60 // Must be constructed on the UI thread. | |
61 explicit URLBlacklistManager(PrefService* pref_service); | |
62 virtual ~URLBlacklistManager(); | |
63 | |
64 // Must be called on the UI thread, before destruction. | |
65 void ShutdownOnUIThread(); | |
66 | |
67 // Returns true if |url| is blocked by the current blacklist. Must be called | |
68 // from the IO thread. | |
69 bool IsURLBlocked(const GURL& url) const; | |
70 | |
71 // Replaces the current blacklist. Must be called on the IO thread. | |
72 void SetBlacklist(linked_ptr<Blacklist> blacklist); | |
73 | |
74 // Registers the preferences related to blacklisting in the given PrefService. | |
75 static void RegisterPrefs(PrefService* pref_service); | |
76 | |
77 protected: | |
78 typedef std::vector<std::string> StringVector; | |
79 | |
80 // These are used to delay updating the blacklist while the preferences are | |
81 // changing, and execute only one update per simultaneous prefs changes. | |
82 void ScheduleUpdate(); | |
83 virtual void PostUpdateTask(Task* task); // Virtual for testing. | |
84 virtual void Update(); // Virtual for testing. | |
85 | |
86 // Starts the blacklist update on the IO thread, using the filters in | |
87 // |block| and |allow|. Protected for testing. | |
88 void UpdateOnIO(linked_ptr<StringVector> block, | |
89 linked_ptr<StringVector> allow); | |
90 | |
91 private: | |
92 virtual void Observe(int type, | |
93 const NotificationSource& source, | |
94 const NotificationDetails& details) OVERRIDE; | |
95 | |
96 // --------- | |
97 // UI thread | |
98 // --------- | |
99 | |
100 // Used to post update tasks to the UI thread. | |
101 ScopedRunnableMethodFactory<URLBlacklistManager> ui_method_factory_; | |
102 | |
103 // Used to track the policies and update the blacklist on changes. | |
104 PrefChangeRegistrar pref_change_registrar_; | |
105 PrefService* pref_service_; // Weak. | |
106 | |
107 // --------- | |
108 // IO thread | |
109 // --------- | |
110 | |
111 // Used to get |weak_ptr_| to self on the IO thread. | |
112 base::WeakPtrFactory<URLBlacklistManager> io_weak_ptr_factory_; | |
113 | |
114 // The current blacklist. | |
115 linked_ptr<Blacklist> blacklist_; | |
116 | |
117 DISALLOW_COPY_AND_ASSIGN(URLBlacklistManager); | |
118 }; | |
119 | |
120 } // namespace policy | |
121 | |
122 #endif // CHROME_BROWSER_POLICY_URL_BLACKLIST_MANAGER_H_ | |
OLD | NEW |