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

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: Reviewed, added netlog 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 class Profile;
25
26 namespace base {
27 class ListValue;
28 }
29
30 namespace policy {
31
32 class Blacklist;
33
34 // Tracks the blacklist policies for a given profile, and updates it on changes.
35 //
36 // This class interacts with both the UI thread, where notifications of pref
37 // changes are received from, and the IO thread, which owns it (in the
38 // ProfileIOData) and checks for blacklisted URLs (from ChromeNetworkDelegate).
39 //
40 // It must be constructed on the UI thread first, to set up
41 // |ui_method_factory_| and |initialize_on_ui_task_|. The task is used to
42 // resume initialization on the UI thread, after initialization on the IO thread
43 // is complete.
44 //
45 // InitializeOnIOThread sets up |io_weak_ptr_factory_| and |weak_ptr_|. The
46 // |weak_ptr_| is valid on the IO thread, and is used to post updates from UI.
47 // InitializeOnUIThread then posts |initialize_on_ui_task_|, which resumes
48 // initialization on the UI thread. At this point, update tasks can pass
49 // |weak_ptr_| around, and use it on IO to check if the instance is stil there
50 // before finalizing the update.
51 //
52 // The task will invoke InitializeOnUIThread, which sets up preference
53 // listeners. These can only start updating once |weak_ptr_| is set.
54 //
55 // Destruction must also pass through both threads. ShutdownOnUIThread must be
56 // called first, and will invalidate any pending updates (and even a pending
57 // initialize_on_ui_task_, if it hasn't executed yet). After that, no more
58 // calls will be made from the UI thread. It is then safe to call the dtor
59 // on the IO thread. Any updates will flight have a weak ptr to self, which
60 // will be invalidated and the update is discarded.
61 class URLBlacklistManager : public NotificationObserver {
62 public:
63 // Must be constructed on the UI thread.
64 explicit URLBlacklistManager(Profile* profile);
willchan no longer on Chromium 2011/09/01 17:05:04 Please pass in PrefService instead. It's a bit lam
Joao da Silva 2011/09/02 14:31:02 Done.
65 virtual ~URLBlacklistManager();
66
67 // Must be called on the IO thread.
68 void InitializeOnIOThread();
69
70 // Must be called on the UI thread, before destruction.
71 void ShutdownOnUIThread();
72
73 // Returns true if |url| is blocked by the current blacklist. Must be called
74 // from the IO thread.
75 bool IsURLBlocked(const GURL& url) const;
76
77 // Replaces the current blacklist. Must be called on the IO thread.
78 void SetBlacklist(Blacklist* blacklist);
79
80 // Registers the preferences related to blacklisting in the given PrefService.
81 static void RegisterPrefs(PrefService* pref_service);
82
83 protected:
84 // These are used to delay updating the blacklist while the preferences are
85 // changing, and execute only one update per simultaneous prefs changes.
86 void ScheduleUpdate();
87 virtual void PostUpdateTask(Task* task); // Virtual for testing.
willchan no longer on Chromium 2011/09/01 17:05:04 Can you move this to private? I don't think it eve
Joao da Silva 2011/09/02 14:31:02 The test just overrides this and posts the task, b
88 virtual void Update(); // Virtual for testing.
89
90 private:
91 virtual void Observe(int type,
92 const NotificationSource& source,
93 const NotificationDetails& details) OVERRIDE;
94
95 // Completes initialization on the UI thread.
96 void InitializeOnUIThread();
97
98 // Used to post update tasks to the UI thread.
99 ScopedRunnableMethodFactory<URLBlacklistManager> ui_method_factory_;
100
101 // Used to get |weak_ptr_| to self on the IO thread.
willchan no longer on Chromium 2011/09/01 17:05:04 For clarity's sake, please organize these member v
Joao da Silva 2011/09/02 14:31:02 Great idea, done.
102 base::WeakPtrFactory<URLBlacklistManager> io_weak_ptr_factory_;
103
104 // Holds a weak reference to self on the IO thread. This is used to enable
105 // the UI thread to posts tasks to IO that reference |this|.
106 base::WeakPtr<URLBlacklistManager> weak_ptr_;
107
108 // A task that is created on the UI thread but posted from the IO thread to
109 // resume initialization on the UI thread.
110 Task* initialize_on_ui_task_;
111
112 // Used to track the policies and update the blacklist on changes.
113 PrefChangeRegistrar pref_change_registrar_;
114 PrefService* pref_service_; // Weak.
115
116 // The current blacklist. Lives in the IO thread.
117 scoped_ptr<Blacklist> blacklist_;
118
119 DISALLOW_COPY_AND_ASSIGN(URLBlacklistManager);
120 };
121
122 } // namespace policy
123
124 #endif // CHROME_BROWSER_POLICY_URL_BLACKLIST_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698