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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 void SupervisedUserService::Shutdown() { | 210 void SupervisedUserService::Shutdown() { |
211 if (!did_init_) | 211 if (!did_init_) |
212 return; | 212 return; |
213 DCHECK(!did_shutdown_); | 213 DCHECK(!did_shutdown_); |
214 did_shutdown_ = true; | 214 did_shutdown_ = true; |
215 if (ProfileIsSupervised()) { | 215 if (ProfileIsSupervised()) { |
216 content::RecordAction(UserMetricsAction("ManagedUsers_QuitBrowser")); | 216 content::RecordAction(UserMetricsAction("ManagedUsers_QuitBrowser")); |
217 } | 217 } |
218 SetActive(false); | 218 SetActive(false); |
219 | 219 |
220 ProfileSyncService* sync_service = | 220 if (profile_sync_service_) |
221 ProfileSyncServiceFactory::GetForProfile(profile_); | 221 profile_sync_service_->RemovePreferenceProvider(this); |
222 // Can be null in tests. | |
223 if (sync_service) | |
224 sync_service->RemovePreferenceProvider(this); | |
225 } | 222 } |
226 | 223 |
227 bool SupervisedUserService::ProfileIsSupervised() const { | 224 bool SupervisedUserService::ProfileIsSupervised() const { |
228 return profile_->IsSupervised(); | 225 return profile_->IsSupervised(); |
229 } | 226 } |
230 | 227 |
231 void SupervisedUserService::OnCustodianInfoChanged() { | 228 void SupervisedUserService::OnCustodianInfoChanged() { |
232 FOR_EACH_OBSERVER( | 229 FOR_EACH_OBSERVER( |
233 SupervisedUserServiceObserver, observer_list_, OnCustodianInfoChanged()); | 230 SupervisedUserServiceObserver, observer_list_, OnCustodianInfoChanged()); |
234 } | 231 } |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 result.Put(syncer::APP_SETTINGS); | 402 result.Put(syncer::APP_SETTINGS); |
406 result.Put(syncer::APP_NOTIFICATIONS); | 403 result.Put(syncer::APP_NOTIFICATIONS); |
407 result.Put(syncer::APP_LIST); | 404 result.Put(syncer::APP_LIST); |
408 return result; | 405 return result; |
409 } | 406 } |
410 | 407 |
411 void SupervisedUserService::OnHistoryRecordingStateChanged() { | 408 void SupervisedUserService::OnHistoryRecordingStateChanged() { |
412 bool record_history = | 409 bool record_history = |
413 profile_->GetPrefs()->GetBoolean(prefs::kRecordHistory); | 410 profile_->GetPrefs()->GetBoolean(prefs::kRecordHistory); |
414 includes_sync_sessions_type_ = record_history; | 411 includes_sync_sessions_type_ = record_history; |
415 ProfileSyncServiceFactory::GetForProfile(profile_) | 412 |
416 ->ReconfigureDatatypeManager(); | 413 if (profile_sync_service_) |
414 profile_sync_service_->ReconfigureDatatypeManager(); | |
417 } | 415 } |
418 | 416 |
419 bool SupervisedUserService::IncludesSyncSessionsType() const { | 417 bool SupervisedUserService::IncludesSyncSessionsType() const { |
420 return includes_sync_sessions_type_; | 418 return includes_sync_sessions_type_; |
421 } | 419 } |
422 | 420 |
423 void SupervisedUserService::OnStateChanged() { | 421 void SupervisedUserService::OnStateChanged() { |
424 ProfileSyncService* service = | 422 if (waiting_for_sync_initialization_ && |
425 ProfileSyncServiceFactory::GetForProfile(profile_); | 423 profile_sync_service_ && |
426 if (waiting_for_sync_initialization_ && service->backend_initialized() && | 424 profile_sync_service_->backend_initialized() && |
427 service->backend_mode() == ProfileSyncService::SYNC) { | 425 profile_sync_service_->backend_mode() == ProfileSyncService::SYNC) { |
428 waiting_for_sync_initialization_ = false; | 426 waiting_for_sync_initialization_ = false; |
429 service->RemoveObserver(this); | 427 profile_sync_service_->RemoveObserver(this); |
430 FinishSetupSync(); | 428 FinishSetupSync(); |
431 return; | 429 return; |
432 } | 430 } |
433 | 431 |
434 DLOG_IF(ERROR, service->GetAuthError().state() == | 432 DLOG_IF(ERROR, profile_sync_service_->GetAuthError().state() == |
435 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS) | 433 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS) |
436 << "Credentials rejected"; | 434 << "Credentials rejected"; |
437 } | 435 } |
438 | 436 |
439 void SupervisedUserService::SetupSync() { | 437 void SupervisedUserService::SetupSync() { |
440 StartSetupSync(); | 438 StartSetupSync(); |
441 FinishSetupSyncWhenReady(); | 439 FinishSetupSyncWhenReady(); |
442 } | 440 } |
443 | 441 |
444 void SupervisedUserService::StartSetupSync() { | 442 void SupervisedUserService::StartSetupSync() { |
445 // Tell the sync service that setup is in progress so we don't start syncing | 443 // Tell the sync service that setup is in progress so we don't start syncing |
446 // until we've finished configuration. | 444 // until we've finished configuration. |
447 ProfileSyncServiceFactory::GetForProfile(profile_)->SetSetupInProgress(true); | 445 if (profile_sync_service_) |
446 profile_sync_service_->SetSetupInProgress(true); | |
448 } | 447 } |
449 | 448 |
450 void SupervisedUserService::FinishSetupSyncWhenReady() { | 449 void SupervisedUserService::FinishSetupSyncWhenReady() { |
451 // If we're already waiting for the Sync backend, there's nothing to do here. | 450 // If we're already waiting for the Sync backend, there's nothing to do here. |
452 if (waiting_for_sync_initialization_) | 451 if (waiting_for_sync_initialization_ || !profile_sync_service_) |
453 return; | 452 return; |
454 | 453 |
455 // Continue in FinishSetupSync() once the Sync backend has been initialized. | 454 // Continue in FinishSetupSync() once the Sync backend has been initialized. |
456 ProfileSyncService* service = | 455 if (profile_sync_service_->backend_initialized() && |
457 ProfileSyncServiceFactory::GetForProfile(profile_); | 456 profile_sync_service_->backend_mode() == ProfileSyncService::SYNC) { |
458 if (service->backend_initialized() && | |
459 service->backend_mode() == ProfileSyncService::SYNC) { | |
460 FinishSetupSync(); | 457 FinishSetupSync(); |
461 } else { | 458 } else { |
462 service->AddObserver(this); | 459 profile_sync_service_->AddObserver(this); |
463 waiting_for_sync_initialization_ = true; | 460 waiting_for_sync_initialization_ = true; |
464 } | 461 } |
465 } | 462 } |
466 | 463 |
467 void SupervisedUserService::FinishSetupSync() { | 464 void SupervisedUserService::FinishSetupSync() { |
468 ProfileSyncService* service = | 465 if (!profile_sync_service_) |
469 ProfileSyncServiceFactory::GetForProfile(profile_); | 466 return; |
470 DCHECK(service->backend_initialized()); | 467 |
471 DCHECK(service->backend_mode() == ProfileSyncService::SYNC); | 468 DCHECK(profile_sync_service_->backend_initialized()); |
469 DCHECK(profile_sync_service_->backend_mode() == ProfileSyncService::SYNC); | |
472 | 470 |
473 // Sync nothing (except types which are set via GetPreferredDataTypes). | 471 // Sync nothing (except types which are set via GetPreferredDataTypes). |
474 bool sync_everything = false; | 472 bool sync_everything = false; |
475 syncer::ModelTypeSet synced_datatypes; | 473 syncer::ModelTypeSet synced_datatypes; |
476 service->OnUserChoseDatatypes(sync_everything, synced_datatypes); | 474 profile_sync_service_->OnUserChoseDatatypes(sync_everything, |
475 synced_datatypes); | |
477 | 476 |
478 // Notify ProfileSyncService that we are done with configuration. | 477 // Notify ProfileSyncService that we are done with configuration. |
479 service->SetSetupInProgress(false); | 478 profile_sync_service_->SetSetupInProgress(false); |
480 service->SetSyncSetupCompleted(); | 479 profile_sync_service_->SetSyncSetupCompleted(); |
481 } | 480 } |
482 | 481 |
483 #if defined(ENABLE_EXTENSIONS) | 482 #if defined(ENABLE_EXTENSIONS) |
484 bool SupervisedUserService::ExtensionManagementPolicyImpl( | 483 bool SupervisedUserService::ExtensionManagementPolicyImpl( |
485 const extensions::Extension* extension, | 484 const extensions::Extension* extension, |
486 base::string16* error) const { | 485 base::string16* error) const { |
487 // |extension| can be NULL in unit_tests. | 486 // |extension| can be NULL in unit_tests. |
488 if (!ProfileIsSupervised() || (extension && extension->is_theme())) | 487 if (!ProfileIsSupervised() || (extension && extension->is_theme())) |
489 return true; | 488 return true; |
490 | 489 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
635 token_service->UpdateCredentials(supervised_users::kSupervisedUserPseudoEmail, | 634 token_service->UpdateCredentials(supervised_users::kSupervisedUserPseudoEmail, |
636 refresh_token); | 635 refresh_token); |
637 | 636 |
638 FinishSetupSyncWhenReady(); | 637 FinishSetupSyncWhenReady(); |
639 } | 638 } |
640 | 639 |
641 void SupervisedUserService::Init() { | 640 void SupervisedUserService::Init() { |
642 DCHECK(!did_init_); | 641 DCHECK(!did_init_); |
643 did_init_ = true; | 642 did_init_ = true; |
644 DCHECK(GetSettingsService()->IsReady()); | 643 DCHECK(GetSettingsService()->IsReady()); |
644 profile_sync_service_ = | |
Alexei Svitkine (slow)
2015/02/19 22:04:08
Initialize this in the ctor too, or some bots will
Mike Lerman
2015/02/20 16:38:01
Done.
| |
645 ProfileSyncServiceFactory::GetForProfile(profile_); | |
645 | 646 |
646 pref_change_registrar_.Init(profile_->GetPrefs()); | 647 pref_change_registrar_.Init(profile_->GetPrefs()); |
647 pref_change_registrar_.Add( | 648 pref_change_registrar_.Add( |
648 prefs::kSupervisedUserId, | 649 prefs::kSupervisedUserId, |
649 base::Bind(&SupervisedUserService::OnSupervisedUserIdChanged, | 650 base::Bind(&SupervisedUserService::OnSupervisedUserIdChanged, |
650 base::Unretained(this))); | 651 base::Unretained(this))); |
651 pref_change_registrar_.Add( | 652 pref_change_registrar_.Add( |
652 prefs::kRecordHistory, | 653 prefs::kRecordHistory, |
653 base::Bind(&SupervisedUserService::OnHistoryRecordingStateChanged, | 654 base::Bind(&SupervisedUserService::OnHistoryRecordingStateChanged, |
654 base::Unretained(this))); | 655 base::Unretained(this))); |
655 | 656 |
656 ProfileSyncService* sync_service = | 657 if (profile_sync_service_) |
657 ProfileSyncServiceFactory::GetForProfile(profile_); | 658 profile_sync_service_->AddPreferenceProvider(this); |
658 // Can be null in tests. | |
659 if (sync_service) | |
660 sync_service->AddPreferenceProvider(this); | |
661 | 659 |
662 std::string client_id = component_updater::SupervisedUserWhitelistInstaller:: | 660 std::string client_id = component_updater::SupervisedUserWhitelistInstaller:: |
663 ClientIdForProfilePath(profile_->GetPath()); | 661 ClientIdForProfilePath(profile_->GetPath()); |
664 whitelist_service_.reset(new SupervisedUserWhitelistService( | 662 whitelist_service_.reset(new SupervisedUserWhitelistService( |
665 profile_->GetPrefs(), | 663 profile_->GetPrefs(), |
666 g_browser_process->supervised_user_whitelist_installer(), client_id)); | 664 g_browser_process->supervised_user_whitelist_installer(), client_id)); |
667 whitelist_service_->AddSiteListsChangedCallback( | 665 whitelist_service_->AddSiteListsChangedCallback( |
668 base::Bind(&SupervisedUserService::OnSiteListsChanged, | 666 base::Bind(&SupervisedUserService::OnSiteListsChanged, |
669 weak_ptr_factory_.GetWeakPtr())); | 667 weak_ptr_factory_.GetWeakPtr())); |
670 | 668 |
(...skipping 19 matching lines...) Expand all Loading... | |
690 | 688 |
691 ProfileOAuth2TokenService* token_service = | 689 ProfileOAuth2TokenService* token_service = |
692 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 690 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
693 token_service->LoadCredentials( | 691 token_service->LoadCredentials( |
694 supervised_users::kSupervisedUserPseudoEmail); | 692 supervised_users::kSupervisedUserPseudoEmail); |
695 | 693 |
696 permissions_creators_.push_back(new PermissionRequestCreatorSync( | 694 permissions_creators_.push_back(new PermissionRequestCreatorSync( |
697 GetSettingsService(), | 695 GetSettingsService(), |
698 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext( | 696 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext( |
699 profile_), | 697 profile_), |
700 ProfileSyncServiceFactory::GetForProfile(profile_), | 698 profile_sync_service_, |
701 GetSupervisedUserName(), | 699 GetSupervisedUserName(), |
702 profile_->GetPrefs()->GetString(prefs::kSupervisedUserId))); | 700 profile_->GetPrefs()->GetString(prefs::kSupervisedUserId))); |
703 | 701 |
704 SetupSync(); | 702 if (profile_sync_service_) |
703 SetupSync(); | |
705 } | 704 } |
706 } | 705 } |
707 | 706 |
708 // Now activate/deactivate anything not handled by the delegate yet. | 707 // Now activate/deactivate anything not handled by the delegate yet. |
709 | 708 |
710 #if defined(ENABLE_THEMES) | 709 #if defined(ENABLE_THEMES) |
711 // Re-set the default theme to turn the SU theme on/off. | 710 // Re-set the default theme to turn the SU theme on/off. |
712 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile_); | 711 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile_); |
713 if (theme_service->UsingDefaultTheme() || theme_service->UsingSystemTheme()) { | 712 if (theme_service->UsingDefaultTheme() || theme_service->UsingSystemTheme()) { |
714 ThemeServiceFactory::GetForProfile(profile_)->UseDefaultTheme(); | 713 ThemeServiceFactory::GetForProfile(profile_)->UseDefaultTheme(); |
715 } | 714 } |
716 #endif | 715 #endif |
717 | 716 |
718 ProfileSyncService* sync_service = | 717 if (profile_sync_service_) |
719 ProfileSyncServiceFactory::GetForProfile(profile_); | 718 profile_sync_service_->SetEncryptEverythingAllowed(!active_); |
720 sync_service->SetEncryptEverythingAllowed(!active_); | |
721 | 719 |
722 GetSettingsService()->SetActive(active_); | 720 GetSettingsService()->SetActive(active_); |
723 | 721 |
724 #if defined(ENABLE_EXTENSIONS) | 722 #if defined(ENABLE_EXTENSIONS) |
725 SetExtensionsActive(); | 723 SetExtensionsActive(); |
726 #endif | 724 #endif |
727 | 725 |
728 if (active_) { | 726 if (active_) { |
729 pref_change_registrar_.Add( | 727 pref_change_registrar_.Add( |
730 prefs::kDefaultSupervisedUserFilteringBehavior, | 728 prefs::kDefaultSupervisedUserFilteringBehavior, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
777 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); | 775 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); |
778 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); | 776 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); |
779 for (const char* pref : kCustodianInfoPrefs) { | 777 for (const char* pref : kCustodianInfoPrefs) { |
780 pref_change_registrar_.Remove(pref); | 778 pref_change_registrar_.Remove(pref); |
781 } | 779 } |
782 | 780 |
783 url_filter_context_.Clear(); | 781 url_filter_context_.Clear(); |
784 FOR_EACH_OBSERVER( | 782 FOR_EACH_OBSERVER( |
785 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 783 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
786 | 784 |
787 if (waiting_for_sync_initialization_) | 785 if (waiting_for_sync_initialization_ && profile_sync_service_) |
788 ProfileSyncServiceFactory::GetForProfile(profile_)->RemoveObserver(this); | 786 profile_sync_service_->RemoveObserver(this); |
789 | 787 |
790 #if !defined(OS_ANDROID) | 788 #if !defined(OS_ANDROID) |
791 // TODO(bauerb): Get rid of the platform-specific #ifdef here. | 789 // TODO(bauerb): Get rid of the platform-specific #ifdef here. |
792 // http://crbug.com/313377 | 790 // http://crbug.com/313377 |
793 BrowserList::RemoveObserver(this); | 791 BrowserList::RemoveObserver(this); |
794 #endif | 792 #endif |
795 } | 793 } |
796 } | 794 } |
797 | 795 |
798 void SupervisedUserService::RegisterAndInitSync( | 796 void SupervisedUserService::RegisterAndInitSync( |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
903 // The active user can be NULL in unit tests. | 901 // The active user can be NULL in unit tests. |
904 if (user_manager::UserManager::Get()->GetActiveUser()) { | 902 if (user_manager::UserManager::Get()->GetActiveUser()) { |
905 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( | 903 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( |
906 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); | 904 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); |
907 } | 905 } |
908 return std::string(); | 906 return std::string(); |
909 #else | 907 #else |
910 return profile_->GetPrefs()->GetString(prefs::kProfileName); | 908 return profile_->GetPrefs()->GetString(prefs::kProfileName); |
911 #endif | 909 #endif |
912 } | 910 } |
OLD | NEW |