OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_ |
6 #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_ | 6 #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/net/file_downloader.h" | 23 #include "chrome/browser/net/file_downloader.h" |
24 #include "chrome/browser/supervised_user/experimental/safe_search_url_reporter.h
" | 24 #include "chrome/browser/supervised_user/experimental/safe_search_url_reporter.h
" |
25 #include "chrome/browser/supervised_user/experimental/supervised_user_blacklist.
h" | 25 #include "chrome/browser/supervised_user/experimental/supervised_user_blacklist.
h" |
26 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" | 26 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" |
27 #include "chrome/browser/supervised_user/supervised_users.h" | 27 #include "chrome/browser/supervised_user/supervised_users.h" |
28 #include "chrome/browser/ui/browser_list_observer.h" | 28 #include "chrome/browser/ui/browser_list_observer.h" |
29 #include "components/keyed_service/core/keyed_service.h" | 29 #include "components/keyed_service/core/keyed_service.h" |
30 #include "components/prefs/pref_change_registrar.h" | 30 #include "components/prefs/pref_change_registrar.h" |
31 #include "components/sync_driver/sync_service_observer.h" | 31 #include "components/sync_driver/sync_service_observer.h" |
32 #include "components/sync_driver/sync_type_preference_provider.h" | 32 #include "components/sync_driver/sync_type_preference_provider.h" |
| 33 #include "extensions/browser/extension_registry_observer.h" |
33 #include "net/url_request/url_request_context_getter.h" | 34 #include "net/url_request/url_request_context_getter.h" |
34 | 35 |
35 #if defined(ENABLE_EXTENSIONS) | 36 #if defined(ENABLE_EXTENSIONS) |
36 #include "extensions/browser/management_policy.h" | 37 #include "extensions/browser/management_policy.h" |
37 #endif | 38 #endif |
38 | 39 |
39 class Browser; | 40 class Browser; |
40 class GoogleServiceAuthError; | 41 class GoogleServiceAuthError; |
41 class PermissionRequestCreator; | 42 class PermissionRequestCreator; |
42 class Profile; | 43 class Profile; |
(...skipping 19 matching lines...) Expand all Loading... |
62 | 63 |
63 namespace user_prefs { | 64 namespace user_prefs { |
64 class PrefRegistrySyncable; | 65 class PrefRegistrySyncable; |
65 } | 66 } |
66 | 67 |
67 // This class handles all the information related to a given supervised profile | 68 // This class handles all the information related to a given supervised profile |
68 // (e.g. the installed content packs, the default URL filtering behavior, or | 69 // (e.g. the installed content packs, the default URL filtering behavior, or |
69 // manual whitelist/blacklist overrides). | 70 // manual whitelist/blacklist overrides). |
70 class SupervisedUserService : public KeyedService, | 71 class SupervisedUserService : public KeyedService, |
71 #if defined(ENABLE_EXTENSIONS) | 72 #if defined(ENABLE_EXTENSIONS) |
| 73 public extensions::ExtensionRegistryObserver, |
72 public extensions::ManagementPolicy::Provider, | 74 public extensions::ManagementPolicy::Provider, |
73 #endif | 75 #endif |
74 public SyncTypePreferenceProvider, | 76 public SyncTypePreferenceProvider, |
75 #if !defined(OS_ANDROID) | 77 #if !defined(OS_ANDROID) |
76 public sync_driver::SyncServiceObserver, | 78 public sync_driver::SyncServiceObserver, |
77 public chrome::BrowserListObserver, | 79 public chrome::BrowserListObserver, |
78 #endif | 80 #endif |
79 public SupervisedUserURLFilter::Observer { | 81 public SupervisedUserURLFilter::Observer { |
80 public: | 82 public: |
81 using NavigationBlockedCallback = base::Callback<void(content::WebContents*)>; | 83 using NavigationBlockedCallback = base::Callback<void(content::WebContents*)>; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // extensions. | 120 // extensions. |
119 bool AccessRequestsEnabled(); | 121 bool AccessRequestsEnabled(); |
120 | 122 |
121 // Adds an access request for the given URL. | 123 // Adds an access request for the given URL. |
122 void AddURLAccessRequest(const GURL& url, const SuccessCallback& callback); | 124 void AddURLAccessRequest(const GURL& url, const SuccessCallback& callback); |
123 | 125 |
124 // Reports |url| to the SafeSearch API, because the user thinks this is an | 126 // Reports |url| to the SafeSearch API, because the user thinks this is an |
125 // inappropriate URL. | 127 // inappropriate URL. |
126 void ReportURL(const GURL& url, const SuccessCallback& callback); | 128 void ReportURL(const GURL& url, const SuccessCallback& callback); |
127 | 129 |
| 130 // Adds an install request for the given WebStore item (App/Extension). |
| 131 void AddExtensionInstallRequest(const std::string& extension_id, |
| 132 const base::Version& version, |
| 133 const SuccessCallback& callback); |
| 134 |
| 135 // Same as above, but without a callback, just logging errors on failure. |
| 136 void AddExtensionInstallRequest(const std::string& extension_id, |
| 137 const base::Version& version); |
| 138 |
128 // Adds an update request for the given WebStore item (App/Extension). | 139 // Adds an update request for the given WebStore item (App/Extension). |
129 void AddExtensionUpdateRequest(const std::string& extension_id, | 140 void AddExtensionUpdateRequest(const std::string& extension_id, |
130 const base::Version& version, | 141 const base::Version& version, |
131 const SuccessCallback& callback); | 142 const SuccessCallback& callback); |
132 | 143 |
133 // Same as above, but without a callback, just logging errors on failure. | 144 // Same as above, but without a callback, just logging errors on failure. |
134 void AddExtensionUpdateRequest(const std::string& extension_id, | 145 void AddExtensionUpdateRequest(const std::string& extension_id, |
135 const base::Version& version); | 146 const base::Version& version); |
136 | 147 |
137 // Get the string used to identify an extension update request. Public for | 148 // Get the string used to identify an extension install or update request. |
138 // testing. | 149 // Public for testing. |
139 static std::string GetExtensionUpdateRequestId( | 150 static std::string GetExtensionRequestId(const std::string& extension_id, |
140 const std::string& extension_id, | 151 const base::Version& version); |
141 const base::Version& version); | 152 |
| 153 // Updates the approved version of the extensions in the |
| 154 // approved_extensions_map_ and re-enables the extension if the approved |
| 155 // version now matches the installed version. |
| 156 void UpdateApprovedExtensionVersion(const std::string& extension_id, |
| 157 const base::Version& version); |
142 | 158 |
143 // Returns the email address of the custodian. | 159 // Returns the email address of the custodian. |
144 std::string GetCustodianEmailAddress() const; | 160 std::string GetCustodianEmailAddress() const; |
145 | 161 |
146 // Returns the name of the custodian, or the email address if the name is | 162 // Returns the name of the custodian, or the email address if the name is |
147 // empty. | 163 // empty. |
148 std::string GetCustodianName() const; | 164 std::string GetCustodianName() const; |
149 | 165 |
150 // Returns the email address of the second custodian, or the empty string | 166 // Returns the email address of the second custodian, or the empty string |
151 // if there is no second custodian. | 167 // if there is no second custodian. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 #endif // !defined(OS_ANDROID) | 223 #endif // !defined(OS_ANDROID) |
208 | 224 |
209 // SupervisedUserURLFilter::Observer implementation: | 225 // SupervisedUserURLFilter::Observer implementation: |
210 void OnSiteListUpdated() override; | 226 void OnSiteListUpdated() override; |
211 | 227 |
212 private: | 228 private: |
213 friend class SupervisedUserServiceExtensionTestBase; | 229 friend class SupervisedUserServiceExtensionTestBase; |
214 friend class SupervisedUserServiceFactory; | 230 friend class SupervisedUserServiceFactory; |
215 FRIEND_TEST_ALL_PREFIXES(SingleClientSupervisedUserSettingsSyncTest, Sanity); | 231 FRIEND_TEST_ALL_PREFIXES(SingleClientSupervisedUserSettingsSyncTest, Sanity); |
216 FRIEND_TEST_ALL_PREFIXES(SupervisedUserServiceTest, ClearOmitOnRegistration); | 232 FRIEND_TEST_ALL_PREFIXES(SupervisedUserServiceTest, ClearOmitOnRegistration); |
217 FRIEND_TEST_ALL_PREFIXES(SupervisedUserServiceExtensionTest, | 233 FRIEND_TEST_ALL_PREFIXES( |
218 ExtensionManagementPolicyProvider); | 234 SupervisedUserServiceExtensionTest, |
| 235 ExtensionManagementPolicyProviderWithoutSUInitiatedInstalls); |
| 236 FRIEND_TEST_ALL_PREFIXES( |
| 237 SupervisedUserServiceExtensionTest, |
| 238 ExtensionManagementPolicyProviderWithSUInitiatedInstalls); |
219 | 239 |
220 using CreatePermissionRequestCallback = | 240 using CreatePermissionRequestCallback = |
221 base::Callback<void(PermissionRequestCreator*, const SuccessCallback&)>; | 241 base::Callback<void(PermissionRequestCreator*, const SuccessCallback&)>; |
222 | 242 |
223 // A bridge from the UI thread to the SupervisedUserURLFilters, one of which | 243 // A bridge from the UI thread to the SupervisedUserURLFilters, one of which |
224 // lives on the IO thread. This class mediates access to them and makes sure | 244 // lives on the IO thread. This class mediates access to them and makes sure |
225 // they are kept in sync. | 245 // they are kept in sync. |
226 class URLFilterContext { | 246 class URLFilterContext { |
227 public: | 247 public: |
228 URLFilterContext(); | 248 URLFilterContext(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 | 310 |
291 #if defined(ENABLE_EXTENSIONS) | 311 #if defined(ENABLE_EXTENSIONS) |
292 // extensions::ManagementPolicy::Provider implementation: | 312 // extensions::ManagementPolicy::Provider implementation: |
293 std::string GetDebugPolicyProviderName() const override; | 313 std::string GetDebugPolicyProviderName() const override; |
294 bool UserMayLoad(const extensions::Extension* extension, | 314 bool UserMayLoad(const extensions::Extension* extension, |
295 base::string16* error) const override; | 315 base::string16* error) const override; |
296 bool UserMayModifySettings(const extensions::Extension* extension, | 316 bool UserMayModifySettings(const extensions::Extension* extension, |
297 base::string16* error) const override; | 317 base::string16* error) const override; |
298 bool MustRemainInstalled(const extensions::Extension* extension, | 318 bool MustRemainInstalled(const extensions::Extension* extension, |
299 base::string16* error) const override; | 319 base::string16* error) const override; |
| 320 bool MustRemainDisabled(const extensions::Extension* extension, |
| 321 extensions::Extension::DisableReason* reason, |
| 322 base::string16* error) const override; |
| 323 |
| 324 // extensions::ExtensionRegistryObserver overrides: |
| 325 void OnExtensionInstalled(content::BrowserContext* browser_context, |
| 326 const extensions::Extension* extension, |
| 327 bool is_update) override; |
| 328 |
| 329 // An extension can be in one of the following states: |
| 330 // |
| 331 // FORCED: if it is installed by the custodian. |
| 332 // REQUIRE_APPROVAL: if it is installed by the supervised user and |
| 333 // hasn't been approved by the custodian yet. |
| 334 // ALLOWED: Components, Themes, Default extensions ..etc |
| 335 // are generally allowed. Extensions that have been approved by the |
| 336 // custodian are also allowed. |
| 337 // BLOCKED: if it is not ALLOWED or FORCED |
| 338 // and supervised users initiated installs are disabled. |
| 339 enum class ExtensionState { FORCED, BLOCKED, ALLOWED, REQUIRE_APPROVAL }; |
| 340 |
| 341 ExtensionState GetExtensionState( |
| 342 const extensions::Extension& extension) const; |
300 | 343 |
301 // Extensions helper to SetActive(). | 344 // Extensions helper to SetActive(). |
302 void SetExtensionsActive(); | 345 void SetExtensionsActive(); |
| 346 |
| 347 // Checks the disable reasons and enables the extension if possible. |
| 348 void EnableExtensionIfPossible(const std::string& extension_id); |
303 #endif | 349 #endif |
304 | 350 |
305 SupervisedUserSettingsService* GetSettingsService(); | 351 SupervisedUserSettingsService* GetSettingsService(); |
306 | 352 |
307 size_t FindEnabledPermissionRequestCreator(size_t start); | 353 size_t FindEnabledPermissionRequestCreator(size_t start); |
308 void AddPermissionRequestInternal( | 354 void AddPermissionRequestInternal( |
309 const CreatePermissionRequestCallback& create_request, | 355 const CreatePermissionRequestCallback& create_request, |
310 const SuccessCallback& callback, | 356 const SuccessCallback& callback, |
311 size_t index); | 357 size_t index); |
312 void OnPermissionRequestIssued( | 358 void OnPermissionRequestIssued( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 void UpdateBlacklist(); | 391 void UpdateBlacklist(); |
346 | 392 |
347 // Updates the manual overrides for hosts in the URL filters when the | 393 // Updates the manual overrides for hosts in the URL filters when the |
348 // corresponding preference is changed. | 394 // corresponding preference is changed. |
349 void UpdateManualHosts(); | 395 void UpdateManualHosts(); |
350 | 396 |
351 // Updates the manual overrides for URLs in the URL filters when the | 397 // Updates the manual overrides for URLs in the URL filters when the |
352 // corresponding preference is changed. | 398 // corresponding preference is changed. |
353 void UpdateManualURLs(); | 399 void UpdateManualURLs(); |
354 | 400 |
| 401 // Updates the map of approved extensions when the corresponding preference |
| 402 // is changed. |
| 403 void UpdateApprovedExtensions(); |
| 404 |
355 // Returns the human readable name of the supervised user. | 405 // Returns the human readable name of the supervised user. |
356 std::string GetSupervisedUserName() const; | 406 std::string GetSupervisedUserName() const; |
357 | 407 |
358 // Subscribes to the SupervisedUserPrefStore, refreshes | 408 // Subscribes to the SupervisedUserPrefStore, refreshes |
359 // |includes_sync_sessions_type_| and triggers reconfiguring the | 409 // |includes_sync_sessions_type_| and triggers reconfiguring the |
360 // ProfileSyncService. | 410 // ProfileSyncService. |
361 void OnForceSessionSyncChanged(); | 411 void OnForceSessionSyncChanged(); |
362 | 412 |
363 // The option a custodian sets to either record or prevent recording the | 413 // The option a custodian sets to either record or prevent recording the |
364 // supervised user's history. Set by |FetchNewSessionSyncState()| and | 414 // supervised user's history. Set by |FetchNewSessionSyncState()| and |
(...skipping 16 matching lines...) Expand all Loading... |
381 std::vector<NavigationBlockedCallback> navigation_blocked_callbacks_; | 431 std::vector<NavigationBlockedCallback> navigation_blocked_callbacks_; |
382 | 432 |
383 // True only when |Init()| method has been called. | 433 // True only when |Init()| method has been called. |
384 bool did_init_; | 434 bool did_init_; |
385 | 435 |
386 // True only when |Shutdown()| method has been called. | 436 // True only when |Shutdown()| method has been called. |
387 bool did_shutdown_; | 437 bool did_shutdown_; |
388 | 438 |
389 URLFilterContext url_filter_context_; | 439 URLFilterContext url_filter_context_; |
390 | 440 |
| 441 // Stores a map from extension_id -> approved version by the custodian. |
| 442 // It is only relevant for SU-initiated installs. |
| 443 std::map<std::string, base::Version> approved_extensions_map_; |
| 444 |
391 enum class BlacklistLoadState { | 445 enum class BlacklistLoadState { |
392 NOT_LOADED, | 446 NOT_LOADED, |
393 LOAD_STARTED, | 447 LOAD_STARTED, |
394 LOADED | 448 LOADED |
395 } blacklist_state_; | 449 } blacklist_state_; |
396 | 450 |
397 SupervisedUserBlacklist blacklist_; | 451 SupervisedUserBlacklist blacklist_; |
398 std::unique_ptr<FileDownloader> blacklist_downloader_; | 452 std::unique_ptr<FileDownloader> blacklist_downloader_; |
399 | 453 |
400 std::unique_ptr<SupervisedUserWhitelistService> whitelist_service_; | 454 std::unique_ptr<SupervisedUserWhitelistService> whitelist_service_; |
401 | 455 |
402 std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists_; | 456 std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists_; |
403 | 457 |
404 // Used to create permission requests. | 458 // Used to create permission requests. |
405 ScopedVector<PermissionRequestCreator> permissions_creators_; | 459 ScopedVector<PermissionRequestCreator> permissions_creators_; |
406 | 460 |
407 // Used to report inappropriate URLs to SafeSarch API. | 461 // Used to report inappropriate URLs to SafeSarch API. |
408 std::unique_ptr<SafeSearchURLReporter> url_reporter_; | 462 std::unique_ptr<SafeSearchURLReporter> url_reporter_; |
409 | 463 |
410 base::ObserverList<SupervisedUserServiceObserver> observer_list_; | 464 base::ObserverList<SupervisedUserServiceObserver> observer_list_; |
411 | 465 |
412 base::WeakPtrFactory<SupervisedUserService> weak_ptr_factory_; | 466 base::WeakPtrFactory<SupervisedUserService> weak_ptr_factory_; |
413 }; | 467 }; |
414 | 468 |
415 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_ | 469 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_ |
OLD | NEW |