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

Side by Side Diff: chrome/browser/policy/url_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: Rebased, reviewed Created 9 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/scoped_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 URLBlacklist {
33 public:
34 URLBlacklist();
35 virtual ~URLBlacklist();
36
37 private:
38 DISALLOW_COPY_AND_ASSIGN(URLBlacklist);
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(URLBlacklist* 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(StringVector* block, StringVector* allow);
89
90 private:
91 virtual void Observe(int type,
92 const NotificationSource& source,
93 const NotificationDetails& details) OVERRIDE;
94
95 // ---------
96 // UI thread
97 // ---------
98
99 // Used to post update tasks to the UI thread.
100 ScopedRunnableMethodFactory<URLBlacklistManager> ui_method_factory_;
101
102 // Used to track the policies and update the blacklist on changes.
103 PrefChangeRegistrar pref_change_registrar_;
104 PrefService* pref_service_; // Weak.
105
106 // ---------
107 // IO thread
108 // ---------
109
110 // Used to get |weak_ptr_| to self on the IO thread.
111 base::WeakPtrFactory<URLBlacklistManager> io_weak_ptr_factory_;
112
113 // The current blacklist.
114 scoped_ptr<URLBlacklist> blacklist_;
115
116 DISALLOW_COPY_AND_ASSIGN(URLBlacklistManager);
117 };
118
119 } // namespace policy
120
121 #endif // CHROME_BROWSER_POLICY_URL_BLACKLIST_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_network_delegate.cc ('k') | chrome/browser/policy/url_blacklist_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698