| 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" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 prefs::kSupervisedUserCustodianName, | 71 prefs::kSupervisedUserCustodianName, |
| 72 prefs::kSupervisedUserCustodianEmail, | 72 prefs::kSupervisedUserCustodianEmail, |
| 73 prefs::kSupervisedUserCustodianProfileImageURL, | 73 prefs::kSupervisedUserCustodianProfileImageURL, |
| 74 prefs::kSupervisedUserCustodianProfileURL, | 74 prefs::kSupervisedUserCustodianProfileURL, |
| 75 prefs::kSupervisedUserSecondCustodianName, | 75 prefs::kSupervisedUserSecondCustodianName, |
| 76 prefs::kSupervisedUserSecondCustodianEmail, | 76 prefs::kSupervisedUserSecondCustodianEmail, |
| 77 prefs::kSupervisedUserSecondCustodianProfileImageURL, | 77 prefs::kSupervisedUserSecondCustodianProfileImageURL, |
| 78 prefs::kSupervisedUserSecondCustodianProfileURL, | 78 prefs::kSupervisedUserSecondCustodianProfileURL, |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 void CreateURLAccessRequest( |
| 82 const GURL& url, |
| 83 PermissionRequestCreator* creator, |
| 84 const SupervisedUserService::SuccessCallback& callback) { |
| 85 creator->CreateURLAccessRequest(url, callback); |
| 86 } |
| 87 |
| 88 void CreateExtensionUpdateRequest( |
| 89 const std::string& extension_id, |
| 90 PermissionRequestCreator* creator, |
| 91 const SupervisedUserService::SuccessCallback& callback) { |
| 92 creator->CreateExtensionUpdateRequest(extension_id, callback); |
| 93 } |
| 94 |
| 81 #if defined(ENABLE_EXTENSIONS) | 95 #if defined(ENABLE_EXTENSIONS) |
| 82 enum ExtensionState { | 96 enum ExtensionState { |
| 83 EXTENSION_FORCED, | 97 EXTENSION_FORCED, |
| 84 EXTENSION_BLOCKED, | 98 EXTENSION_BLOCKED, |
| 85 EXTENSION_ALLOWED | 99 EXTENSION_ALLOWED |
| 86 }; | 100 }; |
| 87 | 101 |
| 88 ExtensionState GetExtensionState(const extensions::Extension* extension) { | 102 ExtensionState GetExtensionState(const extensions::Extension* extension) { |
| 89 if (extension->is_theme()) | 103 if (extension->is_theme()) |
| 90 return EXTENSION_ALLOWED; | 104 return EXTENSION_ALLOWED; |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 | 538 |
| 525 size_t SupervisedUserService::FindEnabledPermissionRequestCreator( | 539 size_t SupervisedUserService::FindEnabledPermissionRequestCreator( |
| 526 size_t start) { | 540 size_t start) { |
| 527 for (size_t i = start; i < permissions_creators_.size(); ++i) { | 541 for (size_t i = start; i < permissions_creators_.size(); ++i) { |
| 528 if (permissions_creators_[i]->IsEnabled()) | 542 if (permissions_creators_[i]->IsEnabled()) |
| 529 return i; | 543 return i; |
| 530 } | 544 } |
| 531 return permissions_creators_.size(); | 545 return permissions_creators_.size(); |
| 532 } | 546 } |
| 533 | 547 |
| 534 void SupervisedUserService::AddAccessRequestInternal( | 548 void SupervisedUserService::AddPermissionRequestInternal( |
| 535 const GURL& url, | 549 const CreatePermissionRequestCallback& create_request, |
| 536 const SuccessCallback& callback, | 550 const SuccessCallback& callback, |
| 537 size_t index) { | 551 size_t index) { |
| 538 // Find a permission request creator that is enabled. | 552 // Find a permission request creator that is enabled. |
| 539 size_t next_index = FindEnabledPermissionRequestCreator(index); | 553 size_t next_index = FindEnabledPermissionRequestCreator(index); |
| 540 if (next_index >= permissions_creators_.size()) { | 554 if (next_index >= permissions_creators_.size()) { |
| 541 callback.Run(false); | 555 callback.Run(false); |
| 542 return; | 556 return; |
| 543 } | 557 } |
| 544 | 558 |
| 545 permissions_creators_[next_index]->CreatePermissionRequest( | 559 create_request.Run( |
| 546 url, | 560 permissions_creators_[next_index], |
| 547 base::Bind(&SupervisedUserService::OnPermissionRequestIssued, | 561 base::Bind(&SupervisedUserService::OnPermissionRequestIssued, |
| 548 weak_ptr_factory_.GetWeakPtr(), url, callback, next_index)); | 562 weak_ptr_factory_.GetWeakPtr(), create_request, |
| 563 callback, next_index)); |
| 549 } | 564 } |
| 550 | 565 |
| 551 void SupervisedUserService::OnPermissionRequestIssued( | 566 void SupervisedUserService::OnPermissionRequestIssued( |
| 552 const GURL& url, | 567 const CreatePermissionRequestCallback& create_request, |
| 553 const SuccessCallback& callback, | 568 const SuccessCallback& callback, |
| 554 size_t index, | 569 size_t index, |
| 555 bool success) { | 570 bool success) { |
| 556 if (success) { | 571 if (success) { |
| 557 callback.Run(true); | 572 callback.Run(true); |
| 558 return; | 573 return; |
| 559 } | 574 } |
| 560 | 575 |
| 561 AddAccessRequestInternal(url, callback, index + 1); | 576 AddPermissionRequestInternal(create_request, callback, index + 1); |
| 562 } | 577 } |
| 563 | 578 |
| 564 void SupervisedUserService::OnSupervisedUserIdChanged() { | 579 void SupervisedUserService::OnSupervisedUserIdChanged() { |
| 565 SetActive(ProfileIsSupervised()); | 580 SetActive(ProfileIsSupervised()); |
| 566 } | 581 } |
| 567 | 582 |
| 568 void SupervisedUserService::OnDefaultFilteringBehaviorChanged() { | 583 void SupervisedUserService::OnDefaultFilteringBehaviorChanged() { |
| 569 DCHECK(ProfileIsSupervised()); | 584 DCHECK(ProfileIsSupervised()); |
| 570 | 585 |
| 571 int behavior_value = profile_->GetPrefs()->GetInteger( | 586 int behavior_value = profile_->GetPrefs()->GetInteger( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 | 639 |
| 625 void SupervisedUserService::OnBlacklistLoaded() { | 640 void SupervisedUserService::OnBlacklistLoaded() { |
| 626 FOR_EACH_OBSERVER( | 641 FOR_EACH_OBSERVER( |
| 627 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 642 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
| 628 } | 643 } |
| 629 | 644 |
| 630 bool SupervisedUserService::AccessRequestsEnabled() { | 645 bool SupervisedUserService::AccessRequestsEnabled() { |
| 631 return FindEnabledPermissionRequestCreator(0) < permissions_creators_.size(); | 646 return FindEnabledPermissionRequestCreator(0) < permissions_creators_.size(); |
| 632 } | 647 } |
| 633 | 648 |
| 634 void SupervisedUserService::AddAccessRequest(const GURL& url, | 649 void SupervisedUserService::AddURLAccessRequest( |
| 635 const SuccessCallback& callback) { | 650 const GURL& url, |
| 636 AddAccessRequestInternal(SupervisedUserURLFilter::Normalize(url), callback, | 651 const SuccessCallback& callback) { |
| 637 0); | 652 AddPermissionRequestInternal( |
| 653 base::Bind(CreateURLAccessRequest, |
| 654 SupervisedUserURLFilter::Normalize(url)), |
| 655 callback, 0); |
| 656 } |
| 657 |
| 658 void SupervisedUserService::AddExtensionUpdateRequest( |
| 659 const std::string& extension_id, |
| 660 const SuccessCallback& callback) { |
| 661 AddPermissionRequestInternal( |
| 662 base::Bind(CreateExtensionUpdateRequest, extension_id), |
| 663 callback, 0); |
| 638 } | 664 } |
| 639 | 665 |
| 640 void SupervisedUserService::InitSync(const std::string& refresh_token) { | 666 void SupervisedUserService::InitSync(const std::string& refresh_token) { |
| 641 StartSetupSync(); | 667 StartSetupSync(); |
| 642 | 668 |
| 643 ProfileOAuth2TokenService* token_service = | 669 ProfileOAuth2TokenService* token_service = |
| 644 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 670 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 645 token_service->UpdateCredentials(supervised_users::kSupervisedUserPseudoEmail, | 671 token_service->UpdateCredentials(supervised_users::kSupervisedUserPseudoEmail, |
| 646 refresh_token); | 672 refresh_token); |
| 647 | 673 |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 // The active user can be NULL in unit tests. | 939 // The active user can be NULL in unit tests. |
| 914 if (user_manager::UserManager::Get()->GetActiveUser()) { | 940 if (user_manager::UserManager::Get()->GetActiveUser()) { |
| 915 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( | 941 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( |
| 916 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); | 942 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); |
| 917 } | 943 } |
| 918 return std::string(); | 944 return std::string(); |
| 919 #else | 945 #else |
| 920 return profile_->GetPrefs()->GetString(prefs::kProfileName); | 946 return profile_->GetPrefs()->GetString(prefs::kProfileName); |
| 921 #endif | 947 #endif |
| 922 } | 948 } |
| OLD | NEW |