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