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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 content::BrowserContext* browser_context, | 316 content::BrowserContext* browser_context, |
317 const extensions::Extension* extension, | 317 const extensions::Extension* extension, |
318 extensions::UnloadedExtensionInfo::Reason reason) { | 318 extensions::UnloadedExtensionInfo::Reason reason) { |
319 if (!extensions::SupervisedUserInfo::GetContentPackSiteList(extension) | 319 if (!extensions::SupervisedUserInfo::GetContentPackSiteList(extension) |
320 .empty()) { | 320 .empty()) { |
321 UpdateSiteLists(); | 321 UpdateSiteLists(); |
322 } | 322 } |
323 } | 323 } |
324 #endif // defined(ENABLE_EXTENSIONS) | 324 #endif // defined(ENABLE_EXTENSIONS) |
325 | 325 |
326 syncer::ModelTypeSet SupervisedUserService::GetRequiredSyncDataTypes() { | |
327 if (!ProfileIsSupervised()) | |
Bernhard Bauer
2014/07/30 12:38:51
If we only add ourselves as a data type provider i
Marc Treib
2014/07/30 13:10:39
Alright, I'm registering/removing the provider in
| |
328 return syncer::ModelTypeSet(); | |
329 | |
330 return syncer::ModelTypeSet(syncer::SESSIONS, | |
331 syncer::APPS, | |
332 syncer::EXTENSIONS); | |
333 } | |
334 | |
326 void SupervisedUserService::OnStateChanged() { | 335 void SupervisedUserService::OnStateChanged() { |
327 ProfileSyncService* service = | 336 ProfileSyncService* service = |
328 ProfileSyncServiceFactory::GetForProfile(profile_); | 337 ProfileSyncServiceFactory::GetForProfile(profile_); |
329 if (waiting_for_sync_initialization_ && service->sync_initialized()) { | 338 if (waiting_for_sync_initialization_ && service->sync_initialized()) { |
330 waiting_for_sync_initialization_ = false; | 339 waiting_for_sync_initialization_ = false; |
331 service->RemoveObserver(this); | 340 service->RemoveObserver(this); |
332 FinishSetupSync(); | 341 FinishSetupSync(); |
333 return; | 342 return; |
334 } | 343 } |
335 | 344 |
(...skipping 27 matching lines...) Expand all Loading... | |
363 service->AddObserver(this); | 372 service->AddObserver(this); |
364 waiting_for_sync_initialization_ = true; | 373 waiting_for_sync_initialization_ = true; |
365 } | 374 } |
366 } | 375 } |
367 | 376 |
368 void SupervisedUserService::FinishSetupSync() { | 377 void SupervisedUserService::FinishSetupSync() { |
369 ProfileSyncService* service = | 378 ProfileSyncService* service = |
370 ProfileSyncServiceFactory::GetForProfile(profile_); | 379 ProfileSyncServiceFactory::GetForProfile(profile_); |
371 DCHECK(service->sync_initialized()); | 380 DCHECK(service->sync_initialized()); |
372 | 381 |
382 // Sync nothing (except types which are set via GetRequiredSyncDataTypes). | |
373 bool sync_everything = false; | 383 bool sync_everything = false; |
374 syncer::ModelTypeSet synced_datatypes; | 384 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); | 385 service->OnUserChoseDatatypes(sync_everything, synced_datatypes); |
379 | 386 |
380 // Notify ProfileSyncService that we are done with configuration. | 387 // Notify ProfileSyncService that we are done with configuration. |
381 service->SetSetupInProgress(false); | 388 service->SetSetupInProgress(false); |
382 service->SetSyncSetupCompleted(); | 389 service->SetSyncSetupCompleted(); |
383 } | 390 } |
384 | 391 |
385 #if defined(ENABLE_EXTENSIONS) | 392 #if defined(ENABLE_EXTENSIONS) |
386 bool SupervisedUserService::ExtensionManagementPolicyImpl( | 393 bool SupervisedUserService::ExtensionManagementPolicyImpl( |
387 const extensions::Extension* extension, | 394 const extensions::Extension* extension, |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
602 } | 609 } |
603 #endif | 610 #endif |
604 | 611 |
605 SupervisedUserSettingsService* settings_service = GetSettingsService(); | 612 SupervisedUserSettingsService* settings_service = GetSettingsService(); |
606 settings_service->SetActive(active_); | 613 settings_service->SetActive(active_); |
607 | 614 |
608 #if defined(ENABLE_EXTENSIONS) | 615 #if defined(ENABLE_EXTENSIONS) |
609 SetExtensionsActive(); | 616 SetExtensionsActive(); |
610 #endif | 617 #endif |
611 | 618 |
619 ProfileSyncService* sync_service = | |
620 ProfileSyncServiceFactory::GetForProfile(profile_); | |
621 | |
612 if (active_) { | 622 if (active_) { |
613 if (CommandLine::ForCurrentProcess()->HasSwitch( | 623 if (CommandLine::ForCurrentProcess()->HasSwitch( |
614 switches::kPermissionRequestApiUrl)) { | 624 switches::kPermissionRequestApiUrl)) { |
615 permissions_creator_ = | 625 permissions_creator_ = |
616 PermissionRequestCreatorApiary::CreateWithProfile(profile_); | 626 PermissionRequestCreatorApiary::CreateWithProfile(profile_); |
617 } else { | 627 } else { |
618 PrefService* pref_service = profile_->GetPrefs(); | 628 PrefService* pref_service = profile_->GetPrefs(); |
619 permissions_creator_.reset(new PermissionRequestCreatorSync( | 629 permissions_creator_.reset(new PermissionRequestCreatorSync( |
620 settings_service, | 630 settings_service, |
621 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext( | 631 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext( |
622 profile_), | 632 profile_), |
623 pref_service->GetString(prefs::kProfileName), | 633 pref_service->GetString(prefs::kProfileName), |
624 pref_service->GetString(prefs::kSupervisedUserId))); | 634 pref_service->GetString(prefs::kSupervisedUserId))); |
625 } | 635 } |
626 | 636 |
627 pref_change_registrar_.Add( | 637 pref_change_registrar_.Add( |
628 prefs::kDefaultSupervisedUserFilteringBehavior, | 638 prefs::kDefaultSupervisedUserFilteringBehavior, |
629 base::Bind(&SupervisedUserService::OnDefaultFilteringBehaviorChanged, | 639 base::Bind(&SupervisedUserService::OnDefaultFilteringBehaviorChanged, |
630 base::Unretained(this))); | 640 base::Unretained(this))); |
631 pref_change_registrar_.Add(prefs::kSupervisedUserManualHosts, | 641 pref_change_registrar_.Add(prefs::kSupervisedUserManualHosts, |
632 base::Bind(&SupervisedUserService::UpdateManualHosts, | 642 base::Bind(&SupervisedUserService::UpdateManualHosts, |
633 base::Unretained(this))); | 643 base::Unretained(this))); |
634 pref_change_registrar_.Add(prefs::kSupervisedUserManualURLs, | 644 pref_change_registrar_.Add(prefs::kSupervisedUserManualURLs, |
635 base::Bind(&SupervisedUserService::UpdateManualURLs, | 645 base::Bind(&SupervisedUserService::UpdateManualURLs, |
636 base::Unretained(this))); | 646 base::Unretained(this))); |
637 | 647 |
648 sync_service->AddDataTypeProvider(this); | |
649 | |
638 // Initialize the filter. | 650 // Initialize the filter. |
639 OnDefaultFilteringBehaviorChanged(); | 651 OnDefaultFilteringBehaviorChanged(); |
640 UpdateSiteLists(); | 652 UpdateSiteLists(); |
641 UpdateManualHosts(); | 653 UpdateManualHosts(); |
642 UpdateManualURLs(); | 654 UpdateManualURLs(); |
643 | 655 |
644 #if !defined(OS_ANDROID) | 656 #if !defined(OS_ANDROID) |
645 // TODO(bauerb): Get rid of the platform-specific #ifdef here. | 657 // TODO(bauerb): Get rid of the platform-specific #ifdef here. |
646 // http://crbug.com/313377 | 658 // http://crbug.com/313377 |
647 BrowserList::AddObserver(this); | 659 BrowserList::AddObserver(this); |
648 #endif | 660 #endif |
649 } else { | 661 } else { |
650 permissions_creator_.reset(); | 662 permissions_creator_.reset(); |
651 | 663 |
652 pref_change_registrar_.Remove( | 664 pref_change_registrar_.Remove( |
653 prefs::kDefaultSupervisedUserFilteringBehavior); | 665 prefs::kDefaultSupervisedUserFilteringBehavior); |
654 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); | 666 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); |
655 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); | 667 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); |
656 | 668 |
657 if (waiting_for_sync_initialization_) { | 669 sync_service->RemoveDataTypeProvider(this); |
658 ProfileSyncService* sync_service = | 670 if (waiting_for_sync_initialization_) |
659 ProfileSyncServiceFactory::GetForProfile(profile_); | |
660 sync_service->RemoveObserver(this); | 671 sync_service->RemoveObserver(this); |
661 } | |
662 | 672 |
663 #if !defined(OS_ANDROID) | 673 #if !defined(OS_ANDROID) |
664 // TODO(bauerb): Get rid of the platform-specific #ifdef here. | 674 // TODO(bauerb): Get rid of the platform-specific #ifdef here. |
665 // http://crbug.com/313377 | 675 // http://crbug.com/313377 |
666 BrowserList::RemoveObserver(this); | 676 BrowserList::RemoveObserver(this); |
667 #endif | 677 #endif |
668 } | 678 } |
669 } | 679 } |
670 | 680 |
671 void SupervisedUserService::RegisterAndInitSync( | 681 void SupervisedUserService::RegisterAndInitSync( |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
757 | 767 |
758 void SupervisedUserService::OnBrowserSetLastActive(Browser* browser) { | 768 void SupervisedUserService::OnBrowserSetLastActive(Browser* browser) { |
759 bool profile_became_active = profile_->IsSameProfile(browser->profile()); | 769 bool profile_became_active = profile_->IsSameProfile(browser->profile()); |
760 if (!is_profile_active_ && profile_became_active) | 770 if (!is_profile_active_ && profile_became_active) |
761 content::RecordAction(UserMetricsAction("ManagedUsers_OpenProfile")); | 771 content::RecordAction(UserMetricsAction("ManagedUsers_OpenProfile")); |
762 else if (is_profile_active_ && !profile_became_active) | 772 else if (is_profile_active_ && !profile_became_active) |
763 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); | 773 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); |
764 | 774 |
765 is_profile_active_ = profile_became_active; | 775 is_profile_active_ = profile_became_active; |
766 } | 776 } |
OLD | NEW |