Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: chrome/browser/extensions/api/settings_private/prefs_util.cc

Issue 2849823003: ChromeOS: implement per-user time zone preferences. (Closed)
Patch Set: Rebased. Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/chromeos/system/timezone_util.cc ('k') | chrome/browser/flag_descriptions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/extensions/api/settings_private/prefs_util.h" 5 #include "chrome/browser/extensions/api/settings_private/prefs_util.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/extensions/chrome_extension_function.h" 9 #include "chrome/browser/extensions/chrome_extension_function.h"
10 #include "chrome/browser/extensions/settings_api_helpers.h" 10 #include "chrome/browser/extensions/settings_api_helpers.h"
(...skipping 22 matching lines...) Expand all
33 #include "extensions/browser/management_policy.h" 33 #include "extensions/browser/management_policy.h"
34 #include "extensions/common/extension.h" 34 #include "extensions/common/extension.h"
35 35
36 #if defined(OS_CHROMEOS) 36 #if defined(OS_CHROMEOS)
37 #include "ash/public/cpp/ash_pref_names.h" // nogncheck 37 #include "ash/public/cpp/ash_pref_names.h" // nogncheck
38 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" 38 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
39 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" 39 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h"
40 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 40 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
41 #include "chrome/browser/chromeos/profiles/profile_helper.h" 41 #include "chrome/browser/chromeos/profiles/profile_helper.h"
42 #include "chrome/browser/chromeos/settings/cros_settings.h" 42 #include "chrome/browser/chromeos/settings/cros_settings.h"
43 #include "chrome/browser/chromeos/system/timezone_util.h"
43 #include "chromeos/settings/cros_settings_names.h" 44 #include "chromeos/settings/cros_settings_names.h"
44 #include "ui/chromeos/events/pref_names.h" 45 #include "ui/chromeos/events/pref_names.h"
45 #endif 46 #endif
46 47
47 namespace { 48 namespace {
48 49
49 #if defined(OS_CHROMEOS) 50 #if defined(OS_CHROMEOS)
50 bool IsPrivilegedCrosSetting(const std::string& pref_name) { 51 bool IsPrivilegedCrosSetting(const std::string& pref_name) {
51 if (!chromeos::CrosSettings::IsCrosSettings(pref_name)) 52 if (!chromeos::CrosSettings::IsCrosSettings(pref_name))
52 return false; 53 return false;
53 // kSystemTimezone should be changeable by all users. 54 if (!chromeos::system::PerUserTimezoneEnabled()) {
54 if (pref_name == chromeos::kSystemTimezone) 55 // kSystemTimezone should be changeable by all users.
55 return false; 56 if (pref_name == chromeos::kSystemTimezone)
56 // All other Cros settings are considered privileged and are either policy 57 return false;
58 }
59 // Cros settings are considered privileged and are either policy
57 // controlled or owner controlled. 60 // controlled or owner controlled.
58 return true; 61 return true;
59 } 62 }
63
64 bool IsCrosSettingReadOnly(const std::string& pref_name) {
65 if (chromeos::system::PerUserTimezoneEnabled()) {
66 // System timezone is never directly changable by user.
67 return pref_name == chromeos::kSystemTimezone;
68 }
69 return false;
70 }
60 #endif 71 #endif
61 72
62 } // namespace 73 } // namespace
63 74
64 namespace extensions { 75 namespace extensions {
65 76
66 namespace settings_private = api::settings_private; 77 namespace settings_private = api::settings_private;
67 78
68 PrefsUtil::PrefsUtil(Profile* profile) : profile_(profile) {} 79 PrefsUtil::PrefsUtil(Profile* profile) : profile_(profile) {}
69 80
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 settings_private::PrefType::PREF_TYPE_BOOLEAN; 306 settings_private::PrefType::PREF_TYPE_BOOLEAN;
296 (*s_whitelist)[proxy_config::prefs::kUseSharedProxies] = 307 (*s_whitelist)[proxy_config::prefs::kUseSharedProxies] =
297 settings_private::PrefType::PREF_TYPE_BOOLEAN; 308 settings_private::PrefType::PREF_TYPE_BOOLEAN;
298 (*s_whitelist)[::prefs::kWakeOnWifiDarkConnect] = 309 (*s_whitelist)[::prefs::kWakeOnWifiDarkConnect] =
299 settings_private::PrefType::PREF_TYPE_BOOLEAN; 310 settings_private::PrefType::PREF_TYPE_BOOLEAN;
300 (*s_whitelist)[::chromeos::kSignedDataRoamingEnabled] = 311 (*s_whitelist)[::chromeos::kSignedDataRoamingEnabled] =
301 settings_private::PrefType::PREF_TYPE_BOOLEAN; 312 settings_private::PrefType::PREF_TYPE_BOOLEAN;
302 313
303 // Timezone settings. 314 // Timezone settings.
304 (*s_whitelist)[chromeos::kSystemTimezone] = 315 (*s_whitelist)[chromeos::kSystemTimezone] =
316 settings_private::PrefType::PREF_TYPE_STRING;
317 (*s_whitelist)[prefs::kUserTimezone] =
318 settings_private::PrefType::PREF_TYPE_STRING;
319 (*s_whitelist)[::prefs::kResolveTimezoneByGeolocation] =
305 settings_private::PrefType::PREF_TYPE_BOOLEAN; 320 settings_private::PrefType::PREF_TYPE_BOOLEAN;
306 (*s_whitelist)[::prefs::kResolveTimezoneByGeolocation] = 321 (*s_whitelist)[chromeos::kPerUserTimezoneEnabled] =
307 settings_private::PrefType::PREF_TYPE_BOOLEAN; 322 settings_private::PrefType::PREF_TYPE_BOOLEAN;
308 323
309 // Ash settings. 324 // Ash settings.
310 (*s_whitelist)[::prefs::kEnableStylusTools] = 325 (*s_whitelist)[::prefs::kEnableStylusTools] =
311 settings_private::PrefType::PREF_TYPE_BOOLEAN; 326 settings_private::PrefType::PREF_TYPE_BOOLEAN;
312 (*s_whitelist)[::prefs::kLaunchPaletteOnEjectEvent] = 327 (*s_whitelist)[::prefs::kLaunchPaletteOnEjectEvent] =
313 settings_private::PrefType::PREF_TYPE_BOOLEAN; 328 settings_private::PrefType::PREF_TYPE_BOOLEAN;
314 (*s_whitelist)[ash::prefs::kNightLightEnabled] = 329 (*s_whitelist)[ash::prefs::kNightLightEnabled] =
315 settings_private::PrefType::PREF_TYPE_BOOLEAN; 330 settings_private::PrefType::PREF_TYPE_BOOLEAN;
316 (*s_whitelist)[ash::prefs::kNightLightTemperature] = 331 (*s_whitelist)[ash::prefs::kNightLightTemperature] =
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 pref = pref_service->FindPreference(name); 482 pref = pref_service->FindPreference(name);
468 if (!pref) 483 if (!pref)
469 return nullptr; 484 return nullptr;
470 pref_object.reset(new settings_private::PrefObject()); 485 pref_object.reset(new settings_private::PrefObject());
471 pref_object->key = pref->name(); 486 pref_object->key = pref->name();
472 pref_object->type = GetType(name, pref->GetType()); 487 pref_object->type = GetType(name, pref->GetType());
473 pref_object->value.reset(pref->GetValue()->DeepCopy()); 488 pref_object->value.reset(pref->GetValue()->DeepCopy());
474 } 489 }
475 490
476 #if defined(OS_CHROMEOS) 491 #if defined(OS_CHROMEOS)
492 // We first check for enterprise-managed, then for primary-user managed.
493 // Otherwise in multiprofile mode enterprise preference for the secondary
494 // user will appear primary-user-controlled, which looks strange, because
495 // primary user preference will be disabled with "enterprise controlled"
496 // status.
497 if (IsPrefEnterpriseManaged(name)) {
498 // Enterprise managed prefs are treated the same as device policy restricted
499 // prefs in the UI.
500 pref_object->controlled_by =
501 settings_private::ControlledBy::CONTROLLED_BY_DEVICE_POLICY;
502 pref_object->enforcement =
503 settings_private::Enforcement::ENFORCEMENT_ENFORCED;
504 return pref_object;
505 }
506
477 if (IsPrefPrimaryUserControlled(name)) { 507 if (IsPrefPrimaryUserControlled(name)) {
478 pref_object->controlled_by = 508 pref_object->controlled_by =
479 settings_private::ControlledBy::CONTROLLED_BY_PRIMARY_USER; 509 settings_private::ControlledBy::CONTROLLED_BY_PRIMARY_USER;
480 pref_object->enforcement = 510 pref_object->enforcement =
481 settings_private::Enforcement::ENFORCEMENT_ENFORCED; 511 settings_private::Enforcement::ENFORCEMENT_ENFORCED;
482 pref_object->controlled_by_name.reset( 512 pref_object->controlled_by_name.reset(
483 new std::string(user_manager::UserManager::Get() 513 new std::string(user_manager::UserManager::Get()
484 ->GetPrimaryUser() 514 ->GetPrimaryUser()
485 ->GetAccountId() 515 ->GetAccountId()
486 .GetUserEmail())); 516 .GetUserEmail()));
487 return pref_object; 517 return pref_object;
488 } 518 }
489
490 if (IsPrefEnterpriseManaged(name)) {
491 // Enterprise managed prefs are treated the same as device policy restricted
492 // prefs in the UI.
493 pref_object->controlled_by =
494 settings_private::ControlledBy::CONTROLLED_BY_DEVICE_POLICY;
495 pref_object->enforcement =
496 settings_private::Enforcement::ENFORCEMENT_ENFORCED;
497 return pref_object;
498 }
499 #endif 519 #endif
500 520
501 if (pref && pref->IsManaged()) { 521 if (pref && pref->IsManaged()) {
502 pref_object->controlled_by = 522 pref_object->controlled_by =
503 settings_private::ControlledBy::CONTROLLED_BY_USER_POLICY; 523 settings_private::ControlledBy::CONTROLLED_BY_USER_POLICY;
504 pref_object->enforcement = 524 pref_object->enforcement =
505 settings_private::Enforcement::ENFORCEMENT_ENFORCED; 525 settings_private::Enforcement::ENFORCEMENT_ENFORCED;
506 return pref_object; 526 return pref_object;
507 } 527 }
508 528
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 #endif 694 #endif
675 } 695 }
676 696
677 bool PrefsUtil::IsPrefTypeURL(const std::string& pref_name) { 697 bool PrefsUtil::IsPrefTypeURL(const std::string& pref_name) {
678 return GetWhitelistedPrefType(pref_name) == 698 return GetWhitelistedPrefType(pref_name) ==
679 settings_private::PrefType::PREF_TYPE_URL; 699 settings_private::PrefType::PREF_TYPE_URL;
680 } 700 }
681 701
682 #if defined(OS_CHROMEOS) 702 #if defined(OS_CHROMEOS)
683 bool PrefsUtil::IsPrefEnterpriseManaged(const std::string& pref_name) { 703 bool PrefsUtil::IsPrefEnterpriseManaged(const std::string& pref_name) {
684 if (IsPrivilegedCrosSetting(pref_name)) { 704 policy::BrowserPolicyConnectorChromeOS* connector =
685 policy::BrowserPolicyConnectorChromeOS* connector = 705 g_browser_process->platform_part()->browser_policy_connector_chromeos();
686 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 706 if (!connector->IsEnterpriseManaged())
687 if (connector->IsEnterpriseManaged()) 707 return false;
688 return true; 708 if (IsPrivilegedCrosSetting(pref_name))
709 return true;
710 if (chromeos::system::PerUserTimezoneEnabled() &&
711 (pref_name == prefs::kUserTimezone ||
712 pref_name == prefs::kResolveTimezoneByGeolocation)) {
713 return chromeos::system::IsTimezonePrefsManaged(pref_name);
689 } 714 }
690 return false; 715 return false;
691 } 716 }
692 717
693 bool PrefsUtil::IsPrefOwnerControlled(const std::string& pref_name) { 718 bool PrefsUtil::IsPrefOwnerControlled(const std::string& pref_name) {
719 // chromeos::kSystemTimezone is global display-only preference and
720 // it should appear as disabled, but not owned.
721 if (pref_name == chromeos::kSystemTimezone)
722 return false;
723
694 if (IsPrivilegedCrosSetting(pref_name)) { 724 if (IsPrivilegedCrosSetting(pref_name)) {
695 if (!chromeos::ProfileHelper::IsOwnerProfile(profile_)) 725 if (!chromeos::ProfileHelper::IsOwnerProfile(profile_))
696 return true; 726 return true;
697 } 727 }
698 return false; 728 return false;
699 } 729 }
700 730
701 bool PrefsUtil::IsPrefPrimaryUserControlled(const std::string& pref_name) { 731 bool PrefsUtil::IsPrefPrimaryUserControlled(const std::string& pref_name) {
702 if (pref_name == prefs::kWakeOnWifiDarkConnect) { 732 // chromeos::kSystemTimezone is read-only, but for the non-primary users
733 // it should have "primary user controlled" attribute.
734 if (pref_name == prefs::kWakeOnWifiDarkConnect ||
735 pref_name == prefs::kResolveTimezoneByGeolocation ||
736 pref_name == prefs::kUserTimezone ||
737 pref_name == chromeos::kSystemTimezone) {
703 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); 738 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
704 const user_manager::User* user = 739 const user_manager::User* user =
705 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); 740 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
706 if (user && 741 if (user && user->GetAccountId() !=
707 user->GetAccountId() != user_manager->GetPrimaryUser()->GetAccountId()) 742 user_manager->GetPrimaryUser()->GetAccountId()) {
708 return true; 743 return true;
744 }
709 } 745 }
710 return false; 746 return false;
711 } 747 }
712 #endif 748 #endif
713 749
714 bool PrefsUtil::IsPrefSupervisorControlled(const std::string& pref_name) { 750 bool PrefsUtil::IsPrefSupervisorControlled(const std::string& pref_name) {
715 if (pref_name != prefs::kBrowserGuestModeEnabled && 751 if (pref_name != prefs::kBrowserGuestModeEnabled &&
716 pref_name != prefs::kBrowserAddPersonEnabled) { 752 pref_name != prefs::kBrowserAddPersonEnabled) {
717 return false; 753 return false;
718 } 754 }
719 return profile_->IsSupervised(); 755 return profile_->IsSupervised();
720 } 756 }
721 757
722 bool PrefsUtil::IsPrefUserModifiable(const std::string& pref_name) { 758 bool PrefsUtil::IsPrefUserModifiable(const std::string& pref_name) {
759 #if defined(OS_CHROMEOS)
760 if (IsCrosSettingReadOnly(pref_name))
761 return false;
762 #endif
763
723 const PrefService::Preference* profile_pref = 764 const PrefService::Preference* profile_pref =
724 profile_->GetPrefs()->FindPreference(pref_name); 765 profile_->GetPrefs()->FindPreference(pref_name);
725 if (profile_pref) 766 if (profile_pref)
726 return profile_pref->IsUserModifiable(); 767 return profile_pref->IsUserModifiable();
727 768
728 const PrefService::Preference* local_state_pref = 769 const PrefService::Preference* local_state_pref =
729 g_browser_process->local_state()->FindPreference(pref_name); 770 g_browser_process->local_state()->FindPreference(pref_name);
730 if (local_state_pref) 771 if (local_state_pref)
731 return local_state_pref->IsUserModifiable(); 772 return local_state_pref->IsUserModifiable();
732 773
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 ExtensionPrefValueMapFactory::GetForBrowserContext(profile_) 841 ExtensionPrefValueMapFactory::GetForBrowserContext(profile_)
801 ->GetExtensionControllingPref(pref_object.key); 842 ->GetExtensionControllingPref(pref_object.key);
802 if (extension_id.empty()) 843 if (extension_id.empty())
803 return nullptr; 844 return nullptr;
804 845
805 return ExtensionRegistry::Get(profile_)->GetExtensionById( 846 return ExtensionRegistry::Get(profile_)->GetExtensionById(
806 extension_id, ExtensionRegistry::ENABLED); 847 extension_id, ExtensionRegistry::ENABLED);
807 } 848 }
808 849
809 } // namespace extensions 850 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/system/timezone_util.cc ('k') | chrome/browser/flag_descriptions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698