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

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: win fix 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 void SetElevatedForTesting(bool is_elevated);
79
80 // Initializes this object. This method does nothing if the profile is not
81 // managed. This method should only be called for testing, to do
82 // initialization after the profile has been manually set to managed,
83 // otherwise it is called automatically,
84 void Init();
85
86 // ExtensionManagementPolicy::Provider implementation:
87 virtual std::string GetDebugPolicyProviderName() const OVERRIDE;
88 virtual bool UserMayLoad(const extensions::Extension* extension,
89 string16* error) const OVERRIDE;
90 virtual bool UserMayModifySettings(const extensions::Extension* extension,
91 string16* error) const OVERRIDE;
92
93 // content::NotificationObserver implementation:
94 virtual void Observe(int type,
95 const content::NotificationSource& source,
96 const content::NotificationDetails& details) OVERRIDE;
97
98 private:
99 friend class ManagedUserServiceExtensionTest;
100
101 // A bridge from ManagedMode (which lives on the UI thread) to the
102 // ManagedModeURLFilters, one of which lives on the IO thread. This class
103 // mediates access to them and makes sure they are kept in sync.
104 class URLFilterContext {
105 public:
106 URLFilterContext();
107 ~URLFilterContext();
108
109 ManagedModeURLFilter* ui_url_filter() const;
110 ManagedModeURLFilter* io_url_filter() const;
111
112 void SetDefaultFilteringBehavior(
113 ManagedModeURLFilter::FilteringBehavior behavior);
114 void LoadWhitelists(ScopedVector<ManagedModeSiteList> site_lists);
115 void SetManualLists(scoped_ptr<base::ListValue> whitelist,
116 scoped_ptr<base::ListValue> blacklist);
117 void AddURLPatternToManualList(const bool isWhitelist,
118 const std::string& url);
119
120 private:
121 // ManagedModeURLFilter is refcounted because the IO thread filter is used
122 // both by ProfileImplIOData and OffTheRecordProfileIOData (to filter
123 // network requests), so they both keep a reference to it.
124 // Clients should not keep references to the UI thread filter, however
125 // (the filter will live as long as the profile lives, and afterwards it
126 // should not be used anymore either).
127 scoped_refptr<ManagedModeURLFilter> ui_url_filter_;
128 scoped_refptr<ManagedModeURLFilter> io_url_filter_;
129
130 DISALLOW_COPY_AND_ASSIGN(URLFilterContext);
131 };
132
133 // Internal implementation for ExtensionManagementPolicy::Delegate methods.
134 // If |error| is not NULL, it will be filled with an error message if the
135 // requested extension action (install, modify status, etc.) is not permitted.
136 bool ExtensionManagementPolicyImpl(string16* error) const;
137
138 // Returns a list of all installed and enabled site lists in the current
139 // managed profile.
140 ScopedVector<ManagedModeSiteList> GetActiveSiteLists();
141
142 void OnDefaultFilteringBehaviorChanged();
143
144 void UpdateSiteLists();
145
146 // Adds the |url_pattern| to the manual lists in the URL filter. This is used
147 // by AddToManualListImpl().
148 void AddURLPatternToManualList(const bool is_whitelist,
149 const std::string& url_pattern);
150
151 // Returns a copy of the manual whitelist which is stored in each profile.
152 scoped_ptr<base::ListValue> GetWhitelist();
153
154 // Returns a copy of the manual blacklist which is stored in each profile.
155 scoped_ptr<base::ListValue> GetBlacklist();
156
157 // Owns us via the ProfileKeyedService mechanism.
158 Profile* profile_;
159
160 // If ManagedUserService is in an elevated state, a custodian user has
161 // authorized making changes (to install additional content packs, for
162 // example).
163 bool is_elevated_;
164
165 content::NotificationRegistrar registrar_;
166 PrefChangeRegistrar pref_change_registrar_;
167
168 URLFilterContext url_filter_context_;
169 };
170
171 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698