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

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

Issue 2004043002: Supervised Users Initiated Installs v2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kid_initiated_install
Patch Set: Response to code review by Marc Created 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_ 5 #ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_
6 #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_ 6 #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 15 matching lines...) Expand all
26 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" 26 #include "chrome/browser/supervised_user/supervised_user_url_filter.h"
27 #include "chrome/browser/supervised_user/supervised_users.h" 27 #include "chrome/browser/supervised_user/supervised_users.h"
28 #include "chrome/browser/ui/browser_list_observer.h" 28 #include "chrome/browser/ui/browser_list_observer.h"
29 #include "components/keyed_service/core/keyed_service.h" 29 #include "components/keyed_service/core/keyed_service.h"
30 #include "components/prefs/pref_change_registrar.h" 30 #include "components/prefs/pref_change_registrar.h"
31 #include "components/sync_driver/sync_service_observer.h" 31 #include "components/sync_driver/sync_service_observer.h"
32 #include "components/sync_driver/sync_type_preference_provider.h" 32 #include "components/sync_driver/sync_type_preference_provider.h"
33 #include "net/url_request/url_request_context_getter.h" 33 #include "net/url_request/url_request_context_getter.h"
34 34
35 #if defined(ENABLE_EXTENSIONS) 35 #if defined(ENABLE_EXTENSIONS)
36 #include "extensions/browser/extension_registry_observer.h"
36 #include "extensions/browser/management_policy.h" 37 #include "extensions/browser/management_policy.h"
37 #endif 38 #endif
38 39
39 class Browser; 40 class Browser;
40 class GoogleServiceAuthError; 41 class GoogleServiceAuthError;
41 class PermissionRequestCreator; 42 class PermissionRequestCreator;
42 class Profile; 43 class Profile;
43 class SupervisedUserRegistrationUtility; 44 class SupervisedUserRegistrationUtility;
44 class SupervisedUserServiceObserver; 45 class SupervisedUserServiceObserver;
45 class SupervisedUserSettingsService; 46 class SupervisedUserSettingsService;
(...skipping 20 matching lines...) Expand all
66 67
67 namespace user_prefs { 68 namespace user_prefs {
68 class PrefRegistrySyncable; 69 class PrefRegistrySyncable;
69 } 70 }
70 71
71 // This class handles all the information related to a given supervised profile 72 // This class handles all the information related to a given supervised profile
72 // (e.g. the installed content packs, the default URL filtering behavior, or 73 // (e.g. the installed content packs, the default URL filtering behavior, or
73 // manual whitelist/blacklist overrides). 74 // manual whitelist/blacklist overrides).
74 class SupervisedUserService : public KeyedService, 75 class SupervisedUserService : public KeyedService,
75 #if defined(ENABLE_EXTENSIONS) 76 #if defined(ENABLE_EXTENSIONS)
77 public extensions::ExtensionRegistryObserver,
76 public extensions::ManagementPolicy::Provider, 78 public extensions::ManagementPolicy::Provider,
77 #endif 79 #endif
78 public SyncTypePreferenceProvider, 80 public SyncTypePreferenceProvider,
79 #if !defined(OS_ANDROID) 81 #if !defined(OS_ANDROID)
80 public sync_driver::SyncServiceObserver, 82 public sync_driver::SyncServiceObserver,
81 public chrome::BrowserListObserver, 83 public chrome::BrowserListObserver,
82 #endif 84 #endif
83 public SupervisedUserURLFilter::Observer { 85 public SupervisedUserURLFilter::Observer {
84 public: 86 public:
85 using NavigationBlockedCallback = base::Callback<void(content::WebContents*)>; 87 using NavigationBlockedCallback = base::Callback<void(content::WebContents*)>;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // extensions. 124 // extensions.
123 bool AccessRequestsEnabled(); 125 bool AccessRequestsEnabled();
124 126
125 // Adds an access request for the given URL. 127 // Adds an access request for the given URL.
126 void AddURLAccessRequest(const GURL& url, const SuccessCallback& callback); 128 void AddURLAccessRequest(const GURL& url, const SuccessCallback& callback);
127 129
128 // Reports |url| to the SafeSearch API, because the user thinks this is an 130 // Reports |url| to the SafeSearch API, because the user thinks this is an
129 // inappropriate URL. 131 // inappropriate URL.
130 void ReportURL(const GURL& url, const SuccessCallback& callback); 132 void ReportURL(const GURL& url, const SuccessCallback& callback);
131 133
134 // Adds an install request for the given WebStore item (App/Extension).
135 void AddExtensionInstallRequest(const std::string& extension_id,
136 const base::Version& version,
137 const SuccessCallback& callback);
138
139 // Same as above, but without a callback, just logging errors on failure.
140 void AddExtensionInstallRequest(const std::string& extension_id,
141 const base::Version& version);
142
132 // Adds an update request for the given WebStore item (App/Extension). 143 // Adds an update request for the given WebStore item (App/Extension).
133 void AddExtensionUpdateRequest(const std::string& extension_id, 144 void AddExtensionUpdateRequest(const std::string& extension_id,
134 const base::Version& version, 145 const base::Version& version,
135 const SuccessCallback& callback); 146 const SuccessCallback& callback);
136 147
137 // Same as above, but without a callback, just logging errors on failure. 148 // Same as above, but without a callback, just logging errors on failure.
138 void AddExtensionUpdateRequest(const std::string& extension_id, 149 void AddExtensionUpdateRequest(const std::string& extension_id,
139 const base::Version& version); 150 const base::Version& version);
140 151
141 // Get the string used to identify an extension update request. Public for 152 // Get the string used to identify an extension install or update request.
142 // testing. 153 // Public for testing.
143 static std::string GetExtensionUpdateRequestId( 154 static std::string GetExtensionRequestId(const std::string& extension_id,
144 const std::string& extension_id, 155 const base::Version& version);
145 const base::Version& version);
146 156
147 // Returns the email address of the custodian. 157 // Returns the email address of the custodian.
148 std::string GetCustodianEmailAddress() const; 158 std::string GetCustodianEmailAddress() const;
149 159
150 // Returns the name of the custodian, or the email address if the name is 160 // Returns the name of the custodian, or the email address if the name is
151 // empty. 161 // empty.
152 std::string GetCustodianName() const; 162 std::string GetCustodianName() const;
153 163
154 // Returns the email address of the second custodian, or the empty string 164 // Returns the email address of the second custodian, or the empty string
155 // if there is no second custodian. 165 // if there is no second custodian.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 #endif // !defined(OS_ANDROID) 221 #endif // !defined(OS_ANDROID)
212 222
213 // SupervisedUserURLFilter::Observer implementation: 223 // SupervisedUserURLFilter::Observer implementation:
214 void OnSiteListUpdated() override; 224 void OnSiteListUpdated() override;
215 225
216 private: 226 private:
217 friend class SupervisedUserServiceExtensionTestBase; 227 friend class SupervisedUserServiceExtensionTestBase;
218 friend class SupervisedUserServiceFactory; 228 friend class SupervisedUserServiceFactory;
219 FRIEND_TEST_ALL_PREFIXES(SingleClientSupervisedUserSettingsSyncTest, Sanity); 229 FRIEND_TEST_ALL_PREFIXES(SingleClientSupervisedUserSettingsSyncTest, Sanity);
220 FRIEND_TEST_ALL_PREFIXES(SupervisedUserServiceTest, ClearOmitOnRegistration); 230 FRIEND_TEST_ALL_PREFIXES(SupervisedUserServiceTest, ClearOmitOnRegistration);
221 FRIEND_TEST_ALL_PREFIXES(SupervisedUserServiceExtensionTest, 231 FRIEND_TEST_ALL_PREFIXES(
222 ExtensionManagementPolicyProvider); 232 SupervisedUserServiceExtensionTest,
233 ExtensionManagementPolicyProviderWithoutSUInitiatedInstalls);
234 FRIEND_TEST_ALL_PREFIXES(
235 SupervisedUserServiceExtensionTest,
236 ExtensionManagementPolicyProviderWithSUInitiatedInstalls);
223 237
224 using CreatePermissionRequestCallback = 238 using CreatePermissionRequestCallback =
225 base::Callback<void(PermissionRequestCreator*, const SuccessCallback&)>; 239 base::Callback<void(PermissionRequestCreator*, const SuccessCallback&)>;
226 240
227 // A bridge from the UI thread to the SupervisedUserURLFilters, one of which 241 // A bridge from the UI thread to the SupervisedUserURLFilters, one of which
228 // lives on the IO thread. This class mediates access to them and makes sure 242 // lives on the IO thread. This class mediates access to them and makes sure
229 // they are kept in sync. 243 // they are kept in sync.
230 class URLFilterContext { 244 class URLFilterContext {
231 public: 245 public:
232 URLFilterContext(); 246 URLFilterContext();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 308
295 #if defined(ENABLE_EXTENSIONS) 309 #if defined(ENABLE_EXTENSIONS)
296 // extensions::ManagementPolicy::Provider implementation: 310 // extensions::ManagementPolicy::Provider implementation:
297 std::string GetDebugPolicyProviderName() const override; 311 std::string GetDebugPolicyProviderName() const override;
298 bool UserMayLoad(const extensions::Extension* extension, 312 bool UserMayLoad(const extensions::Extension* extension,
299 base::string16* error) const override; 313 base::string16* error) const override;
300 bool UserMayModifySettings(const extensions::Extension* extension, 314 bool UserMayModifySettings(const extensions::Extension* extension,
301 base::string16* error) const override; 315 base::string16* error) const override;
302 bool MustRemainInstalled(const extensions::Extension* extension, 316 bool MustRemainInstalled(const extensions::Extension* extension,
303 base::string16* error) const override; 317 base::string16* error) const override;
318 bool MustRemainDisabled(const extensions::Extension* extension,
319 extensions::Extension::DisableReason* reason,
320 base::string16* error) const override;
321
322 // extensions::ExtensionRegistryObserver overrides:
323 void OnExtensionInstalled(content::BrowserContext* browser_context,
324 const extensions::Extension* extension,
325 bool is_update) override;
304 326
305 // An extension can be in one of the following states: 327 // An extension can be in one of the following states:
306 // 328 //
307 // FORCED: if it is installed by the custodian. 329 // FORCED: if it is installed by the custodian.
330 // REQUIRE_APPROVAL: if it is installed by the supervised user and
331 // hasn't been approved by the custodian yet.
308 // ALLOWED: Components, Themes, Default extensions ..etc 332 // ALLOWED: Components, Themes, Default extensions ..etc
309 // are generally allowed. Extensions that have been approved by the 333 // are generally allowed. Extensions that have been approved by the
310 // custodian are also allowed. 334 // custodian are also allowed.
311 // BLOCKED: if it is not ALLOWED or FORCED 335 // BLOCKED: if it is not ALLOWED or FORCED
312 // and supervised users initiated installs are disabled. 336 // and supervised users initiated installs are disabled.
313 enum ExtensionState { 337 enum class ExtensionState { FORCED, BLOCKED, ALLOWED, REQUIRE_APPROVAL };
314 EXTENSION_FORCED,
315 EXTENSION_BLOCKED,
316 EXTENSION_ALLOWED
317 };
318 338
319 // Returns the state of an extension whether being FORCED, BLOCK, or ALLOWED 339 // Returns the state of an extension whether being FORCED, BLOCKED, ALLOWED or
320 // from the Supervised User service's point of view. 340 // REQUIRE_APPROVAL from the Supervised User service's point of view.
321 ExtensionState GetExtensionState( 341 ExtensionState GetExtensionState(
322 const extensions::Extension* extension) const; 342 const extensions::Extension& extension) const;
323 343
324 // Extensions helper to SetActive(). 344 // Extensions helper to SetActive().
325 void SetExtensionsActive(); 345 void SetExtensionsActive();
346
347 // Enables/Disables extensions upon change in approved version of the
348 // extension_id.
349 void ChangeExtensionStateIfNecessary(const std::string& extension_id);
350
351 // Updates the map of approved extensions when the corresponding preference
352 // is changed.
353 void UpdateApprovedExtensions();
326 #endif 354 #endif
327 355
328 SupervisedUserSettingsService* GetSettingsService(); 356 SupervisedUserSettingsService* GetSettingsService();
329 357
330 size_t FindEnabledPermissionRequestCreator(size_t start); 358 size_t FindEnabledPermissionRequestCreator(size_t start);
331 void AddPermissionRequestInternal( 359 void AddPermissionRequestInternal(
332 const CreatePermissionRequestCallback& create_request, 360 const CreatePermissionRequestCallback& create_request,
333 const SuccessCallback& callback, 361 const SuccessCallback& callback,
334 size_t index); 362 size_t index);
335 void OnPermissionRequestIssued( 363 void OnPermissionRequestIssued(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 std::vector<NavigationBlockedCallback> navigation_blocked_callbacks_; 432 std::vector<NavigationBlockedCallback> navigation_blocked_callbacks_;
405 433
406 // True only when |Init()| method has been called. 434 // True only when |Init()| method has been called.
407 bool did_init_; 435 bool did_init_;
408 436
409 // True only when |Shutdown()| method has been called. 437 // True only when |Shutdown()| method has been called.
410 bool did_shutdown_; 438 bool did_shutdown_;
411 439
412 URLFilterContext url_filter_context_; 440 URLFilterContext url_filter_context_;
413 441
442 // Stores a map from extension_id -> approved version by the custodian.
443 // It is only relevant for SU-initiated installs.
444 std::map<std::string, base::Version> approved_extensions_map_;
445
414 enum class BlacklistLoadState { 446 enum class BlacklistLoadState {
415 NOT_LOADED, 447 NOT_LOADED,
416 LOAD_STARTED, 448 LOAD_STARTED,
417 LOADED 449 LOADED
418 } blacklist_state_; 450 } blacklist_state_;
419 451
420 SupervisedUserBlacklist blacklist_; 452 SupervisedUserBlacklist blacklist_;
421 std::unique_ptr<FileDownloader> blacklist_downloader_; 453 std::unique_ptr<FileDownloader> blacklist_downloader_;
422 454
423 std::unique_ptr<SupervisedUserWhitelistService> whitelist_service_; 455 std::unique_ptr<SupervisedUserWhitelistService> whitelist_service_;
424 456
425 std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists_; 457 std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists_;
426 458
427 // Used to create permission requests. 459 // Used to create permission requests.
428 ScopedVector<PermissionRequestCreator> permissions_creators_; 460 ScopedVector<PermissionRequestCreator> permissions_creators_;
429 461
430 // Used to report inappropriate URLs to SafeSarch API. 462 // Used to report inappropriate URLs to SafeSarch API.
431 std::unique_ptr<SafeSearchURLReporter> url_reporter_; 463 std::unique_ptr<SafeSearchURLReporter> url_reporter_;
432 464
465 #if defined(ENABLE_EXTENSIONS)
466 ScopedObserver<extensions::ExtensionRegistry,
467 extensions::ExtensionRegistryObserver>
468 registry_observer_;
469 #endif
470
433 base::ObserverList<SupervisedUserServiceObserver> observer_list_; 471 base::ObserverList<SupervisedUserServiceObserver> observer_list_;
434 472
435 // Prevents Sync from running until configuration is complete. 473 // Prevents Sync from running until configuration is complete.
436 std::unique_ptr<sync_driver::SyncSetupInProgressHandle> sync_blocker_; 474 std::unique_ptr<sync_driver::SyncSetupInProgressHandle> sync_blocker_;
437 475
438 base::WeakPtrFactory<SupervisedUserService> weak_ptr_factory_; 476 base::WeakPtrFactory<SupervisedUserService> weak_ptr_factory_;
439 }; 477 };
440 478
441 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_ 479 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698