| 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/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 SupervisedUserService::~SupervisedUserService() { | 149 SupervisedUserService::~SupervisedUserService() { |
| 150 DCHECK(did_shutdown_); | 150 DCHECK(did_shutdown_); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void SupervisedUserService::Shutdown() { | 153 void SupervisedUserService::Shutdown() { |
| 154 did_shutdown_ = true; | 154 did_shutdown_ = true; |
| 155 if (ProfileIsSupervised()) { | 155 if (ProfileIsSupervised()) { |
| 156 content::RecordAction(UserMetricsAction("ManagedUsers_QuitBrowser")); | 156 content::RecordAction(UserMetricsAction("ManagedUsers_QuitBrowser")); |
| 157 } | 157 } |
| 158 SetActive(false); | 158 SetActive(false); |
| 159 |
| 160 ProfileSyncServiceFactory::GetForProfile(profile_)->RemovePreferenceProvider( |
| 161 this); |
| 159 } | 162 } |
| 160 | 163 |
| 161 bool SupervisedUserService::ProfileIsSupervised() const { | 164 bool SupervisedUserService::ProfileIsSupervised() const { |
| 162 return profile_->IsSupervised(); | 165 return profile_->IsSupervised(); |
| 163 } | 166 } |
| 164 | 167 |
| 165 // static | 168 // static |
| 166 void SupervisedUserService::RegisterProfilePrefs( | 169 void SupervisedUserService::RegisterProfilePrefs( |
| 167 user_prefs::PrefRegistrySyncable* registry) { | 170 user_prefs::PrefRegistrySyncable* registry) { |
| 168 registry->RegisterDictionaryPref( | 171 registry->RegisterDictionaryPref( |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 content::BrowserContext* browser_context, | 319 content::BrowserContext* browser_context, |
| 317 const extensions::Extension* extension, | 320 const extensions::Extension* extension, |
| 318 extensions::UnloadedExtensionInfo::Reason reason) { | 321 extensions::UnloadedExtensionInfo::Reason reason) { |
| 319 if (!extensions::SupervisedUserInfo::GetContentPackSiteList(extension) | 322 if (!extensions::SupervisedUserInfo::GetContentPackSiteList(extension) |
| 320 .empty()) { | 323 .empty()) { |
| 321 UpdateSiteLists(); | 324 UpdateSiteLists(); |
| 322 } | 325 } |
| 323 } | 326 } |
| 324 #endif // defined(ENABLE_EXTENSIONS) | 327 #endif // defined(ENABLE_EXTENSIONS) |
| 325 | 328 |
| 329 syncer::ModelTypeSet SupervisedUserService::GetPreferredDataTypes() { |
| 330 if (!ProfileIsSupervised()) |
| 331 return syncer::ModelTypeSet(); |
| 332 |
| 333 syncer::ModelTypeSet result; |
| 334 result.Put(syncer::SESSIONS); |
| 335 result.Put(syncer::EXTENSIONS); |
| 336 result.Put(syncer::EXTENSION_SETTINGS); |
| 337 result.Put(syncer::APPS); |
| 338 result.Put(syncer::APP_SETTINGS); |
| 339 result.Put(syncer::APP_NOTIFICATIONS); |
| 340 result.Put(syncer::APP_LIST); |
| 341 return result; |
| 342 } |
| 343 |
| 326 void SupervisedUserService::OnStateChanged() { | 344 void SupervisedUserService::OnStateChanged() { |
| 327 ProfileSyncService* service = | 345 ProfileSyncService* service = |
| 328 ProfileSyncServiceFactory::GetForProfile(profile_); | 346 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 329 if (waiting_for_sync_initialization_ && service->sync_initialized()) { | 347 if (waiting_for_sync_initialization_ && service->sync_initialized()) { |
| 330 waiting_for_sync_initialization_ = false; | 348 waiting_for_sync_initialization_ = false; |
| 331 service->RemoveObserver(this); | 349 service->RemoveObserver(this); |
| 332 FinishSetupSync(); | 350 FinishSetupSync(); |
| 333 return; | 351 return; |
| 334 } | 352 } |
| 335 | 353 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 363 service->AddObserver(this); | 381 service->AddObserver(this); |
| 364 waiting_for_sync_initialization_ = true; | 382 waiting_for_sync_initialization_ = true; |
| 365 } | 383 } |
| 366 } | 384 } |
| 367 | 385 |
| 368 void SupervisedUserService::FinishSetupSync() { | 386 void SupervisedUserService::FinishSetupSync() { |
| 369 ProfileSyncService* service = | 387 ProfileSyncService* service = |
| 370 ProfileSyncServiceFactory::GetForProfile(profile_); | 388 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 371 DCHECK(service->sync_initialized()); | 389 DCHECK(service->sync_initialized()); |
| 372 | 390 |
| 391 // Sync nothing (except types which are set via GetPreferredDataTypes). |
| 373 bool sync_everything = false; | 392 bool sync_everything = false; |
| 374 syncer::ModelTypeSet synced_datatypes; | 393 syncer::ModelTypeSet synced_datatypes; |
| 375 synced_datatypes.Put(syncer::SESSIONS); | |
| 376 synced_datatypes.Put(syncer::APPS); | |
| 377 synced_datatypes.Put(syncer::EXTENSIONS); | |
| 378 service->OnUserChoseDatatypes(sync_everything, synced_datatypes); | 394 service->OnUserChoseDatatypes(sync_everything, synced_datatypes); |
| 379 | 395 |
| 380 // Notify ProfileSyncService that we are done with configuration. | 396 // Notify ProfileSyncService that we are done with configuration. |
| 381 service->SetSetupInProgress(false); | 397 service->SetSetupInProgress(false); |
| 382 service->SetSyncSetupCompleted(); | 398 service->SetSyncSetupCompleted(); |
| 383 } | 399 } |
| 384 | 400 |
| 385 #if defined(ENABLE_EXTENSIONS) | 401 #if defined(ENABLE_EXTENSIONS) |
| 386 bool SupervisedUserService::ExtensionManagementPolicyImpl( | 402 bool SupervisedUserService::ExtensionManagementPolicyImpl( |
| 387 const extensions::Extension* extension, | 403 const extensions::Extension* extension, |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 | 572 |
| 557 void SupervisedUserService::Init() { | 573 void SupervisedUserService::Init() { |
| 558 DCHECK(GetSettingsService()->IsReady()); | 574 DCHECK(GetSettingsService()->IsReady()); |
| 559 | 575 |
| 560 pref_change_registrar_.Init(profile_->GetPrefs()); | 576 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 561 pref_change_registrar_.Add( | 577 pref_change_registrar_.Add( |
| 562 prefs::kSupervisedUserId, | 578 prefs::kSupervisedUserId, |
| 563 base::Bind(&SupervisedUserService::OnSupervisedUserIdChanged, | 579 base::Bind(&SupervisedUserService::OnSupervisedUserIdChanged, |
| 564 base::Unretained(this))); | 580 base::Unretained(this))); |
| 565 | 581 |
| 582 ProfileSyncServiceFactory::GetForProfile(profile_)->AddPreferenceProvider( |
| 583 this); |
| 584 |
| 566 SetActive(ProfileIsSupervised()); | 585 SetActive(ProfileIsSupervised()); |
| 567 } | 586 } |
| 568 | 587 |
| 569 void SupervisedUserService::SetActive(bool active) { | 588 void SupervisedUserService::SetActive(bool active) { |
| 570 if (active_ == active) | 589 if (active_ == active) |
| 571 return; | 590 return; |
| 572 active_ = active; | 591 active_ = active; |
| 573 | 592 |
| 574 if (!delegate_ || !delegate_->SetActive(active_)) { | 593 if (!delegate_ || !delegate_->SetActive(active_)) { |
| 575 if (active_) { | 594 if (active_) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 BrowserList::AddObserver(this); | 666 BrowserList::AddObserver(this); |
| 648 #endif | 667 #endif |
| 649 } else { | 668 } else { |
| 650 permissions_creator_.reset(); | 669 permissions_creator_.reset(); |
| 651 | 670 |
| 652 pref_change_registrar_.Remove( | 671 pref_change_registrar_.Remove( |
| 653 prefs::kDefaultSupervisedUserFilteringBehavior); | 672 prefs::kDefaultSupervisedUserFilteringBehavior); |
| 654 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); | 673 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); |
| 655 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); | 674 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); |
| 656 | 675 |
| 657 if (waiting_for_sync_initialization_) { | 676 if (waiting_for_sync_initialization_) |
| 658 ProfileSyncService* sync_service = | 677 ProfileSyncServiceFactory::GetForProfile(profile_)->RemoveObserver(this); |
| 659 ProfileSyncServiceFactory::GetForProfile(profile_); | |
| 660 sync_service->RemoveObserver(this); | |
| 661 } | |
| 662 | 678 |
| 663 #if !defined(OS_ANDROID) | 679 #if !defined(OS_ANDROID) |
| 664 // TODO(bauerb): Get rid of the platform-specific #ifdef here. | 680 // TODO(bauerb): Get rid of the platform-specific #ifdef here. |
| 665 // http://crbug.com/313377 | 681 // http://crbug.com/313377 |
| 666 BrowserList::RemoveObserver(this); | 682 BrowserList::RemoveObserver(this); |
| 667 #endif | 683 #endif |
| 668 } | 684 } |
| 669 } | 685 } |
| 670 | 686 |
| 671 void SupervisedUserService::RegisterAndInitSync( | 687 void SupervisedUserService::RegisterAndInitSync( |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 // The active user can be NULL in unit tests. | 786 // The active user can be NULL in unit tests. |
| 771 if (chromeos::UserManager::Get()->GetActiveUser()) { | 787 if (chromeos::UserManager::Get()->GetActiveUser()) { |
| 772 return UTF16ToUTF8(chromeos::UserManager::Get()->GetUserDisplayName( | 788 return UTF16ToUTF8(chromeos::UserManager::Get()->GetUserDisplayName( |
| 773 chromeos::UserManager::Get()->GetActiveUser()->GetUserID())); | 789 chromeos::UserManager::Get()->GetActiveUser()->GetUserID())); |
| 774 } | 790 } |
| 775 return std::string(); | 791 return std::string(); |
| 776 #else | 792 #else |
| 777 return profile_->GetPrefs()->GetString(prefs::kProfileName); | 793 return profile_->GetPrefs()->GetString(prefs::kProfileName); |
| 778 #endif | 794 #endif |
| 779 } | 795 } |
| OLD | NEW |