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 15 matching lines...) Expand all Loading... | |
26 namespace chromeos { | 26 namespace chromeos { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 const char kTrueIncantation[] = "true"; | 30 const char kTrueIncantation[] = "true"; |
31 const char kFalseIncantation[] = "false"; | 31 const char kFalseIncantation[] = "false"; |
32 const char kTrustedSuffix[] = "/trusted"; | 32 const char kTrustedSuffix[] = "/trusted"; |
33 | 33 |
34 // For all our boolean settings following is applicable: | 34 // For all our boolean settings following is applicable: |
35 // true is default permissive value and false is safe prohibitic value. | 35 // true is default permissive value and false is safe prohibitic value. |
36 // Exception: kSignedDataRoamingEnabled which has default value of false. | |
36 const char* kBooleanSettings[] = { | 37 const char* kBooleanSettings[] = { |
37 kAccountsPrefAllowNewUser, | 38 kAccountsPrefAllowNewUser, |
38 kAccountsPrefAllowGuest, | 39 kAccountsPrefAllowGuest, |
39 kAccountsPrefShowUserNamesOnSignIn | 40 kAccountsPrefShowUserNamesOnSignIn, |
41 kSignedDataRoamingEnabled, | |
40 }; | 42 }; |
41 | 43 |
42 const char* kStringSettings[] = { | 44 const char* kStringSettings[] = { |
43 kDeviceOwner | 45 kDeviceOwner |
44 }; | 46 }; |
45 | 47 |
46 const char* kListSettings[] = { | 48 const char* kListSettings[] = { |
47 kAccountsPrefUsers | 49 kAccountsPrefUsers |
48 }; | 50 }; |
49 | 51 |
50 bool IsControlledBooleanSetting(const std::string& pref_path) { | 52 bool IsControlledBooleanSetting(const std::string& pref_path) { |
51 return std::find(kBooleanSettings, | 53 // TODO(nkostylev): Using std::find for 4 value array generates this warning |
52 kBooleanSettings + arraysize(kBooleanSettings), | 54 // in chroot stl_algo.h:231: error: array subscript is above array bounds. |
53 pref_path) != | 55 // GCC 4.4.3 |
54 kBooleanSettings + arraysize(kBooleanSettings); | 56 return (pref_path == kAccountsPrefAllowNewUser) || |
57 (pref_path == kAccountsPrefAllowGuest) || | |
Denis Lagno
2011/03/17 11:05:27
nit: is this correct indentation?
Nikita (slow)
2011/03/18 10:53:17
Done.
| |
58 (pref_path == kAccountsPrefShowUserNamesOnSignIn) || | |
59 (pref_path == kSignedDataRoamingEnabled); | |
55 } | 60 } |
56 | 61 |
57 bool IsControlledStringSetting(const std::string& pref_path) { | 62 bool IsControlledStringSetting(const std::string& pref_path) { |
58 return std::find(kStringSettings, | 63 return std::find(kStringSettings, |
59 kStringSettings + arraysize(kStringSettings), | 64 kStringSettings + arraysize(kStringSettings), |
60 pref_path) != | 65 pref_path) != |
61 kStringSettings + arraysize(kStringSettings); | 66 kStringSettings + arraysize(kStringSettings); |
62 } | 67 } |
63 | 68 |
64 bool IsControlledListSetting(const std::string& pref_path) { | 69 bool IsControlledListSetting(const std::string& pref_path) { |
65 return std::find(kListSettings, | 70 return std::find(kListSettings, |
66 kListSettings + arraysize(kListSettings), | 71 kListSettings + arraysize(kListSettings), |
67 pref_path) != | 72 pref_path) != |
68 kListSettings + arraysize(kListSettings); | 73 kListSettings + arraysize(kListSettings); |
69 } | 74 } |
70 | 75 |
71 void RegisterSetting(PrefService* local_state, const std::string& pref_path) { | 76 void RegisterSetting(PrefService* local_state, const std::string& pref_path) { |
72 local_state->RegisterBooleanPref((pref_path + kTrustedSuffix).c_str(), | 77 local_state->RegisterBooleanPref((pref_path + kTrustedSuffix).c_str(), |
73 false); | 78 false); |
74 if (IsControlledBooleanSetting(pref_path)) { | 79 if (IsControlledBooleanSetting(pref_path)) { |
75 local_state->RegisterBooleanPref(pref_path.c_str(), true); | 80 if (pref_path == kSignedDataRoamingEnabled) |
81 local_state->RegisterBooleanPref(pref_path.c_str(), false); | |
82 else | |
83 local_state->RegisterBooleanPref(pref_path.c_str(), true); | |
76 } else if (IsControlledStringSetting(pref_path)) { | 84 } else if (IsControlledStringSetting(pref_path)) { |
77 local_state->RegisterStringPref(pref_path.c_str(), ""); | 85 local_state->RegisterStringPref(pref_path.c_str(), ""); |
78 } else { | 86 } else { |
79 DCHECK(IsControlledListSetting(pref_path)); | 87 DCHECK(IsControlledListSetting(pref_path)); |
80 local_state->RegisterListPref(pref_path.c_str()); | 88 local_state->RegisterListPref(pref_path.c_str()); |
81 } | 89 } |
82 } | 90 } |
83 | 91 |
84 Value* CreateSettingsBooleanValue(bool value, bool managed) { | 92 Value* CreateSettingsBooleanValue(bool value, bool managed) { |
85 DictionaryValue* dict = new DictionaryValue; | 93 DictionaryValue* dict = new DictionaryValue; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 case SignedSettings::NOT_FOUND: | 279 case SignedSettings::NOT_FOUND: |
272 case SignedSettings::KEY_UNAVAILABLE: { | 280 case SignedSettings::KEY_UNAVAILABLE: { |
273 bool fallback_to_default = !is_owned | 281 bool fallback_to_default = !is_owned |
274 || (code == SignedSettings::NOT_FOUND); | 282 || (code == SignedSettings::NOT_FOUND); |
275 DCHECK(fallback_to_default || code == SignedSettings::SUCCESS); | 283 DCHECK(fallback_to_default || code == SignedSettings::SUCCESS); |
276 if (fallback_to_default) | 284 if (fallback_to_default) |
277 VLOG(1) << "Going default for cros setting " << name; | 285 VLOG(1) << "Going default for cros setting " << name; |
278 else | 286 else |
279 VLOG(1) << "Retrieved cros setting " << name << "=" << value; | 287 VLOG(1) << "Retrieved cros setting " << name << "=" << value; |
280 if (IsControlledBooleanSetting(name)) { | 288 if (IsControlledBooleanSetting(name)) { |
281 // We assume our boolean settings are true before explicitly set. | |
282 UpdateCacheBool(name, (value == kTrueIncantation), | 289 UpdateCacheBool(name, (value == kTrueIncantation), |
283 fallback_to_default ? USE_VALUE_DEFAULT : USE_VALUE_SUPPLIED); | 290 fallback_to_default ? USE_VALUE_DEFAULT : USE_VALUE_SUPPLIED); |
284 } else if (IsControlledStringSetting(name)) { | 291 } else if (IsControlledStringSetting(name)) { |
285 UpdateCacheString(name, value, | 292 UpdateCacheString(name, value, |
286 fallback_to_default ? USE_VALUE_DEFAULT : USE_VALUE_SUPPLIED); | 293 fallback_to_default ? USE_VALUE_DEFAULT : USE_VALUE_SUPPLIED); |
287 } | 294 } |
288 break; | 295 break; |
289 } | 296 } |
290 case SignedSettings::OPERATION_FAILED: | 297 case SignedSettings::OPERATION_FAILED: |
291 default: { | 298 default: { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 bool UserCrosSettingsProvider::RequestTrustedAllowNewUser(Task* callback) { | 408 bool UserCrosSettingsProvider::RequestTrustedAllowNewUser(Task* callback) { |
402 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( | 409 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( |
403 kAccountsPrefAllowNewUser, callback); | 410 kAccountsPrefAllowNewUser, callback); |
404 } | 411 } |
405 | 412 |
406 bool UserCrosSettingsProvider::RequestTrustedShowUsersOnSignin(Task* callback) { | 413 bool UserCrosSettingsProvider::RequestTrustedShowUsersOnSignin(Task* callback) { |
407 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( | 414 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( |
408 kAccountsPrefShowUserNamesOnSignIn, callback); | 415 kAccountsPrefShowUserNamesOnSignIn, callback); |
409 } | 416 } |
410 | 417 |
418 bool UserCrosSettingsProvider::RequestTrustedDataRoamingEnabled( | |
419 Task* callback) { | |
420 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( | |
421 kSignedDataRoamingEnabled, callback); | |
422 } | |
423 | |
411 bool UserCrosSettingsProvider::RequestTrustedOwner(Task* callback) { | 424 bool UserCrosSettingsProvider::RequestTrustedOwner(Task* callback) { |
412 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( | 425 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( |
413 kDeviceOwner, callback); | 426 kDeviceOwner, callback); |
414 } | 427 } |
415 | 428 |
416 // static | 429 // static |
417 bool UserCrosSettingsProvider::cached_allow_guest() { | 430 bool UserCrosSettingsProvider::cached_allow_guest() { |
418 // Trigger prefetching if singleton object still does not exist. | 431 // Trigger prefetching if singleton object still does not exist. |
419 UserCrosSettingsTrust::GetInstance(); | 432 UserCrosSettingsTrust::GetInstance(); |
420 return g_browser_process->local_state()->GetBoolean(kAccountsPrefAllowGuest); | 433 return g_browser_process->local_state()->GetBoolean(kAccountsPrefAllowGuest); |
421 } | 434 } |
422 | 435 |
423 // static | 436 // static |
424 bool UserCrosSettingsProvider::cached_allow_new_user() { | 437 bool UserCrosSettingsProvider::cached_allow_new_user() { |
425 // Trigger prefetching if singleton object still does not exist. | 438 // Trigger prefetching if singleton object still does not exist. |
426 UserCrosSettingsTrust::GetInstance(); | 439 UserCrosSettingsTrust::GetInstance(); |
427 return g_browser_process->local_state()->GetBoolean( | 440 return g_browser_process->local_state()->GetBoolean( |
428 kAccountsPrefAllowNewUser); | 441 kAccountsPrefAllowNewUser); |
429 } | 442 } |
430 | 443 |
431 // static | 444 // static |
445 bool UserCrosSettingsProvider::cached_data_roaming_enabled() { | |
446 // Trigger prefetching if singleton object still does not exist. | |
447 UserCrosSettingsTrust::GetInstance(); | |
448 return g_browser_process->local_state()->GetBoolean( | |
449 kSignedDataRoamingEnabled); | |
450 } | |
451 | |
452 // static | |
432 bool UserCrosSettingsProvider::cached_show_users_on_signin() { | 453 bool UserCrosSettingsProvider::cached_show_users_on_signin() { |
433 // Trigger prefetching if singleton object still does not exist. | 454 // Trigger prefetching if singleton object still does not exist. |
434 UserCrosSettingsTrust::GetInstance(); | 455 UserCrosSettingsTrust::GetInstance(); |
435 return g_browser_process->local_state()->GetBoolean( | 456 return g_browser_process->local_state()->GetBoolean( |
436 kAccountsPrefShowUserNamesOnSignIn); | 457 kAccountsPrefShowUserNamesOnSignIn); |
437 } | 458 } |
438 | 459 |
439 // static | 460 // static |
440 const ListValue* UserCrosSettingsProvider::cached_whitelist() { | 461 const ListValue* UserCrosSettingsProvider::cached_whitelist() { |
441 PrefService* prefs = g_browser_process->local_state(); | 462 PrefService* prefs = g_browser_process->local_state(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
496 ListValue* user_list = new ListValue; | 517 ListValue* user_list = new ListValue; |
497 GetUserWhitelist(user_list); | 518 GetUserWhitelist(user_list); |
498 *out_value = user_list; | 519 *out_value = user_list; |
499 return true; | 520 return true; |
500 } | 521 } |
501 | 522 |
502 return false; | 523 return false; |
503 } | 524 } |
504 | 525 |
505 bool UserCrosSettingsProvider::HandlesSetting(const std::string& path) { | 526 bool UserCrosSettingsProvider::HandlesSetting(const std::string& path) { |
506 return ::StartsWithASCII(path, "cros.accounts.", true); | 527 return ::StartsWithASCII(path, "cros.accounts.", true) || |
528 ::StartsWithASCII(path, "cros.signed.", true); | |
507 } | 529 } |
508 | 530 |
509 void UserCrosSettingsProvider::WhitelistUser(const std::string& email) { | 531 void UserCrosSettingsProvider::WhitelistUser(const std::string& email) { |
510 SignedSettingsHelper::Get()->StartWhitelistOp( | 532 SignedSettingsHelper::Get()->StartWhitelistOp( |
511 email, true, UserCrosSettingsTrust::GetInstance()); | 533 email, true, UserCrosSettingsTrust::GetInstance()); |
512 PrefService* prefs = g_browser_process->local_state(); | 534 PrefService* prefs = g_browser_process->local_state(); |
513 ListValue* cached_whitelist = prefs->GetMutableList(kAccountsPrefUsers); | 535 ListValue* cached_whitelist = prefs->GetMutableList(kAccountsPrefUsers); |
514 cached_whitelist->Append(Value::CreateStringValue(email)); | 536 cached_whitelist->Append(Value::CreateStringValue(email)); |
515 prefs->ScheduleSavePersistentPrefs(); | 537 prefs->ScheduleSavePersistentPrefs(); |
516 } | 538 } |
517 | 539 |
518 void UserCrosSettingsProvider::UnwhitelistUser(const std::string& email) { | 540 void UserCrosSettingsProvider::UnwhitelistUser(const std::string& email) { |
519 SignedSettingsHelper::Get()->StartWhitelistOp( | 541 SignedSettingsHelper::Get()->StartWhitelistOp( |
520 email, false, UserCrosSettingsTrust::GetInstance()); | 542 email, false, UserCrosSettingsTrust::GetInstance()); |
521 | 543 |
522 PrefService* prefs = g_browser_process->local_state(); | 544 PrefService* prefs = g_browser_process->local_state(); |
523 ListValue* cached_whitelist = prefs->GetMutableList(kAccountsPrefUsers); | 545 ListValue* cached_whitelist = prefs->GetMutableList(kAccountsPrefUsers); |
524 StringValue email_value(email); | 546 StringValue email_value(email); |
525 if (cached_whitelist->Remove(email_value) != -1) | 547 if (cached_whitelist->Remove(email_value) != -1) |
526 prefs->ScheduleSavePersistentPrefs(); | 548 prefs->ScheduleSavePersistentPrefs(); |
527 } | 549 } |
528 | 550 |
529 // static | 551 // static |
530 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { | 552 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { |
531 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); | 553 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); |
532 } | 554 } |
533 | 555 |
534 } // namespace chromeos | 556 } // namespace chromeos |
OLD | NEW |