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 26 matching lines...) Expand all Loading... | |
| 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) |
| 72 public extensions::ManagementPolicy::Provider, | 73 public extensions::ManagementPolicy::Provider, |
| 73 #endif | 74 #endif |
| 74 public SyncTypePreferenceProvider, | 75 public SyncTypePreferenceProvider, |
| 75 #if !defined(OS_ANDROID) | 76 #if !defined(OS_ANDROID) |
| 76 public sync_driver::SyncServiceObserver, | 77 public sync_driver::SyncServiceObserver, |
| 77 public chrome::BrowserListObserver, | 78 public chrome::BrowserListObserver, |
| 78 #endif | 79 #endif |
| 79 public SupervisedUserURLFilter::Observer { | 80 public SupervisedUserURLFilter::Observer, |
| 81 public extensions::ExtensionRegistryObserver { | |
|
Marc Treib
2016/06/03 13:24:14
This should go into the ENABLE_EXTENSIONS above
mamir
2016/06/06 15:01:37
Done.
| |
| 80 public: | 82 public: |
| 81 using NavigationBlockedCallback = base::Callback<void(content::WebContents*)>; | 83 using NavigationBlockedCallback = base::Callback<void(content::WebContents*)>; |
| 82 using AuthErrorCallback = base::Callback<void(const GoogleServiceAuthError&)>; | 84 using AuthErrorCallback = base::Callback<void(const GoogleServiceAuthError&)>; |
| 83 using SuccessCallback = base::Callback<void(bool)>; | 85 using SuccessCallback = base::Callback<void(bool)>; |
| 84 | 86 |
| 85 class Delegate { | 87 class Delegate { |
| 86 public: | 88 public: |
| 87 virtual ~Delegate() {} | 89 virtual ~Delegate() {} |
| 88 // Returns true to indicate that the delegate handled the (de)activation, or | 90 // Returns true to indicate that the delegate handled the (de)activation, or |
| 89 // false to indicate that the SupervisedUserService itself should handle it. | 91 // false to indicate that the SupervisedUserService itself should handle it. |
| (...skipping 28 matching lines...) Expand all 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_. | |
| 155 void UpdateApprovedVersion(const std::string& extension_id, | |
|
Marc Treib
2016/06/03 13:24:14
UpdateApprovedExtensionVersion?
mamir
2016/06/06 15:01:37
Done.
| |
| 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 // 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(); |
| 303 #endif | 340 #endif |
| 304 | 341 |
| 305 SupervisedUserSettingsService* GetSettingsService(); | 342 SupervisedUserSettingsService* GetSettingsService(); |
| 306 | 343 |
| 307 size_t FindEnabledPermissionRequestCreator(size_t start); | 344 size_t FindEnabledPermissionRequestCreator(size_t start); |
| 308 void AddPermissionRequestInternal( | 345 void AddPermissionRequestInternal( |
| 309 const CreatePermissionRequestCallback& create_request, | 346 const CreatePermissionRequestCallback& create_request, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 void UpdateBlacklist(); | 382 void UpdateBlacklist(); |
| 346 | 383 |
| 347 // Updates the manual overrides for hosts in the URL filters when the | 384 // Updates the manual overrides for hosts in the URL filters when the |
| 348 // corresponding preference is changed. | 385 // corresponding preference is changed. |
| 349 void UpdateManualHosts(); | 386 void UpdateManualHosts(); |
| 350 | 387 |
| 351 // Updates the manual overrides for URLs in the URL filters when the | 388 // Updates the manual overrides for URLs in the URL filters when the |
| 352 // corresponding preference is changed. | 389 // corresponding preference is changed. |
| 353 void UpdateManualURLs(); | 390 void UpdateManualURLs(); |
| 354 | 391 |
| 392 // Updates the map of approved extensions when the corresponding preference | |
| 393 // is changed. | |
| 394 void UpdateApprovedExtensions(); | |
| 395 | |
| 396 // Checks the disable reasons and enables the extension if possible. | |
| 397 void EnableExtensionIfPossible(const std::string& extension_id); | |
| 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 |
| 407 // extensions::ExtensionRegistryObserver overrides: | |
| 408 void OnExtensionInstalled(content::BrowserContext* browser_context, | |
|
Marc Treib
2016/06/03 13:24:14
This should go into the ENABLE_EXTENSIONS above; E
mamir
2016/06/06 15:01:37
Done.
| |
| 409 const extensions::Extension* extension, | |
| 410 bool is_update) override; | |
| 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 |
| 365 // defaults to true. | 414 // defaults to true. |
| 366 bool includes_sync_sessions_type_; | 415 bool includes_sync_sessions_type_; |
| 367 | 416 |
| 368 // Owns us via the KeyedService mechanism. | 417 // Owns us via the KeyedService mechanism. |
| 369 Profile* profile_; | 418 Profile* profile_; |
| 370 | 419 |
| 371 bool active_; | 420 bool active_; |
| 372 | 421 |
| 373 Delegate* delegate_; | 422 Delegate* delegate_; |
| 374 | 423 |
| 375 PrefChangeRegistrar pref_change_registrar_; | 424 PrefChangeRegistrar pref_change_registrar_; |
| 376 | 425 |
| 377 // True iff we're waiting for the Sync service to be initialized. | 426 // True iff we're waiting for the Sync service to be initialized. |
| 378 bool waiting_for_sync_initialization_; | 427 bool waiting_for_sync_initialization_; |
| 379 bool is_profile_active_; | 428 bool is_profile_active_; |
| 380 | 429 |
| 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 |