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