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

Side by Side Diff: chrome/browser/supervised_user/supervised_user_service.h

Issue 335833003: Rename "managed (mode|user)" to "supervised user" (part 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments (+ a few other cleanups) Created 6 years, 6 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SERVICE_H_ 5 #ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_
6 #define CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SERVICE_H_ 6 #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_
7 7
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/prefs/pref_change_registrar.h" 14 #include "base/prefs/pref_change_registrar.h"
15 #include "base/scoped_observer.h" 15 #include "base/scoped_observer.h"
16 #include "base/strings/string16.h" 16 #include "base/strings/string16.h"
17 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" 17 #include "chrome/browser/supervised_user/supervised_user_url_filter.h"
18 #include "chrome/browser/managed_mode/managed_users.h" 18 #include "chrome/browser/supervised_user/supervised_users.h"
19 #include "chrome/browser/sync/profile_sync_service_observer.h" 19 #include "chrome/browser/sync/profile_sync_service_observer.h"
20 #include "chrome/browser/ui/browser_list_observer.h" 20 #include "chrome/browser/ui/browser_list_observer.h"
21 #include "components/keyed_service/core/keyed_service.h" 21 #include "components/keyed_service/core/keyed_service.h"
22 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
23 #include "extensions/browser/extension_registry_observer.h" 23 #include "extensions/browser/extension_registry_observer.h"
24 #include "extensions/browser/management_policy.h" 24 #include "extensions/browser/management_policy.h"
25 25
26 class Browser; 26 class Browser;
27 class GoogleServiceAuthError; 27 class GoogleServiceAuthError;
28 class ManagedModeURLFilter;
29 class ManagedModeSiteList;
30 class ManagedUserRegistrationUtility;
31 class ManagedUserSettingsService;
32 class PermissionRequestCreator; 28 class PermissionRequestCreator;
33 class Profile; 29 class Profile;
30 class SupervisedUserRegistrationUtility;
31 class SupervisedUserSettingsService;
32 class SupervisedUserSiteList;
33 class SupervisedUserURLFilter;
34 34
35 namespace extensions { 35 namespace extensions {
36 class ExtensionRegistry; 36 class ExtensionRegistry;
37 } 37 }
38 38
39 namespace user_prefs { 39 namespace user_prefs {
40 class PrefRegistrySyncable; 40 class PrefRegistrySyncable;
41 } 41 }
42 42
43 // This class handles all the information related to a given managed profile 43 // This class handles all the information related to a given supervised profile
44 // (e.g. the installed content packs, the default URL filtering behavior, or 44 // (e.g. the installed content packs, the default URL filtering behavior, or
45 // manual whitelist/blacklist overrides). 45 // manual whitelist/blacklist overrides).
46 class ManagedUserService : public KeyedService, 46 class SupervisedUserService : public KeyedService,
47 public extensions::ManagementPolicy::Provider, 47 public extensions::ManagementPolicy::Provider,
48 public ProfileSyncServiceObserver, 48 public ProfileSyncServiceObserver,
49 public extensions::ExtensionRegistryObserver, 49 public extensions::ExtensionRegistryObserver,
50 public chrome::BrowserListObserver { 50 public chrome::BrowserListObserver {
51 public: 51 public:
52 typedef std::vector<base::string16> CategoryList; 52 typedef std::vector<base::string16> CategoryList;
53 typedef base::Callback<void(content::WebContents*)> NavigationBlockedCallback; 53 typedef base::Callback<void(content::WebContents*)> NavigationBlockedCallback;
54 typedef base::Callback<void(const GoogleServiceAuthError&)> AuthErrorCallback; 54 typedef base::Callback<void(const GoogleServiceAuthError&)> AuthErrorCallback;
55 55
56 enum ManualBehavior { 56 enum ManualBehavior {
57 MANUAL_NONE = 0, 57 MANUAL_NONE = 0,
58 MANUAL_ALLOW, 58 MANUAL_ALLOW,
59 MANUAL_BLOCK 59 MANUAL_BLOCK
60 }; 60 };
61 61
62 class Delegate { 62 class Delegate {
63 public: 63 public:
64 virtual ~Delegate() {} 64 virtual ~Delegate() {}
65 // Returns true to indicate that the delegate handled the (de)activation, or 65 // Returns true to indicate that the delegate handled the (de)activation, or
66 // false to indicate that the ManagedUserService itself should handle it. 66 // false to indicate that the SupervisedUserService itself should handle it.
67 virtual bool SetActive(bool active) = 0; 67 virtual bool SetActive(bool active) = 0;
68 }; 68 };
69 69
70 virtual ~ManagedUserService(); 70 virtual ~SupervisedUserService();
71 71
72 // ProfileKeyedService override: 72 // ProfileKeyedService override:
73 virtual void Shutdown() OVERRIDE; 73 virtual void Shutdown() OVERRIDE;
74 74
75 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 75 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
76 76
77 static void MigrateUserPrefs(PrefService* prefs); 77 static void MigrateUserPrefs(PrefService* prefs);
78 78
79 void SetDelegate(Delegate* delegate); 79 void SetDelegate(Delegate* delegate);
80 80
81 // Returns the URL filter for the IO thread, for filtering network requests 81 // Returns the URL filter for the IO thread, for filtering network requests
82 // (in ManagedModeResourceThrottle). 82 // (in SupervisedUserResourceThrottle).
83 scoped_refptr<const ManagedModeURLFilter> GetURLFilterForIOThread(); 83 scoped_refptr<const SupervisedUserURLFilter> GetURLFilterForIOThread();
84 84
85 // Returns the URL filter for the UI thread, for filtering navigations and 85 // Returns the URL filter for the UI thread, for filtering navigations and
86 // classifying sites in the history view. 86 // classifying sites in the history view.
87 ManagedModeURLFilter* GetURLFilterForUIThread(); 87 SupervisedUserURLFilter* GetURLFilterForUIThread();
88 88
89 // Returns the URL's category, obtained from the installed content packs. 89 // Returns the URL's category, obtained from the installed content packs.
90 int GetCategory(const GURL& url); 90 int GetCategory(const GURL& url);
91 91
92 // Returns the list of all known human-readable category names, sorted by ID 92 // Returns the list of all known human-readable category names, sorted by ID
93 // number. Called in the critical path of drawing the history UI, so needs to 93 // number. Called in the critical path of drawing the history UI, so needs to
94 // be fast. 94 // be fast.
95 void GetCategoryNames(CategoryList* list); 95 void GetCategoryNames(CategoryList* list);
96 96
97 // Whether the user can request access to blocked URLs. 97 // Whether the user can request access to blocked URLs.
(...skipping 21 matching lines...) Expand all
119 ManualBehavior GetManualBehaviorForHost(const std::string& hostname); 119 ManualBehavior GetManualBehaviorForHost(const std::string& hostname);
120 120
121 // Returns the manual behavior for the given URL. 121 // Returns the manual behavior for the given URL.
122 ManualBehavior GetManualBehaviorForURL(const GURL& url); 122 ManualBehavior GetManualBehaviorForURL(const GURL& url);
123 123
124 // Returns all URLS on the given host that have exceptions. 124 // Returns all URLS on the given host that have exceptions.
125 void GetManualExceptionsForHost(const std::string& host, 125 void GetManualExceptionsForHost(const std::string& host,
126 std::vector<GURL>* urls); 126 std::vector<GURL>* urls);
127 127
128 // Initializes this object. This method does nothing if the profile is not 128 // Initializes this object. This method does nothing if the profile is not
129 // managed. 129 // supervised.
130 void Init(); 130 void Init();
131 131
132 // Initializes this profile for syncing, using the provided |refresh_token| to 132 // Initializes this profile for syncing, using the provided |refresh_token| to
133 // mint access tokens for Sync. 133 // mint access tokens for Sync.
134 void InitSync(const std::string& refresh_token); 134 void InitSync(const std::string& refresh_token);
135 135
136 // Convenience method that registers this managed user using 136 // Convenience method that registers this supervised user using
137 // |registration_utility| and initializes sync with the returned token. 137 // |registration_utility| and initializes sync with the returned token.
138 // The |callback| will be called when registration is complete, 138 // The |callback| will be called when registration is complete,
139 // whether it suceeded or not -- unless registration was cancelled manually, 139 // whether it suceeded or not -- unless registration was cancelled manually,
140 // in which case the callback will be ignored. 140 // in which case the callback will be ignored.
141 void RegisterAndInitSync(ManagedUserRegistrationUtility* registration_utility, 141 void RegisterAndInitSync(
142 Profile* custodian_profile, 142 SupervisedUserRegistrationUtility* registration_utility,
143 const std::string& managed_user_id, 143 Profile* custodian_profile,
144 const AuthErrorCallback& callback); 144 const std::string& supervised_user_id,
145 const AuthErrorCallback& callback);
145 146
146 void set_elevated_for_testing(bool skip) { 147 void set_elevated_for_testing(bool skip) {
147 elevated_for_testing_ = skip; 148 elevated_for_testing_ = skip;
148 } 149 }
149 150
150 void AddNavigationBlockedCallback(const NavigationBlockedCallback& callback); 151 void AddNavigationBlockedCallback(const NavigationBlockedCallback& callback);
151 void DidBlockNavigation(content::WebContents* web_contents); 152 void DidBlockNavigation(content::WebContents* web_contents);
152 153
153 // extensions::ManagementPolicy::Provider implementation: 154 // extensions::ManagementPolicy::Provider implementation:
154 virtual std::string GetDebugPolicyProviderName() const OVERRIDE; 155 virtual std::string GetDebugPolicyProviderName() const OVERRIDE;
(...skipping 11 matching lines...) Expand all
166 const extensions::Extension* extension) OVERRIDE; 167 const extensions::Extension* extension) OVERRIDE;
167 virtual void OnExtensionUnloaded( 168 virtual void OnExtensionUnloaded(
168 content::BrowserContext* browser_context, 169 content::BrowserContext* browser_context,
169 const extensions::Extension* extension, 170 const extensions::Extension* extension,
170 extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE; 171 extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE;
171 172
172 // chrome::BrowserListObserver implementation: 173 // chrome::BrowserListObserver implementation:
173 virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE; 174 virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE;
174 175
175 private: 176 private:
176 friend class ManagedUserServiceExtensionTestBase; 177 friend class SupervisedUserServiceExtensionTestBase;
177 friend class ManagedUserServiceFactory; 178 friend class SupervisedUserServiceFactory;
178 FRIEND_TEST_ALL_PREFIXES(ManagedUserServiceTest, ClearOmitOnRegistration); 179 FRIEND_TEST_ALL_PREFIXES(SupervisedUserServiceTest, ClearOmitOnRegistration);
179 180
180 // A bridge from ManagedMode (which lives on the UI thread) to the 181 // A bridge from the UI thread to the SupervisedUserURLFilters, one of which
181 // ManagedModeURLFilters, one of which lives on the IO thread. This class 182 // lives on the IO thread. This class mediates access to them and makes sure
182 // mediates access to them and makes sure they are kept in sync. 183 // they are kept in sync.
183 class URLFilterContext { 184 class URLFilterContext {
184 public: 185 public:
185 URLFilterContext(); 186 URLFilterContext();
186 ~URLFilterContext(); 187 ~URLFilterContext();
187 188
188 ManagedModeURLFilter* ui_url_filter() const; 189 SupervisedUserURLFilter* ui_url_filter() const;
189 ManagedModeURLFilter* io_url_filter() const; 190 SupervisedUserURLFilter* io_url_filter() const;
190 191
191 void SetDefaultFilteringBehavior( 192 void SetDefaultFilteringBehavior(
192 ManagedModeURLFilter::FilteringBehavior behavior); 193 SupervisedUserURLFilter::FilteringBehavior behavior);
193 void LoadWhitelists(ScopedVector<ManagedModeSiteList> site_lists); 194 void LoadWhitelists(ScopedVector<SupervisedUserSiteList> site_lists);
194 void SetManualHosts(scoped_ptr<std::map<std::string, bool> > host_map); 195 void SetManualHosts(scoped_ptr<std::map<std::string, bool> > host_map);
195 void SetManualURLs(scoped_ptr<std::map<GURL, bool> > url_map); 196 void SetManualURLs(scoped_ptr<std::map<GURL, bool> > url_map);
196 197
197 private: 198 private:
198 // ManagedModeURLFilter is refcounted because the IO thread filter is used 199 // SupervisedUserURLFilter is refcounted because the IO thread filter is
199 // both by ProfileImplIOData and OffTheRecordProfileIOData (to filter 200 // used both by ProfileImplIOData and OffTheRecordProfileIOData (to filter
200 // network requests), so they both keep a reference to it. 201 // network requests), so they both keep a reference to it.
201 // Clients should not keep references to the UI thread filter, however 202 // Clients should not keep references to the UI thread filter, however
202 // (the filter will live as long as the profile lives, and afterwards it 203 // (the filter will live as long as the profile lives, and afterwards it
203 // should not be used anymore either). 204 // should not be used anymore either).
204 scoped_refptr<ManagedModeURLFilter> ui_url_filter_; 205 scoped_refptr<SupervisedUserURLFilter> ui_url_filter_;
205 scoped_refptr<ManagedModeURLFilter> io_url_filter_; 206 scoped_refptr<SupervisedUserURLFilter> io_url_filter_;
206 207
207 DISALLOW_COPY_AND_ASSIGN(URLFilterContext); 208 DISALLOW_COPY_AND_ASSIGN(URLFilterContext);
208 }; 209 };
209 210
210 // Use |ManagedUserServiceFactory::GetForProfile(..)| to get 211 // Use |SupervisedUserServiceFactory::GetForProfile(..)| to get
211 // an instance of this service. 212 // an instance of this service.
212 explicit ManagedUserService(Profile* profile); 213 explicit SupervisedUserService(Profile* profile);
213 214
214 void SetActive(bool active); 215 void SetActive(bool active);
215 216
216 void OnCustodianProfileDownloaded(const base::string16& full_name); 217 void OnCustodianProfileDownloaded(const base::string16& full_name);
217 218
218 void OnManagedUserRegistered(const AuthErrorCallback& callback, 219 void OnSupervisedUserRegistered(const AuthErrorCallback& callback,
219 Profile* custodian_profile, 220 Profile* custodian_profile,
220 const GoogleServiceAuthError& auth_error, 221 const GoogleServiceAuthError& auth_error,
221 const std::string& token); 222 const std::string& token);
222 223
223 void SetupSync(); 224 void SetupSync();
224 225
225 bool ProfileIsManaged() const; 226 bool ProfileIsSupervised() const;
226 227
227 // Internal implementation for ExtensionManagementPolicy::Delegate methods. 228 // Internal implementation for ExtensionManagementPolicy::Delegate methods.
228 // If |error| is not NULL, it will be filled with an error message if the 229 // If |error| is not NULL, it will be filled with an error message if the
229 // requested extension action (install, modify status, etc.) is not permitted. 230 // requested extension action (install, modify status, etc.) is not permitted.
230 bool ExtensionManagementPolicyImpl(const extensions::Extension* extension, 231 bool ExtensionManagementPolicyImpl(const extensions::Extension* extension,
231 base::string16* error) const; 232 base::string16* error) const;
232 233
233 // Returns a list of all installed and enabled site lists in the current 234 // Returns a list of all installed and enabled site lists in the current
234 // managed profile. 235 // supervised profile.
235 ScopedVector<ManagedModeSiteList> GetActiveSiteLists(); 236 ScopedVector<SupervisedUserSiteList> GetActiveSiteLists();
236 237
237 ManagedUserSettingsService* GetSettingsService(); 238 SupervisedUserSettingsService* GetSettingsService();
238 239
239 void OnManagedUserIdChanged(); 240 void OnSupervisedUserIdChanged();
240 241
241 void OnDefaultFilteringBehaviorChanged(); 242 void OnDefaultFilteringBehaviorChanged();
242 243
243 void UpdateSiteLists(); 244 void UpdateSiteLists();
244 245
245 // Updates the manual overrides for hosts in the URL filters when the 246 // Updates the manual overrides for hosts in the URL filters when the
246 // corresponding preference is changed. 247 // corresponding preference is changed.
247 void UpdateManualHosts(); 248 void UpdateManualHosts();
248 249
249 // Updates the manual overrides for URLs in the URL filters when the 250 // Updates the manual overrides for URLs in the URL filters when the
(...skipping 26 matching lines...) Expand all
276 bool did_shutdown_; 277 bool did_shutdown_;
277 278
278 URLFilterContext url_filter_context_; 279 URLFilterContext url_filter_context_;
279 280
280 // Used to create permission requests. 281 // Used to create permission requests.
281 scoped_ptr<PermissionRequestCreator> permissions_creator_; 282 scoped_ptr<PermissionRequestCreator> permissions_creator_;
282 283
283 // True iff we are waiting for a permission request to be issued. 284 // True iff we are waiting for a permission request to be issued.
284 bool waiting_for_permissions_; 285 bool waiting_for_permissions_;
285 286
286 base::WeakPtrFactory<ManagedUserService> weak_ptr_factory_; 287 base::WeakPtrFactory<SupervisedUserService> weak_ptr_factory_;
287 }; 288 };
288 289
289 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SERVICE_H_ 290 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698