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 #include "chrome/browser/supervised_user/supervised_user_service.h" | 5 #include "chrome/browser/supervised_user/supervised_user_service.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/profiles/profile_attributes_entry.h" | 24 #include "chrome/browser/profiles/profile_attributes_entry.h" |
25 #include "chrome/browser/profiles/profile_attributes_storage.h" | 25 #include "chrome/browser/profiles/profile_attributes_storage.h" |
26 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
27 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 27 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
28 #include "chrome/browser/signin/signin_manager_factory.h" | 28 #include "chrome/browser/signin/signin_manager_factory.h" |
29 #include "chrome/browser/supervised_user/experimental/supervised_user_filtering_
switches.h" | 29 #include "chrome/browser/supervised_user/experimental/supervised_user_filtering_
switches.h" |
30 #include "chrome/browser/supervised_user/permission_request_creator.h" | 30 #include "chrome/browser/supervised_user/permission_request_creator.h" |
31 #include "chrome/browser/supervised_user/supervised_user_constants.h" | 31 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
32 #include "chrome/browser/supervised_user/supervised_user_features.h" | 32 #include "chrome/browser/supervised_user/supervised_user_features.h" |
| 33 #include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h" |
33 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 34 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
34 #include "chrome/browser/supervised_user/supervised_user_service_observer.h" | 35 #include "chrome/browser/supervised_user/supervised_user_service_observer.h" |
35 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" | 36 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
36 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor
y.h" | 37 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor
y.h" |
37 #include "chrome/browser/supervised_user/supervised_user_site_list.h" | 38 #include "chrome/browser/supervised_user/supervised_user_site_list.h" |
38 #include "chrome/browser/supervised_user/supervised_user_whitelist_service.h" | 39 #include "chrome/browser/supervised_user/supervised_user_whitelist_service.h" |
39 #include "chrome/browser/sync/profile_sync_service_factory.h" | 40 #include "chrome/browser/sync/profile_sync_service_factory.h" |
40 #include "chrome/browser/ui/browser.h" | 41 #include "chrome/browser/ui/browser.h" |
41 #include "chrome/browser/ui/browser_list.h" | 42 #include "chrome/browser/ui/browser_list.h" |
42 #include "chrome/common/chrome_paths.h" | 43 #include "chrome/common/chrome_paths.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 base::FilePath GetBlacklistPath() { | 151 base::FilePath GetBlacklistPath() { |
151 base::FilePath blacklist_dir; | 152 base::FilePath blacklist_dir; |
152 PathService::Get(chrome::DIR_USER_DATA, &blacklist_dir); | 153 PathService::Get(chrome::DIR_USER_DATA, &blacklist_dir); |
153 return blacklist_dir.AppendASCII(kBlacklistFilename); | 154 return blacklist_dir.AppendASCII(kBlacklistFilename); |
154 } | 155 } |
155 | 156 |
156 } // namespace | 157 } // namespace |
157 | 158 |
158 SupervisedUserService::~SupervisedUserService() { | 159 SupervisedUserService::~SupervisedUserService() { |
159 DCHECK(!did_init_ || did_shutdown_); | 160 DCHECK(!did_init_ || did_shutdown_); |
160 url_filter_context_.ui_url_filter()->RemoveObserver(this); | 161 url_filter_.RemoveObserver(this); |
161 } | 162 } |
162 | 163 |
163 // static | 164 // static |
164 void SupervisedUserService::RegisterProfilePrefs( | 165 void SupervisedUserService::RegisterProfilePrefs( |
165 user_prefs::PrefRegistrySyncable* registry) { | 166 user_prefs::PrefRegistrySyncable* registry) { |
166 registry->RegisterDictionaryPref(prefs::kSupervisedUserApprovedExtensions); | 167 registry->RegisterDictionaryPref(prefs::kSupervisedUserApprovedExtensions); |
167 registry->RegisterDictionaryPref(prefs::kSupervisedUserManualHosts); | 168 registry->RegisterDictionaryPref(prefs::kSupervisedUserManualHosts); |
168 registry->RegisterDictionaryPref(prefs::kSupervisedUserManualURLs); | 169 registry->RegisterDictionaryPref(prefs::kSupervisedUserManualURLs); |
169 registry->RegisterIntegerPref(prefs::kDefaultSupervisedUserFilteringBehavior, | 170 registry->RegisterIntegerPref(prefs::kDefaultSupervisedUserFilteringBehavior, |
170 SupervisedUserURLFilter::ALLOW); | 171 SupervisedUserURLFilter::ALLOW); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 // Changing delegates isn't allowed. | 214 // Changing delegates isn't allowed. |
214 DCHECK(!delegate_); | 215 DCHECK(!delegate_); |
215 } else { | 216 } else { |
216 // If the delegate is removed, deactivate first to give the old delegate a | 217 // If the delegate is removed, deactivate first to give the old delegate a |
217 // chance to clean up. | 218 // chance to clean up. |
218 SetActive(false); | 219 SetActive(false); |
219 } | 220 } |
220 delegate_ = delegate; | 221 delegate_ = delegate; |
221 } | 222 } |
222 | 223 |
223 scoped_refptr<const SupervisedUserURLFilter> | 224 SupervisedUserURLFilter* SupervisedUserService::GetURLFilter() { |
224 SupervisedUserService::GetURLFilterForIOThread() { | 225 return &url_filter_; |
225 return url_filter_context_.io_url_filter(); | |
226 } | |
227 | |
228 SupervisedUserURLFilter* SupervisedUserService::GetURLFilterForUIThread() { | |
229 return url_filter_context_.ui_url_filter(); | |
230 } | 226 } |
231 | 227 |
232 SupervisedUserWhitelistService* SupervisedUserService::GetWhitelistService() { | 228 SupervisedUserWhitelistService* SupervisedUserService::GetWhitelistService() { |
233 return whitelist_service_.get(); | 229 return whitelist_service_.get(); |
234 } | 230 } |
235 | 231 |
236 bool SupervisedUserService::AccessRequestsEnabled() { | 232 bool SupervisedUserService::AccessRequestsEnabled() { |
237 return FindEnabledPermissionRequestCreator(0) < permissions_creators_.size(); | 233 return FindEnabledPermissionRequestCreator(0) < permissions_creators_.size(); |
238 } | 234 } |
239 | 235 |
240 void SupervisedUserService::AddURLAccessRequest( | 236 void SupervisedUserService::AddURLAccessRequest( |
241 const GURL& url, | 237 const GURL& url, |
242 const SuccessCallback& callback) { | 238 const SuccessCallback& callback) { |
243 GURL effective_url = GetURLFilterForUIThread()->GetEmbeddedURL(url); | 239 GURL effective_url = url_filter_.GetEmbeddedURL(url); |
244 if (!effective_url.is_valid()) | 240 if (!effective_url.is_valid()) |
245 effective_url = url; | 241 effective_url = url; |
246 AddPermissionRequestInternal( | 242 AddPermissionRequestInternal( |
247 base::Bind(CreateURLAccessRequest, | 243 base::Bind(CreateURLAccessRequest, |
248 SupervisedUserURLFilter::Normalize(effective_url)), | 244 SupervisedUserURLFilter::Normalize(effective_url)), |
249 callback, 0); | 245 callback, 0); |
250 } | 246 } |
251 | 247 |
252 void SupervisedUserService::ReportURL(const GURL& url, | 248 void SupervisedUserService::ReportURL(const GURL& url, |
253 const SuccessCallback& callback) { | 249 const SuccessCallback& callback) { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 416 |
421 void SupervisedUserService::SetSafeSearchURLReporter( | 417 void SupervisedUserService::SetSafeSearchURLReporter( |
422 std::unique_ptr<SafeSearchURLReporter> reporter) { | 418 std::unique_ptr<SafeSearchURLReporter> reporter) { |
423 url_reporter_ = std::move(reporter); | 419 url_reporter_ = std::move(reporter); |
424 } | 420 } |
425 | 421 |
426 bool SupervisedUserService::IncludesSyncSessionsType() const { | 422 bool SupervisedUserService::IncludesSyncSessionsType() const { |
427 return includes_sync_sessions_type_; | 423 return includes_sync_sessions_type_; |
428 } | 424 } |
429 | 425 |
430 SupervisedUserService::URLFilterContext::URLFilterContext() | |
431 : ui_url_filter_(new SupervisedUserURLFilter), | |
432 io_url_filter_(new SupervisedUserURLFilter) {} | |
433 SupervisedUserService::URLFilterContext::~URLFilterContext() {} | |
434 | |
435 SupervisedUserURLFilter* | |
436 SupervisedUserService::URLFilterContext::ui_url_filter() const { | |
437 return ui_url_filter_.get(); | |
438 } | |
439 | |
440 SupervisedUserURLFilter* | |
441 SupervisedUserService::URLFilterContext::io_url_filter() const { | |
442 return io_url_filter_.get(); | |
443 } | |
444 | |
445 void SupervisedUserService::URLFilterContext::SetDefaultFilteringBehavior( | |
446 SupervisedUserURLFilter::FilteringBehavior behavior) { | |
447 ui_url_filter_->SetDefaultFilteringBehavior(behavior); | |
448 BrowserThread::PostTask( | |
449 BrowserThread::IO, | |
450 FROM_HERE, | |
451 base::Bind(&SupervisedUserURLFilter::SetDefaultFilteringBehavior, | |
452 io_url_filter_, behavior)); | |
453 } | |
454 | |
455 void SupervisedUserService::URLFilterContext::LoadWhitelists( | |
456 const std::vector<scoped_refptr<SupervisedUserSiteList> >& site_lists) { | |
457 ui_url_filter_->LoadWhitelists(site_lists); | |
458 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
459 base::Bind(&SupervisedUserURLFilter::LoadWhitelists, | |
460 io_url_filter_, site_lists)); | |
461 } | |
462 | |
463 void SupervisedUserService::URLFilterContext::SetBlacklist( | |
464 const SupervisedUserBlacklist* blacklist) { | |
465 ui_url_filter_->SetBlacklist(blacklist); | |
466 BrowserThread::PostTask( | |
467 BrowserThread::IO, | |
468 FROM_HERE, | |
469 base::Bind(&SupervisedUserURLFilter::SetBlacklist, | |
470 io_url_filter_, | |
471 blacklist)); | |
472 } | |
473 | |
474 bool SupervisedUserService::URLFilterContext::HasBlacklist() const { | |
475 return ui_url_filter_->HasBlacklist(); | |
476 } | |
477 | |
478 void SupervisedUserService::URLFilterContext::SetManualHosts( | |
479 std::unique_ptr<std::map<std::string, bool>> host_map) { | |
480 ui_url_filter_->SetManualHosts(host_map.get()); | |
481 BrowserThread::PostTask( | |
482 BrowserThread::IO, | |
483 FROM_HERE, | |
484 base::Bind(&SupervisedUserURLFilter::SetManualHosts, | |
485 io_url_filter_, base::Owned(host_map.release()))); | |
486 } | |
487 | |
488 void SupervisedUserService::URLFilterContext::SetManualURLs( | |
489 std::unique_ptr<std::map<GURL, bool>> url_map) { | |
490 ui_url_filter_->SetManualURLs(url_map.get()); | |
491 BrowserThread::PostTask( | |
492 BrowserThread::IO, | |
493 FROM_HERE, | |
494 base::Bind(&SupervisedUserURLFilter::SetManualURLs, | |
495 io_url_filter_, base::Owned(url_map.release()))); | |
496 } | |
497 | |
498 void SupervisedUserService::URLFilterContext::Clear() { | |
499 ui_url_filter_->Clear(); | |
500 BrowserThread::PostTask( | |
501 BrowserThread::IO, | |
502 FROM_HERE, | |
503 base::Bind(&SupervisedUserURLFilter::Clear, | |
504 io_url_filter_)); | |
505 } | |
506 | |
507 void SupervisedUserService::URLFilterContext::InitAsyncURLChecker( | |
508 const scoped_refptr<net::URLRequestContextGetter>& context) { | |
509 ui_url_filter_->InitAsyncURLChecker(context.get()); | |
510 BrowserThread::PostTask( | |
511 BrowserThread::IO, FROM_HERE, | |
512 base::Bind(&SupervisedUserURLFilter::InitAsyncURLChecker, io_url_filter_, | |
513 base::RetainedRef(context))); | |
514 } | |
515 | |
516 bool SupervisedUserService::URLFilterContext::HasAsyncURLChecker() const { | |
517 return ui_url_filter_->HasAsyncURLChecker(); | |
518 } | |
519 | |
520 void SupervisedUserService::URLFilterContext::ClearAsyncURLChecker() { | |
521 ui_url_filter_->ClearAsyncURLChecker(); | |
522 BrowserThread::PostTask( | |
523 BrowserThread::IO, | |
524 FROM_HERE, | |
525 base::Bind(&SupervisedUserURLFilter::ClearAsyncURLChecker, | |
526 io_url_filter_)); | |
527 } | |
528 | |
529 SupervisedUserService::SupervisedUserService(Profile* profile) | 426 SupervisedUserService::SupervisedUserService(Profile* profile) |
530 : includes_sync_sessions_type_(true), | 427 : includes_sync_sessions_type_(true), |
531 profile_(profile), | 428 profile_(profile), |
532 active_(false), | 429 active_(false), |
533 delegate_(NULL), | 430 delegate_(NULL), |
534 waiting_for_sync_initialization_(false), | 431 waiting_for_sync_initialization_(false), |
535 is_profile_active_(false), | 432 is_profile_active_(false), |
536 did_init_(false), | 433 did_init_(false), |
537 did_shutdown_(false), | 434 did_shutdown_(false), |
538 blacklist_state_(BlacklistLoadState::NOT_LOADED), | 435 blacklist_state_(BlacklistLoadState::NOT_LOADED), |
539 #if BUILDFLAG(ENABLE_EXTENSIONS) | 436 #if BUILDFLAG(ENABLE_EXTENSIONS) |
540 registry_observer_(this), | 437 registry_observer_(this), |
541 #endif | 438 #endif |
542 weak_ptr_factory_(this) { | 439 weak_ptr_factory_(this) { |
543 url_filter_context_.ui_url_filter()->AddObserver(this); | 440 url_filter_.AddObserver(this); |
544 #if BUILDFLAG(ENABLE_EXTENSIONS) | 441 #if BUILDFLAG(ENABLE_EXTENSIONS) |
545 registry_observer_.Add(extensions::ExtensionRegistry::Get(profile)); | 442 registry_observer_.Add(extensions::ExtensionRegistry::Get(profile)); |
546 #endif | 443 #endif |
547 } | 444 } |
548 | 445 |
549 void SupervisedUserService::SetActive(bool active) { | 446 void SupervisedUserService::SetActive(bool active) { |
550 if (active_ == active) | 447 if (active_ == active) |
551 return; | 448 return; |
552 active_ = active; | 449 active_ = active; |
553 | 450 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 prefs::kDefaultSupervisedUserFilteringBehavior); | 550 prefs::kDefaultSupervisedUserFilteringBehavior); |
654 #if BUILDFLAG(ENABLE_EXTENSIONS) | 551 #if BUILDFLAG(ENABLE_EXTENSIONS) |
655 pref_change_registrar_.Remove(prefs::kSupervisedUserApprovedExtensions); | 552 pref_change_registrar_.Remove(prefs::kSupervisedUserApprovedExtensions); |
656 #endif | 553 #endif |
657 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); | 554 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); |
658 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); | 555 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); |
659 for (const char* pref : kCustodianInfoPrefs) { | 556 for (const char* pref : kCustodianInfoPrefs) { |
660 pref_change_registrar_.Remove(pref); | 557 pref_change_registrar_.Remove(pref); |
661 } | 558 } |
662 | 559 |
663 url_filter_context_.Clear(); | 560 url_filter_.Clear(); |
664 for (SupervisedUserServiceObserver& observer : observer_list_) | 561 for (SupervisedUserServiceObserver& observer : observer_list_) |
665 observer.OnURLFilterChanged(); | 562 observer.OnURLFilterChanged(); |
666 | 563 |
667 #if !defined(OS_ANDROID) | 564 #if !defined(OS_ANDROID) |
668 if (waiting_for_sync_initialization_) | 565 if (waiting_for_sync_initialization_) |
669 ProfileSyncServiceFactory::GetForProfile(profile_)->RemoveObserver(this); | 566 ProfileSyncServiceFactory::GetForProfile(profile_)->RemoveObserver(this); |
670 | 567 |
671 // TODO(bauerb): Get rid of the platform-specific #ifdef here. | 568 // TODO(bauerb): Get rid of the platform-specific #ifdef here. |
672 // http://crbug.com/313377 | 569 // http://crbug.com/313377 |
673 BrowserList::RemoveObserver(this); | 570 BrowserList::RemoveObserver(this); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 | 704 |
808 void SupervisedUserService::OnSupervisedUserIdChanged() { | 705 void SupervisedUserService::OnSupervisedUserIdChanged() { |
809 SetActive(ProfileIsSupervised()); | 706 SetActive(ProfileIsSupervised()); |
810 } | 707 } |
811 | 708 |
812 void SupervisedUserService::OnDefaultFilteringBehaviorChanged() { | 709 void SupervisedUserService::OnDefaultFilteringBehaviorChanged() { |
813 int behavior_value = profile_->GetPrefs()->GetInteger( | 710 int behavior_value = profile_->GetPrefs()->GetInteger( |
814 prefs::kDefaultSupervisedUserFilteringBehavior); | 711 prefs::kDefaultSupervisedUserFilteringBehavior); |
815 SupervisedUserURLFilter::FilteringBehavior behavior = | 712 SupervisedUserURLFilter::FilteringBehavior behavior = |
816 SupervisedUserURLFilter::BehaviorFromInt(behavior_value); | 713 SupervisedUserURLFilter::BehaviorFromInt(behavior_value); |
817 url_filter_context_.SetDefaultFilteringBehavior(behavior); | 714 url_filter_.SetDefaultFilteringBehavior(behavior); |
818 | 715 |
819 for (SupervisedUserServiceObserver& observer : observer_list_) | 716 for (SupervisedUserServiceObserver& observer : observer_list_) |
820 observer.OnURLFilterChanged(); | 717 observer.OnURLFilterChanged(); |
821 } | 718 } |
822 | 719 |
823 void SupervisedUserService::OnSafeSitesSettingChanged() { | 720 void SupervisedUserService::OnSafeSitesSettingChanged() { |
824 bool use_blacklist = supervised_users::IsSafeSitesBlacklistEnabled(profile_); | 721 bool use_blacklist = supervised_users::IsSafeSitesBlacklistEnabled(profile_); |
825 if (use_blacklist != url_filter_context_.HasBlacklist()) { | 722 if (use_blacklist != url_filter_.HasBlacklist()) { |
826 if (use_blacklist && blacklist_state_ == BlacklistLoadState::NOT_LOADED) { | 723 if (use_blacklist && blacklist_state_ == BlacklistLoadState::NOT_LOADED) { |
827 LoadBlacklist(GetBlacklistPath(), GURL(kBlacklistURL)); | 724 LoadBlacklist(GetBlacklistPath(), GURL(kBlacklistURL)); |
828 } else if (!use_blacklist || | 725 } else if (!use_blacklist || |
829 blacklist_state_ == BlacklistLoadState::LOADED) { | 726 blacklist_state_ == BlacklistLoadState::LOADED) { |
830 // Either the blacklist was turned off, or it was turned on but has | 727 // Either the blacklist was turned off, or it was turned on but has |
831 // already been loaded previously. Just update the setting. | 728 // already been loaded previously. Just update the setting. |
832 UpdateBlacklist(); | 729 UpdateBlacklist(); |
833 } | 730 } |
834 // Else: The blacklist was enabled, but the load is already in progress. | 731 // Else: The blacklist was enabled, but the load is already in progress. |
835 // Do nothing - we'll check the setting again when the load finishes. | 732 // Do nothing - we'll check the setting again when the load finishes. |
836 } | 733 } |
837 | 734 |
838 bool use_online_check = | 735 bool use_online_check = |
839 supervised_users::IsSafeSitesOnlineCheckEnabled(profile_); | 736 supervised_users::IsSafeSitesOnlineCheckEnabled(profile_); |
840 if (use_online_check != url_filter_context_.HasAsyncURLChecker()) { | 737 if (use_online_check != url_filter_.HasAsyncURLChecker()) { |
841 if (use_online_check) | 738 if (use_online_check) |
842 url_filter_context_.InitAsyncURLChecker(profile_->GetRequestContext()); | 739 url_filter_.InitAsyncURLChecker(profile_->GetRequestContext()); |
843 else | 740 else |
844 url_filter_context_.ClearAsyncURLChecker(); | 741 url_filter_.ClearAsyncURLChecker(); |
845 } | 742 } |
846 } | 743 } |
847 | 744 |
848 void SupervisedUserService::OnSiteListsChanged( | 745 void SupervisedUserService::OnSiteListsChanged( |
849 const std::vector<scoped_refptr<SupervisedUserSiteList> >& site_lists) { | 746 const std::vector<scoped_refptr<SupervisedUserSiteList> >& site_lists) { |
850 whitelists_ = site_lists; | 747 whitelists_ = site_lists; |
851 url_filter_context_.LoadWhitelists(site_lists); | 748 url_filter_.LoadWhitelists(site_lists); |
852 } | 749 } |
853 | 750 |
854 void SupervisedUserService::LoadBlacklist(const base::FilePath& path, | 751 void SupervisedUserService::LoadBlacklist(const base::FilePath& path, |
855 const GURL& url) { | 752 const GURL& url) { |
856 DCHECK(blacklist_state_ == BlacklistLoadState::NOT_LOADED); | 753 DCHECK(blacklist_state_ == BlacklistLoadState::NOT_LOADED); |
857 blacklist_state_ = BlacklistLoadState::LOAD_STARTED; | 754 blacklist_state_ = BlacklistLoadState::LOAD_STARTED; |
858 base::PostTaskAndReplyWithResult( | 755 base::PostTaskAndReplyWithResult( |
859 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( | 756 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
860 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN).get(), | 757 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN).get(), |
861 FROM_HERE, | 758 FROM_HERE, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 } | 833 } |
937 | 834 |
938 void SupervisedUserService::OnBlacklistLoaded() { | 835 void SupervisedUserService::OnBlacklistLoaded() { |
939 DCHECK(blacklist_state_ == BlacklistLoadState::LOAD_STARTED); | 836 DCHECK(blacklist_state_ == BlacklistLoadState::LOAD_STARTED); |
940 blacklist_state_ = BlacklistLoadState::LOADED; | 837 blacklist_state_ = BlacklistLoadState::LOADED; |
941 UpdateBlacklist(); | 838 UpdateBlacklist(); |
942 } | 839 } |
943 | 840 |
944 void SupervisedUserService::UpdateBlacklist() { | 841 void SupervisedUserService::UpdateBlacklist() { |
945 bool use_blacklist = supervised_users::IsSafeSitesBlacklistEnabled(profile_); | 842 bool use_blacklist = supervised_users::IsSafeSitesBlacklistEnabled(profile_); |
946 url_filter_context_.SetBlacklist(use_blacklist ? &blacklist_ : nullptr); | 843 url_filter_.SetBlacklist(use_blacklist ? &blacklist_ : nullptr); |
947 for (SupervisedUserServiceObserver& observer : observer_list_) | 844 for (SupervisedUserServiceObserver& observer : observer_list_) |
948 observer.OnURLFilterChanged(); | 845 observer.OnURLFilterChanged(); |
949 } | 846 } |
950 | 847 |
951 void SupervisedUserService::UpdateManualHosts() { | 848 void SupervisedUserService::UpdateManualHosts() { |
952 const base::DictionaryValue* dict = | 849 const base::DictionaryValue* dict = |
953 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualHosts); | 850 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualHosts); |
954 std::unique_ptr<std::map<std::string, bool>> host_map( | 851 std::map<std::string, bool> host_map; |
955 new std::map<std::string, bool>()); | |
956 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 852 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
957 bool allow = false; | 853 bool allow = false; |
958 bool result = it.value().GetAsBoolean(&allow); | 854 bool result = it.value().GetAsBoolean(&allow); |
959 DCHECK(result); | 855 DCHECK(result); |
960 (*host_map)[it.key()] = allow; | 856 host_map[it.key()] = allow; |
961 } | 857 } |
962 url_filter_context_.SetManualHosts(std::move(host_map)); | 858 url_filter_.SetManualHosts(std::move(host_map)); |
963 | 859 |
964 for (SupervisedUserServiceObserver& observer : observer_list_) | 860 for (SupervisedUserServiceObserver& observer : observer_list_) |
965 observer.OnURLFilterChanged(); | 861 observer.OnURLFilterChanged(); |
966 } | 862 } |
967 | 863 |
968 void SupervisedUserService::UpdateManualURLs() { | 864 void SupervisedUserService::UpdateManualURLs() { |
969 const base::DictionaryValue* dict = | 865 const base::DictionaryValue* dict = |
970 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualURLs); | 866 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualURLs); |
971 std::unique_ptr<std::map<GURL, bool>> url_map(new std::map<GURL, bool>()); | 867 std::map<GURL, bool> url_map; |
972 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 868 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
973 bool allow = false; | 869 bool allow = false; |
974 bool result = it.value().GetAsBoolean(&allow); | 870 bool result = it.value().GetAsBoolean(&allow); |
975 DCHECK(result); | 871 DCHECK(result); |
976 (*url_map)[GURL(it.key())] = allow; | 872 url_map[GURL(it.key())] = allow; |
977 } | 873 } |
978 url_filter_context_.SetManualURLs(std::move(url_map)); | 874 url_filter_.SetManualURLs(std::move(url_map)); |
979 | 875 |
980 for (SupervisedUserServiceObserver& observer : observer_list_) | 876 for (SupervisedUserServiceObserver& observer : observer_list_) |
981 observer.OnURLFilterChanged(); | 877 observer.OnURLFilterChanged(); |
982 } | 878 } |
983 | 879 |
984 std::string SupervisedUserService::GetSupervisedUserName() const { | 880 std::string SupervisedUserService::GetSupervisedUserName() const { |
985 #if defined(OS_CHROMEOS) | 881 #if defined(OS_CHROMEOS) |
986 // The active user can be NULL in unit tests. | 882 // The active user can be NULL in unit tests. |
987 if (user_manager::UserManager::Get()->GetActiveUser()) { | 883 if (user_manager::UserManager::Get()->GetActiveUser()) { |
988 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( | 884 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); | 1206 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); |
1311 | 1207 |
1312 is_profile_active_ = profile_became_active; | 1208 is_profile_active_ = profile_became_active; |
1313 } | 1209 } |
1314 #endif // !defined(OS_ANDROID) | 1210 #endif // !defined(OS_ANDROID) |
1315 | 1211 |
1316 void SupervisedUserService::OnSiteListUpdated() { | 1212 void SupervisedUserService::OnSiteListUpdated() { |
1317 for (SupervisedUserServiceObserver& observer : observer_list_) | 1213 for (SupervisedUserServiceObserver& observer : observer_list_) |
1318 observer.OnURLFilterChanged(); | 1214 observer.OnURLFilterChanged(); |
1319 } | 1215 } |
OLD | NEW |