Chromium Code Reviews| 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 const scoped_refptr<net::URLRequestContextGetter>& context, | 218 const scoped_refptr<net::URLRequestContextGetter>& context, |
| 219 const std::string& cx) { | 219 const std::string& cx) { |
| 220 ui_url_filter_->InitAsyncURLChecker(context.get(), cx); | 220 ui_url_filter_->InitAsyncURLChecker(context.get(), cx); |
| 221 BrowserThread::PostTask( | 221 BrowserThread::PostTask( |
| 222 BrowserThread::IO, | 222 BrowserThread::IO, |
| 223 FROM_HERE, | 223 FROM_HERE, |
| 224 base::Bind(&SupervisedUserURLFilter::InitAsyncURLChecker, | 224 base::Bind(&SupervisedUserURLFilter::InitAsyncURLChecker, |
| 225 io_url_filter_, context, cx)); | 225 io_url_filter_, context, cx)); |
| 226 } | 226 } |
| 227 | 227 |
| 228 class SupervisedUserService::SendPermissionRequestHelper { | |
| 229 public: | |
| 230 virtual ~SendPermissionRequestHelper() {} | |
| 231 | |
| 232 virtual void SendPermissionRequest(PermissionRequestCreator* creator, | |
|
Bernhard Bauer
2015/03/02 23:09:59
Nice! Now that I see this, I'm wondering though wh
Marc Treib
2015/03/03 10:04:50
You're right, it's much less boilerplate with call
| |
| 233 const SuccessCallback& callback) = 0; | |
| 234 }; | |
| 235 | |
| 236 class SupervisedUserService::SendURLAccessRequestHelper | |
| 237 : public SupervisedUserService::SendPermissionRequestHelper { | |
| 238 public: | |
| 239 explicit SendURLAccessRequestHelper(const GURL& url) : url_(url) {} | |
| 240 | |
| 241 void SendPermissionRequest(PermissionRequestCreator* creator, | |
| 242 const SuccessCallback& callback) override { | |
| 243 creator->CreateURLAccessRequest(url_, callback); | |
| 244 } | |
| 245 | |
| 246 private: | |
| 247 const GURL url_; | |
| 248 }; | |
| 249 | |
| 250 class SupervisedUserService::SendExtensionUpdateRequestHelper | |
| 251 : public SupervisedUserService::SendPermissionRequestHelper { | |
| 252 public: | |
| 253 explicit SendExtensionUpdateRequestHelper(const std::string& id) : id_(id) {} | |
| 254 | |
| 255 void SendPermissionRequest(PermissionRequestCreator* creator, | |
| 256 const SuccessCallback& callback) override { | |
| 257 creator->CreateExtensionUpdateRequest(id_, callback); | |
| 258 } | |
| 259 | |
| 260 private: | |
| 261 const std::string id_; | |
| 262 }; | |
| 263 | |
| 228 SupervisedUserService::SupervisedUserService(Profile* profile) | 264 SupervisedUserService::SupervisedUserService(Profile* profile) |
| 229 : includes_sync_sessions_type_(true), | 265 : includes_sync_sessions_type_(true), |
| 230 profile_(profile), | 266 profile_(profile), |
| 231 active_(false), | 267 active_(false), |
| 232 delegate_(NULL), | 268 delegate_(NULL), |
| 233 waiting_for_sync_initialization_(false), | 269 waiting_for_sync_initialization_(false), |
| 234 is_profile_active_(false), | 270 is_profile_active_(false), |
| 235 did_init_(false), | 271 did_init_(false), |
| 236 did_shutdown_(false), | 272 did_shutdown_(false), |
| 237 weak_ptr_factory_(this) { | 273 weak_ptr_factory_(this) { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 524 | 560 |
| 525 size_t SupervisedUserService::FindEnabledPermissionRequestCreator( | 561 size_t SupervisedUserService::FindEnabledPermissionRequestCreator( |
| 526 size_t start) { | 562 size_t start) { |
| 527 for (size_t i = start; i < permissions_creators_.size(); ++i) { | 563 for (size_t i = start; i < permissions_creators_.size(); ++i) { |
| 528 if (permissions_creators_[i]->IsEnabled()) | 564 if (permissions_creators_[i]->IsEnabled()) |
| 529 return i; | 565 return i; |
| 530 } | 566 } |
| 531 return permissions_creators_.size(); | 567 return permissions_creators_.size(); |
| 532 } | 568 } |
| 533 | 569 |
| 534 void SupervisedUserService::AddAccessRequestInternal( | 570 void SupervisedUserService::AddPermissionRequestInternal( |
| 535 const GURL& url, | 571 scoped_ptr<SendPermissionRequestHelper> helper, |
| 536 const SuccessCallback& callback, | 572 const SuccessCallback& callback, |
| 537 size_t index) { | 573 size_t index) { |
| 538 // Find a permission request creator that is enabled. | 574 // Find a permission request creator that is enabled. |
| 539 size_t next_index = FindEnabledPermissionRequestCreator(index); | 575 size_t next_index = FindEnabledPermissionRequestCreator(index); |
| 540 if (next_index >= permissions_creators_.size()) { | 576 if (next_index >= permissions_creators_.size()) { |
| 541 callback.Run(false); | 577 callback.Run(false); |
| 542 return; | 578 return; |
| 543 } | 579 } |
| 544 | 580 |
| 545 permissions_creators_[next_index]->CreatePermissionRequest( | 581 helper->SendPermissionRequest( |
| 546 url, | 582 permissions_creators_[next_index], |
| 547 base::Bind(&SupervisedUserService::OnPermissionRequestIssued, | 583 base::Bind(&SupervisedUserService::OnPermissionRequestIssued, |
| 548 weak_ptr_factory_.GetWeakPtr(), url, callback, next_index)); | 584 weak_ptr_factory_.GetWeakPtr(), base::Passed(&helper), |
|
Marc Treib
2015/03/02 18:26:00
This is ugly: The base::Passed nulls the helper, b
Bernhard Bauer
2015/03/02 23:09:59
Wait, how would we call the method before its argu
Marc Treib
2015/03/03 10:04:50
Thinking about this again, it probably depends on
| |
| 585 callback, next_index)); | |
| 549 } | 586 } |
| 550 | 587 |
| 551 void SupervisedUserService::OnPermissionRequestIssued( | 588 void SupervisedUserService::OnPermissionRequestIssued( |
| 552 const GURL& url, | 589 scoped_ptr<SendPermissionRequestHelper> helper, |
| 553 const SuccessCallback& callback, | 590 const SuccessCallback& callback, |
| 554 size_t index, | 591 size_t index, |
| 555 bool success) { | 592 bool success) { |
| 556 if (success) { | 593 if (success) { |
| 557 callback.Run(true); | 594 callback.Run(true); |
| 558 return; | 595 return; |
| 559 } | 596 } |
| 560 | 597 |
| 561 AddAccessRequestInternal(url, callback, index + 1); | 598 AddPermissionRequestInternal(helper.Pass(), callback, index + 1); |
| 562 } | 599 } |
| 563 | 600 |
| 564 void SupervisedUserService::OnSupervisedUserIdChanged() { | 601 void SupervisedUserService::OnSupervisedUserIdChanged() { |
| 565 SetActive(ProfileIsSupervised()); | 602 SetActive(ProfileIsSupervised()); |
| 566 } | 603 } |
| 567 | 604 |
| 568 void SupervisedUserService::OnDefaultFilteringBehaviorChanged() { | 605 void SupervisedUserService::OnDefaultFilteringBehaviorChanged() { |
| 569 DCHECK(ProfileIsSupervised()); | 606 DCHECK(ProfileIsSupervised()); |
| 570 | 607 |
| 571 int behavior_value = profile_->GetPrefs()->GetInteger( | 608 int behavior_value = profile_->GetPrefs()->GetInteger( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 624 | 661 |
| 625 void SupervisedUserService::OnBlacklistLoaded() { | 662 void SupervisedUserService::OnBlacklistLoaded() { |
| 626 FOR_EACH_OBSERVER( | 663 FOR_EACH_OBSERVER( |
| 627 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 664 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
| 628 } | 665 } |
| 629 | 666 |
| 630 bool SupervisedUserService::AccessRequestsEnabled() { | 667 bool SupervisedUserService::AccessRequestsEnabled() { |
| 631 return FindEnabledPermissionRequestCreator(0) < permissions_creators_.size(); | 668 return FindEnabledPermissionRequestCreator(0) < permissions_creators_.size(); |
| 632 } | 669 } |
| 633 | 670 |
| 634 void SupervisedUserService::AddAccessRequest(const GURL& url, | 671 void SupervisedUserService::AddURLAccessRequest( |
| 635 const SuccessCallback& callback) { | 672 const GURL& url, |
| 636 AddAccessRequestInternal(SupervisedUserURLFilter::Normalize(url), callback, | 673 const SuccessCallback& callback) { |
| 637 0); | 674 AddPermissionRequestInternal( |
| 675 make_scoped_ptr(new SendURLAccessRequestHelper( | |
| 676 SupervisedUserURLFilter::Normalize(url))), | |
| 677 callback, 0); | |
| 678 } | |
| 679 | |
| 680 void SupervisedUserService::AddExtensionUpdateRequest( | |
| 681 const std::string& extension_id, | |
| 682 const SuccessCallback& callback) { | |
| 683 AddPermissionRequestInternal( | |
| 684 make_scoped_ptr(new SendExtensionUpdateRequestHelper(extension_id)), | |
| 685 callback, 0); | |
| 638 } | 686 } |
| 639 | 687 |
| 640 void SupervisedUserService::InitSync(const std::string& refresh_token) { | 688 void SupervisedUserService::InitSync(const std::string& refresh_token) { |
| 641 StartSetupSync(); | 689 StartSetupSync(); |
| 642 | 690 |
| 643 ProfileOAuth2TokenService* token_service = | 691 ProfileOAuth2TokenService* token_service = |
| 644 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 692 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 645 token_service->UpdateCredentials(supervised_users::kSupervisedUserPseudoEmail, | 693 token_service->UpdateCredentials(supervised_users::kSupervisedUserPseudoEmail, |
| 646 refresh_token); | 694 refresh_token); |
| 647 | 695 |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 913 // The active user can be NULL in unit tests. | 961 // The active user can be NULL in unit tests. |
| 914 if (user_manager::UserManager::Get()->GetActiveUser()) { | 962 if (user_manager::UserManager::Get()->GetActiveUser()) { |
| 915 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( | 963 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( |
| 916 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); | 964 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); |
| 917 } | 965 } |
| 918 return std::string(); | 966 return std::string(); |
| 919 #else | 967 #else |
| 920 return profile_->GetPrefs()->GetString(prefs::kProfileName); | 968 return profile_->GetPrefs()->GetString(prefs::kProfileName); |
| 921 #endif | 969 #endif |
| 922 } | 970 } |
| OLD | NEW |