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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 prefs::kSupervisedUserCustodianName, | 76 prefs::kSupervisedUserCustodianName, |
| 77 prefs::kSupervisedUserCustodianEmail, | 77 prefs::kSupervisedUserCustodianEmail, |
| 78 prefs::kSupervisedUserCustodianProfileImageURL, | 78 prefs::kSupervisedUserCustodianProfileImageURL, |
| 79 prefs::kSupervisedUserCustodianProfileURL, | 79 prefs::kSupervisedUserCustodianProfileURL, |
| 80 prefs::kSupervisedUserSecondCustodianName, | 80 prefs::kSupervisedUserSecondCustodianName, |
| 81 prefs::kSupervisedUserSecondCustodianEmail, | 81 prefs::kSupervisedUserSecondCustodianEmail, |
| 82 prefs::kSupervisedUserSecondCustodianProfileImageURL, | 82 prefs::kSupervisedUserSecondCustodianProfileImageURL, |
| 83 prefs::kSupervisedUserSecondCustodianProfileURL, | 83 prefs::kSupervisedUserSecondCustodianProfileURL, |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 #if defined(ENABLE_EXTENSIONS) | |
| 87 enum ExtensionState { | |
| 88 EXTENSION_FORCED, | |
| 89 EXTENSION_BLOCKED, | |
| 90 EXTENSION_ALLOWED | |
| 91 }; | |
| 92 | |
| 93 ExtensionState GetExtensionState(const extensions::Extension* extension) { | |
| 94 // |extension| can be NULL in unit_tests. | |
| 95 if (extension && extension->is_theme()) | |
| 96 return EXTENSION_ALLOWED; | |
| 97 | |
| 98 bool was_installed_by_default = extension->was_installed_by_default(); | |
|
Pam (message me for reviews)
2015/02/23 10:18:50
If indeed |extension| can be NULL in unit tests, k
Marc Treib
2015/02/23 12:07:38
Huh. Since I got green try runs, looks like extens
| |
| 99 bool was_installed_by_custodian = extension->was_installed_by_custodian(); | |
| 100 #if defined(OS_CHROMEOS) | |
| 101 // On Chrome OS all external sources are controlled by us so it means that | |
| 102 // they are "default". Method was_installed_by_default returns false because | |
| 103 // extensions creation flags are ignored in case of default extensions with | |
| 104 // update URL(the flags aren't passed to OnExternalExtensionUpdateUrlFound). | |
| 105 // TODO(dpolukhin): remove this Chrome OS specific code as soon as creation | |
| 106 // flags are not ignored. | |
| 107 was_installed_by_default = | |
| 108 extensions::Manifest::IsExternalLocation(extension->location()); | |
| 109 #endif | |
| 110 if (extensions::Manifest::IsComponentLocation(extension->location()) || | |
| 111 was_installed_by_default || | |
| 112 was_installed_by_custodian) { | |
| 113 // Enforce default extensions as well as custodian-installed extensions | |
| 114 // (if we'd allow the supervised user to uninstall them, there'd be no way | |
| 115 // to get them back). | |
| 116 return EXTENSION_FORCED; | |
| 117 } | |
| 118 | |
| 119 return EXTENSION_BLOCKED; | |
| 120 } | |
| 121 #endif | |
| 122 | |
| 86 } // namespace | 123 } // namespace |
| 87 | 124 |
| 88 base::FilePath SupervisedUserService::Delegate::GetBlacklistPath() const { | 125 base::FilePath SupervisedUserService::Delegate::GetBlacklistPath() const { |
| 89 return base::FilePath(); | 126 return base::FilePath(); |
| 90 } | 127 } |
| 91 | 128 |
| 92 GURL SupervisedUserService::Delegate::GetBlacklistURL() const { | 129 GURL SupervisedUserService::Delegate::GetBlacklistURL() const { |
| 93 return GURL(); | 130 return GURL(); |
| 94 } | 131 } |
| 95 | 132 |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 void SupervisedUserService::RemoveObserver( | 379 void SupervisedUserService::RemoveObserver( |
| 343 SupervisedUserServiceObserver* observer) { | 380 SupervisedUserServiceObserver* observer) { |
| 344 observer_list_.RemoveObserver(observer); | 381 observer_list_.RemoveObserver(observer); |
| 345 } | 382 } |
| 346 | 383 |
| 347 void SupervisedUserService::AddPermissionRequestCreator( | 384 void SupervisedUserService::AddPermissionRequestCreator( |
| 348 scoped_ptr<PermissionRequestCreator> creator) { | 385 scoped_ptr<PermissionRequestCreator> creator) { |
| 349 permissions_creators_.push_back(creator.release()); | 386 permissions_creators_.push_back(creator.release()); |
| 350 } | 387 } |
| 351 | 388 |
| 352 #if defined(ENABLE_EXTENSIONS) | |
| 353 std::string SupervisedUserService::GetDebugPolicyProviderName() const { | |
| 354 // Save the string space in official builds. | |
| 355 #ifdef NDEBUG | |
| 356 NOTREACHED(); | |
| 357 return std::string(); | |
| 358 #else | |
| 359 return "Supervised User Service"; | |
| 360 #endif | |
| 361 } | |
| 362 | |
| 363 bool SupervisedUserService::UserMayLoad(const extensions::Extension* extension, | |
| 364 base::string16* error) const { | |
| 365 base::string16 tmp_error; | |
| 366 if (ExtensionManagementPolicyImpl(extension, &tmp_error)) | |
| 367 return true; | |
| 368 | |
| 369 bool was_installed_by_default = extension->was_installed_by_default(); | |
| 370 bool was_installed_by_custodian = extension->was_installed_by_custodian(); | |
| 371 #if defined(OS_CHROMEOS) | |
| 372 // On Chrome OS all external sources are controlled by us so it means that | |
| 373 // they are "default". Method was_installed_by_default returns false because | |
| 374 // extensions creation flags are ignored in case of default extensions with | |
| 375 // update URL(the flags aren't passed to OnExternalExtensionUpdateUrlFound). | |
| 376 // TODO(dpolukhin): remove this Chrome OS specific code as soon as creation | |
| 377 // flags are not ignored. | |
| 378 was_installed_by_default = | |
| 379 extensions::Manifest::IsExternalLocation(extension->location()); | |
| 380 #endif | |
| 381 if (extensions::Manifest::IsComponentLocation(extension->location()) || | |
| 382 was_installed_by_default || | |
| 383 was_installed_by_custodian) { | |
| 384 return true; | |
| 385 } | |
| 386 | |
| 387 if (error) | |
| 388 *error = tmp_error; | |
| 389 return false; | |
| 390 } | |
| 391 | |
| 392 bool SupervisedUserService::UserMayModifySettings( | |
| 393 const extensions::Extension* extension, | |
| 394 base::string16* error) const { | |
| 395 return ExtensionManagementPolicyImpl(extension, error); | |
| 396 } | |
| 397 | |
| 398 #endif // defined(ENABLE_EXTENSIONS) | |
| 399 | |
| 400 syncer::ModelTypeSet SupervisedUserService::GetPreferredDataTypes() const { | 389 syncer::ModelTypeSet SupervisedUserService::GetPreferredDataTypes() const { |
| 401 if (!ProfileIsSupervised()) | 390 if (!ProfileIsSupervised()) |
| 402 return syncer::ModelTypeSet(); | 391 return syncer::ModelTypeSet(); |
| 403 | 392 |
| 404 syncer::ModelTypeSet result; | 393 syncer::ModelTypeSet result; |
| 405 if (IncludesSyncSessionsType()) | 394 if (IncludesSyncSessionsType()) |
| 406 result.Put(syncer::SESSIONS); | 395 result.Put(syncer::SESSIONS); |
| 407 result.Put(syncer::EXTENSIONS); | 396 result.Put(syncer::EXTENSIONS); |
| 408 result.Put(syncer::EXTENSION_SETTINGS); | 397 result.Put(syncer::EXTENSION_SETTINGS); |
| 409 result.Put(syncer::APPS); | 398 result.Put(syncer::APPS); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 bool sync_everything = false; | 468 bool sync_everything = false; |
| 480 syncer::ModelTypeSet synced_datatypes; | 469 syncer::ModelTypeSet synced_datatypes; |
| 481 service->OnUserChoseDatatypes(sync_everything, synced_datatypes); | 470 service->OnUserChoseDatatypes(sync_everything, synced_datatypes); |
| 482 | 471 |
| 483 // Notify ProfileSyncService that we are done with configuration. | 472 // Notify ProfileSyncService that we are done with configuration. |
| 484 service->SetSetupInProgress(false); | 473 service->SetSetupInProgress(false); |
| 485 service->SetSyncSetupCompleted(); | 474 service->SetSyncSetupCompleted(); |
| 486 } | 475 } |
| 487 | 476 |
| 488 #if defined(ENABLE_EXTENSIONS) | 477 #if defined(ENABLE_EXTENSIONS) |
| 489 bool SupervisedUserService::ExtensionManagementPolicyImpl( | 478 std::string SupervisedUserService::GetDebugPolicyProviderName() const { |
| 479 // Save the string space in official builds. | |
| 480 #ifdef NDEBUG | |
| 481 NOTREACHED(); | |
| 482 return std::string(); | |
| 483 #else | |
| 484 return "Supervised User Service"; | |
| 485 #endif | |
| 486 } | |
| 487 | |
| 488 bool SupervisedUserService::UserMayLoad(const extensions::Extension* extension, | |
| 489 base::string16* error) const { | |
| 490 DCHECK(ProfileIsSupervised()); | |
| 491 ExtensionState result = GetExtensionState(extension); | |
| 492 bool may_load = (result != EXTENSION_BLOCKED); | |
| 493 if (!may_load && error) | |
| 494 *error = l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_SUPERVISED_USER); | |
| 495 return may_load; | |
| 496 } | |
| 497 | |
| 498 // Note: Having MustRemainInstalled always say "true" for custodian-installed | |
| 499 // extensions does NOT prevent remote uninstalls (which is a bit unexpected, but | |
| 500 // exactly what we want). | |
| 501 bool SupervisedUserService::MustRemainInstalled( | |
| 490 const extensions::Extension* extension, | 502 const extensions::Extension* extension, |
| 491 base::string16* error) const { | 503 base::string16* error) const { |
| 492 // |extension| can be NULL in unit_tests. | 504 DCHECK(ProfileIsSupervised()); |
| 493 if (!ProfileIsSupervised() || (extension && extension->is_theme())) | 505 ExtensionState result = GetExtensionState(extension); |
| 494 return true; | 506 bool may_uninstall = (result != EXTENSION_FORCED); |
|
Pam (message me for reviews)
2015/02/23 10:18:50
Please change the sense of this (i.e. use may_not_
Marc Treib
2015/02/23 12:07:38
Done.
| |
| 495 | 507 if (!may_uninstall && error) |
| 496 if (error) | |
| 497 *error = l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_SUPERVISED_USER); | 508 *error = l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_SUPERVISED_USER); |
| 498 return false; | 509 return !may_uninstall; |
| 499 } | 510 } |
| 500 | 511 |
| 501 void SupervisedUserService::SetExtensionsActive() { | 512 void SupervisedUserService::SetExtensionsActive() { |
| 502 extensions::ExtensionSystem* extension_system = | 513 extensions::ExtensionSystem* extension_system = |
| 503 extensions::ExtensionSystem::Get(profile_); | 514 extensions::ExtensionSystem::Get(profile_); |
| 504 extensions::ManagementPolicy* management_policy = | 515 extensions::ManagementPolicy* management_policy = |
| 505 extension_system->management_policy(); | 516 extension_system->management_policy(); |
| 506 | 517 |
| 507 if (management_policy) { | 518 if (management_policy) { |
| 508 if (active_) | 519 if (active_) |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 948 // The active user can be NULL in unit tests. | 959 // The active user can be NULL in unit tests. |
| 949 if (user_manager::UserManager::Get()->GetActiveUser()) { | 960 if (user_manager::UserManager::Get()->GetActiveUser()) { |
| 950 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( | 961 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( |
| 951 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); | 962 user_manager::UserManager::Get()->GetActiveUser()->GetUserID())); |
| 952 } | 963 } |
| 953 return std::string(); | 964 return std::string(); |
| 954 #else | 965 #else |
| 955 return profile_->GetPrefs()->GetString(prefs::kProfileName); | 966 return profile_->GetPrefs()->GetString(prefs::kProfileName); |
| 956 #endif | 967 #endif |
| 957 } | 968 } |
| OLD | NEW |