[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_ |
| 6 | #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_ |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 7 | |
avi | 664c07b | 2015-12-26 02:18:31 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | |
treib | 950c6e8 | 2014-09-23 13:07:29 | [diff] [blame] | 10 | #include <map> |
dcheng | f624e47 | 2016-04-12 08:33:17 | [diff] [blame] | 11 | #include <memory> |
treib | 950c6e8 | 2014-09-23 13:07:29 | [diff] [blame] | 12 | #include <string> |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 13 | #include <vector> |
| 14 | |
[email protected] | 438f7e1 | 2013-08-07 06:59:00 | [diff] [blame] | 15 | #include "base/callback.h" |
[email protected] | 076ebeda | 2014-06-06 21:47:26 | [diff] [blame] | 16 | #include "base/gtest_prod_util.h" |
avi | 664c07b | 2015-12-26 02:18:31 | [diff] [blame] | 17 | #include "base/macros.h" |
thestig | 7790a35 | 2015-08-22 00:05:11 | [diff] [blame] | 18 | #include "base/memory/scoped_vector.h" |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 19 | #include "base/observer_list.h" |
[email protected] | f2253ac | 2014-05-28 08:37:21 | [diff] [blame] | 20 | #include "base/scoped_observer.h" |
[email protected] | f9b29436 | 2013-06-10 20:22:31 | [diff] [blame] | 21 | #include "base/strings/string16.h" |
avi | 664c07b | 2015-12-26 02:18:31 | [diff] [blame] | 22 | #include "build/build_config.h" |
treib | f38cc25 | 2016-04-07 14:44:11 | [diff] [blame] | 23 | #include "chrome/browser/net/file_downloader.h" |
atanasova | ac67603 | 2016-04-05 16:31:05 | [diff] [blame] | 24 | #include "chrome/browser/supervised_user/experimental/safe_search_url_reporter.h" |
treib | 4edbded | 2014-09-05 08:43:55 | [diff] [blame] | 25 | #include "chrome/browser/supervised_user/experimental/supervised_user_blacklist.h" |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 26 | #include "chrome/browser/supervised_user/supervised_user_url_filter.h" |
| 27 | #include "chrome/browser/supervised_user/supervised_users.h" |
[email protected] | 514fcf2 | 2013-08-13 06:37:24 | [diff] [blame] | 28 | #include "chrome/browser/ui/browser_list_observer.h" |
[email protected] | 12b7af3 | 2014-03-13 05:28:20 | [diff] [blame] | 29 | #include "components/keyed_service/core/keyed_service.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 30 | #include "components/prefs/pref_change_registrar.h" |
maxbogue | 455a57e3 | 2016-08-14 00:08:32 | [diff] [blame] | 31 | #include "components/sync/driver/sync_service_observer.h" |
| 32 | #include "components/sync/driver/sync_type_preference_provider.h" |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame^] | 33 | #include "extensions/features/features.h" |
maxbogue | 8e4fb45 | 2015-02-11 20:26:09 | [diff] [blame] | 34 | #include "net/url_request/url_request_context_getter.h" |
[email protected] | c14a680 | 2014-07-11 21:51:12 | [diff] [blame] | 35 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame^] | 36 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
mamir | e960964 | 2016-06-28 22:17:54 | [diff] [blame] | 37 | #include "extensions/browser/extension_registry_observer.h" |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 38 | #include "extensions/browser/management_policy.h" |
[email protected] | c14a680 | 2014-07-11 21:51:12 | [diff] [blame] | 39 | #endif |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 40 | |
[email protected] | 509ad1a9 | 2013-03-19 21:41:06 | [diff] [blame] | 41 | class Browser; |
[email protected] | acfcfbb | 2013-05-13 18:01:27 | [diff] [blame] | 42 | class GoogleServiceAuthError; |
[email protected] | 4db65f95 | 2014-05-20 15:46:30 | [diff] [blame] | 43 | class PermissionRequestCreator; |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 44 | class Profile; |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 45 | class SupervisedUserRegistrationUtility; |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 46 | class SupervisedUserServiceObserver; |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 47 | class SupervisedUserSettingsService; |
| 48 | class SupervisedUserSiteList; |
| 49 | class SupervisedUserURLFilter; |
bauerb | 4da3613 | 2014-12-26 19:53:13 | [diff] [blame] | 50 | class SupervisedUserWhitelistService; |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 51 | |
treib | daece84f | 2014-09-05 12:58:15 | [diff] [blame] | 52 | namespace base { |
| 53 | class FilePath; |
treib | f832a99 | 2015-03-24 18:09:24 | [diff] [blame] | 54 | class Version; |
treib | daece84f | 2014-09-05 12:58:15 | [diff] [blame] | 55 | } |
| 56 | |
treib | 565a019 | 2014-12-04 13:17:31 | [diff] [blame] | 57 | namespace content { |
| 58 | class WebContents; |
| 59 | } |
| 60 | |
[email protected] | f2253ac | 2014-05-28 08:37:21 | [diff] [blame] | 61 | namespace extensions { |
| 62 | class ExtensionRegistry; |
| 63 | } |
| 64 | |
maxbogue | 7e006db | 2016-10-03 19:48:28 | [diff] [blame] | 65 | namespace syncer { |
tommycli | f3a1551e | 2016-06-21 18:11:23 | [diff] [blame] | 66 | class SyncSetupInProgressHandle; |
| 67 | } |
| 68 | |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 69 | namespace user_prefs { |
| 70 | class PrefRegistrySyncable; |
| 71 | } |
| 72 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 73 | // This class handles all the information related to a given supervised profile |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 74 | // (e.g. the installed content packs, the default URL filtering behavior, or |
| 75 | // manual whitelist/blacklist overrides). |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 76 | class SupervisedUserService : public KeyedService, |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame^] | 77 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
mamir | e960964 | 2016-06-28 22:17:54 | [diff] [blame] | 78 | public extensions::ExtensionRegistryObserver, |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 79 | public extensions::ManagementPolicy::Provider, |
[email protected] | c14a680 | 2014-07-11 21:51:12 | [diff] [blame] | 80 | #endif |
maxbogue | 7e006db | 2016-10-03 19:48:28 | [diff] [blame] | 81 | public syncer::SyncTypePreferenceProvider, |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame] | 82 | #if !defined(OS_ANDROID) |
maxbogue | 7e006db | 2016-10-03 19:48:28 | [diff] [blame] | 83 | public syncer::SyncServiceObserver, |
bauerb | ce9a1a8 | 2014-12-18 13:34:24 | [diff] [blame] | 84 | public chrome::BrowserListObserver, |
bauerb | 5f8cda9 | 2015-10-07 15:36:44 | [diff] [blame] | 85 | #endif |
bauerb | ce9a1a8 | 2014-12-18 13:34:24 | [diff] [blame] | 86 | public SupervisedUserURLFilter::Observer { |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 87 | public: |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 88 | using NavigationBlockedCallback = base::Callback<void(content::WebContents*)>; |
| 89 | using AuthErrorCallback = base::Callback<void(const GoogleServiceAuthError&)>; |
| 90 | using SuccessCallback = base::Callback<void(bool)>; |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 91 | |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 92 | class Delegate { |
| 93 | public: |
| 94 | virtual ~Delegate() {} |
| 95 | // Returns true to indicate that the delegate handled the (de)activation, or |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 96 | // false to indicate that the SupervisedUserService itself should handle it. |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 97 | virtual bool SetActive(bool active) = 0; |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 98 | }; |
| 99 | |
dcheng | c072fff | 2014-10-21 11:39:05 | [diff] [blame] | 100 | ~SupervisedUserService() override; |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 101 | |
[email protected] | 37ca3fe0 | 2013-07-05 15:32:44 | [diff] [blame] | 102 | static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 103 | |
bauerb | 5f8cda9 | 2015-10-07 15:36:44 | [diff] [blame] | 104 | // Initializes this object. |
| 105 | void Init(); |
| 106 | |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 107 | void SetDelegate(Delegate* delegate); |
| 108 | |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 109 | // Returns the URL filter for the IO thread, for filtering network requests |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 110 | // (in SupervisedUserResourceThrottle). |
| 111 | scoped_refptr<const SupervisedUserURLFilter> GetURLFilterForIOThread(); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 112 | |
| 113 | // Returns the URL filter for the UI thread, for filtering navigations and |
| 114 | // classifying sites in the history view. |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 115 | SupervisedUserURLFilter* GetURLFilterForUIThread(); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 116 | |
bauerb | 4da3613 | 2014-12-26 19:53:13 | [diff] [blame] | 117 | // Returns the whitelist service. |
| 118 | SupervisedUserWhitelistService* GetWhitelistService(); |
| 119 | |
atanasova | 9572aaf | 2016-02-26 18:08:26 | [diff] [blame] | 120 | const std::vector<scoped_refptr<SupervisedUserSiteList>>& whitelists() const { |
| 121 | return whitelists_; |
| 122 | } |
| 123 | |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 124 | // Whether the user can request to get access to blocked URLs or to new |
| 125 | // extensions. |
[email protected] | 0369d6ab | 2013-08-09 01:52:59 | [diff] [blame] | 126 | bool AccessRequestsEnabled(); |
| 127 | |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 128 | // Adds an access request for the given URL. |
| 129 | void AddURLAccessRequest(const GURL& url, const SuccessCallback& callback); |
| 130 | |
atanasova | ac67603 | 2016-04-05 16:31:05 | [diff] [blame] | 131 | // Reports |url| to the SafeSearch API, because the user thinks this is an |
| 132 | // inappropriate URL. |
| 133 | void ReportURL(const GURL& url, const SuccessCallback& callback); |
| 134 | |
mamir | e960964 | 2016-06-28 22:17:54 | [diff] [blame] | 135 | // Adds an install request for the given WebStore item (App/Extension). |
| 136 | void AddExtensionInstallRequest(const std::string& extension_id, |
| 137 | const base::Version& version, |
| 138 | const SuccessCallback& callback); |
| 139 | |
| 140 | // Same as above, but without a callback, just logging errors on failure. |
| 141 | void AddExtensionInstallRequest(const std::string& extension_id, |
| 142 | const base::Version& version); |
| 143 | |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 144 | // Adds an update request for the given WebStore item (App/Extension). |
| 145 | void AddExtensionUpdateRequest(const std::string& extension_id, |
treib | f832a99 | 2015-03-24 18:09:24 | [diff] [blame] | 146 | const base::Version& version, |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 147 | const SuccessCallback& callback); |
[email protected] | e861bba | 2013-06-17 15:20:54 | [diff] [blame] | 148 | |
treib | 40d3ad9 | 2015-10-20 18:15:42 | [diff] [blame] | 149 | // Same as above, but without a callback, just logging errors on failure. |
| 150 | void AddExtensionUpdateRequest(const std::string& extension_id, |
| 151 | const base::Version& version); |
| 152 | |
mamir | e960964 | 2016-06-28 22:17:54 | [diff] [blame] | 153 | // Get the string used to identify an extension install or update request. |
| 154 | // Public for testing. |
| 155 | static std::string GetExtensionRequestId(const std::string& extension_id, |
| 156 | const base::Version& version); |
treib | 40d3ad9 | 2015-10-20 18:15:42 | [diff] [blame] | 157 | |
[email protected] | a9c2d64 | 2013-05-31 14:37:14 | [diff] [blame] | 158 | // Returns the email address of the custodian. |
| 159 | std::string GetCustodianEmailAddress() const; |
| 160 | |
[email protected] | fae057a | 2013-06-21 22:46:08 | [diff] [blame] | 161 | // Returns the name of the custodian, or the email address if the name is |
| 162 | // empty. |
| 163 | std::string GetCustodianName() const; |
| 164 | |
treib | 3e7ecf7 | 2014-10-24 16:44:07 | [diff] [blame] | 165 | // Returns the email address of the second custodian, or the empty string |
| 166 | // if there is no second custodian. |
| 167 | std::string GetSecondCustodianEmailAddress() const; |
| 168 | |
| 169 | // Returns the name of the second custodian, or the email address if the name |
| 170 | // is empty, or the empty string is there is no second custodian. |
| 171 | std::string GetSecondCustodianName() const; |
| 172 | |
treib | 2170ea0 | 2015-10-13 14:55:12 | [diff] [blame] | 173 | // Returns a message saying that extensions can only be modified by the |
| 174 | // custodian. |
| 175 | base::string16 GetExtensionsLockedMessage() const; |
| 176 | |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame] | 177 | #if !defined(OS_ANDROID) |
[email protected] | a243d644c | 2013-06-20 18:37:55 | [diff] [blame] | 178 | // Initializes this profile for syncing, using the provided |refresh_token| to |
| 179 | // mint access tokens for Sync. |
| 180 | void InitSync(const std::string& refresh_token); |
[email protected] | acfcfbb | 2013-05-13 18:01:27 | [diff] [blame] | 181 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 182 | // Convenience method that registers this supervised user using |
[email protected] | 458d5944 | 2013-08-01 14:19:32 | [diff] [blame] | 183 | // |registration_utility| and initializes sync with the returned token. |
| 184 | // The |callback| will be called when registration is complete, |
[email protected] | 3a276ff | 2014-08-12 14:22:09 | [diff] [blame] | 185 | // whether it succeeded or not -- unless registration was cancelled manually, |
[email protected] | 458d5944 | 2013-08-01 14:19:32 | [diff] [blame] | 186 | // in which case the callback will be ignored. |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 187 | void RegisterAndInitSync( |
| 188 | SupervisedUserRegistrationUtility* registration_utility, |
| 189 | Profile* custodian_profile, |
| 190 | const std::string& supervised_user_id, |
| 191 | const AuthErrorCallback& callback); |
thestig | 1b76f1a | 2015-09-30 22:52:38 | [diff] [blame] | 192 | #endif |
[email protected] | acfcfbb | 2013-05-13 18:01:27 | [diff] [blame] | 193 | |
[email protected] | 438f7e1 | 2013-08-07 06:59:00 | [diff] [blame] | 194 | void AddNavigationBlockedCallback(const NavigationBlockedCallback& callback); |
| 195 | void DidBlockNavigation(content::WebContents* web_contents); |
| 196 | |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 197 | void AddObserver(SupervisedUserServiceObserver* observer); |
| 198 | void RemoveObserver(SupervisedUserServiceObserver* observer); |
| 199 | |
treib | 531fc731 | 2014-12-09 12:49:20 | [diff] [blame] | 200 | void AddPermissionRequestCreator( |
dcheng | f624e47 | 2016-04-12 08:33:17 | [diff] [blame] | 201 | std::unique_ptr<PermissionRequestCreator> creator); |
bauerb | 646019b1 | 2014-10-16 16:23:09 | [diff] [blame] | 202 | |
dcheng | f624e47 | 2016-04-12 08:33:17 | [diff] [blame] | 203 | void SetSafeSearchURLReporter( |
| 204 | std::unique_ptr<SafeSearchURLReporter> reporter); |
atanasova | ac67603 | 2016-04-05 16:31:05 | [diff] [blame] | 205 | |
bauerb | b519f825 | 2016-05-13 09:16:39 | [diff] [blame] | 206 | // Returns true if the syncer::SESSIONS type should be included in Sync. |
| 207 | // Public for testing. |
| 208 | bool IncludesSyncSessionsType() const; |
| 209 | |
bauerb | 5f8cda9 | 2015-10-07 15:36:44 | [diff] [blame] | 210 | // ProfileKeyedService override: |
| 211 | void Shutdown() override; |
| 212 | |
[email protected] | 3a276ff | 2014-08-12 14:22:09 | [diff] [blame] | 213 | // SyncTypePreferenceProvider implementation: |
dcheng | c072fff | 2014-10-21 11:39:05 | [diff] [blame] | 214 | syncer::ModelTypeSet GetPreferredDataTypes() const override; |
[email protected] | 3a276ff | 2014-08-12 14:22:09 | [diff] [blame] | 215 | |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame] | 216 | #if !defined(OS_ANDROID) |
maxbogue | 7e006db | 2016-10-03 19:48:28 | [diff] [blame] | 217 | // syncer::SyncServiceObserver implementation: |
dcheng | c072fff | 2014-10-21 11:39:05 | [diff] [blame] | 218 | void OnStateChanged() override; |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 219 | |
[email protected] | dfddd02 | 2013-07-10 17:29:48 | [diff] [blame] | 220 | // chrome::BrowserListObserver implementation: |
dcheng | c072fff | 2014-10-21 11:39:05 | [diff] [blame] | 221 | void OnBrowserSetLastActive(Browser* browser) override; |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame] | 222 | #endif // !defined(OS_ANDROID) |
[email protected] | dfddd02 | 2013-07-10 17:29:48 | [diff] [blame] | 223 | |
bauerb | ce9a1a8 | 2014-12-18 13:34:24 | [diff] [blame] | 224 | // SupervisedUserURLFilter::Observer implementation: |
| 225 | void OnSiteListUpdated() override; |
| 226 | |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 227 | private: |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 228 | friend class SupervisedUserServiceExtensionTestBase; |
| 229 | friend class SupervisedUserServiceFactory; |
pvalenzuela | c2ca458 | 2014-10-14 19:24:57 | [diff] [blame] | 230 | FRIEND_TEST_ALL_PREFIXES(SingleClientSupervisedUserSettingsSyncTest, Sanity); |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 231 | FRIEND_TEST_ALL_PREFIXES(SupervisedUserServiceTest, ClearOmitOnRegistration); |
mamir | e960964 | 2016-06-28 22:17:54 | [diff] [blame] | 232 | FRIEND_TEST_ALL_PREFIXES( |
| 233 | SupervisedUserServiceExtensionTest, |
| 234 | ExtensionManagementPolicyProviderWithoutSUInitiatedInstalls); |
| 235 | FRIEND_TEST_ALL_PREFIXES( |
| 236 | SupervisedUserServiceExtensionTest, |
| 237 | ExtensionManagementPolicyProviderWithSUInitiatedInstalls); |
bauerb | 95a5068 | 2015-01-07 17:04:15 | [diff] [blame] | 238 | |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 239 | using CreatePermissionRequestCallback = |
| 240 | base::Callback<void(PermissionRequestCreator*, const SuccessCallback&)>; |
| 241 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 242 | // A bridge from the UI thread to the SupervisedUserURLFilters, one of which |
| 243 | // lives on the IO thread. This class mediates access to them and makes sure |
| 244 | // they are kept in sync. |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 245 | class URLFilterContext { |
| 246 | public: |
| 247 | URLFilterContext(); |
| 248 | ~URLFilterContext(); |
| 249 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 250 | SupervisedUserURLFilter* ui_url_filter() const; |
| 251 | SupervisedUserURLFilter* io_url_filter() const; |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 252 | |
| 253 | void SetDefaultFilteringBehavior( |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 254 | SupervisedUserURLFilter::FilteringBehavior behavior); |
bauerb | 95a5068 | 2015-01-07 17:04:15 | [diff] [blame] | 255 | void LoadWhitelists( |
| 256 | const std::vector<scoped_refptr<SupervisedUserSiteList>>& site_lists); |
treib | 9cc1b11 | 2016-01-08 10:08:01 | [diff] [blame] | 257 | // TODO(treib): Make SupervisedUserBlacklist refcounted, so the IO thread |
| 258 | // will retain a reference to the blacklist. |
| 259 | void SetBlacklist(const SupervisedUserBlacklist* blacklist); |
| 260 | bool HasBlacklist() const; |
dcheng | f624e47 | 2016-04-12 08:33:17 | [diff] [blame] | 261 | void SetManualHosts(std::unique_ptr<std::map<std::string, bool>> host_map); |
| 262 | void SetManualURLs(std::unique_ptr<std::map<GURL, bool>> url_map); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 263 | |
maxbogue | 8e4fb45 | 2015-02-11 20:26:09 | [diff] [blame] | 264 | void InitAsyncURLChecker( |
treib | d3f8b7a | 2015-04-10 11:41:33 | [diff] [blame] | 265 | const scoped_refptr<net::URLRequestContextGetter>& context); |
treib | 9cc1b11 | 2016-01-08 10:08:01 | [diff] [blame] | 266 | bool HasAsyncURLChecker() const; |
| 267 | void ClearAsyncURLChecker(); |
treib | 9e4fab90 | 2014-10-29 14:25:26 | [diff] [blame] | 268 | |
treib | 22c3a04 | 2015-01-15 21:30:13 | [diff] [blame] | 269 | void Clear(); |
| 270 | |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 271 | private: |
bauerb | ce9a1a8 | 2014-12-18 13:34:24 | [diff] [blame] | 272 | void OnBlacklistLoaded(const base::Closure& callback); |
treib | 4edbded | 2014-09-05 08:43:55 | [diff] [blame] | 273 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 274 | // SupervisedUserURLFilter is refcounted because the IO thread filter is |
| 275 | // used both by ProfileImplIOData and OffTheRecordProfileIOData (to filter |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 276 | // network requests), so they both keep a reference to it. |
| 277 | // Clients should not keep references to the UI thread filter, however |
| 278 | // (the filter will live as long as the profile lives, and afterwards it |
| 279 | // should not be used anymore either). |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 280 | scoped_refptr<SupervisedUserURLFilter> ui_url_filter_; |
| 281 | scoped_refptr<SupervisedUserURLFilter> io_url_filter_; |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 282 | |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 283 | DISALLOW_COPY_AND_ASSIGN(URLFilterContext); |
| 284 | }; |
| 285 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 286 | // Use |SupervisedUserServiceFactory::GetForProfile(..)| to get |
[email protected] | 3bf45d0 | 2013-07-10 00:03:41 | [diff] [blame] | 287 | // an instance of this service. |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 288 | explicit SupervisedUserService(Profile* profile); |
[email protected] | 3bf45d0 | 2013-07-10 00:03:41 | [diff] [blame] | 289 | |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 290 | void SetActive(bool active); |
| 291 | |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame] | 292 | #if !defined(OS_ANDROID) |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 293 | void OnCustodianProfileDownloaded(const base::string16& full_name); |
[email protected] | 200729f8 | 2013-06-22 07:05:55 | [diff] [blame] | 294 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 295 | void OnSupervisedUserRegistered(const AuthErrorCallback& callback, |
| 296 | Profile* custodian_profile, |
| 297 | const GoogleServiceAuthError& auth_error, |
| 298 | const std::string& token); |
[email protected] | acfcfbb | 2013-05-13 18:01:27 | [diff] [blame] | 299 | |
[email protected] | a243d644c | 2013-06-20 18:37:55 | [diff] [blame] | 300 | void SetupSync(); |
[email protected] | 6e08b9a6 | 2014-07-08 00:32:48 | [diff] [blame] | 301 | void StartSetupSync(); |
| 302 | void FinishSetupSyncWhenReady(); |
| 303 | void FinishSetupSync(); |
bauerb | 5f8cda9 | 2015-10-07 15:36:44 | [diff] [blame] | 304 | #endif |
[email protected] | a243d644c | 2013-06-20 18:37:55 | [diff] [blame] | 305 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 306 | bool ProfileIsSupervised() const; |
[email protected] | e000daf | 2013-07-31 16:50:58 | [diff] [blame] | 307 | |
treib | 3fce4e9 | 2014-09-26 16:06:25 | [diff] [blame] | 308 | void OnCustodianInfoChanged(); |
| 309 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame^] | 310 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
treib | bb9a196 | 2015-02-25 13:40:59 | [diff] [blame] | 311 | // extensions::ManagementPolicy::Provider implementation: |
| 312 | std::string GetDebugPolicyProviderName() const override; |
| 313 | bool UserMayLoad(const extensions::Extension* extension, |
| 314 | base::string16* error) const override; |
treib | 755c12d | 2015-03-30 08:46:25 | [diff] [blame] | 315 | bool UserMayModifySettings(const extensions::Extension* extension, |
| 316 | base::string16* error) const override; |
treib | bb9a196 | 2015-02-25 13:40:59 | [diff] [blame] | 317 | bool MustRemainInstalled(const extensions::Extension* extension, |
| 318 | base::string16* error) const override; |
mamir | e960964 | 2016-06-28 22:17:54 | [diff] [blame] | 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; |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 327 | |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 328 | // An extension can be in one of the following states: |
| 329 | // |
| 330 | // FORCED: if it is installed by the custodian. |
mamir | e960964 | 2016-06-28 22:17:54 | [diff] [blame] | 331 | // REQUIRE_APPROVAL: if it is installed by the supervised user and |
| 332 | // hasn't been approved by the custodian yet. |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 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. |
mamir | e960964 | 2016-06-28 22:17:54 | [diff] [blame] | 338 | enum class ExtensionState { FORCED, BLOCKED, ALLOWED, REQUIRE_APPROVAL }; |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 339 | |
mamir | e960964 | 2016-06-28 22:17:54 | [diff] [blame] | 340 | // Returns the state of an extension whether being FORCED, BLOCKED, ALLOWED or |
| 341 | // REQUIRE_APPROVAL from the Supervised User service's point of view. |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 342 | ExtensionState GetExtensionState( |
mamir | e960964 | 2016-06-28 22:17:54 | [diff] [blame] | 343 | const extensions::Extension& extension) const; |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 344 | |
[email protected] | c14a680 | 2014-07-11 21:51:12 | [diff] [blame] | 345 | // Extensions helper to SetActive(). |
| 346 | void SetExtensionsActive(); |
mamir | e960964 | 2016-06-28 22:17:54 | [diff] [blame] | 347 | |
| 348 | // Enables/Disables extensions upon change in approved version of the |
| 349 | // extension_id. |
| 350 | void ChangeExtensionStateIfNecessary(const std::string& extension_id); |
| 351 | |
| 352 | // Updates the map of approved extensions when the corresponding preference |
| 353 | // is changed. |
| 354 | void UpdateApprovedExtensions(); |
[email protected] | c14a680 | 2014-07-11 21:51:12 | [diff] [blame] | 355 | #endif |
| 356 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 357 | SupervisedUserSettingsService* GetSettingsService(); |
[email protected] | e861bba | 2013-06-17 15:20:54 | [diff] [blame] | 358 | |
bauerb | d3a36cc4 | 2014-10-01 13:05:49 | [diff] [blame] | 359 | size_t FindEnabledPermissionRequestCreator(size_t start); |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 360 | void AddPermissionRequestInternal( |
| 361 | const CreatePermissionRequestCallback& create_request, |
| 362 | const SuccessCallback& callback, |
| 363 | size_t index); |
| 364 | void OnPermissionRequestIssued( |
| 365 | const CreatePermissionRequestCallback& create_request, |
| 366 | const SuccessCallback& callback, |
| 367 | size_t index, |
| 368 | bool success); |
bauerb | d3a36cc4 | 2014-10-01 13:05:49 | [diff] [blame] | 369 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 370 | void OnSupervisedUserIdChanged(); |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 371 | |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 372 | void OnDefaultFilteringBehaviorChanged(); |
| 373 | |
treib | 9cc1b11 | 2016-01-08 10:08:01 | [diff] [blame] | 374 | void OnSafeSitesSettingChanged(); |
| 375 | |
bauerb | 95a5068 | 2015-01-07 17:04:15 | [diff] [blame] | 376 | void OnSiteListsChanged( |
| 377 | const std::vector<scoped_refptr<SupervisedUserSiteList>>& site_lists); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 378 | |
treib | 2fd18739 | 2015-04-16 17:19:38 | [diff] [blame] | 379 | // Asynchronously loads a blacklist from a binary file at |path| and applies |
| 380 | // it to the URL filters. If no file exists at |path| yet, downloads a file |
| 381 | // from |url| and stores it at |path| first. |
treib | f136dfb | 2014-09-25 17:37:47 | [diff] [blame] | 382 | void LoadBlacklist(const base::FilePath& path, const GURL& url); |
| 383 | |
treib | 2fd18739 | 2015-04-16 17:19:38 | [diff] [blame] | 384 | void OnBlacklistFileChecked(const base::FilePath& path, |
| 385 | const GURL& url, |
| 386 | bool file_exists); |
| 387 | |
| 388 | // Asynchronously loads a blacklist from a binary file at |path| and applies |
| 389 | // it to the URL filters. |
treib | f136dfb | 2014-09-25 17:37:47 | [diff] [blame] | 390 | void LoadBlacklistFromFile(const base::FilePath& path); |
| 391 | |
treib | f38cc25 | 2016-04-07 14:44:11 | [diff] [blame] | 392 | void OnBlacklistDownloadDone(const base::FilePath& path, |
| 393 | FileDownloader::Result result); |
treib | 4edbded | 2014-09-05 08:43:55 | [diff] [blame] | 394 | |
bauerb | ce9a1a8 | 2014-12-18 13:34:24 | [diff] [blame] | 395 | void OnBlacklistLoaded(); |
| 396 | |
treib | 9cc1b11 | 2016-01-08 10:08:01 | [diff] [blame] | 397 | void UpdateBlacklist(); |
| 398 | |
[email protected] | 5e02229 | 2013-02-06 16:42:17 | [diff] [blame] | 399 | // Updates the manual overrides for hosts in the URL filters when the |
| 400 | // corresponding preference is changed. |
| 401 | void UpdateManualHosts(); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 402 | |
[email protected] | 5e02229 | 2013-02-06 16:42:17 | [diff] [blame] | 403 | // Updates the manual overrides for URLs in the URL filters when the |
| 404 | // corresponding preference is changed. |
| 405 | void UpdateManualURLs(); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 406 | |
[email protected] | 0b4c6b2 | 2014-08-04 09:46:31 | [diff] [blame] | 407 | // Returns the human readable name of the supervised user. |
| 408 | std::string GetSupervisedUserName() const; |
| 409 | |
fhorschig | 1f351f0 | 2014-09-30 12:30:22 | [diff] [blame] | 410 | // Subscribes to the SupervisedUserPrefStore, refreshes |
| 411 | // |includes_sync_sessions_type_| and triggers reconfiguring the |
| 412 | // ProfileSyncService. |
bauerb | b519f825 | 2016-05-13 09:16:39 | [diff] [blame] | 413 | void OnForceSessionSyncChanged(); |
fhorschig | 1f351f0 | 2014-09-30 12:30:22 | [diff] [blame] | 414 | |
| 415 | // The option a custodian sets to either record or prevent recording the |
| 416 | // supervised user's history. Set by |FetchNewSessionSyncState()| and |
| 417 | // defaults to true. |
| 418 | bool includes_sync_sessions_type_; |
| 419 | |
[email protected] | 12b7af3 | 2014-03-13 05:28:20 | [diff] [blame] | 420 | // Owns us via the KeyedService mechanism. |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 421 | Profile* profile_; |
| 422 | |
[email protected] | f085fdd5 | 2014-06-11 18:09:20 | [diff] [blame] | 423 | bool active_; |
| 424 | |
| 425 | Delegate* delegate_; |
| 426 | |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 427 | PrefChangeRegistrar pref_change_registrar_; |
| 428 | |
[email protected] | a243d644c | 2013-06-20 18:37:55 | [diff] [blame] | 429 | // True iff we're waiting for the Sync service to be initialized. |
| 430 | bool waiting_for_sync_initialization_; |
[email protected] | dfddd02 | 2013-07-10 17:29:48 | [diff] [blame] | 431 | bool is_profile_active_; |
[email protected] | a243d644c | 2013-06-20 18:37:55 | [diff] [blame] | 432 | |
[email protected] | 438f7e1 | 2013-08-07 06:59:00 | [diff] [blame] | 433 | std::vector<NavigationBlockedCallback> navigation_blocked_callbacks_; |
| 434 | |
[email protected] | 3a276ff | 2014-08-12 14:22:09 | [diff] [blame] | 435 | // True only when |Init()| method has been called. |
| 436 | bool did_init_; |
| 437 | |
[email protected] | 3bf45d0 | 2013-07-10 00:03:41 | [diff] [blame] | 438 | // True only when |Shutdown()| method has been called. |
| 439 | bool did_shutdown_; |
| 440 | |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 441 | URLFilterContext url_filter_context_; |
treib | 9cc1b11 | 2016-01-08 10:08:01 | [diff] [blame] | 442 | |
mamir | e960964 | 2016-06-28 22:17:54 | [diff] [blame] | 443 | // Stores a map from extension_id -> approved version by the custodian. |
| 444 | // It is only relevant for SU-initiated installs. |
| 445 | std::map<std::string, base::Version> approved_extensions_map_; |
| 446 | |
treib | 9cc1b11 | 2016-01-08 10:08:01 | [diff] [blame] | 447 | enum class BlacklistLoadState { |
| 448 | NOT_LOADED, |
| 449 | LOAD_STARTED, |
| 450 | LOADED |
| 451 | } blacklist_state_; |
| 452 | |
| 453 | SupervisedUserBlacklist blacklist_; |
dcheng | f624e47 | 2016-04-12 08:33:17 | [diff] [blame] | 454 | std::unique_ptr<FileDownloader> blacklist_downloader_; |
[email protected] | 8052b24 | 2013-11-15 16:40:55 | [diff] [blame] | 455 | |
dcheng | f624e47 | 2016-04-12 08:33:17 | [diff] [blame] | 456 | std::unique_ptr<SupervisedUserWhitelistService> whitelist_service_; |
bauerb | 4da3613 | 2014-12-26 19:53:13 | [diff] [blame] | 457 | |
atanasova | 9572aaf | 2016-02-26 18:08:26 | [diff] [blame] | 458 | std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists_; |
| 459 | |
[email protected] | 4db65f95 | 2014-05-20 15:46:30 | [diff] [blame] | 460 | // Used to create permission requests. |
bauerb | d3a36cc4 | 2014-10-01 13:05:49 | [diff] [blame] | 461 | ScopedVector<PermissionRequestCreator> permissions_creators_; |
[email protected] | 4db65f95 | 2014-05-20 15:46:30 | [diff] [blame] | 462 | |
atanasova | ac67603 | 2016-04-05 16:31:05 | [diff] [blame] | 463 | // Used to report inappropriate URLs to SafeSarch API. |
dcheng | f624e47 | 2016-04-12 08:33:17 | [diff] [blame] | 464 | std::unique_ptr<SafeSearchURLReporter> url_reporter_; |
atanasova | ac67603 | 2016-04-05 16:31:05 | [diff] [blame] | 465 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame^] | 466 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
mamir | e960964 | 2016-06-28 22:17:54 | [diff] [blame] | 467 | ScopedObserver<extensions::ExtensionRegistry, |
| 468 | extensions::ExtensionRegistryObserver> |
| 469 | registry_observer_; |
| 470 | #endif |
| 471 | |
brettw | d195c95 | 2015-06-02 17:31:12 | [diff] [blame] | 472 | base::ObserverList<SupervisedUserServiceObserver> observer_list_; |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 473 | |
tommycli | f3a1551e | 2016-06-21 18:11:23 | [diff] [blame] | 474 | // Prevents Sync from running until configuration is complete. |
maxbogue | 7e006db | 2016-10-03 19:48:28 | [diff] [blame] | 475 | std::unique_ptr<syncer::SyncSetupInProgressHandle> sync_blocker_; |
tommycli | f3a1551e | 2016-06-21 18:11:23 | [diff] [blame] | 476 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 477 | base::WeakPtrFactory<SupervisedUserService> weak_ptr_factory_; |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 478 | }; |
| 479 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 480 | #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_ |