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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/profiles/profile_info_cache.h" | 15 #include "chrome/browser/profiles/profile_info_cache.h" |
16 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
18 #include "chrome/browser/signin/signin_manager_factory.h" | 18 #include "chrome/browser/signin/signin_manager_factory.h" |
19 #include "chrome/browser/supervised_user/custodian_profile_downloader_service.h" | 19 #include "chrome/browser/supervised_user/custodian_profile_downloader_service.h" |
20 #include "chrome/browser/supervised_user/custodian_profile_downloader_service_fa
ctory.h" | 20 #include "chrome/browser/supervised_user/custodian_profile_downloader_service_fa
ctory.h" |
21 #include "chrome/browser/supervised_user/permission_request_creator_apiary.h" | 21 #include "chrome/browser/supervised_user/permission_request_creator_apiary.h" |
22 #include "chrome/browser/supervised_user/permission_request_creator_sync.h" | 22 #include "chrome/browser/supervised_user/permission_request_creator_sync.h" |
23 #include "chrome/browser/supervised_user/supervised_user_constants.h" | 23 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
24 #include "chrome/browser/supervised_user/supervised_user_pref_mapping_service.h" | 24 #include "chrome/browser/supervised_user/supervised_user_pref_mapping_service.h" |
25 #include "chrome/browser/supervised_user/supervised_user_pref_mapping_service_fa
ctory.h" | 25 #include "chrome/browser/supervised_user/supervised_user_pref_mapping_service_fa
ctory.h" |
26 #include "chrome/browser/supervised_user/supervised_user_registration_utility.h" | 26 #include "chrome/browser/supervised_user/supervised_user_registration_utility.h" |
| 27 #include "chrome/browser/supervised_user/supervised_user_service_observer.h" |
27 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" | 28 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
28 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor
y.h" | 29 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor
y.h" |
29 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service
_factory.h" | 30 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service
_factory.h" |
30 #include "chrome/browser/supervised_user/supervised_user_site_list.h" | 31 #include "chrome/browser/supervised_user/supervised_user_site_list.h" |
31 #include "chrome/browser/supervised_user/supervised_user_sync_service.h" | 32 #include "chrome/browser/supervised_user/supervised_user_sync_service.h" |
32 #include "chrome/browser/supervised_user/supervised_user_sync_service_factory.h" | 33 #include "chrome/browser/supervised_user/supervised_user_sync_service_factory.h" |
33 #include "chrome/browser/sync/profile_sync_service.h" | 34 #include "chrome/browser/sync/profile_sync_service.h" |
34 #include "chrome/browser/sync/profile_sync_service_factory.h" | 35 #include "chrome/browser/sync/profile_sync_service_factory.h" |
35 #include "chrome/browser/ui/browser.h" | 36 #include "chrome/browser/ui/browser.h" |
36 #include "chrome/browser/ui/browser_list.h" | 37 #include "chrome/browser/ui/browser_list.h" |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 | 307 |
307 void SupervisedUserService::DidBlockNavigation( | 308 void SupervisedUserService::DidBlockNavigation( |
308 content::WebContents* web_contents) { | 309 content::WebContents* web_contents) { |
309 for (std::vector<NavigationBlockedCallback>::iterator it = | 310 for (std::vector<NavigationBlockedCallback>::iterator it = |
310 navigation_blocked_callbacks_.begin(); | 311 navigation_blocked_callbacks_.begin(); |
311 it != navigation_blocked_callbacks_.end(); ++it) { | 312 it != navigation_blocked_callbacks_.end(); ++it) { |
312 it->Run(web_contents); | 313 it->Run(web_contents); |
313 } | 314 } |
314 } | 315 } |
315 | 316 |
| 317 void SupervisedUserService::AddObserver( |
| 318 SupervisedUserServiceObserver* observer) { |
| 319 observer_list_.AddObserver(observer); |
| 320 } |
| 321 |
| 322 void SupervisedUserService::RemoveObserver( |
| 323 SupervisedUserServiceObserver* observer) { |
| 324 observer_list_.RemoveObserver(observer); |
| 325 } |
| 326 |
316 #if defined(ENABLE_EXTENSIONS) | 327 #if defined(ENABLE_EXTENSIONS) |
317 std::string SupervisedUserService::GetDebugPolicyProviderName() const { | 328 std::string SupervisedUserService::GetDebugPolicyProviderName() const { |
318 // Save the string space in official builds. | 329 // Save the string space in official builds. |
319 #ifdef NDEBUG | 330 #ifdef NDEBUG |
320 NOTREACHED(); | 331 NOTREACHED(); |
321 return std::string(); | 332 return std::string(); |
322 #else | 333 #else |
323 return "Supervised User Service"; | 334 return "Supervised User Service"; |
324 #endif | 335 #endif |
325 } | 336 } |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 } | 536 } |
526 | 537 |
527 void SupervisedUserService::OnDefaultFilteringBehaviorChanged() { | 538 void SupervisedUserService::OnDefaultFilteringBehaviorChanged() { |
528 DCHECK(ProfileIsSupervised()); | 539 DCHECK(ProfileIsSupervised()); |
529 | 540 |
530 int behavior_value = profile_->GetPrefs()->GetInteger( | 541 int behavior_value = profile_->GetPrefs()->GetInteger( |
531 prefs::kDefaultSupervisedUserFilteringBehavior); | 542 prefs::kDefaultSupervisedUserFilteringBehavior); |
532 SupervisedUserURLFilter::FilteringBehavior behavior = | 543 SupervisedUserURLFilter::FilteringBehavior behavior = |
533 SupervisedUserURLFilter::BehaviorFromInt(behavior_value); | 544 SupervisedUserURLFilter::BehaviorFromInt(behavior_value); |
534 url_filter_context_.SetDefaultFilteringBehavior(behavior); | 545 url_filter_context_.SetDefaultFilteringBehavior(behavior); |
| 546 |
| 547 FOR_EACH_OBSERVER( |
| 548 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
535 } | 549 } |
536 | 550 |
537 void SupervisedUserService::UpdateSiteLists() { | 551 void SupervisedUserService::UpdateSiteLists() { |
538 #if defined(ENABLE_EXTENSIONS) | 552 #if defined(ENABLE_EXTENSIONS) |
539 url_filter_context_.LoadWhitelists(GetActiveSiteLists()); | 553 url_filter_context_.LoadWhitelists(GetActiveSiteLists()); |
| 554 |
| 555 FOR_EACH_OBSERVER( |
| 556 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
540 #endif | 557 #endif |
541 } | 558 } |
542 | 559 |
543 void SupervisedUserService::LoadBlacklist(const base::FilePath& path) { | 560 void SupervisedUserService::LoadBlacklist(const base::FilePath& path) { |
544 url_filter_context_.LoadBlacklist(path); | 561 url_filter_context_.LoadBlacklist(path); |
| 562 |
| 563 FOR_EACH_OBSERVER( |
| 564 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
545 } | 565 } |
546 | 566 |
547 bool SupervisedUserService::AccessRequestsEnabled() { | 567 bool SupervisedUserService::AccessRequestsEnabled() { |
548 ProfileSyncService* service = | 568 ProfileSyncService* service = |
549 ProfileSyncServiceFactory::GetForProfile(profile_); | 569 ProfileSyncServiceFactory::GetForProfile(profile_); |
550 GoogleServiceAuthError::State state = service->GetAuthError().state(); | 570 GoogleServiceAuthError::State state = service->GetAuthError().state(); |
551 // We allow requesting access if Sync is working or has a transient error. | 571 // We allow requesting access if Sync is working or has a transient error. |
552 return (state == GoogleServiceAuthError::NONE || | 572 return (state == GoogleServiceAuthError::NONE || |
553 state == GoogleServiceAuthError::CONNECTION_FAILED || | 573 state == GoogleServiceAuthError::CONNECTION_FAILED || |
554 state == GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 574 state == GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualHosts); | 827 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualHosts); |
808 scoped_ptr<std::map<std::string, bool> > host_map( | 828 scoped_ptr<std::map<std::string, bool> > host_map( |
809 new std::map<std::string, bool>()); | 829 new std::map<std::string, bool>()); |
810 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 830 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
811 bool allow = false; | 831 bool allow = false; |
812 bool result = it.value().GetAsBoolean(&allow); | 832 bool result = it.value().GetAsBoolean(&allow); |
813 DCHECK(result); | 833 DCHECK(result); |
814 (*host_map)[it.key()] = allow; | 834 (*host_map)[it.key()] = allow; |
815 } | 835 } |
816 url_filter_context_.SetManualHosts(host_map.Pass()); | 836 url_filter_context_.SetManualHosts(host_map.Pass()); |
| 837 |
| 838 FOR_EACH_OBSERVER( |
| 839 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
817 } | 840 } |
818 | 841 |
819 void SupervisedUserService::UpdateManualURLs() { | 842 void SupervisedUserService::UpdateManualURLs() { |
820 const base::DictionaryValue* dict = | 843 const base::DictionaryValue* dict = |
821 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualURLs); | 844 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualURLs); |
822 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); | 845 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); |
823 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 846 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
824 bool allow = false; | 847 bool allow = false; |
825 bool result = it.value().GetAsBoolean(&allow); | 848 bool result = it.value().GetAsBoolean(&allow); |
826 DCHECK(result); | 849 DCHECK(result); |
827 (*url_map)[GURL(it.key())] = allow; | 850 (*url_map)[GURL(it.key())] = allow; |
828 } | 851 } |
829 url_filter_context_.SetManualURLs(url_map.Pass()); | 852 url_filter_context_.SetManualURLs(url_map.Pass()); |
| 853 |
| 854 FOR_EACH_OBSERVER( |
| 855 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
830 } | 856 } |
831 | 857 |
832 void SupervisedUserService::OnBrowserSetLastActive(Browser* browser) { | 858 void SupervisedUserService::OnBrowserSetLastActive(Browser* browser) { |
833 bool profile_became_active = profile_->IsSameProfile(browser->profile()); | 859 bool profile_became_active = profile_->IsSameProfile(browser->profile()); |
834 if (!is_profile_active_ && profile_became_active) | 860 if (!is_profile_active_ && profile_became_active) |
835 content::RecordAction(UserMetricsAction("ManagedUsers_OpenProfile")); | 861 content::RecordAction(UserMetricsAction("ManagedUsers_OpenProfile")); |
836 else if (is_profile_active_ && !profile_became_active) | 862 else if (is_profile_active_ && !profile_became_active) |
837 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); | 863 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); |
838 | 864 |
839 is_profile_active_ = profile_became_active; | 865 is_profile_active_ = profile_became_active; |
840 } | 866 } |
841 | 867 |
842 std::string SupervisedUserService::GetSupervisedUserName() const { | 868 std::string SupervisedUserService::GetSupervisedUserName() const { |
843 #if defined(OS_CHROMEOS) | 869 #if defined(OS_CHROMEOS) |
844 // The active user can be NULL in unit tests. | 870 // The active user can be NULL in unit tests. |
845 if (user_manager::UserManager::Get()->GetActiveUser()) { | 871 if (user_manager::UserManager::Get()->GetActiveUser()) { |
846 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( | 872 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( |
847 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); | 873 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); |
848 } | 874 } |
849 return std::string(); | 875 return std::string(); |
850 #else | 876 #else |
851 return profile_->GetPrefs()->GetString(prefs::kProfileName); | 877 return profile_->GetPrefs()->GetString(prefs::kProfileName); |
852 #endif | 878 #endif |
853 } | 879 } |
OLD | NEW |