| OLD | NEW |
| 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 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/browser/net/file_downloader.h" | 23 #include "chrome/browser/net/file_downloader.h" |
| 24 #include "chrome/browser/supervised_user/experimental/safe_search_url_reporter.h
" | 24 #include "chrome/browser/supervised_user/experimental/safe_search_url_reporter.h
" |
| 25 #include "chrome/browser/supervised_user/experimental/supervised_user_blacklist.
h" | 25 #include "chrome/browser/supervised_user/experimental/supervised_user_blacklist.
h" |
| 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 "extensions/browser/extension_registry_observer.h" |
| 33 #include "net/url_request/url_request_context_getter.h" | 34 #include "net/url_request/url_request_context_getter.h" |
| 34 | 35 |
| 35 #if defined(ENABLE_EXTENSIONS) | 36 #if defined(ENABLE_EXTENSIONS) |
| 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; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 62 | 63 |
| 63 namespace user_prefs { | 64 namespace user_prefs { |
| 64 class PrefRegistrySyncable; | 65 class PrefRegistrySyncable; |
| 65 } | 66 } |
| 66 | 67 |
| 67 // This class handles all the information related to a given supervised profile | 68 // This class handles all the information related to a given supervised profile |
| 68 // (e.g. the installed content packs, the default URL filtering behavior, or | 69 // (e.g. the installed content packs, the default URL filtering behavior, or |
| 69 // manual whitelist/blacklist overrides). | 70 // manual whitelist/blacklist overrides). |
| 70 class SupervisedUserService : public KeyedService, | 71 class SupervisedUserService : public KeyedService, |
| 71 #if defined(ENABLE_EXTENSIONS) | 72 #if defined(ENABLE_EXTENSIONS) |
| 73 public extensions::ExtensionRegistryObserver, |
| 72 public extensions::ManagementPolicy::Provider, | 74 public extensions::ManagementPolicy::Provider, |
| 73 #endif | 75 #endif |
| 74 public SyncTypePreferenceProvider, | 76 public SyncTypePreferenceProvider, |
| 75 #if !defined(OS_ANDROID) | 77 #if !defined(OS_ANDROID) |
| 76 public sync_driver::SyncServiceObserver, | 78 public sync_driver::SyncServiceObserver, |
| 77 public chrome::BrowserListObserver, | 79 public chrome::BrowserListObserver, |
| 78 #endif | 80 #endif |
| 79 public SupervisedUserURLFilter::Observer { | 81 public SupervisedUserURLFilter::Observer { |
| 80 public: | 82 public: |
| 81 using NavigationBlockedCallback = base::Callback<void(content::WebContents*)>; | 83 using NavigationBlockedCallback = base::Callback<void(content::WebContents*)>; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // extensions. | 120 // extensions. |
| 119 bool AccessRequestsEnabled(); | 121 bool AccessRequestsEnabled(); |
| 120 | 122 |
| 121 // Adds an access request for the given URL. | 123 // Adds an access request for the given URL. |
| 122 void AddURLAccessRequest(const GURL& url, const SuccessCallback& callback); | 124 void AddURLAccessRequest(const GURL& url, const SuccessCallback& callback); |
| 123 | 125 |
| 124 // Reports |url| to the SafeSearch API, because the user thinks this is an | 126 // Reports |url| to the SafeSearch API, because the user thinks this is an |
| 125 // inappropriate URL. | 127 // inappropriate URL. |
| 126 void ReportURL(const GURL& url, const SuccessCallback& callback); | 128 void ReportURL(const GURL& url, const SuccessCallback& callback); |
| 127 | 129 |
| 130 // Adds an install request for the given WebStore item (App/Extension). |
| 131 void AddExtensionInstallRequest(const std::string& extension_id, |
| 132 const base::Version& version, |
| 133 const SuccessCallback& callback); |
| 134 |
| 135 // Same as above, but without a callback, just logging errors on failure. |
| 136 void AddExtensionInstallRequest(const std::string& extension_id, |
| 137 const base::Version& version); |
| 138 |
| 128 // Adds an update request for the given WebStore item (App/Extension). | 139 // Adds an update request for the given WebStore item (App/Extension). |
| 129 void AddExtensionUpdateRequest(const std::string& extension_id, | 140 void AddExtensionUpdateRequest(const std::string& extension_id, |
| 130 const base::Version& version, | 141 const base::Version& version, |
| 131 const SuccessCallback& callback); | 142 const SuccessCallback& callback); |
| 132 | 143 |
| 133 // Same as above, but without a callback, just logging errors on failure. | 144 // Same as above, but without a callback, just logging errors on failure. |
| 134 void AddExtensionUpdateRequest(const std::string& extension_id, | 145 void AddExtensionUpdateRequest(const std::string& extension_id, |
| 135 const base::Version& version); | 146 const base::Version& version); |
| 136 | 147 |
| 137 // Get the string used to identify an extension update request. Public for | 148 // Get the string used to identify an extension install or update request. |
| 138 // testing. | 149 // Public for testing. |
| 139 static std::string GetExtensionUpdateRequestId( | 150 static std::string GetExtensionRequestId(const std::string& extension_id, |
| 140 const std::string& extension_id, | 151 const base::Version& version); |
| 141 const base::Version& version); | |
| 142 | 152 |
| 143 // Returns the email address of the custodian. | 153 // Returns the email address of the custodian. |
| 144 std::string GetCustodianEmailAddress() const; | 154 std::string GetCustodianEmailAddress() const; |
| 145 | 155 |
| 146 // Returns the name of the custodian, or the email address if the name is | 156 // Returns the name of the custodian, or the email address if the name is |
| 147 // empty. | 157 // empty. |
| 148 std::string GetCustodianName() const; | 158 std::string GetCustodianName() const; |
| 149 | 159 |
| 150 // Returns the email address of the second custodian, or the empty string | 160 // Returns the email address of the second custodian, or the empty string |
| 151 // if there is no second custodian. | 161 // if there is no second custodian. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 #endif // !defined(OS_ANDROID) | 217 #endif // !defined(OS_ANDROID) |
| 208 | 218 |
| 209 // SupervisedUserURLFilter::Observer implementation: | 219 // SupervisedUserURLFilter::Observer implementation: |
| 210 void OnSiteListUpdated() override; | 220 void OnSiteListUpdated() override; |
| 211 | 221 |
| 212 private: | 222 private: |
| 213 friend class SupervisedUserServiceExtensionTestBase; | 223 friend class SupervisedUserServiceExtensionTestBase; |
| 214 friend class SupervisedUserServiceFactory; | 224 friend class SupervisedUserServiceFactory; |
| 215 FRIEND_TEST_ALL_PREFIXES(SingleClientSupervisedUserSettingsSyncTest, Sanity); | 225 FRIEND_TEST_ALL_PREFIXES(SingleClientSupervisedUserSettingsSyncTest, Sanity); |
| 216 FRIEND_TEST_ALL_PREFIXES(SupervisedUserServiceTest, ClearOmitOnRegistration); | 226 FRIEND_TEST_ALL_PREFIXES(SupervisedUserServiceTest, ClearOmitOnRegistration); |
| 217 FRIEND_TEST_ALL_PREFIXES(SupervisedUserServiceExtensionTest, | 227 FRIEND_TEST_ALL_PREFIXES( |
| 218 ExtensionManagementPolicyProvider); | 228 SupervisedUserServiceExtensionTest, |
| 229 ExtensionManagementPolicyProviderWithoutSUInitiatedInstalls); |
| 230 FRIEND_TEST_ALL_PREFIXES( |
| 231 SupervisedUserServiceExtensionTest, |
| 232 ExtensionManagementPolicyProviderWithSUInitiatedInstalls); |
| 219 | 233 |
| 220 using CreatePermissionRequestCallback = | 234 using CreatePermissionRequestCallback = |
| 221 base::Callback<void(PermissionRequestCreator*, const SuccessCallback&)>; | 235 base::Callback<void(PermissionRequestCreator*, const SuccessCallback&)>; |
| 222 | 236 |
| 223 // A bridge from the UI thread to the SupervisedUserURLFilters, one of which | 237 // A bridge from the UI thread to the SupervisedUserURLFilters, one of which |
| 224 // lives on the IO thread. This class mediates access to them and makes sure | 238 // lives on the IO thread. This class mediates access to them and makes sure |
| 225 // they are kept in sync. | 239 // they are kept in sync. |
| 226 class URLFilterContext { | 240 class URLFilterContext { |
| 227 public: | 241 public: |
| 228 URLFilterContext(); | 242 URLFilterContext(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 | 304 |
| 291 #if defined(ENABLE_EXTENSIONS) | 305 #if defined(ENABLE_EXTENSIONS) |
| 292 // extensions::ManagementPolicy::Provider implementation: | 306 // extensions::ManagementPolicy::Provider implementation: |
| 293 std::string GetDebugPolicyProviderName() const override; | 307 std::string GetDebugPolicyProviderName() const override; |
| 294 bool UserMayLoad(const extensions::Extension* extension, | 308 bool UserMayLoad(const extensions::Extension* extension, |
| 295 base::string16* error) const override; | 309 base::string16* error) const override; |
| 296 bool UserMayModifySettings(const extensions::Extension* extension, | 310 bool UserMayModifySettings(const extensions::Extension* extension, |
| 297 base::string16* error) const override; | 311 base::string16* error) const override; |
| 298 bool MustRemainInstalled(const extensions::Extension* extension, | 312 bool MustRemainInstalled(const extensions::Extension* extension, |
| 299 base::string16* error) const override; | 313 base::string16* error) const override; |
| 314 bool MustRemainDisabled(const extensions::Extension* extension, |
| 315 extensions::Extension::DisableReason* reason, |
| 316 base::string16* error) const override; |
| 317 |
| 318 // extensions::ExtensionRegistryObserver overrides: |
| 319 void OnExtensionInstalled(content::BrowserContext* browser_context, |
| 320 const extensions::Extension* extension, |
| 321 bool is_update) override; |
| 322 |
| 323 // An extension can be in one of the following states: |
| 324 // |
| 325 // FORCED: if it is installed by the custodian. |
| 326 // REQUIRE_APPROVAL: if it is installed by the supervised user and |
| 327 // hasn't been approved by the custodian yet. |
| 328 // ALLOWED: Components, Themes, Default extensions ..etc |
| 329 // are generally allowed. Extensions that have been approved by the |
| 330 // custodian are also allowed. |
| 331 // BLOCKED: if it is not ALLOWED or FORCED |
| 332 // and supervised users initiated installs are disabled. |
| 333 enum class ExtensionState { FORCED, BLOCKED, ALLOWED, REQUIRE_APPROVAL }; |
| 334 |
| 335 ExtensionState GetExtensionState( |
| 336 const extensions::Extension& extension) const; |
| 300 | 337 |
| 301 // Extensions helper to SetActive(). | 338 // Extensions helper to SetActive(). |
| 302 void SetExtensionsActive(); | 339 void SetExtensionsActive(); |
| 340 |
| 341 // Checks the disable reasons and enables the extension if possible. |
| 342 void EnableExtensionIfPossible(const std::string& extension_id); |
| 303 #endif | 343 #endif |
| 304 | 344 |
| 305 SupervisedUserSettingsService* GetSettingsService(); | 345 SupervisedUserSettingsService* GetSettingsService(); |
| 306 | 346 |
| 307 size_t FindEnabledPermissionRequestCreator(size_t start); | 347 size_t FindEnabledPermissionRequestCreator(size_t start); |
| 308 void AddPermissionRequestInternal( | 348 void AddPermissionRequestInternal( |
| 309 const CreatePermissionRequestCallback& create_request, | 349 const CreatePermissionRequestCallback& create_request, |
| 310 const SuccessCallback& callback, | 350 const SuccessCallback& callback, |
| 311 size_t index); | 351 size_t index); |
| 312 void OnPermissionRequestIssued( | 352 void OnPermissionRequestIssued( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 void UpdateBlacklist(); | 385 void UpdateBlacklist(); |
| 346 | 386 |
| 347 // Updates the manual overrides for hosts in the URL filters when the | 387 // Updates the manual overrides for hosts in the URL filters when the |
| 348 // corresponding preference is changed. | 388 // corresponding preference is changed. |
| 349 void UpdateManualHosts(); | 389 void UpdateManualHosts(); |
| 350 | 390 |
| 351 // Updates the manual overrides for URLs in the URL filters when the | 391 // Updates the manual overrides for URLs in the URL filters when the |
| 352 // corresponding preference is changed. | 392 // corresponding preference is changed. |
| 353 void UpdateManualURLs(); | 393 void UpdateManualURLs(); |
| 354 | 394 |
| 395 // Updates the map of approved extensions when the corresponding preference |
| 396 // is changed. |
| 397 void UpdateApprovedExtensions(); |
| 398 |
| 355 // Returns the human readable name of the supervised user. | 399 // Returns the human readable name of the supervised user. |
| 356 std::string GetSupervisedUserName() const; | 400 std::string GetSupervisedUserName() const; |
| 357 | 401 |
| 358 // Subscribes to the SupervisedUserPrefStore, refreshes | 402 // Subscribes to the SupervisedUserPrefStore, refreshes |
| 359 // |includes_sync_sessions_type_| and triggers reconfiguring the | 403 // |includes_sync_sessions_type_| and triggers reconfiguring the |
| 360 // ProfileSyncService. | 404 // ProfileSyncService. |
| 361 void OnForceSessionSyncChanged(); | 405 void OnForceSessionSyncChanged(); |
| 362 | 406 |
| 363 // The option a custodian sets to either record or prevent recording the | 407 // The option a custodian sets to either record or prevent recording the |
| 364 // supervised user's history. Set by |FetchNewSessionSyncState()| and | 408 // supervised user's history. Set by |FetchNewSessionSyncState()| and |
| (...skipping 16 matching lines...) Expand all Loading... |
| 381 std::vector<NavigationBlockedCallback> navigation_blocked_callbacks_; | 425 std::vector<NavigationBlockedCallback> navigation_blocked_callbacks_; |
| 382 | 426 |
| 383 // True only when |Init()| method has been called. | 427 // True only when |Init()| method has been called. |
| 384 bool did_init_; | 428 bool did_init_; |
| 385 | 429 |
| 386 // True only when |Shutdown()| method has been called. | 430 // True only when |Shutdown()| method has been called. |
| 387 bool did_shutdown_; | 431 bool did_shutdown_; |
| 388 | 432 |
| 389 URLFilterContext url_filter_context_; | 433 URLFilterContext url_filter_context_; |
| 390 | 434 |
| 435 // Stores a map from extension_id -> approved version by the custodian. |
| 436 // It is only relevant for SU-initiated installs. |
| 437 std::map<std::string, base::Version> approved_extensions_map_; |
| 438 |
| 391 enum class BlacklistLoadState { | 439 enum class BlacklistLoadState { |
| 392 NOT_LOADED, | 440 NOT_LOADED, |
| 393 LOAD_STARTED, | 441 LOAD_STARTED, |
| 394 LOADED | 442 LOADED |
| 395 } blacklist_state_; | 443 } blacklist_state_; |
| 396 | 444 |
| 397 SupervisedUserBlacklist blacklist_; | 445 SupervisedUserBlacklist blacklist_; |
| 398 std::unique_ptr<FileDownloader> blacklist_downloader_; | 446 std::unique_ptr<FileDownloader> blacklist_downloader_; |
| 399 | 447 |
| 400 std::unique_ptr<SupervisedUserWhitelistService> whitelist_service_; | 448 std::unique_ptr<SupervisedUserWhitelistService> whitelist_service_; |
| 401 | 449 |
| 402 std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists_; | 450 std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists_; |
| 403 | 451 |
| 404 // Used to create permission requests. | 452 // Used to create permission requests. |
| 405 ScopedVector<PermissionRequestCreator> permissions_creators_; | 453 ScopedVector<PermissionRequestCreator> permissions_creators_; |
| 406 | 454 |
| 407 // Used to report inappropriate URLs to SafeSarch API. | 455 // Used to report inappropriate URLs to SafeSarch API. |
| 408 std::unique_ptr<SafeSearchURLReporter> url_reporter_; | 456 std::unique_ptr<SafeSearchURLReporter> url_reporter_; |
| 409 | 457 |
| 458 #if defined(ENABLE_EXTENSIONS) |
| 459 ScopedObserver<extensions::ExtensionRegistry, |
| 460 extensions::ExtensionRegistryObserver> |
| 461 registry_observer_; |
| 462 #endif |
| 463 |
| 410 base::ObserverList<SupervisedUserServiceObserver> observer_list_; | 464 base::ObserverList<SupervisedUserServiceObserver> observer_list_; |
| 411 | 465 |
| 412 base::WeakPtrFactory<SupervisedUserService> weak_ptr_factory_; | 466 base::WeakPtrFactory<SupervisedUserService> weak_ptr_factory_; |
| 413 }; | 467 }; |
| 414 | 468 |
| 415 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_ | 469 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_ |
| OLD | NEW |