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); | |
142 | 152 |
143 // Returns the email address of the custodian. | 153 // Returns the email address of the custodian. |
144 std::string GetCustodianEmailAddress() const; | 154 std::string GetCustodianEmailAddress() const; |
145 | 155 |
146 // Returns the name of the custodian, or the email address if the name is | 156 // Returns the name of the custodian, or the email address if the name is |
147 // empty. | 157 // empty. |
148 std::string GetCustodianName() const; | 158 std::string GetCustodianName() const; |
149 | 159 |
150 // Returns the email address of the second custodian, or the empty string | 160 // Returns the email address of the second custodian, or the empty string |
151 // if there is no second custodian. | 161 // if there is no second custodian. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 #endif // !defined(OS_ANDROID) | 217 #endif // !defined(OS_ANDROID) |
208 | 218 |
209 // SupervisedUserURLFilter::Observer implementation: | 219 // SupervisedUserURLFilter::Observer implementation: |
210 void OnSiteListUpdated() override; | 220 void OnSiteListUpdated() override; |
211 | 221 |
212 private: | 222 private: |
213 friend class SupervisedUserServiceExtensionTestBase; | 223 friend class SupervisedUserServiceExtensionTestBase; |
214 friend class SupervisedUserServiceFactory; | 224 friend class SupervisedUserServiceFactory; |
215 FRIEND_TEST_ALL_PREFIXES(SingleClientSupervisedUserSettingsSyncTest, Sanity); | 225 FRIEND_TEST_ALL_PREFIXES(SingleClientSupervisedUserSettingsSyncTest, Sanity); |
216 FRIEND_TEST_ALL_PREFIXES(SupervisedUserServiceTest, ClearOmitOnRegistration); | 226 FRIEND_TEST_ALL_PREFIXES(SupervisedUserServiceTest, ClearOmitOnRegistration); |
217 FRIEND_TEST_ALL_PREFIXES(SupervisedUserServiceExtensionTest, | 227 FRIEND_TEST_ALL_PREFIXES( |
218 ExtensionManagementPolicyProvider); | 228 SupervisedUserServiceExtensionTest, |
| 229 ExtensionManagementPolicyProviderWithoutSUInitiatedInstalls); |
| 230 FRIEND_TEST_ALL_PREFIXES( |
| 231 SupervisedUserServiceExtensionTest, |
| 232 ExtensionManagementPolicyProviderWithSUInitiatedInstalls); |
219 | 233 |
220 using CreatePermissionRequestCallback = | 234 using CreatePermissionRequestCallback = |
221 base::Callback<void(PermissionRequestCreator*, const SuccessCallback&)>; | 235 base::Callback<void(PermissionRequestCreator*, const SuccessCallback&)>; |
222 | 236 |
223 // A bridge from the UI thread to the SupervisedUserURLFilters, one of which | 237 // 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 | 238 // lives on the IO thread. This class mediates access to them and makes sure |
225 // they are kept in sync. | 239 // they are kept in sync. |
226 class URLFilterContext { | 240 class URLFilterContext { |
227 public: | 241 public: |
228 URLFilterContext(); | 242 URLFilterContext(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 | 304 |
291 #if defined(ENABLE_EXTENSIONS) | 305 #if defined(ENABLE_EXTENSIONS) |
292 // extensions::ManagementPolicy::Provider implementation: | 306 // extensions::ManagementPolicy::Provider implementation: |
293 std::string GetDebugPolicyProviderName() const override; | 307 std::string GetDebugPolicyProviderName() const override; |
294 bool UserMayLoad(const extensions::Extension* extension, | 308 bool UserMayLoad(const extensions::Extension* extension, |
295 base::string16* error) const override; | 309 base::string16* error) const override; |
296 bool UserMayModifySettings(const extensions::Extension* extension, | 310 bool UserMayModifySettings(const extensions::Extension* extension, |
297 base::string16* error) const override; | 311 base::string16* error) const override; |
298 bool MustRemainInstalled(const extensions::Extension* extension, | 312 bool MustRemainInstalled(const extensions::Extension* extension, |
299 base::string16* error) const override; | 313 base::string16* error) const override; |
| 314 bool MustRemainDisabled(const extensions::Extension* extension, |
| 315 extensions::Extension::DisableReason* reason, |
| 316 base::string16* error) const override; |
| 317 |
| 318 // extensions::ExtensionRegistryObserver overrides: |
| 319 void OnExtensionInstalled(content::BrowserContext* browser_context, |
| 320 const extensions::Extension* extension, |
| 321 bool is_update) override; |
| 322 |
| 323 // An extension can be in one of the following states: |
| 324 // |
| 325 // FORCED: if it is installed by the custodian. |
| 326 // REQUIRE_APPROVAL: if it is installed by the supervised user and |
| 327 // hasn't been approved by the custodian yet. |
| 328 // ALLOWED: Components, Themes, Default extensions ..etc |
| 329 // are generally allowed. Extensions that have been approved by the |
| 330 // custodian are also allowed. |
| 331 // BLOCKED: if it is not ALLOWED or FORCED |
| 332 // and supervised users initiated installs are disabled. |
| 333 enum class ExtensionState { FORCED, BLOCKED, ALLOWED, REQUIRE_APPROVAL }; |
| 334 |
| 335 ExtensionState GetExtensionState( |
| 336 const extensions::Extension& extension) const; |
300 | 337 |
301 // Extensions helper to SetActive(). | 338 // Extensions helper to SetActive(). |
302 void SetExtensionsActive(); | 339 void SetExtensionsActive(); |
| 340 |
| 341 // Enables/Disables extensions upon change in approved version of the |
| 342 // extension_id. |
| 343 void ChangeExtensionStateIfNecessary(const std::string& extension_id); |
303 #endif | 344 #endif |
304 | 345 |
305 SupervisedUserSettingsService* GetSettingsService(); | 346 SupervisedUserSettingsService* GetSettingsService(); |
306 | 347 |
307 size_t FindEnabledPermissionRequestCreator(size_t start); | 348 size_t FindEnabledPermissionRequestCreator(size_t start); |
308 void AddPermissionRequestInternal( | 349 void AddPermissionRequestInternal( |
309 const CreatePermissionRequestCallback& create_request, | 350 const CreatePermissionRequestCallback& create_request, |
310 const SuccessCallback& callback, | 351 const SuccessCallback& callback, |
311 size_t index); | 352 size_t index); |
312 void OnPermissionRequestIssued( | 353 void OnPermissionRequestIssued( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 void UpdateBlacklist(); | 386 void UpdateBlacklist(); |
346 | 387 |
347 // Updates the manual overrides for hosts in the URL filters when the | 388 // Updates the manual overrides for hosts in the URL filters when the |
348 // corresponding preference is changed. | 389 // corresponding preference is changed. |
349 void UpdateManualHosts(); | 390 void UpdateManualHosts(); |
350 | 391 |
351 // Updates the manual overrides for URLs in the URL filters when the | 392 // Updates the manual overrides for URLs in the URL filters when the |
352 // corresponding preference is changed. | 393 // corresponding preference is changed. |
353 void UpdateManualURLs(); | 394 void UpdateManualURLs(); |
354 | 395 |
| 396 // Updates the map of approved extensions when the corresponding preference |
| 397 // is changed. |
| 398 void UpdateApprovedExtensions(); |
| 399 |
355 // Returns the human readable name of the supervised user. | 400 // Returns the human readable name of the supervised user. |
356 std::string GetSupervisedUserName() const; | 401 std::string GetSupervisedUserName() const; |
357 | 402 |
358 // Subscribes to the SupervisedUserPrefStore, refreshes | 403 // Subscribes to the SupervisedUserPrefStore, refreshes |
359 // |includes_sync_sessions_type_| and triggers reconfiguring the | 404 // |includes_sync_sessions_type_| and triggers reconfiguring the |
360 // ProfileSyncService. | 405 // ProfileSyncService. |
361 void OnForceSessionSyncChanged(); | 406 void OnForceSessionSyncChanged(); |
362 | 407 |
363 // The option a custodian sets to either record or prevent recording the | 408 // The option a custodian sets to either record or prevent recording the |
364 // supervised user's history. Set by |FetchNewSessionSyncState()| and | 409 // supervised user's history. Set by |FetchNewSessionSyncState()| and |
(...skipping 16 matching lines...) Expand all Loading... |
381 std::vector<NavigationBlockedCallback> navigation_blocked_callbacks_; | 426 std::vector<NavigationBlockedCallback> navigation_blocked_callbacks_; |
382 | 427 |
383 // True only when |Init()| method has been called. | 428 // True only when |Init()| method has been called. |
384 bool did_init_; | 429 bool did_init_; |
385 | 430 |
386 // True only when |Shutdown()| method has been called. | 431 // True only when |Shutdown()| method has been called. |
387 bool did_shutdown_; | 432 bool did_shutdown_; |
388 | 433 |
389 URLFilterContext url_filter_context_; | 434 URLFilterContext url_filter_context_; |
390 | 435 |
| 436 // Stores a map from extension_id -> approved version by the custodian. |
| 437 // It is only relevant for SU-initiated installs. |
| 438 std::map<std::string, base::Version> approved_extensions_map_; |
| 439 |
391 enum class BlacklistLoadState { | 440 enum class BlacklistLoadState { |
392 NOT_LOADED, | 441 NOT_LOADED, |
393 LOAD_STARTED, | 442 LOAD_STARTED, |
394 LOADED | 443 LOADED |
395 } blacklist_state_; | 444 } blacklist_state_; |
396 | 445 |
397 SupervisedUserBlacklist blacklist_; | 446 SupervisedUserBlacklist blacklist_; |
398 std::unique_ptr<FileDownloader> blacklist_downloader_; | 447 std::unique_ptr<FileDownloader> blacklist_downloader_; |
399 | 448 |
400 std::unique_ptr<SupervisedUserWhitelistService> whitelist_service_; | 449 std::unique_ptr<SupervisedUserWhitelistService> whitelist_service_; |
401 | 450 |
402 std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists_; | 451 std::vector<scoped_refptr<SupervisedUserSiteList>> whitelists_; |
403 | 452 |
404 // Used to create permission requests. | 453 // Used to create permission requests. |
405 ScopedVector<PermissionRequestCreator> permissions_creators_; | 454 ScopedVector<PermissionRequestCreator> permissions_creators_; |
406 | 455 |
407 // Used to report inappropriate URLs to SafeSarch API. | 456 // Used to report inappropriate URLs to SafeSarch API. |
408 std::unique_ptr<SafeSearchURLReporter> url_reporter_; | 457 std::unique_ptr<SafeSearchURLReporter> url_reporter_; |
409 | 458 |
| 459 #if defined(ENABLE_EXTENSIONS) |
| 460 ScopedObserver<extensions::ExtensionRegistry, |
| 461 extensions::ExtensionRegistryObserver> |
| 462 registry_observer_; |
| 463 #endif |
| 464 |
410 base::ObserverList<SupervisedUserServiceObserver> observer_list_; | 465 base::ObserverList<SupervisedUserServiceObserver> observer_list_; |
411 | 466 |
412 base::WeakPtrFactory<SupervisedUserService> weak_ptr_factory_; | 467 base::WeakPtrFactory<SupervisedUserService> weak_ptr_factory_; |
413 }; | 468 }; |
414 | 469 |
415 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_ | 470 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_H_ |
OLD | NEW |