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