Chromium Code Reviews| 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); | 152 |
| 153 // Updates the approved version of the extensions in the | |
| 154 // approved_extensions_map_. | |
|
Marc Treib
2016/06/07 10:27:04
Misleading comment: If it only did that, it wouldn
mamir
2016/06/07 17:00:07
Done.
| |
| 155 void UpdateApprovedExtensionVersion(const std::string& extension_id, | |
| 156 const base::Version& version); | |
| 142 | 157 |
| 143 // Returns the email address of the custodian. | 158 // Returns the email address of the custodian. |
| 144 std::string GetCustodianEmailAddress() const; | 159 std::string GetCustodianEmailAddress() const; |
| 145 | 160 |
| 146 // Returns the name of the custodian, or the email address if the name is | 161 // Returns the name of the custodian, or the email address if the name is |
| 147 // empty. | 162 // empty. |
| 148 std::string GetCustodianName() const; | 163 std::string GetCustodianName() const; |
| 149 | 164 |
| 150 // Returns the email address of the second custodian, or the empty string | 165 // Returns the email address of the second custodian, or the empty string |
| 151 // if there is no second custodian. | 166 // if there is no second custodian. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 #endif // !defined(OS_ANDROID) | 222 #endif // !defined(OS_ANDROID) |
| 208 | 223 |
| 209 // SupervisedUserURLFilter::Observer implementation: | 224 // SupervisedUserURLFilter::Observer implementation: |
| 210 void OnSiteListUpdated() override; | 225 void OnSiteListUpdated() override; |
| 211 | 226 |
| 212 private: | 227 private: |
| 213 friend class SupervisedUserServiceExtensionTestBase; | 228 friend class SupervisedUserServiceExtensionTestBase; |
| 214 friend class SupervisedUserServiceFactory; | 229 friend class SupervisedUserServiceFactory; |
| 215 FRIEND_TEST_ALL_PREFIXES(SingleClientSupervisedUserSettingsSyncTest, Sanity); | 230 FRIEND_TEST_ALL_PREFIXES(SingleClientSupervisedUserSettingsSyncTest, Sanity); |
| 216 FRIEND_TEST_ALL_PREFIXES(SupervisedUserServiceTest, ClearOmitOnRegistration); | 231 FRIEND_TEST_ALL_PREFIXES(SupervisedUserServiceTest, ClearOmitOnRegistration); |
| 217 FRIEND_TEST_ALL_PREFIXES(SupervisedUserServiceExtensionTest, | 232 FRIEND_TEST_ALL_PREFIXES( |
| 218 ExtensionManagementPolicyProvider); | 233 SupervisedUserServiceExtensionTest, |
| 234 ExtensionManagementPolicyProviderWithoutSUInitiatedInstalls); | |
| 235 FRIEND_TEST_ALL_PREFIXES( | |
| 236 SupervisedUserServiceExtensionTest, | |
| 237 ExtensionManagementPolicyProviderWithSUInitiatedInstalls); | |
| 219 | 238 |
| 220 using CreatePermissionRequestCallback = | 239 using CreatePermissionRequestCallback = |
| 221 base::Callback<void(PermissionRequestCreator*, const SuccessCallback&)>; | 240 base::Callback<void(PermissionRequestCreator*, const SuccessCallback&)>; |
| 222 | 241 |
| 223 // A bridge from the UI thread to the SupervisedUserURLFilters, one of which | 242 // 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 | 243 // lives on the IO thread. This class mediates access to them and makes sure |
| 225 // they are kept in sync. | 244 // they are kept in sync. |
| 226 class URLFilterContext { | 245 class URLFilterContext { |
| 227 public: | 246 public: |
| 228 URLFilterContext(); | 247 URLFilterContext(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 | 309 |
| 291 #if defined(ENABLE_EXTENSIONS) | 310 #if defined(ENABLE_EXTENSIONS) |
| 292 // extensions::ManagementPolicy::Provider implementation: | 311 // extensions::ManagementPolicy::Provider implementation: |
| 293 std::string GetDebugPolicyProviderName() const override; | 312 std::string GetDebugPolicyProviderName() const override; |
| 294 bool UserMayLoad(const extensions::Extension* extension, | 313 bool UserMayLoad(const extensions::Extension* extension, |
| 295 base::string16* error) const override; | 314 base::string16* error) const override; |
| 296 bool UserMayModifySettings(const extensions::Extension* extension, | 315 bool UserMayModifySettings(const extensions::Extension* extension, |
| 297 base::string16* error) const override; | 316 base::string16* error) const override; |
| 298 bool MustRemainInstalled(const extensions::Extension* extension, | 317 bool MustRemainInstalled(const extensions::Extension* extension, |
| 299 base::string16* error) const override; | 318 base::string16* error) const override; |
| 319 bool MustRemainDisabled(const extensions::Extension* extension, | |
| 320 extensions::Extension::DisableReason* reason, | |
| 321 base::string16* error) const override; | |
| 322 | |
| 323 // extensions::ExtensionRegistryObserver overrides: | |
| 324 void OnExtensionInstalled(content::BrowserContext* browser_context, | |
| 325 const extensions::Extension* extension, | |
| 326 bool is_update) override; | |
| 327 | |
| 328 // An extension can be in one of the following states: | |
| 329 // | |
| 330 // FORCED: if it is installed by the custodian. | |
| 331 // REQUIRE_APPROVAL: if it is installed by the supervised user and | |
| 332 // hasn't been approved by the custodian yet. | |
| 333 // ALLOWED: Components, Themes, Default extensions ..etc | |
| 334 // are generally allowed. Extensions that have been approved by the | |
| 335 // custodian are also allowed. | |
| 336 // BLOCKED: if it is not ALLOWED or FORCED | |
| 337 // and supervised users initiated installs are disabled. | |
| 338 enum class ExtensionState { FORCED, BLOCKED, ALLOWED, REQUIRE_APPROVAL }; | |
| 339 | |
| 340 ExtensionState GetExtensionState( | |
| 341 const extensions::Extension& extension) const; | |
| 300 | 342 |
| 301 // Extensions helper to SetActive(). | 343 // Extensions helper to SetActive(). |
| 302 void SetExtensionsActive(); | 344 void SetExtensionsActive(); |
| 345 | |
| 346 // Checks the disable reasons and enables the extension if possible. | |
| 347 void EnableExtensionIfPossible(const std::string& extension_id); | |
| 303 #endif | 348 #endif |
| 304 | 349 |
| 305 SupervisedUserSettingsService* GetSettingsService(); | 350 SupervisedUserSettingsService* GetSettingsService(); |
| 306 | 351 |
| 307 size_t FindEnabledPermissionRequestCreator(size_t start); | 352 size_t FindEnabledPermissionRequestCreator(size_t start); |
| 308 void AddPermissionRequestInternal( | 353 void AddPermissionRequestInternal( |
| 309 const CreatePermissionRequestCallback& create_request, | 354 const CreatePermissionRequestCallback& create_request, |
| 310 const SuccessCallback& callback, | 355 const SuccessCallback& callback, |
| 311 size_t index); | 356 size_t index); |
| 312 void OnPermissionRequestIssued( | 357 void OnPermissionRequestIssued( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 void UpdateBlacklist(); | 390 void UpdateBlacklist(); |
| 346 | 391 |
| 347 // Updates the manual overrides for hosts in the URL filters when the | 392 // Updates the manual overrides for hosts in the URL filters when the |
| 348 // corresponding preference is changed. | 393 // corresponding preference is changed. |
| 349 void UpdateManualHosts(); | 394 void UpdateManualHosts(); |
| 350 | 395 |
| 351 // Updates the manual overrides for URLs in the URL filters when the | 396 // Updates the manual overrides for URLs in the URL filters when the |
| 352 // corresponding preference is changed. | 397 // corresponding preference is changed. |
| 353 void UpdateManualURLs(); | 398 void UpdateManualURLs(); |
| 354 | 399 |
| 400 // Updates the map of approved extensions when the corresponding preference | |
| 401 // is changed. | |
| 402 void UpdateApprovedExtensions(); | |
| 403 | |
| 355 // Returns the human readable name of the supervised user. | 404 // Returns the human readable name of the supervised user. |
| 356 std::string GetSupervisedUserName() const; | 405 std::string GetSupervisedUserName() const; |
| 357 | 406 |
| 358 // Subscribes to the SupervisedUserPrefStore, refreshes | 407 // Subscribes to the SupervisedUserPrefStore, refreshes |
| 359 // |includes_sync_sessions_type_| and triggers reconfiguring the | 408 // |includes_sync_sessions_type_| and triggers reconfiguring the |
| 360 // ProfileSyncService. | 409 // ProfileSyncService. |
| 361 void OnForceSessionSyncChanged(); | 410 void OnForceSessionSyncChanged(); |
| 362 | 411 |
| 363 // The option a custodian sets to either record or prevent recording the | 412 // The option a custodian sets to either record or prevent recording the |
| 364 // supervised user's history. Set by |FetchNewSessionSyncState()| and | 413 // supervised user's history. Set by |FetchNewSessionSyncState()| and |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 381 std::vector<NavigationBlockedCallback> navigation_blocked_callbacks_; | 430 std::vector<NavigationBlockedCallback> navigation_blocked_callbacks_; |
| 382 | 431 |
| 383 // True only when |Init()| method has been called. | 432 // True only when |Init()| method has been called. |
| 384 bool did_init_; | 433 bool did_init_; |
| 385 | 434 |
| 386 // True only when |Shutdown()| method has been called. | 435 // True only when |Shutdown()| method has been called. |
| 387 bool did_shutdown_; | 436 bool did_shutdown_; |
| 388 | 437 |
| 389 URLFilterContext url_filter_context_; | 438 URLFilterContext url_filter_context_; |
| 390 | 439 |
| 440 // Stores a map from extension_id -> approved version by the custodian. | |
| 441 // It is only relevant for SU-initiated installs. | |
| 442 std::map<std::string, base::Version> approved_extensions_map_; | |
| 443 | |
| 391 enum class BlacklistLoadState { | 444 enum class BlacklistLoadState { |
| 392 NOT_LOADED, | 445 NOT_LOADED, |
| 393 LOAD_STARTED, | 446 LOAD_STARTED, |
| 394 LOADED | 447 LOADED |
| 395 } blacklist_state_; | 448 } blacklist_state_; |
| 396 | 449 |
| 397 SupervisedUserBlacklist blacklist_; | 450 SupervisedUserBlacklist blacklist_; |
| 398 std::unique_ptr<FileDownloader> blacklist_downloader_; | 451 std::unique_ptr<FileDownloader> blacklist_downloader_; |
| 399 | 452 |
| 400 std::unique_ptr<SupervisedUserWhitelistService> whitelist_service_; | 453 std::unique_ptr<SupervisedUserWhitelistService> whitelist_service_; |
| 401 | 454 |
| 402 std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists_; | 455 std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists_; |
| 403 | 456 |
| 404 // Used to create permission requests. | 457 // Used to create permission requests. |
| 405 ScopedVector<PermissionRequestCreator> permissions_creators_; | 458 ScopedVector<PermissionRequestCreator> permissions_creators_; |
| 406 | 459 |
| 407 // Used to report inappropriate URLs to SafeSarch API. | 460 // Used to report inappropriate URLs to SafeSarch API. |
| 408 std::unique_ptr<SafeSearchURLReporter> url_reporter_; | 461 std::unique_ptr<SafeSearchURLReporter> url_reporter_; |
| 409 | 462 |
| 410 base::ObserverList<SupervisedUserServiceObserver> observer_list_; | 463 base::ObserverList<SupervisedUserServiceObserver> observer_list_; |
| 411 | 464 |
| 412 base::WeakPtrFactory<SupervisedUserService> weak_ptr_factory_; | 465 base::WeakPtrFactory<SupervisedUserService> weak_ptr_factory_; |
| 413 }; | 466 }; |
| 414 | 467 |
| 415 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_ | 468 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_ |
| OLD | NEW |