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

Side by Side Diff: chrome/browser/managed_mode/managed_user_service.h

Issue 11826059: Add ManagedUserService for profile-specific managed user data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 7 years, 11 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) 2013 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_MANAGED_MODE_MANAGED_USER_SERVICE_H_
6 #define CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SERVICE_H_
7
8 #include <vector>
9
10 #include "base/prefs/public/pref_change_registrar.h"
11 #include "base/string16.h"
12 #include "chrome/browser/extensions/management_policy.h"
13 #include "chrome/browser/managed_mode/managed_mode_url_filter.h"
14 #include "chrome/browser/profiles/profile_keyed_service.h"
15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
17
18 class ManagedModeURLFilter;
19 class ManagedModeSiteList;
20 class PrefServiceSyncable;
21 class Profile;
22
23 // This class handles all the information related to a given managed profile
24 // (e.g. the installed content packs, the default URL filtering behavior, or
25 // manual whitelist/blacklist overrides).
26 class ManagedUserService : public ProfileKeyedService,
27 public extensions::ManagementPolicy::Provider,
28 public content::NotificationObserver {
29 public:
30 typedef std::vector<string16> CategoryList;
31
32 explicit ManagedUserService(Profile* profile);
33 virtual ~ManagedUserService();
34
35 bool ProfileIsManaged() const;
36
37 static void RegisterUserPrefs(PrefServiceSyncable* prefs);
38
39 // Returns the URL filter for the IO thread, for filtering network requests
40 // (in ManagedModeResourceThrottle).
41 scoped_refptr<const ManagedModeURLFilter> GetURLFilterForIOThread();
42
43 // Returns the URL filter for the UI thread, for filtering navigations and
44 // classifying sites in the history view.
45 ManagedModeURLFilter* GetURLFilterForUIThread();
46
47 // Returns the URL's category, obtained from the installed content packs.
48 int GetCategory(const GURL& url);
49
50 // Returns the list of all known human-readable category names, sorted by ID
51 // number. Called in the critical path of drawing the history UI, so needs to
52 // be fast.
53 void GetCategoryNames(CategoryList* list);
54
55 // The functions that handle manual whitelists use |url_pattern| or lists
56 // of "url patterns". An "url pattern" is a pattern in the format used by the
57 // policy::URLBlacklist filter. A description of the format used can be found
58 // here: http://dev.chromium.org/administrators/url-blacklist-filter-format.
59 // They all receive the |is_whitelist| parameter which dictates whether they
60 // act on the whitelist (for |is_whitelist| == true) or on the blacklist (for
61 // |is_whitelist| == false).
62
63 // Checks if the |url_pattern| is in the manual whitelist.
64 bool IsInManualList(const bool is_whitelist, const std::string& url_pattern);
65
66 // Appends |list| to the manual white/black list (according to |is_whitelist|)
67 // both in URL filter and in preferences.
68 void AddToManualList(const bool is_whitelist, const base::ListValue& list);
69
70 // Removes |list| from the manual white/black list (according to
71 // |is_whitelist|) both in URL filter and in preferences.
72 void RemoveFromManualList(const bool is_whitelist,
73 const base::ListValue& list);
74
75 // Updates the whitelist and the blacklist from the prefs.
76 void UpdateManualLists();
77
78 // ExtensionManagementPolicy::Provider implementation:
79 virtual std::string GetDebugPolicyProviderName() const OVERRIDE;
80 virtual bool UserMayLoad(const extensions::Extension* extension,
81 string16* error) const OVERRIDE;
82 virtual bool UserMayModifySettings(const extensions::Extension* extension,
83 string16* error) const OVERRIDE;
84
85 // content::NotificationObserver implementation:
86 virtual void Observe(int type,
87 const content::NotificationSource& source,
88 const content::NotificationDetails& details) OVERRIDE;
89
90 private:
91 friend class ManagedUserServiceExtensionTest;
92
93 // A bridge from ManagedMode (which lives on the UI thread) to the
94 // ManagedModeURLFilters, one of which lives on the IO thread. This class
95 // mediates access to them and makes sure they are kept in sync.
96 class URLFilterContext {
97 public:
98 URLFilterContext();
99 ~URLFilterContext();
100
101 ManagedModeURLFilter* ui_url_filter() const;
102 ManagedModeURLFilter* io_url_filter() const;
103
104 void SetDefaultFilteringBehavior(
105 ManagedModeURLFilter::FilteringBehavior behavior);
106 void LoadWhitelists(ScopedVector<ManagedModeSiteList> site_lists);
107 void SetManualLists(scoped_ptr<base::ListValue> whitelist,
108 scoped_ptr<base::ListValue> blacklist);
109 void AddURLPatternToManualList(const bool isWhitelist,
110 const std::string& url);
111
112 private:
113 // ManagedModeURLFilter is refcounted because the IO thread filter is used
114 // both by ProfileImplIOData and OffTheRecordProfileIOData (to filter
115 // network requests), so they both keep a reference to it.
116 // Clients should not keep references to the UI thread filter, however
117 // (the filter will live as long as the profile lives, and afterwards it
118 // should not be used anymore either).
119 scoped_refptr<ManagedModeURLFilter> ui_url_filter_;
120 scoped_refptr<ManagedModeURLFilter> io_url_filter_;
121
122 DISALLOW_COPY_AND_ASSIGN(URLFilterContext);
123 };
124
125 // Internal implementation for ExtensionManagementPolicy::Delegate methods.
126 // If |error| is not NULL, it will be filled with an error message if the
127 // requested extension action (install, modify status, etc.) is not permitted.
128 bool ExtensionManagementPolicyImpl(string16* error) const;
129
130 // Returns a list of all installed and enabled site lists in the current
131 // managed profile.
132 ScopedVector<ManagedModeSiteList> GetActiveSiteLists();
133
134 void OnDefaultFilteringBehaviorChanged();
135
136 void UpdateSiteLists();
137
138 // Adds the |url_pattern| to the manual lists in the URL filter. This is used
139 // by AddToManualListImpl().
140 void AddURLPatternToManualList(const bool is_whitelist,
141 const std::string& url_pattern);
142
143 // Returns a copy of the manual whitelist which is stored in each profile.
144 scoped_ptr<base::ListValue> GetWhitelist();
145
146 // Returns a copy of the manual blacklist which is stored in each profile.
147 scoped_ptr<base::ListValue> GetBlacklist();
148
149 // Owns us via the ProfileKeyedService mechanism.
150 Profile* profile_;
151
152 content::NotificationRegistrar registrar_;
153 PrefChangeRegistrar pref_change_registrar_;
154
155 URLFilterContext url_filter_context_;
156 };
157
158 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698