| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/managed_mode/managed_user_service.h" | 5 #include "chrome/browser/managed_mode/managed_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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 147 |
| 148 void ManagedUserService::Shutdown() { | 148 void ManagedUserService::Shutdown() { |
| 149 did_shutdown_ = true; | 149 did_shutdown_ = true; |
| 150 if (ProfileIsManaged()) { | 150 if (ProfileIsManaged()) { |
| 151 content::RecordAction(UserMetricsAction("ManagedUsers_QuitBrowser")); | 151 content::RecordAction(UserMetricsAction("ManagedUsers_QuitBrowser")); |
| 152 } | 152 } |
| 153 SetActive(false); | 153 SetActive(false); |
| 154 } | 154 } |
| 155 | 155 |
| 156 bool ManagedUserService::ProfileIsManaged() const { | 156 bool ManagedUserService::ProfileIsManaged() const { |
| 157 return profile_->IsManaged(); | 157 return profile_->IsSupervised(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 // static | 160 // static |
| 161 void ManagedUserService::RegisterProfilePrefs( | 161 void ManagedUserService::RegisterProfilePrefs( |
| 162 user_prefs::PrefRegistrySyncable* registry) { | 162 user_prefs::PrefRegistrySyncable* registry) { |
| 163 registry->RegisterDictionaryPref( | 163 registry->RegisterDictionaryPref( |
| 164 prefs::kManagedModeManualHosts, | 164 prefs::kSupervisedUserManualHosts, |
| 165 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 165 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 166 registry->RegisterDictionaryPref( | 166 registry->RegisterDictionaryPref( |
| 167 prefs::kManagedModeManualURLs, | 167 prefs::kSupervisedUserManualURLs, |
| 168 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 168 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 169 registry->RegisterIntegerPref( | 169 registry->RegisterIntegerPref( |
| 170 prefs::kDefaultManagedModeFilteringBehavior, ManagedModeURLFilter::ALLOW, | 170 prefs::kDefaultSupervisedUserFilteringBehavior, |
| 171 ManagedModeURLFilter::ALLOW, |
| 171 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 172 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 172 registry->RegisterStringPref( | 173 registry->RegisterStringPref( |
| 173 prefs::kManagedUserCustodianEmail, std::string(), | 174 prefs::kSupervisedUserCustodianEmail, std::string(), |
| 174 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 175 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 175 registry->RegisterStringPref( | 176 registry->RegisterStringPref( |
| 176 prefs::kManagedUserCustodianName, std::string(), | 177 prefs::kSupervisedUserCustodianName, std::string(), |
| 177 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 178 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 178 registry->RegisterBooleanPref(prefs::kManagedUserCreationAllowed, true, | 179 registry->RegisterBooleanPref(prefs::kSupervisedUserCreationAllowed, true, |
| 179 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 180 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 180 } | 181 } |
| 181 | 182 |
| 182 // static | 183 // static |
| 183 void ManagedUserService::MigrateUserPrefs(PrefService* prefs) { | 184 void ManagedUserService::MigrateUserPrefs(PrefService* prefs) { |
| 184 if (!prefs->HasPrefPath(prefs::kProfileIsManaged)) | 185 if (!prefs->HasPrefPath(prefs::kProfileIsSupervised)) |
| 185 return; | 186 return; |
| 186 | 187 |
| 187 bool is_managed = prefs->GetBoolean(prefs::kProfileIsManaged); | 188 bool is_managed = prefs->GetBoolean(prefs::kProfileIsSupervised); |
| 188 prefs->ClearPref(prefs::kProfileIsManaged); | 189 prefs->ClearPref(prefs::kProfileIsSupervised); |
| 189 | 190 |
| 190 if (!is_managed) | 191 if (!is_managed) |
| 191 return; | 192 return; |
| 192 | 193 |
| 193 std::string managed_user_id = prefs->GetString(prefs::kManagedUserId); | 194 std::string managed_user_id = prefs->GetString(prefs::kSupervisedUserId); |
| 194 if (!managed_user_id.empty()) | 195 if (!managed_user_id.empty()) |
| 195 return; | 196 return; |
| 196 | 197 |
| 197 prefs->SetString(prefs::kManagedUserId, "Dummy ID"); | 198 prefs->SetString(prefs::kSupervisedUserId, "Dummy ID"); |
| 198 } | 199 } |
| 199 | 200 |
| 200 void ManagedUserService::SetDelegate(Delegate* delegate) { | 201 void ManagedUserService::SetDelegate(Delegate* delegate) { |
| 201 if (delegate_ == delegate) | 202 if (delegate_ == delegate) |
| 202 return; | 203 return; |
| 203 // If the delegate changed, deactivate first to give the old delegate a chance | 204 // If the delegate changed, deactivate first to give the old delegate a chance |
| 204 // to clean up. | 205 // to clean up. |
| 205 SetActive(false); | 206 SetActive(false); |
| 206 delegate_ = delegate; | 207 delegate_ = delegate; |
| 207 } | 208 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 233 void ManagedUserService::GetCategoryNames(CategoryList* list) { | 234 void ManagedUserService::GetCategoryNames(CategoryList* list) { |
| 234 ManagedModeSiteList::GetCategoryNames(list); | 235 ManagedModeSiteList::GetCategoryNames(list); |
| 235 } | 236 } |
| 236 | 237 |
| 237 std::string ManagedUserService::GetCustodianEmailAddress() const { | 238 std::string ManagedUserService::GetCustodianEmailAddress() const { |
| 238 #if defined(OS_CHROMEOS) | 239 #if defined(OS_CHROMEOS) |
| 239 return chromeos::UserManager::Get()->GetSupervisedUserManager()-> | 240 return chromeos::UserManager::Get()->GetSupervisedUserManager()-> |
| 240 GetManagerDisplayEmail( | 241 GetManagerDisplayEmail( |
| 241 chromeos::UserManager::Get()->GetActiveUser()->email()); | 242 chromeos::UserManager::Get()->GetActiveUser()->email()); |
| 242 #else | 243 #else |
| 243 return profile_->GetPrefs()->GetString(prefs::kManagedUserCustodianEmail); | 244 return profile_->GetPrefs()->GetString(prefs::kSupervisedUserCustodianEmail); |
| 244 #endif | 245 #endif |
| 245 } | 246 } |
| 246 | 247 |
| 247 std::string ManagedUserService::GetCustodianName() const { | 248 std::string ManagedUserService::GetCustodianName() const { |
| 248 #if defined(OS_CHROMEOS) | 249 #if defined(OS_CHROMEOS) |
| 249 return base::UTF16ToUTF8(chromeos::UserManager::Get()-> | 250 return base::UTF16ToUTF8(chromeos::UserManager::Get()-> |
| 250 GetSupervisedUserManager()->GetManagerDisplayName( | 251 GetSupervisedUserManager()->GetManagerDisplayName( |
| 251 chromeos::UserManager::Get()->GetActiveUser()->email())); | 252 chromeos::UserManager::Get()->GetActiveUser()->email())); |
| 252 #else | 253 #else |
| 253 std::string name = profile_->GetPrefs()->GetString( | 254 std::string name = profile_->GetPrefs()->GetString( |
| 254 prefs::kManagedUserCustodianName); | 255 prefs::kSupervisedUserCustodianName); |
| 255 return name.empty() ? GetCustodianEmailAddress() : name; | 256 return name.empty() ? GetCustodianEmailAddress() : name; |
| 256 #endif | 257 #endif |
| 257 } | 258 } |
| 258 | 259 |
| 259 void ManagedUserService::AddNavigationBlockedCallback( | 260 void ManagedUserService::AddNavigationBlockedCallback( |
| 260 const NavigationBlockedCallback& callback) { | 261 const NavigationBlockedCallback& callback) { |
| 261 navigation_blocked_callbacks_.push_back(callback); | 262 navigation_blocked_callbacks_.push_back(callback); |
| 262 } | 263 } |
| 263 | 264 |
| 264 void ManagedUserService::DidBlockNavigation( | 265 void ManagedUserService::DidBlockNavigation( |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 } | 355 } |
| 355 } | 356 } |
| 356 | 357 |
| 357 void ManagedUserService::SetupSync() { | 358 void ManagedUserService::SetupSync() { |
| 358 ProfileSyncService* service = | 359 ProfileSyncService* service = |
| 359 ProfileSyncServiceFactory::GetForProfile(profile_); | 360 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 360 DCHECK(service->sync_initialized()); | 361 DCHECK(service->sync_initialized()); |
| 361 | 362 |
| 362 bool sync_everything = false; | 363 bool sync_everything = false; |
| 363 syncer::ModelTypeSet synced_datatypes; | 364 syncer::ModelTypeSet synced_datatypes; |
| 364 synced_datatypes.Put(syncer::MANAGED_USER_SETTINGS); | 365 synced_datatypes.Put(syncer::SUPERVISED_USER_SETTINGS); |
| 365 service->OnUserChoseDatatypes(sync_everything, synced_datatypes); | 366 service->OnUserChoseDatatypes(sync_everything, synced_datatypes); |
| 366 | 367 |
| 367 // Notify ProfileSyncService that we are done with configuration. | 368 // Notify ProfileSyncService that we are done with configuration. |
| 368 service->SetSetupInProgress(false); | 369 service->SetSetupInProgress(false); |
| 369 service->SetSyncSetupCompleted(); | 370 service->SetSyncSetupCompleted(); |
| 370 } | 371 } |
| 371 | 372 |
| 372 bool ManagedUserService::ExtensionManagementPolicyImpl( | 373 bool ManagedUserService::ExtensionManagementPolicyImpl( |
| 373 const extensions::Extension* extension, | 374 const extensions::Extension* extension, |
| 374 base::string16* error) const { | 375 base::string16* error) const { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 | 410 |
| 410 return site_lists.Pass(); | 411 return site_lists.Pass(); |
| 411 } | 412 } |
| 412 | 413 |
| 413 ManagedUserSettingsService* ManagedUserService::GetSettingsService() { | 414 ManagedUserSettingsService* ManagedUserService::GetSettingsService() { |
| 414 return ManagedUserSettingsServiceFactory::GetForProfile(profile_); | 415 return ManagedUserSettingsServiceFactory::GetForProfile(profile_); |
| 415 } | 416 } |
| 416 | 417 |
| 417 void ManagedUserService::OnManagedUserIdChanged() { | 418 void ManagedUserService::OnManagedUserIdChanged() { |
| 418 std::string managed_user_id = | 419 std::string managed_user_id = |
| 419 profile_->GetPrefs()->GetString(prefs::kManagedUserId); | 420 profile_->GetPrefs()->GetString(prefs::kSupervisedUserId); |
| 420 SetActive(!managed_user_id.empty()); | 421 SetActive(!managed_user_id.empty()); |
| 421 } | 422 } |
| 422 | 423 |
| 423 void ManagedUserService::OnDefaultFilteringBehaviorChanged() { | 424 void ManagedUserService::OnDefaultFilteringBehaviorChanged() { |
| 424 DCHECK(ProfileIsManaged()); | 425 DCHECK(ProfileIsManaged()); |
| 425 | 426 |
| 426 int behavior_value = profile_->GetPrefs()->GetInteger( | 427 int behavior_value = profile_->GetPrefs()->GetInteger( |
| 427 prefs::kDefaultManagedModeFilteringBehavior); | 428 prefs::kDefaultSupervisedUserFilteringBehavior); |
| 428 ManagedModeURLFilter::FilteringBehavior behavior = | 429 ManagedModeURLFilter::FilteringBehavior behavior = |
| 429 ManagedModeURLFilter::BehaviorFromInt(behavior_value); | 430 ManagedModeURLFilter::BehaviorFromInt(behavior_value); |
| 430 url_filter_context_.SetDefaultFilteringBehavior(behavior); | 431 url_filter_context_.SetDefaultFilteringBehavior(behavior); |
| 431 } | 432 } |
| 432 | 433 |
| 433 void ManagedUserService::UpdateSiteLists() { | 434 void ManagedUserService::UpdateSiteLists() { |
| 434 url_filter_context_.LoadWhitelists(GetActiveSiteLists()); | 435 url_filter_context_.LoadWhitelists(GetActiveSiteLists()); |
| 435 } | 436 } |
| 436 | 437 |
| 437 bool ManagedUserService::AccessRequestsEnabled() { | 438 bool ManagedUserService::AccessRequestsEnabled() { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 464 waiting_for_permissions_ = true; | 465 waiting_for_permissions_ = true; |
| 465 permissions_creator_->CreatePermissionRequest( | 466 permissions_creator_->CreatePermissionRequest( |
| 466 output, | 467 output, |
| 467 base::Bind(&ManagedUserService::OnPermissionRequestIssued, | 468 base::Bind(&ManagedUserService::OnPermissionRequestIssued, |
| 468 weak_ptr_factory_.GetWeakPtr())); | 469 weak_ptr_factory_.GetWeakPtr())); |
| 469 } | 470 } |
| 470 | 471 |
| 471 ManagedUserService::ManualBehavior ManagedUserService::GetManualBehaviorForHost( | 472 ManagedUserService::ManualBehavior ManagedUserService::GetManualBehaviorForHost( |
| 472 const std::string& hostname) { | 473 const std::string& hostname) { |
| 473 const base::DictionaryValue* dict = | 474 const base::DictionaryValue* dict = |
| 474 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualHosts); | 475 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualHosts); |
| 475 bool allow = false; | 476 bool allow = false; |
| 476 if (!dict->GetBooleanWithoutPathExpansion(hostname, &allow)) | 477 if (!dict->GetBooleanWithoutPathExpansion(hostname, &allow)) |
| 477 return MANUAL_NONE; | 478 return MANUAL_NONE; |
| 478 | 479 |
| 479 return allow ? MANUAL_ALLOW : MANUAL_BLOCK; | 480 return allow ? MANUAL_ALLOW : MANUAL_BLOCK; |
| 480 } | 481 } |
| 481 | 482 |
| 482 ManagedUserService::ManualBehavior ManagedUserService::GetManualBehaviorForURL( | 483 ManagedUserService::ManualBehavior ManagedUserService::GetManualBehaviorForURL( |
| 483 const GURL& url) { | 484 const GURL& url) { |
| 484 const base::DictionaryValue* dict = | 485 const base::DictionaryValue* dict = |
| 485 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); | 486 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualURLs); |
| 486 GURL normalized_url = ManagedModeURLFilter::Normalize(url); | 487 GURL normalized_url = ManagedModeURLFilter::Normalize(url); |
| 487 bool allow = false; | 488 bool allow = false; |
| 488 if (!dict->GetBooleanWithoutPathExpansion(normalized_url.spec(), &allow)) | 489 if (!dict->GetBooleanWithoutPathExpansion(normalized_url.spec(), &allow)) |
| 489 return MANUAL_NONE; | 490 return MANUAL_NONE; |
| 490 | 491 |
| 491 return allow ? MANUAL_ALLOW : MANUAL_BLOCK; | 492 return allow ? MANUAL_ALLOW : MANUAL_BLOCK; |
| 492 } | 493 } |
| 493 | 494 |
| 494 void ManagedUserService::GetManualExceptionsForHost(const std::string& host, | 495 void ManagedUserService::GetManualExceptionsForHost(const std::string& host, |
| 495 std::vector<GURL>* urls) { | 496 std::vector<GURL>* urls) { |
| 496 const base::DictionaryValue* dict = | 497 const base::DictionaryValue* dict = |
| 497 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); | 498 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualURLs); |
| 498 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 499 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
| 499 GURL url(it.key()); | 500 GURL url(it.key()); |
| 500 if (url.host() == host) | 501 if (url.host() == host) |
| 501 urls->push_back(url); | 502 urls->push_back(url); |
| 502 } | 503 } |
| 503 } | 504 } |
| 504 | 505 |
| 505 void ManagedUserService::InitSync(const std::string& refresh_token) { | 506 void ManagedUserService::InitSync(const std::string& refresh_token) { |
| 506 ProfileSyncService* service = | 507 ProfileSyncService* service = |
| 507 ProfileSyncServiceFactory::GetForProfile(profile_); | 508 ProfileSyncServiceFactory::GetForProfile(profile_); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 521 ProfileSyncServiceFactory::GetForProfile(profile_)->AddObserver(this); | 522 ProfileSyncServiceFactory::GetForProfile(profile_)->AddObserver(this); |
| 522 waiting_for_sync_initialization_ = true; | 523 waiting_for_sync_initialization_ = true; |
| 523 } | 524 } |
| 524 } | 525 } |
| 525 | 526 |
| 526 void ManagedUserService::Init() { | 527 void ManagedUserService::Init() { |
| 527 DCHECK(GetSettingsService()->IsReady()); | 528 DCHECK(GetSettingsService()->IsReady()); |
| 528 | 529 |
| 529 pref_change_registrar_.Init(profile_->GetPrefs()); | 530 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 530 pref_change_registrar_.Add( | 531 pref_change_registrar_.Add( |
| 531 prefs::kManagedUserId, | 532 prefs::kSupervisedUserId, |
| 532 base::Bind(&ManagedUserService::OnManagedUserIdChanged, | 533 base::Bind(&ManagedUserService::OnManagedUserIdChanged, |
| 533 base::Unretained(this))); | 534 base::Unretained(this))); |
| 534 | 535 |
| 535 SetActive(ProfileIsManaged()); | 536 SetActive(ProfileIsManaged()); |
| 536 } | 537 } |
| 537 | 538 |
| 538 void ManagedUserService::SetActive(bool active) { | 539 void ManagedUserService::SetActive(bool active) { |
| 539 if (active_ == active) | 540 if (active_ == active) |
| 540 return; | 541 return; |
| 541 active_ = active; | 542 active_ = active; |
| 542 | 543 |
| 543 if (!delegate_ || !delegate_->SetActive(active_)) { | 544 if (!delegate_ || !delegate_->SetActive(active_)) { |
| 544 if (active_) { | 545 if (active_) { |
| 545 SupervisedUserPrefMappingServiceFactory::GetForBrowserContext(profile_) | 546 SupervisedUserPrefMappingServiceFactory::GetForBrowserContext(profile_) |
| 546 ->Init(); | 547 ->Init(); |
| 547 | 548 |
| 548 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 549 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 549 if (command_line->HasSwitch(switches::kManagedUserSyncToken)) { | 550 if (command_line->HasSwitch(switches::kSupervisedUserSyncToken)) { |
| 550 InitSync( | 551 InitSync( |
| 551 command_line->GetSwitchValueASCII(switches::kManagedUserSyncToken)); | 552 command_line->GetSwitchValueASCII( |
| 553 switches::kSupervisedUserSyncToken)); |
| 552 } | 554 } |
| 553 | 555 |
| 554 ProfileOAuth2TokenService* token_service = | 556 ProfileOAuth2TokenService* token_service = |
| 555 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 557 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 556 token_service->LoadCredentials(managed_users::kManagedUserPseudoEmail); | 558 token_service->LoadCredentials(managed_users::kManagedUserPseudoEmail); |
| 557 } | 559 } |
| 558 } | 560 } |
| 559 | 561 |
| 560 // Now activate/deactivate anything not handled by the delegate yet. | 562 // Now activate/deactivate anything not handled by the delegate yet. |
| 561 | 563 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 580 switches::kPermissionRequestApiUrl)) { | 582 switches::kPermissionRequestApiUrl)) { |
| 581 permissions_creator_ = | 583 permissions_creator_ = |
| 582 PermissionRequestCreatorApiary::CreateWithProfile(profile_); | 584 PermissionRequestCreatorApiary::CreateWithProfile(profile_); |
| 583 } else { | 585 } else { |
| 584 PrefService* pref_service = profile_->GetPrefs(); | 586 PrefService* pref_service = profile_->GetPrefs(); |
| 585 permissions_creator_.reset(new PermissionRequestCreatorSync( | 587 permissions_creator_.reset(new PermissionRequestCreatorSync( |
| 586 settings_service, | 588 settings_service, |
| 587 ManagedUserSharedSettingsServiceFactory::GetForBrowserContext( | 589 ManagedUserSharedSettingsServiceFactory::GetForBrowserContext( |
| 588 profile_), | 590 profile_), |
| 589 pref_service->GetString(prefs::kProfileName), | 591 pref_service->GetString(prefs::kProfileName), |
| 590 pref_service->GetString(prefs::kManagedUserId))); | 592 pref_service->GetString(prefs::kSupervisedUserId))); |
| 591 } | 593 } |
| 592 | 594 |
| 593 if (management_policy) | 595 if (management_policy) |
| 594 management_policy->RegisterProvider(this); | 596 management_policy->RegisterProvider(this); |
| 595 | 597 |
| 596 extension_registry_observer_.Add( | 598 extension_registry_observer_.Add( |
| 597 extensions::ExtensionRegistry::Get(profile_)); | 599 extensions::ExtensionRegistry::Get(profile_)); |
| 598 | 600 |
| 599 pref_change_registrar_.Add( | 601 pref_change_registrar_.Add( |
| 600 prefs::kDefaultManagedModeFilteringBehavior, | 602 prefs::kDefaultSupervisedUserFilteringBehavior, |
| 601 base::Bind(&ManagedUserService::OnDefaultFilteringBehaviorChanged, | 603 base::Bind(&ManagedUserService::OnDefaultFilteringBehaviorChanged, |
| 602 base::Unretained(this))); | 604 base::Unretained(this))); |
| 603 pref_change_registrar_.Add(prefs::kManagedModeManualHosts, | 605 pref_change_registrar_.Add(prefs::kSupervisedUserManualHosts, |
| 604 base::Bind(&ManagedUserService::UpdateManualHosts, | 606 base::Bind(&ManagedUserService::UpdateManualHosts, |
| 605 base::Unretained(this))); | 607 base::Unretained(this))); |
| 606 pref_change_registrar_.Add(prefs::kManagedModeManualURLs, | 608 pref_change_registrar_.Add(prefs::kSupervisedUserManualURLs, |
| 607 base::Bind(&ManagedUserService::UpdateManualURLs, | 609 base::Bind(&ManagedUserService::UpdateManualURLs, |
| 608 base::Unretained(this))); | 610 base::Unretained(this))); |
| 609 | 611 |
| 610 // Initialize the filter. | 612 // Initialize the filter. |
| 611 OnDefaultFilteringBehaviorChanged(); | 613 OnDefaultFilteringBehaviorChanged(); |
| 612 UpdateSiteLists(); | 614 UpdateSiteLists(); |
| 613 UpdateManualHosts(); | 615 UpdateManualHosts(); |
| 614 UpdateManualURLs(); | 616 UpdateManualURLs(); |
| 615 | 617 |
| 616 #if !defined(OS_ANDROID) | 618 #if !defined(OS_ANDROID) |
| 617 // TODO(bauerb): Get rid of the platform-specific #ifdef here. | 619 // TODO(bauerb): Get rid of the platform-specific #ifdef here. |
| 618 // http://crbug.com/313377 | 620 // http://crbug.com/313377 |
| 619 BrowserList::AddObserver(this); | 621 BrowserList::AddObserver(this); |
| 620 #endif | 622 #endif |
| 621 } else { | 623 } else { |
| 622 permissions_creator_.reset(); | 624 permissions_creator_.reset(); |
| 623 | 625 |
| 624 if (management_policy) | 626 if (management_policy) |
| 625 management_policy->UnregisterProvider(this); | 627 management_policy->UnregisterProvider(this); |
| 626 | 628 |
| 627 extension_registry_observer_.RemoveAll(); | 629 extension_registry_observer_.RemoveAll(); |
| 628 | 630 |
| 629 pref_change_registrar_.Remove(prefs::kDefaultManagedModeFilteringBehavior); | 631 pref_change_registrar_.Remove( |
| 630 pref_change_registrar_.Remove(prefs::kManagedModeManualHosts); | 632 prefs::kDefaultSupervisedUserFilteringBehavior); |
| 631 pref_change_registrar_.Remove(prefs::kManagedModeManualURLs); | 633 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); |
| 634 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); |
| 632 | 635 |
| 633 if (waiting_for_sync_initialization_) { | 636 if (waiting_for_sync_initialization_) { |
| 634 ProfileSyncService* sync_service = | 637 ProfileSyncService* sync_service = |
| 635 ProfileSyncServiceFactory::GetForProfile(profile_); | 638 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 636 sync_service->RemoveObserver(this); | 639 sync_service->RemoveObserver(this); |
| 637 } | 640 } |
| 638 | 641 |
| 639 #if !defined(OS_ANDROID) | 642 #if !defined(OS_ANDROID) |
| 640 // TODO(bauerb): Get rid of the platform-specific #ifdef here. | 643 // TODO(bauerb): Get rid of the platform-specific #ifdef here. |
| 641 // http://crbug.com/313377 | 644 // http://crbug.com/313377 |
| 642 BrowserList::RemoveObserver(this); | 645 BrowserList::RemoveObserver(this); |
| 643 #endif | 646 #endif |
| 644 } | 647 } |
| 645 } | 648 } |
| 646 | 649 |
| 647 void ManagedUserService::RegisterAndInitSync( | 650 void ManagedUserService::RegisterAndInitSync( |
| 648 ManagedUserRegistrationUtility* registration_utility, | 651 ManagedUserRegistrationUtility* registration_utility, |
| 649 Profile* custodian_profile, | 652 Profile* custodian_profile, |
| 650 const std::string& managed_user_id, | 653 const std::string& managed_user_id, |
| 651 const AuthErrorCallback& callback) { | 654 const AuthErrorCallback& callback) { |
| 652 DCHECK(ProfileIsManaged()); | 655 DCHECK(ProfileIsManaged()); |
| 653 DCHECK(!custodian_profile->IsManaged()); | 656 DCHECK(!custodian_profile->IsSupervised()); |
| 654 | 657 |
| 655 base::string16 name = base::UTF8ToUTF16( | 658 base::string16 name = base::UTF8ToUTF16( |
| 656 profile_->GetPrefs()->GetString(prefs::kProfileName)); | 659 profile_->GetPrefs()->GetString(prefs::kProfileName)); |
| 657 int avatar_index = profile_->GetPrefs()->GetInteger( | 660 int avatar_index = profile_->GetPrefs()->GetInteger( |
| 658 prefs::kProfileAvatarIndex); | 661 prefs::kProfileAvatarIndex); |
| 659 ManagedUserRegistrationInfo info(name, avatar_index); | 662 ManagedUserRegistrationInfo info(name, avatar_index); |
| 660 registration_utility->Register( | 663 registration_utility->Register( |
| 661 managed_user_id, | 664 managed_user_id, |
| 662 info, | 665 info, |
| 663 base::Bind(&ManagedUserService::OnManagedUserRegistered, | 666 base::Bind(&ManagedUserService::OnManagedUserRegistered, |
| 664 weak_ptr_factory_.GetWeakPtr(), callback, custodian_profile)); | 667 weak_ptr_factory_.GetWeakPtr(), callback, custodian_profile)); |
| 665 | 668 |
| 666 // Fetch the custodian's profile information, to store the name. | 669 // Fetch the custodian's profile information, to store the name. |
| 667 // TODO(pamg): If --google-profile-info (flag: switches::kGoogleProfileInfo) | 670 // TODO(pamg): If --google-profile-info (flag: switches::kGoogleProfileInfo) |
| 668 // is ever enabled, take the name from the ProfileInfoCache instead. | 671 // is ever enabled, take the name from the ProfileInfoCache instead. |
| 669 CustodianProfileDownloaderService* profile_downloader_service = | 672 CustodianProfileDownloaderService* profile_downloader_service = |
| 670 CustodianProfileDownloaderServiceFactory::GetForProfile( | 673 CustodianProfileDownloaderServiceFactory::GetForProfile( |
| 671 custodian_profile); | 674 custodian_profile); |
| 672 profile_downloader_service->DownloadProfile( | 675 profile_downloader_service->DownloadProfile( |
| 673 base::Bind(&ManagedUserService::OnCustodianProfileDownloaded, | 676 base::Bind(&ManagedUserService::OnCustodianProfileDownloaded, |
| 674 weak_ptr_factory_.GetWeakPtr())); | 677 weak_ptr_factory_.GetWeakPtr())); |
| 675 } | 678 } |
| 676 | 679 |
| 677 void ManagedUserService::OnCustodianProfileDownloaded( | 680 void ManagedUserService::OnCustodianProfileDownloaded( |
| 678 const base::string16& full_name) { | 681 const base::string16& full_name) { |
| 679 profile_->GetPrefs()->SetString(prefs::kManagedUserCustodianName, | 682 profile_->GetPrefs()->SetString(prefs::kSupervisedUserCustodianName, |
| 680 base::UTF16ToUTF8(full_name)); | 683 base::UTF16ToUTF8(full_name)); |
| 681 } | 684 } |
| 682 | 685 |
| 683 void ManagedUserService::OnManagedUserRegistered( | 686 void ManagedUserService::OnManagedUserRegistered( |
| 684 const AuthErrorCallback& callback, | 687 const AuthErrorCallback& callback, |
| 685 Profile* custodian_profile, | 688 Profile* custodian_profile, |
| 686 const GoogleServiceAuthError& auth_error, | 689 const GoogleServiceAuthError& auth_error, |
| 687 const std::string& token) { | 690 const std::string& token) { |
| 688 if (auth_error.state() == GoogleServiceAuthError::NONE) { | 691 if (auth_error.state() == GoogleServiceAuthError::NONE) { |
| 689 InitSync(token); | 692 InitSync(token); |
| 690 SigninManagerBase* signin = | 693 SigninManagerBase* signin = |
| 691 SigninManagerFactory::GetForProfile(custodian_profile); | 694 SigninManagerFactory::GetForProfile(custodian_profile); |
| 692 profile_->GetPrefs()->SetString(prefs::kManagedUserCustodianEmail, | 695 profile_->GetPrefs()->SetString(prefs::kSupervisedUserCustodianEmail, |
| 693 signin->GetAuthenticatedUsername()); | 696 signin->GetAuthenticatedUsername()); |
| 694 | 697 |
| 695 // The managed-user profile is now ready for use. | 698 // The managed-user profile is now ready for use. |
| 696 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 699 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 697 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 700 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 698 size_t index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | 701 size_t index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); |
| 699 cache.SetIsOmittedProfileAtIndex(index, false); | 702 cache.SetIsOmittedProfileAtIndex(index, false); |
| 700 } else { | 703 } else { |
| 701 DCHECK_EQ(std::string(), token); | 704 DCHECK_EQ(std::string(), token); |
| 702 } | 705 } |
| 703 | 706 |
| 704 callback.Run(auth_error); | 707 callback.Run(auth_error); |
| 705 } | 708 } |
| 706 | 709 |
| 707 void ManagedUserService::UpdateManualHosts() { | 710 void ManagedUserService::UpdateManualHosts() { |
| 708 const base::DictionaryValue* dict = | 711 const base::DictionaryValue* dict = |
| 709 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualHosts); | 712 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualHosts); |
| 710 scoped_ptr<std::map<std::string, bool> > host_map( | 713 scoped_ptr<std::map<std::string, bool> > host_map( |
| 711 new std::map<std::string, bool>()); | 714 new std::map<std::string, bool>()); |
| 712 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 715 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
| 713 bool allow = false; | 716 bool allow = false; |
| 714 bool result = it.value().GetAsBoolean(&allow); | 717 bool result = it.value().GetAsBoolean(&allow); |
| 715 DCHECK(result); | 718 DCHECK(result); |
| 716 (*host_map)[it.key()] = allow; | 719 (*host_map)[it.key()] = allow; |
| 717 } | 720 } |
| 718 url_filter_context_.SetManualHosts(host_map.Pass()); | 721 url_filter_context_.SetManualHosts(host_map.Pass()); |
| 719 } | 722 } |
| 720 | 723 |
| 721 void ManagedUserService::UpdateManualURLs() { | 724 void ManagedUserService::UpdateManualURLs() { |
| 722 const base::DictionaryValue* dict = | 725 const base::DictionaryValue* dict = |
| 723 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); | 726 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualURLs); |
| 724 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); | 727 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); |
| 725 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 728 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
| 726 bool allow = false; | 729 bool allow = false; |
| 727 bool result = it.value().GetAsBoolean(&allow); | 730 bool result = it.value().GetAsBoolean(&allow); |
| 728 DCHECK(result); | 731 DCHECK(result); |
| 729 (*url_map)[GURL(it.key())] = allow; | 732 (*url_map)[GURL(it.key())] = allow; |
| 730 } | 733 } |
| 731 url_filter_context_.SetManualURLs(url_map.Pass()); | 734 url_filter_context_.SetManualURLs(url_map.Pass()); |
| 732 } | 735 } |
| 733 | 736 |
| 734 void ManagedUserService::OnBrowserSetLastActive(Browser* browser) { | 737 void ManagedUserService::OnBrowserSetLastActive(Browser* browser) { |
| 735 bool profile_became_active = profile_->IsSameProfile(browser->profile()); | 738 bool profile_became_active = profile_->IsSameProfile(browser->profile()); |
| 736 if (!is_profile_active_ && profile_became_active) | 739 if (!is_profile_active_ && profile_became_active) |
| 737 content::RecordAction(UserMetricsAction("ManagedUsers_OpenProfile")); | 740 content::RecordAction(UserMetricsAction("ManagedUsers_OpenProfile")); |
| 738 else if (is_profile_active_ && !profile_became_active) | 741 else if (is_profile_active_ && !profile_became_active) |
| 739 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); | 742 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); |
| 740 | 743 |
| 741 is_profile_active_ = profile_became_active; | 744 is_profile_active_ = profile_became_active; |
| 742 } | 745 } |
| OLD | NEW |