| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/chromeos/user_cros_settings_provider.h" | 5 #include "chrome/browser/chromeos/user_cros_settings_provider.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/task.h" | 14 #include "base/task.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/chromeos/cros/cros_library.h" | 17 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 18 #include "chrome/browser/chromeos/cros/login_library.h" | 18 #include "chrome/browser/chromeos/cros/login_library.h" |
| 19 #include "chrome/browser/chromeos/cros/network_library.h" | 19 #include "chrome/browser/chromeos/cros/network_library.h" |
| 20 #include "chrome/browser/chromeos/cros_settings.h" | 20 #include "chrome/browser/chromeos/cros_settings.h" |
| 21 #include "chrome/browser/chromeos/cros_settings_names.h" | 21 #include "chrome/browser/chromeos/cros_settings_names.h" |
| 22 #include "chrome/browser/chromeos/login/ownership_service.h" | 22 #include "chrome/browser/chromeos/login/ownership_service.h" |
| 23 #include "chrome/browser/chromeos/login/user_manager.h" | 23 #include "chrome/browser/chromeos/login/user_manager.h" |
| 24 #include "chrome/browser/policy/browser_policy_connector.h" | 24 #include "chrome/browser/policy/browser_policy_connector.h" |
| 25 #include "chrome/browser/prefs/pref_service.h" | 25 #include "chrome/browser/prefs/pref_service.h" |
| 26 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 26 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 27 #include "chrome/browser/ui/options/options_util.h" | |
| 28 #include "chrome/installer/util/google_update_settings.h" | |
| 29 #include "content/browser/browser_thread.h" | 27 #include "content/browser/browser_thread.h" |
| 30 | 28 |
| 31 namespace chromeos { | 29 namespace chromeos { |
| 32 | 30 |
| 33 namespace { | 31 namespace { |
| 34 | 32 |
| 35 const char kTrueIncantation[] = "true"; | 33 const char kTrueIncantation[] = "true"; |
| 36 const char kFalseIncantation[] = "false"; | 34 const char kFalseIncantation[] = "false"; |
| 37 const char kTrustedSuffix[] = "/trusted"; | 35 const char kTrustedSuffix[] = "/trusted"; |
| 38 | 36 |
| 39 // For all our boolean settings following is applicable: | 37 // For all our boolean settings following is applicable: |
| 40 // true is default permissive value and false is safe prohibitic value. | 38 // true is default permissive value and false is safe prohibitic value. |
| 41 // Exception: kSignedDataRoamingEnabled which has default value of false. | 39 // Exception: kSignedDataRoamingEnabled which has default value of false. |
| 42 const char* kBooleanSettings[] = { | 40 const char* kBooleanSettings[] = { |
| 43 kAccountsPrefAllowNewUser, | 41 kAccountsPrefAllowNewUser, |
| 44 kAccountsPrefAllowGuest, | 42 kAccountsPrefAllowGuest, |
| 45 kAccountsPrefShowUserNamesOnSignIn, | 43 kAccountsPrefShowUserNamesOnSignIn, |
| 46 kSignedDataRoamingEnabled, | 44 kSignedDataRoamingEnabled, |
| 47 kStatsReportingPref | |
| 48 }; | 45 }; |
| 49 | 46 |
| 50 const char* kStringSettings[] = { | 47 const char* kStringSettings[] = { |
| 51 kDeviceOwner, | 48 kDeviceOwner, |
| 52 kReleaseChannel | 49 kReleaseChannel |
| 53 }; | 50 }; |
| 54 | 51 |
| 55 const char* kListSettings[] = { | 52 const char* kListSettings[] = { |
| 56 kAccountsPrefUsers | 53 kAccountsPrefUsers |
| 57 }; | 54 }; |
| 58 | 55 |
| 59 bool IsControlledBooleanSetting(const std::string& pref_path) { | 56 bool IsControlledBooleanSetting(const std::string& pref_path) { |
| 60 // TODO(nkostylev): Using std::find for 4 value array generates this warning | 57 // TODO(nkostylev): Using std::find for 4 value array generates this warning |
| 61 // in chroot stl_algo.h:231: error: array subscript is above array bounds. | 58 // in chroot stl_algo.h:231: error: array subscript is above array bounds. |
| 62 // GCC 4.4.3 | 59 // GCC 4.4.3 |
| 63 return (pref_path == kAccountsPrefAllowNewUser) || | 60 return (pref_path == kAccountsPrefAllowNewUser) || |
| 64 (pref_path == kAccountsPrefAllowGuest) || | 61 (pref_path == kAccountsPrefAllowGuest) || |
| 65 (pref_path == kAccountsPrefShowUserNamesOnSignIn) || | 62 (pref_path == kAccountsPrefShowUserNamesOnSignIn) || |
| 66 (pref_path == kSignedDataRoamingEnabled) || | 63 (pref_path == kSignedDataRoamingEnabled); |
| 67 (pref_path == kStatsReportingPref); | |
| 68 } | 64 } |
| 69 | 65 |
| 70 bool IsControlledStringSetting(const std::string& pref_path) { | 66 bool IsControlledStringSetting(const std::string& pref_path) { |
| 71 return std::find(kStringSettings, | 67 return std::find(kStringSettings, |
| 72 kStringSettings + arraysize(kStringSettings), | 68 kStringSettings + arraysize(kStringSettings), |
| 73 pref_path) != | 69 pref_path) != |
| 74 kStringSettings + arraysize(kStringSettings); | 70 kStringSettings + arraysize(kStringSettings); |
| 75 } | 71 } |
| 76 | 72 |
| 77 bool IsControlledListSetting(const std::string& pref_path) { | 73 bool IsControlledListSetting(const std::string& pref_path) { |
| 78 return std::find(kListSettings, | 74 return std::find(kListSettings, |
| 79 kListSettings + arraysize(kListSettings), | 75 kListSettings + arraysize(kListSettings), |
| 80 pref_path) != | 76 pref_path) != |
| 81 kListSettings + arraysize(kListSettings); | 77 kListSettings + arraysize(kListSettings); |
| 82 } | 78 } |
| 83 | 79 |
| 84 void RegisterSetting(PrefService* local_state, const std::string& pref_path) { | 80 void RegisterSetting(PrefService* local_state, const std::string& pref_path) { |
| 85 local_state->RegisterBooleanPref((pref_path + kTrustedSuffix).c_str(), | 81 local_state->RegisterBooleanPref((pref_path + kTrustedSuffix).c_str(), |
| 86 false, | 82 false, |
| 87 PrefService::UNSYNCABLE_PREF); | 83 PrefService::UNSYNCABLE_PREF); |
| 88 if (IsControlledBooleanSetting(pref_path)) { | 84 if (IsControlledBooleanSetting(pref_path)) { |
| 89 if (pref_path == kSignedDataRoamingEnabled || | 85 if (pref_path == kSignedDataRoamingEnabled) |
| 90 pref_path == kStatsReportingPref) | |
| 91 local_state->RegisterBooleanPref(pref_path.c_str(), | 86 local_state->RegisterBooleanPref(pref_path.c_str(), |
| 92 false, | 87 false, |
| 93 PrefService::UNSYNCABLE_PREF); | 88 PrefService::UNSYNCABLE_PREF); |
| 94 else | 89 else |
| 95 local_state->RegisterBooleanPref(pref_path.c_str(), | 90 local_state->RegisterBooleanPref(pref_path.c_str(), |
| 96 true, | 91 true, |
| 97 PrefService::UNSYNCABLE_PREF); | 92 PrefService::UNSYNCABLE_PREF); |
| 98 } else if (IsControlledStringSetting(pref_path)) { | 93 } else if (IsControlledStringSetting(pref_path)) { |
| 99 local_state->RegisterStringPref(pref_path.c_str(), | 94 local_state->RegisterStringPref(pref_path.c_str(), |
| 100 "", | 95 "", |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 } | 279 } |
| 285 | 280 |
| 286 // Called right before boolean property is changed. | 281 // Called right before boolean property is changed. |
| 287 void OnBooleanPropertyChange(const std::string& path, bool new_value) { | 282 void OnBooleanPropertyChange(const std::string& path, bool new_value) { |
| 288 if (path == kSignedDataRoamingEnabled) { | 283 if (path == kSignedDataRoamingEnabled) { |
| 289 if (!CrosLibrary::Get()->EnsureLoaded()) | 284 if (!CrosLibrary::Get()->EnsureLoaded()) |
| 290 return; | 285 return; |
| 291 | 286 |
| 292 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 287 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 293 cros->SetCellularDataRoamingAllowed(new_value); | 288 cros->SetCellularDataRoamingAllowed(new_value); |
| 294 } else if (path == kStatsReportingPref) { | |
| 295 // TODO(pastarmovj): Remove this once we don't need to regenerate the | |
| 296 // consent file for the GUID anymore. | |
| 297 OptionsUtil::ResolveMetricsReportingEnabled(new_value); | |
| 298 } | 289 } |
| 299 } | 290 } |
| 300 | 291 |
| 301 // Called right after signed value was checked. | 292 // Called right after signed value was checked. |
| 302 void OnBooleanPropertyRetrieve(const std::string& path, | 293 void OnBooleanPropertyRetrieve(const std::string& path, |
| 303 bool value, | 294 bool value, |
| 304 UseValue use_value) { | 295 UseValue use_value) { |
| 305 if (path == kSignedDataRoamingEnabled) { | 296 if (path == kSignedDataRoamingEnabled) { |
| 306 if (!CrosLibrary::Get()->EnsureLoaded()) | 297 if (!CrosLibrary::Get()->EnsureLoaded()) |
| 307 return; | 298 return; |
| 308 | 299 |
| 309 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 300 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 310 const NetworkDevice* cellular = cros->FindCellularDevice(); | 301 const NetworkDevice* cellular = cros->FindCellularDevice(); |
| 311 if (cellular) { | 302 if (cellular) { |
| 312 bool device_value = cellular->data_roaming_allowed(); | 303 bool device_value = cellular->data_roaming_allowed(); |
| 313 bool new_value = (use_value == USE_VALUE_SUPPLIED) ? value : false; | 304 bool new_value = (use_value == USE_VALUE_SUPPLIED) ? value : false; |
| 314 if (device_value != new_value) | 305 if (device_value != new_value) |
| 315 cros->SetCellularDataRoamingAllowed(new_value); | 306 cros->SetCellularDataRoamingAllowed(new_value); |
| 316 } | 307 } |
| 317 } else if (path == kStatsReportingPref) { | |
| 318 bool stats_consent = (use_value == USE_VALUE_SUPPLIED) ? value : false; | |
| 319 // TODO(pastarmovj): Remove this once we don't need to regenerate the | |
| 320 // consent file for the GUID anymore. | |
| 321 VLOG(1) << "Metrics policy is being set to : " << stats_consent | |
| 322 << "(reason : " << use_value << ")"; | |
| 323 OptionsUtil::ResolveMetricsReportingEnabled(stats_consent); | |
| 324 } | 308 } |
| 325 } | 309 } |
| 326 | 310 |
| 327 void StartFetchingSetting(const std::string& name) { | 311 void StartFetchingSetting(const std::string& name) { |
| 328 DCHECK(g_browser_process); | 312 DCHECK(g_browser_process); |
| 329 PrefService* prefs = g_browser_process->local_state(); | 313 PrefService* prefs = g_browser_process->local_state(); |
| 330 if (!prefs) | 314 if (!prefs) |
| 331 return; | 315 return; |
| 332 // Do not trust before fetching complete. | 316 // Do not trust before fetching complete. |
| 333 prefs->ClearPref((name + kTrustedSuffix).c_str()); | 317 prefs->ClearPref((name + kTrustedSuffix).c_str()); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 Task* callback) { | 481 Task* callback) { |
| 498 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( | 482 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( |
| 499 kSignedDataRoamingEnabled, callback); | 483 kSignedDataRoamingEnabled, callback); |
| 500 } | 484 } |
| 501 | 485 |
| 502 bool UserCrosSettingsProvider::RequestTrustedOwner(Task* callback) { | 486 bool UserCrosSettingsProvider::RequestTrustedOwner(Task* callback) { |
| 503 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( | 487 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( |
| 504 kDeviceOwner, callback); | 488 kDeviceOwner, callback); |
| 505 } | 489 } |
| 506 | 490 |
| 507 bool UserCrosSettingsProvider::RequestTrustedReportingEnabled(Task* callback) { | |
| 508 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( | |
| 509 kStatsReportingPref, callback); | |
| 510 } | |
| 511 | |
| 512 void UserCrosSettingsProvider::Reload() { | 491 void UserCrosSettingsProvider::Reload() { |
| 513 UserCrosSettingsTrust::GetInstance()->Reload(); | 492 UserCrosSettingsTrust::GetInstance()->Reload(); |
| 514 } | 493 } |
| 515 | 494 |
| 516 // static | 495 // static |
| 517 bool UserCrosSettingsProvider::cached_allow_guest() { | 496 bool UserCrosSettingsProvider::cached_allow_guest() { |
| 518 // Trigger prefetching if singleton object still does not exist. | 497 // Trigger prefetching if singleton object still does not exist. |
| 519 UserCrosSettingsTrust::GetInstance(); | 498 UserCrosSettingsTrust::GetInstance(); |
| 520 return g_browser_process->local_state()->GetBoolean(kAccountsPrefAllowGuest); | 499 return g_browser_process->local_state()->GetBoolean(kAccountsPrefAllowGuest); |
| 521 } | 500 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 538 | 517 |
| 539 // static | 518 // static |
| 540 bool UserCrosSettingsProvider::cached_show_users_on_signin() { | 519 bool UserCrosSettingsProvider::cached_show_users_on_signin() { |
| 541 // Trigger prefetching if singleton object still does not exist. | 520 // Trigger prefetching if singleton object still does not exist. |
| 542 UserCrosSettingsTrust::GetInstance(); | 521 UserCrosSettingsTrust::GetInstance(); |
| 543 return g_browser_process->local_state()->GetBoolean( | 522 return g_browser_process->local_state()->GetBoolean( |
| 544 kAccountsPrefShowUserNamesOnSignIn); | 523 kAccountsPrefShowUserNamesOnSignIn); |
| 545 } | 524 } |
| 546 | 525 |
| 547 // static | 526 // static |
| 548 bool UserCrosSettingsProvider::cached_reporting_enabled() { | |
| 549 // Trigger prefetching if singleton object still does not exist. | |
| 550 UserCrosSettingsTrust::GetInstance(); | |
| 551 return g_browser_process->local_state()->GetBoolean( | |
| 552 kStatsReportingPref); | |
| 553 } | |
| 554 | |
| 555 // static | |
| 556 const ListValue* UserCrosSettingsProvider::cached_whitelist() { | 527 const ListValue* UserCrosSettingsProvider::cached_whitelist() { |
| 557 PrefService* prefs = g_browser_process->local_state(); | 528 PrefService* prefs = g_browser_process->local_state(); |
| 558 const ListValue* cached_users = prefs->GetList(kAccountsPrefUsers); | 529 const ListValue* cached_users = prefs->GetList(kAccountsPrefUsers); |
| 559 if (!prefs->IsManagedPreference(kAccountsPrefUsers)) { | 530 if (!prefs->IsManagedPreference(kAccountsPrefUsers)) { |
| 560 if (cached_users == NULL) { | 531 if (cached_users == NULL) { |
| 561 // Update whitelist cache. | 532 // Update whitelist cache. |
| 562 GetUserWhitelist(NULL); | 533 GetUserWhitelist(NULL); |
| 563 cached_users = prefs->GetList(kAccountsPrefUsers); | 534 cached_users = prefs->GetList(kAccountsPrefUsers); |
| 564 } | 535 } |
| 565 } | 536 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 !UserManager::Get()->current_user_is_owner()); | 590 !UserManager::Get()->current_user_is_owner()); |
| 620 return true; | 591 return true; |
| 621 } | 592 } |
| 622 | 593 |
| 623 return false; | 594 return false; |
| 624 } | 595 } |
| 625 | 596 |
| 626 bool UserCrosSettingsProvider::HandlesSetting(const std::string& path) { | 597 bool UserCrosSettingsProvider::HandlesSetting(const std::string& path) { |
| 627 return ::StartsWithASCII(path, "cros.accounts.", true) || | 598 return ::StartsWithASCII(path, "cros.accounts.", true) || |
| 628 ::StartsWithASCII(path, "cros.signed.", true) || | 599 ::StartsWithASCII(path, "cros.signed.", true) || |
| 629 ::StartsWithASCII(path, "cros.metrics.", true) || | |
| 630 path == kReleaseChannel; | 600 path == kReleaseChannel; |
| 631 } | 601 } |
| 632 | 602 |
| 633 void UserCrosSettingsProvider::WhitelistUser(const std::string& email) { | 603 void UserCrosSettingsProvider::WhitelistUser(const std::string& email) { |
| 634 SignedSettingsHelper::Get()->StartWhitelistOp( | 604 SignedSettingsHelper::Get()->StartWhitelistOp( |
| 635 email, true, UserCrosSettingsTrust::GetInstance()); | 605 email, true, UserCrosSettingsTrust::GetInstance()); |
| 636 PrefService* prefs = g_browser_process->local_state(); | 606 PrefService* prefs = g_browser_process->local_state(); |
| 637 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers); | 607 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers); |
| 638 cached_whitelist_update->Append(Value::CreateStringValue(email)); | 608 cached_whitelist_update->Append(Value::CreateStringValue(email)); |
| 639 prefs->ScheduleSavePersistentPrefs(); | 609 prefs->ScheduleSavePersistentPrefs(); |
| 640 } | 610 } |
| 641 | 611 |
| 642 void UserCrosSettingsProvider::UnwhitelistUser(const std::string& email) { | 612 void UserCrosSettingsProvider::UnwhitelistUser(const std::string& email) { |
| 643 SignedSettingsHelper::Get()->StartWhitelistOp( | 613 SignedSettingsHelper::Get()->StartWhitelistOp( |
| 644 email, false, UserCrosSettingsTrust::GetInstance()); | 614 email, false, UserCrosSettingsTrust::GetInstance()); |
| 645 | 615 |
| 646 PrefService* prefs = g_browser_process->local_state(); | 616 PrefService* prefs = g_browser_process->local_state(); |
| 647 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers); | 617 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers); |
| 648 StringValue email_value(email); | 618 StringValue email_value(email); |
| 649 if (cached_whitelist_update->Remove(email_value) != -1) | 619 if (cached_whitelist_update->Remove(email_value) != -1) |
| 650 prefs->ScheduleSavePersistentPrefs(); | 620 prefs->ScheduleSavePersistentPrefs(); |
| 651 } | 621 } |
| 652 | 622 |
| 653 // static | 623 // static |
| 654 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { | 624 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { |
| 655 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); | 625 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); |
| 656 } | 626 } |
| 657 | 627 |
| 658 } // namespace chromeos | 628 } // namespace chromeos |
| OLD | NEW |