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 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 | 524 |
525 size_t SupervisedUserService::FindEnabledPermissionRequestCreator( | 525 size_t SupervisedUserService::FindEnabledPermissionRequestCreator( |
526 size_t start) { | 526 size_t start) { |
527 for (size_t i = start; i < permissions_creators_.size(); ++i) { | 527 for (size_t i = start; i < permissions_creators_.size(); ++i) { |
528 if (permissions_creators_[i]->IsEnabled()) | 528 if (permissions_creators_[i]->IsEnabled()) |
529 return i; | 529 return i; |
530 } | 530 } |
531 return permissions_creators_.size(); | 531 return permissions_creators_.size(); |
532 } | 532 } |
533 | 533 |
534 void SupervisedUserService::AddAccessRequestInternal( | 534 void SupervisedUserService::AddURLAccessRequestInternal( |
535 const GURL& url, | 535 const GURL& url, |
536 const SuccessCallback& callback, | 536 const SuccessCallback& callback, |
537 size_t index) { | 537 size_t index) { |
538 // Find a permission request creator that is enabled. | 538 // Find a permission request creator that is enabled. |
539 size_t next_index = FindEnabledPermissionRequestCreator(index); | 539 size_t next_index = FindEnabledPermissionRequestCreator(index); |
540 if (next_index >= permissions_creators_.size()) { | 540 if (next_index >= permissions_creators_.size()) { |
541 callback.Run(false); | 541 callback.Run(false); |
542 return; | 542 return; |
543 } | 543 } |
544 | 544 |
545 permissions_creators_[next_index]->CreatePermissionRequest( | 545 permissions_creators_[next_index]->CreateURLAccessRequest( |
546 url, | 546 url, |
547 base::Bind(&SupervisedUserService::OnPermissionRequestIssued, | 547 base::Bind(&SupervisedUserService::OnURLAccessRequestIssued, |
548 weak_ptr_factory_.GetWeakPtr(), url, callback, next_index)); | 548 weak_ptr_factory_.GetWeakPtr(), url, callback, next_index)); |
549 } | 549 } |
550 | 550 |
551 void SupervisedUserService::OnPermissionRequestIssued( | 551 void SupervisedUserService::OnURLAccessRequestIssued( |
552 const GURL& url, | 552 const GURL& url, |
553 const SuccessCallback& callback, | 553 const SuccessCallback& callback, |
554 size_t index, | 554 size_t index, |
555 bool success) { | 555 bool success) { |
556 if (success) { | 556 if (success) { |
557 callback.Run(true); | 557 callback.Run(true); |
558 return; | 558 return; |
559 } | 559 } |
560 | 560 |
561 AddAccessRequestInternal(url, callback, index + 1); | 561 AddURLAccessRequestInternal(url, callback, index + 1); |
562 } | |
563 | |
564 void SupervisedUserService::AddExtensionUpdateRequestInternal( | |
565 const std::string& extension_id, | |
566 const SuccessCallback& callback, | |
567 size_t index) { | |
568 // Find a permission request creator that is enabled. | |
Bernhard Bauer
2015/03/02 16:41:56
Urr... it's not particularly nice to duplicate thi
Marc Treib
2015/03/02 18:26:00
Done.
| |
569 size_t next_index = FindEnabledPermissionRequestCreator(index); | |
570 if (next_index >= permissions_creators_.size()) { | |
571 callback.Run(false); | |
572 return; | |
573 } | |
574 | |
575 permissions_creators_[next_index]->CreateExtensionUpdateRequest( | |
576 extension_id, | |
577 base::Bind(&SupervisedUserService::OnExtensionUpdateRequestIssued, | |
578 weak_ptr_factory_.GetWeakPtr(), | |
579 extension_id, callback, next_index)); | |
580 } | |
581 | |
582 void SupervisedUserService::OnExtensionUpdateRequestIssued( | |
583 const std::string& extension_id, | |
584 const SuccessCallback& callback, | |
585 size_t index, | |
586 bool success) { | |
587 if (success) { | |
588 callback.Run(true); | |
589 return; | |
590 } | |
591 | |
592 AddExtensionUpdateRequestInternal(extension_id, callback, index + 1); | |
562 } | 593 } |
563 | 594 |
564 void SupervisedUserService::OnSupervisedUserIdChanged() { | 595 void SupervisedUserService::OnSupervisedUserIdChanged() { |
565 SetActive(ProfileIsSupervised()); | 596 SetActive(ProfileIsSupervised()); |
566 } | 597 } |
567 | 598 |
568 void SupervisedUserService::OnDefaultFilteringBehaviorChanged() { | 599 void SupervisedUserService::OnDefaultFilteringBehaviorChanged() { |
569 DCHECK(ProfileIsSupervised()); | 600 DCHECK(ProfileIsSupervised()); |
570 | 601 |
571 int behavior_value = profile_->GetPrefs()->GetInteger( | 602 int behavior_value = profile_->GetPrefs()->GetInteger( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
624 | 655 |
625 void SupervisedUserService::OnBlacklistLoaded() { | 656 void SupervisedUserService::OnBlacklistLoaded() { |
626 FOR_EACH_OBSERVER( | 657 FOR_EACH_OBSERVER( |
627 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 658 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
628 } | 659 } |
629 | 660 |
630 bool SupervisedUserService::AccessRequestsEnabled() { | 661 bool SupervisedUserService::AccessRequestsEnabled() { |
631 return FindEnabledPermissionRequestCreator(0) < permissions_creators_.size(); | 662 return FindEnabledPermissionRequestCreator(0) < permissions_creators_.size(); |
632 } | 663 } |
633 | 664 |
634 void SupervisedUserService::AddAccessRequest(const GURL& url, | 665 void SupervisedUserService::AddURLAccessRequest( |
635 const SuccessCallback& callback) { | 666 const GURL& url, |
636 AddAccessRequestInternal(SupervisedUserURLFilter::Normalize(url), callback, | 667 const SuccessCallback& callback) { |
637 0); | 668 AddURLAccessRequestInternal( |
669 SupervisedUserURLFilter::Normalize(url), callback, 0); | |
670 } | |
671 | |
672 void SupervisedUserService::AddExtensionUpdateRequest( | |
673 const std::string& extension_id, | |
674 const SuccessCallback& callback) { | |
675 AddExtensionUpdateRequestInternal(extension_id, callback, 0); | |
638 } | 676 } |
639 | 677 |
640 void SupervisedUserService::InitSync(const std::string& refresh_token) { | 678 void SupervisedUserService::InitSync(const std::string& refresh_token) { |
641 StartSetupSync(); | 679 StartSetupSync(); |
642 | 680 |
643 ProfileOAuth2TokenService* token_service = | 681 ProfileOAuth2TokenService* token_service = |
644 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 682 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
645 token_service->UpdateCredentials(supervised_users::kSupervisedUserPseudoEmail, | 683 token_service->UpdateCredentials(supervised_users::kSupervisedUserPseudoEmail, |
646 refresh_token); | 684 refresh_token); |
647 | 685 |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
913 // The active user can be NULL in unit tests. | 951 // The active user can be NULL in unit tests. |
914 if (user_manager::UserManager::Get()->GetActiveUser()) { | 952 if (user_manager::UserManager::Get()->GetActiveUser()) { |
915 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( | 953 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( |
916 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); | 954 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); |
917 } | 955 } |
918 return std::string(); | 956 return std::string(); |
919 #else | 957 #else |
920 return profile_->GetPrefs()->GetString(prefs::kProfileName); | 958 return profile_->GetPrefs()->GetString(prefs::kProfileName); |
921 #endif | 959 #endif |
922 } | 960 } |
OLD | NEW |