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/experimental/supervised_user_blacklist_
downloader.h" |
21 #include "chrome/browser/supervised_user/permission_request_creator_apiary.h" | 22 #include "chrome/browser/supervised_user/permission_request_creator_apiary.h" |
22 #include "chrome/browser/supervised_user/permission_request_creator_sync.h" | 23 #include "chrome/browser/supervised_user/permission_request_creator_sync.h" |
23 #include "chrome/browser/supervised_user/supervised_user_constants.h" | 24 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
24 #include "chrome/browser/supervised_user/supervised_user_pref_mapping_service.h" | 25 #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" | 26 #include "chrome/browser/supervised_user/supervised_user_pref_mapping_service_fa
ctory.h" |
26 #include "chrome/browser/supervised_user/supervised_user_registration_utility.h" | 27 #include "chrome/browser/supervised_user/supervised_user_registration_utility.h" |
27 #include "chrome/browser/supervised_user/supervised_user_service_observer.h" | 28 #include "chrome/browser/supervised_user/supervised_user_service_observer.h" |
28 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" | 29 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
29 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor
y.h" | 30 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor
y.h" |
30 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service
_factory.h" | 31 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service
_factory.h" |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 | 551 |
551 void SupervisedUserService::UpdateSiteLists() { | 552 void SupervisedUserService::UpdateSiteLists() { |
552 #if defined(ENABLE_EXTENSIONS) | 553 #if defined(ENABLE_EXTENSIONS) |
553 url_filter_context_.LoadWhitelists(GetActiveSiteLists()); | 554 url_filter_context_.LoadWhitelists(GetActiveSiteLists()); |
554 | 555 |
555 FOR_EACH_OBSERVER( | 556 FOR_EACH_OBSERVER( |
556 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 557 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
557 #endif | 558 #endif |
558 } | 559 } |
559 | 560 |
560 void SupervisedUserService::LoadBlacklist(const base::FilePath& path) { | 561 void SupervisedUserService::LoadBlacklist(const base::FilePath& path, |
| 562 const GURL& url) { |
| 563 if (!url.is_valid()) { |
| 564 LoadBlacklistFromFile(path); |
| 565 return; |
| 566 } |
| 567 |
| 568 DCHECK(!blacklist_downloader_.get()); |
| 569 blacklist_downloader_.reset(new SupervisedUserBlacklistDownloader( |
| 570 url, |
| 571 path, |
| 572 profile_->GetRequestContext(), |
| 573 base::Bind(&SupervisedUserService::OnBlacklistDownloadDone, |
| 574 base::Unretained(this), path))); |
| 575 } |
| 576 |
| 577 void SupervisedUserService::LoadBlacklistFromFile(const base::FilePath& path) { |
561 url_filter_context_.LoadBlacklist(path); | 578 url_filter_context_.LoadBlacklist(path); |
562 | 579 |
563 FOR_EACH_OBSERVER( | 580 FOR_EACH_OBSERVER( |
564 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 581 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
565 } | 582 } |
566 | 583 |
| 584 void SupervisedUserService::OnBlacklistDownloadDone(const base::FilePath& path, |
| 585 bool success) { |
| 586 if (success) { |
| 587 LoadBlacklistFromFile(path); |
| 588 } else { |
| 589 LOG(WARNING) << "Blacklist download failed"; |
| 590 } |
| 591 blacklist_downloader_.reset(); |
| 592 } |
| 593 |
567 bool SupervisedUserService::AccessRequestsEnabled() { | 594 bool SupervisedUserService::AccessRequestsEnabled() { |
568 ProfileSyncService* service = | 595 ProfileSyncService* service = |
569 ProfileSyncServiceFactory::GetForProfile(profile_); | 596 ProfileSyncServiceFactory::GetForProfile(profile_); |
570 GoogleServiceAuthError::State state = service->GetAuthError().state(); | 597 GoogleServiceAuthError::State state = service->GetAuthError().state(); |
571 // We allow requesting access if Sync is working or has a transient error. | 598 // We allow requesting access if Sync is working or has a transient error. |
572 return (state == GoogleServiceAuthError::NONE || | 599 return (state == GoogleServiceAuthError::NONE || |
573 state == GoogleServiceAuthError::CONNECTION_FAILED || | 600 state == GoogleServiceAuthError::CONNECTION_FAILED || |
574 state == GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 601 state == GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
575 } | 602 } |
576 | 603 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 OnDefaultFilteringBehaviorChanged(); | 755 OnDefaultFilteringBehaviorChanged(); |
729 UpdateSiteLists(); | 756 UpdateSiteLists(); |
730 UpdateManualHosts(); | 757 UpdateManualHosts(); |
731 UpdateManualURLs(); | 758 UpdateManualURLs(); |
732 bool use_blacklist = | 759 bool use_blacklist = |
733 CommandLine::ForCurrentProcess()->HasSwitch( | 760 CommandLine::ForCurrentProcess()->HasSwitch( |
734 switches::kEnableSupervisedUserBlacklist); | 761 switches::kEnableSupervisedUserBlacklist); |
735 if (delegate_ && use_blacklist) { | 762 if (delegate_ && use_blacklist) { |
736 base::FilePath blacklist_path = delegate_->GetBlacklistPath(); | 763 base::FilePath blacklist_path = delegate_->GetBlacklistPath(); |
737 if (!blacklist_path.empty()) | 764 if (!blacklist_path.empty()) |
738 LoadBlacklist(blacklist_path); | 765 LoadBlacklist(blacklist_path, delegate_->GetBlacklistURL()); |
739 } | 766 } |
740 | 767 |
741 #if !defined(OS_ANDROID) | 768 #if !defined(OS_ANDROID) |
742 // TODO(bauerb): Get rid of the platform-specific #ifdef here. | 769 // TODO(bauerb): Get rid of the platform-specific #ifdef here. |
743 // http://crbug.com/313377 | 770 // http://crbug.com/313377 |
744 BrowserList::AddObserver(this); | 771 BrowserList::AddObserver(this); |
745 #endif | 772 #endif |
746 } else { | 773 } else { |
747 permissions_creator_.reset(); | 774 permissions_creator_.reset(); |
748 | 775 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 // The active user can be NULL in unit tests. | 897 // The active user can be NULL in unit tests. |
871 if (user_manager::UserManager::Get()->GetActiveUser()) { | 898 if (user_manager::UserManager::Get()->GetActiveUser()) { |
872 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( | 899 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( |
873 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); | 900 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); |
874 } | 901 } |
875 return std::string(); | 902 return std::string(); |
876 #else | 903 #else |
877 return profile_->GetPrefs()->GetString(prefs::kProfileName); | 904 return profile_->GetPrefs()->GetString(prefs::kProfileName); |
878 #endif | 905 #endif |
879 } | 906 } |
OLD | NEW |