| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 } | 150 } |
| 151 | 151 |
| 152 prefs->ScheduleSavePersistentPrefs(); | 152 prefs->ScheduleSavePersistentPrefs(); |
| 153 | 153 |
| 154 return true; | 154 return true; |
| 155 } | 155 } |
| 156 | 156 |
| 157 class UserCrosSettingsTrust : public SignedSettingsHelper::Callback, | 157 class UserCrosSettingsTrust : public SignedSettingsHelper::Callback, |
| 158 public NotificationObserver { | 158 public NotificationObserver { |
| 159 public: | 159 public: |
| 160 static UserCrosSettingsTrust* GetSharedInstance() { | 160 static UserCrosSettingsTrust* GetInstance() { |
| 161 return Singleton<UserCrosSettingsTrust>::get(); | 161 return Singleton<UserCrosSettingsTrust>::get(); |
| 162 } | 162 } |
| 163 | 163 |
| 164 // Working horse for UserCrosSettingsProvider::RequestTrusted* family. | 164 // Working horse for UserCrosSettingsProvider::RequestTrusted* family. |
| 165 bool RequestTrustedEntity(const std::string& name, Task* callback) { | 165 bool RequestTrustedEntity(const std::string& name, Task* callback) { |
| 166 if (GetOwnershipStatus() == OWNERSHIP_NONE) | 166 if (GetOwnershipStatus() == OWNERSHIP_NONE) |
| 167 return true; | 167 return true; |
| 168 if (GetOwnershipStatus() == OWNERSHIP_TAKEN) { | 168 if (GetOwnershipStatus() == OWNERSHIP_TAKEN) { |
| 169 DCHECK(g_browser_process); | 169 DCHECK(g_browser_process); |
| 170 PrefService* prefs = g_browser_process->local_state(); | 170 PrefService* prefs = g_browser_process->local_state(); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 } // namespace chromeos | 431 } // namespace chromeos |
| 432 | 432 |
| 433 // We want to use NewRunnableMethod with this class but need to disable | 433 // We want to use NewRunnableMethod with this class but need to disable |
| 434 // reference counting since it is singleton. | 434 // reference counting since it is singleton. |
| 435 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::UserCrosSettingsTrust); | 435 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::UserCrosSettingsTrust); |
| 436 | 436 |
| 437 namespace chromeos { | 437 namespace chromeos { |
| 438 | 438 |
| 439 UserCrosSettingsProvider::UserCrosSettingsProvider() { | 439 UserCrosSettingsProvider::UserCrosSettingsProvider() { |
| 440 // Trigger prefetching of settings. | 440 // Trigger prefetching of settings. |
| 441 UserCrosSettingsTrust::GetSharedInstance(); | 441 UserCrosSettingsTrust::GetInstance(); |
| 442 } | 442 } |
| 443 | 443 |
| 444 // static | 444 // static |
| 445 void UserCrosSettingsProvider::RegisterPrefs(PrefService* local_state) { | 445 void UserCrosSettingsProvider::RegisterPrefs(PrefService* local_state) { |
| 446 for (size_t i = 0; i < arraysize(kBooleanSettings); ++i) | 446 for (size_t i = 0; i < arraysize(kBooleanSettings); ++i) |
| 447 RegisterSetting(local_state, kBooleanSettings[i]); | 447 RegisterSetting(local_state, kBooleanSettings[i]); |
| 448 for (size_t i = 0; i < arraysize(kStringSettings); ++i) | 448 for (size_t i = 0; i < arraysize(kStringSettings); ++i) |
| 449 RegisterSetting(local_state, kStringSettings[i]); | 449 RegisterSetting(local_state, kStringSettings[i]); |
| 450 for (size_t i = 0; i < arraysize(kListSettings); ++i) | 450 for (size_t i = 0; i < arraysize(kListSettings); ++i) |
| 451 RegisterSetting(local_state, kListSettings[i]); | 451 RegisterSetting(local_state, kListSettings[i]); |
| 452 } | 452 } |
| 453 | 453 |
| 454 bool UserCrosSettingsProvider::RequestTrustedAllowGuest(Task* callback) { | 454 bool UserCrosSettingsProvider::RequestTrustedAllowGuest(Task* callback) { |
| 455 return UserCrosSettingsTrust::GetSharedInstance()->RequestTrustedEntity( | 455 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( |
| 456 kAccountsPrefAllowGuest, callback); | 456 kAccountsPrefAllowGuest, callback); |
| 457 } | 457 } |
| 458 | 458 |
| 459 bool UserCrosSettingsProvider::RequestTrustedAllowNewUser(Task* callback) { | 459 bool UserCrosSettingsProvider::RequestTrustedAllowNewUser(Task* callback) { |
| 460 return UserCrosSettingsTrust::GetSharedInstance()->RequestTrustedEntity( | 460 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( |
| 461 kAccountsPrefAllowNewUser, callback); | 461 kAccountsPrefAllowNewUser, callback); |
| 462 } | 462 } |
| 463 | 463 |
| 464 bool UserCrosSettingsProvider::RequestTrustedShowUsersOnSignin(Task* callback) { | 464 bool UserCrosSettingsProvider::RequestTrustedShowUsersOnSignin(Task* callback) { |
| 465 return UserCrosSettingsTrust::GetSharedInstance()->RequestTrustedEntity( | 465 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( |
| 466 kAccountsPrefShowUserNamesOnSignIn, callback); | 466 kAccountsPrefShowUserNamesOnSignIn, callback); |
| 467 } | 467 } |
| 468 | 468 |
| 469 bool UserCrosSettingsProvider::RequestTrustedOwner(Task* callback) { | 469 bool UserCrosSettingsProvider::RequestTrustedOwner(Task* callback) { |
| 470 return UserCrosSettingsTrust::GetSharedInstance()->RequestTrustedEntity( | 470 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( |
| 471 kDeviceOwner, callback); | 471 kDeviceOwner, callback); |
| 472 } | 472 } |
| 473 | 473 |
| 474 // static | 474 // static |
| 475 bool UserCrosSettingsProvider::cached_allow_guest() { | 475 bool UserCrosSettingsProvider::cached_allow_guest() { |
| 476 // Trigger prefetching if singleton object still does not exist. | 476 // Trigger prefetching if singleton object still does not exist. |
| 477 UserCrosSettingsTrust::GetSharedInstance(); | 477 UserCrosSettingsTrust::GetInstance(); |
| 478 return g_browser_process->local_state()->GetBoolean(kAccountsPrefAllowGuest); | 478 return g_browser_process->local_state()->GetBoolean(kAccountsPrefAllowGuest); |
| 479 } | 479 } |
| 480 | 480 |
| 481 // static | 481 // static |
| 482 bool UserCrosSettingsProvider::cached_allow_new_user() { | 482 bool UserCrosSettingsProvider::cached_allow_new_user() { |
| 483 // Trigger prefetching if singleton object still does not exist. | 483 // Trigger prefetching if singleton object still does not exist. |
| 484 UserCrosSettingsTrust::GetSharedInstance(); | 484 UserCrosSettingsTrust::GetInstance(); |
| 485 return g_browser_process->local_state()->GetBoolean( | 485 return g_browser_process->local_state()->GetBoolean( |
| 486 kAccountsPrefAllowNewUser); | 486 kAccountsPrefAllowNewUser); |
| 487 } | 487 } |
| 488 | 488 |
| 489 // static | 489 // static |
| 490 bool UserCrosSettingsProvider::cached_show_users_on_signin() { | 490 bool UserCrosSettingsProvider::cached_show_users_on_signin() { |
| 491 // Trigger prefetching if singleton object still does not exist. | 491 // Trigger prefetching if singleton object still does not exist. |
| 492 UserCrosSettingsTrust::GetSharedInstance(); | 492 UserCrosSettingsTrust::GetInstance(); |
| 493 return g_browser_process->local_state()->GetBoolean( | 493 return g_browser_process->local_state()->GetBoolean( |
| 494 kAccountsPrefShowUserNamesOnSignIn); | 494 kAccountsPrefShowUserNamesOnSignIn); |
| 495 } | 495 } |
| 496 | 496 |
| 497 // static | 497 // static |
| 498 const ListValue* UserCrosSettingsProvider::cached_whitelist() { | 498 const ListValue* UserCrosSettingsProvider::cached_whitelist() { |
| 499 PrefService* prefs = g_browser_process->local_state(); | 499 PrefService* prefs = g_browser_process->local_state(); |
| 500 const ListValue* cached_users = prefs->GetList(kAccountsPrefUsers); | 500 const ListValue* cached_users = prefs->GetList(kAccountsPrefUsers); |
| 501 | 501 |
| 502 if (!cached_users) { | 502 if (!cached_users) { |
| 503 // Update whitelist cache. | 503 // Update whitelist cache. |
| 504 GetUserWhitelist(NULL); | 504 GetUserWhitelist(NULL); |
| 505 | 505 |
| 506 cached_users = prefs->GetList(kAccountsPrefUsers); | 506 cached_users = prefs->GetList(kAccountsPrefUsers); |
| 507 } | 507 } |
| 508 | 508 |
| 509 return cached_users; | 509 return cached_users; |
| 510 } | 510 } |
| 511 | 511 |
| 512 // static | 512 // static |
| 513 std::string UserCrosSettingsProvider::cached_owner() { | 513 std::string UserCrosSettingsProvider::cached_owner() { |
| 514 // Trigger prefetching if singleton object still does not exist. | 514 // Trigger prefetching if singleton object still does not exist. |
| 515 UserCrosSettingsTrust::GetSharedInstance(); | 515 UserCrosSettingsTrust::GetInstance(); |
| 516 if (!g_browser_process || !g_browser_process->local_state()) | 516 if (!g_browser_process || !g_browser_process->local_state()) |
| 517 return std::string(); | 517 return std::string(); |
| 518 return g_browser_process->local_state()->GetString(kDeviceOwner); | 518 return g_browser_process->local_state()->GetString(kDeviceOwner); |
| 519 } | 519 } |
| 520 | 520 |
| 521 // static | 521 // static |
| 522 bool UserCrosSettingsProvider::IsEmailInCachedWhitelist( | 522 bool UserCrosSettingsProvider::IsEmailInCachedWhitelist( |
| 523 const std::string& email) { | 523 const std::string& email) { |
| 524 const ListValue* whitelist = cached_whitelist(); | 524 const ListValue* whitelist = cached_whitelist(); |
| 525 if (whitelist) { | 525 if (whitelist) { |
| 526 StringValue email_value(email); | 526 StringValue email_value(email); |
| 527 for (ListValue::const_iterator i(whitelist->begin()); | 527 for (ListValue::const_iterator i(whitelist->begin()); |
| 528 i != whitelist->end(); ++i) { | 528 i != whitelist->end(); ++i) { |
| 529 if ((*i)->Equals(&email_value)) | 529 if ((*i)->Equals(&email_value)) |
| 530 return true; | 530 return true; |
| 531 } | 531 } |
| 532 } | 532 } |
| 533 return false; | 533 return false; |
| 534 } | 534 } |
| 535 | 535 |
| 536 void UserCrosSettingsProvider::DoSet(const std::string& path, | 536 void UserCrosSettingsProvider::DoSet(const std::string& path, |
| 537 Value* in_value) { | 537 Value* in_value) { |
| 538 UserCrosSettingsTrust::GetSharedInstance()->Set(path, in_value); | 538 UserCrosSettingsTrust::GetInstance()->Set(path, in_value); |
| 539 } | 539 } |
| 540 | 540 |
| 541 bool UserCrosSettingsProvider::Get(const std::string& path, | 541 bool UserCrosSettingsProvider::Get(const std::string& path, |
| 542 Value** out_value) const { | 542 Value** out_value) const { |
| 543 if (IsControlledBooleanSetting(path)) { | 543 if (IsControlledBooleanSetting(path)) { |
| 544 *out_value = CreateSettingsBooleanValue( | 544 *out_value = CreateSettingsBooleanValue( |
| 545 g_browser_process->local_state()->GetBoolean(path.c_str()), | 545 g_browser_process->local_state()->GetBoolean(path.c_str()), |
| 546 !UserManager::Get()->current_user_is_owner()); | 546 !UserManager::Get()->current_user_is_owner()); |
| 547 return true; | 547 return true; |
| 548 } else if (path == kAccountsPrefUsers) { | 548 } else if (path == kAccountsPrefUsers) { |
| 549 ListValue* user_list = new ListValue; | 549 ListValue* user_list = new ListValue; |
| 550 GetUserWhitelist(user_list); | 550 GetUserWhitelist(user_list); |
| 551 *out_value = user_list; | 551 *out_value = user_list; |
| 552 return true; | 552 return true; |
| 553 } | 553 } |
| 554 | 554 |
| 555 return false; | 555 return false; |
| 556 } | 556 } |
| 557 | 557 |
| 558 bool UserCrosSettingsProvider::HandlesSetting(const std::string& path) { | 558 bool UserCrosSettingsProvider::HandlesSetting(const std::string& path) { |
| 559 return ::StartsWithASCII(path, "cros.accounts.", true); | 559 return ::StartsWithASCII(path, "cros.accounts.", true); |
| 560 } | 560 } |
| 561 | 561 |
| 562 void UserCrosSettingsProvider::WhitelistUser(const std::string& email) { | 562 void UserCrosSettingsProvider::WhitelistUser(const std::string& email) { |
| 563 SignedSettingsHelper::Get()->StartWhitelistOp( | 563 SignedSettingsHelper::Get()->StartWhitelistOp( |
| 564 email, true, UserCrosSettingsTrust::GetSharedInstance()); | 564 email, true, UserCrosSettingsTrust::GetInstance()); |
| 565 PrefService* prefs = g_browser_process->local_state(); | 565 PrefService* prefs = g_browser_process->local_state(); |
| 566 ListValue* cached_whitelist = prefs->GetMutableList(kAccountsPrefUsers); | 566 ListValue* cached_whitelist = prefs->GetMutableList(kAccountsPrefUsers); |
| 567 cached_whitelist->Append(Value::CreateStringValue(email)); | 567 cached_whitelist->Append(Value::CreateStringValue(email)); |
| 568 prefs->ScheduleSavePersistentPrefs(); | 568 prefs->ScheduleSavePersistentPrefs(); |
| 569 } | 569 } |
| 570 | 570 |
| 571 void UserCrosSettingsProvider::UnwhitelistUser(const std::string& email) { | 571 void UserCrosSettingsProvider::UnwhitelistUser(const std::string& email) { |
| 572 SignedSettingsHelper::Get()->StartWhitelistOp( | 572 SignedSettingsHelper::Get()->StartWhitelistOp( |
| 573 email, false, UserCrosSettingsTrust::GetSharedInstance()); | 573 email, false, UserCrosSettingsTrust::GetInstance()); |
| 574 | 574 |
| 575 PrefService* prefs = g_browser_process->local_state(); | 575 PrefService* prefs = g_browser_process->local_state(); |
| 576 ListValue* cached_whitelist = prefs->GetMutableList(kAccountsPrefUsers); | 576 ListValue* cached_whitelist = prefs->GetMutableList(kAccountsPrefUsers); |
| 577 StringValue email_value(email); | 577 StringValue email_value(email); |
| 578 if (cached_whitelist->Remove(email_value) != -1) | 578 if (cached_whitelist->Remove(email_value) != -1) |
| 579 prefs->ScheduleSavePersistentPrefs(); | 579 prefs->ScheduleSavePersistentPrefs(); |
| 580 } | 580 } |
| 581 | 581 |
| 582 // static | 582 // static |
| 583 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { | 583 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { |
| 584 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); | 584 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); |
| 585 } | 585 } |
| 586 | 586 |
| 587 } // namespace chromeos | 587 } // namespace chromeos |
| OLD | NEW |