From c1ec1cfc7adb4f7d06f70d92344250040798c4f3 Mon Sep 17 00:00:00 2001 From: "alemate@chromium.org" Date: Wed, 7 Aug 2013 18:10:34 +0000 Subject: [PATCH] Login screen and Guest mode should use device owner preference settings.clock.use_24hour_clock value for time format. BUG=258199 Review URL: https://chromiumcodereview.appspot.com/21133012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216232 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/app/policy/policy_templates.json | 16 +++++++++- .../policy/device_policy_decoder_chromeos.cc | 11 +++++++ .../chromeos/settings/cros_settings_names.cc | 4 +++ .../chromeos/settings/cros_settings_names.h | 1 + .../chromeos/settings/device_settings_provider.cc | 18 ++++++++++++ .../chromeos/system/ash_system_tray_delegate.cc | 34 ++++++++++++++++++++-- .../proto/chromeos/chrome_device_policy.proto | 7 +++++ chrome/test/data/policy/policy_test_cases.json | 3 ++ 8 files changed, 90 insertions(+), 4 deletions(-) diff --git a/chrome/app/policy/policy_templates.json b/chrome/app/policy/policy_templates.json index 1cc92452f637..10ad804e04cd 100644 --- a/chrome/app/policy/policy_templates.json +++ b/chrome/app/policy/policy_templates.json @@ -117,7 +117,7 @@ # persistent IDs for all fields (but not for groups!) are needed. These are # specified by the 'id' keys of each policy. NEVER CHANGE EXISTING IDs, # because doing so would break the deployed wire format! -# For your editing convenience: highest ID currently used: 235 +# For your editing convenience: highest ID currently used: 236 # # Placeholders: # The following placeholder strings are automatically substituted: @@ -4065,6 +4065,20 @@ The format of the value follows the names of timezones in the "IANA Time Zone Database" (see "http://en.wikipedia.org/wiki/List_of_tz_database_time"). In particular, most timezones can be referred to by "continent/large_city" or "ocean/large_city".''', }, { + 'name': 'SystemUse24HourClock', + 'type': 'main', + 'schema': { 'type': 'boolean' }, + 'supported_on': ['chrome_os:30-'], + 'device_only': True, + 'features': { + 'dynamic_refresh': True, + }, + 'example_value': True, + 'id': 236, + 'caption': '''Use 24 hour clock by default''', + 'desc': '''Specifies the clock format be used for the device. Users can override clock format for the current session. However, on logout it is set back to the specified value. If an empty string is provided, device owner preference is used.''', + }, + { 'name': 'ShowLogoutButtonInTray', 'type': 'main', 'schema': { 'type': 'boolean' }, diff --git a/chrome/browser/chromeos/policy/device_policy_decoder_chromeos.cc b/chrome/browser/chromeos/policy/device_policy_decoder_chromeos.cc index 237d66ae1402..a0438e01e8e6 100644 --- a/chrome/browser/chromeos/policy/device_policy_decoder_chromeos.cc +++ b/chrome/browser/chromeos/policy/device_policy_decoder_chromeos.cc @@ -569,6 +569,17 @@ void DecodeGenericPolicies(const em::ChromeDeviceSettingsProto& policy, } } + if (policy.has_use_24hour_clock()) { + if (policy.use_24hour_clock().has_use_24hour_clock()) { + policies->Set(key::kSystemUse24HourClock, + POLICY_LEVEL_MANDATORY, + POLICY_SCOPE_MACHINE, + Value::CreateBooleanValue( + policy.use_24hour_clock().use_24hour_clock()), + NULL); + } + } + if (policy.has_allow_redeem_offers()) { const em::AllowRedeemChromeOsRegistrationOffersProto& container( policy.allow_redeem_offers()); diff --git a/chrome/browser/chromeos/settings/cros_settings_names.cc b/chrome/browser/chromeos/settings/cros_settings_names.cc index cea9665b55a2..ac3369d225e4 100644 --- a/chrome/browser/chromeos/settings/cros_settings_names.cc +++ b/chrome/browser/chromeos/settings/cros_settings_names.cc @@ -53,6 +53,10 @@ const char kAllowedConnectionTypesForUpdate[] = const char kSystemTimezone[] = "cros.system.timezone"; const char kSystemTimezonePolicy[] = "cros.system.timezone_policy"; +// Value of kUse24HourClock user preference of device' owner. +// ChromeOS device uses this setting on login screen. +const char kSystemUse24HourClock[] = "cros.system.use_24hour_clock"; + const char kDeviceOwner[] = "cros.device.owner"; const char kStatsReportingPref[] = "cros.metrics.reportingEnabled"; diff --git a/chrome/browser/chromeos/settings/cros_settings_names.h b/chrome/browser/chromeos/settings/cros_settings_names.h index 226e9301875a..eff6785301cd 100644 --- a/chrome/browser/chromeos/settings/cros_settings_names.h +++ b/chrome/browser/chromeos/settings/cros_settings_names.h @@ -31,6 +31,7 @@ extern const char kAllowedConnectionTypesForUpdate[]; extern const char kSystemTimezonePolicy[]; extern const char kSystemTimezone[]; +extern const char kSystemUse24HourClock[]; extern const char kDeviceOwner[]; diff --git a/chrome/browser/chromeos/settings/device_settings_provider.cc b/chrome/browser/chromeos/settings/device_settings_provider.cc index f18d144b6f35..7816dc7d6a36 100644 --- a/chrome/browser/chromeos/settings/device_settings_provider.cc +++ b/chrome/browser/chromeos/settings/device_settings_provider.cc @@ -75,6 +75,7 @@ const char* kKnownSettings[] = { kStartUpUrls, kStatsReportingPref, kSystemTimezonePolicy, + kSystemUse24HourClock, kUpdateDisabled, kVariationsRestrictParameter, }; @@ -375,6 +376,16 @@ void DeviceSettingsProvider::SetInPolicy() { flags_proto->add_flags(flag); } } + } else if (prop == kSystemUse24HourClock) { + em::SystemUse24HourClockProto* use_24hour_clock_proto = + device_settings_.mutable_use_24hour_clock(); + use_24hour_clock_proto->Clear(); + bool use_24hour_clock_value; + if (value->GetAsBoolean(&use_24hour_clock_value)) { + use_24hour_clock_proto->set_use_24hour_clock(use_24hour_clock_value); + } else { + NOTREACHED(); + } } else { // The remaining settings don't support Set(), since they are not // intended to be customizable by the user: @@ -704,6 +715,13 @@ void DeviceSettingsProvider::DecodeGenericPolicies( } } + if (policy.has_use_24hour_clock()) { + if (policy.use_24hour_clock().has_use_24hour_clock()) { + new_values_cache->SetBoolean( + kSystemUse24HourClock, policy.use_24hour_clock().use_24hour_clock()); + } + } + if (policy.has_allow_redeem_offers()) { new_values_cache->SetBoolean( kAllowRedeemChromeOsRegistrationOffers, diff --git a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc index 150b3b6cf9f3..764b81e30ab8 100644 --- a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc +++ b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc @@ -66,6 +66,7 @@ #include "chrome/browser/chromeos/options/network_config_view.h" #include "chrome/browser/chromeos/options/network_connect.h" #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" +#include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/chromeos/sim_dialog_delegate.h" #include "chrome/browser/chromeos/status/data_promo_notification.h" #include "chrome/browser/chromeos/system/timezone_settings.h" @@ -970,13 +971,40 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, integration_service->job_list()->RemoveObserver(this); } + bool ShouldUse24HourClock() const { + // On login screen and in guest mode owner default is used for + // kUse24HourClock preference. + // All other modes default to the default locale value. + const ash::user::LoginStatus status = GetUserLoginStatus(); + const CrosSettings* const cros_settings = CrosSettings::Get(); + bool system_use_24_hour_clock = true; + const bool system_value_found = cros_settings->GetBoolean( + kSystemUse24HourClock, &system_use_24_hour_clock); + + if (status == ash::user::LOGGED_IN_NONE) + return (system_value_found ? system_use_24_hour_clock : true); + + const PrefService::Preference* user_pref = + user_pref_registrar_->prefs()->FindPreference(prefs::kUse24HourClock); + if (status == ash::user::LOGGED_IN_GUEST && user_pref->IsDefaultValue()) + return (system_value_found ? system_use_24_hour_clock : true); + + bool use_24_hour_clock = true; + user_pref->GetValue()->GetAsBoolean(&use_24_hour_clock); + return use_24_hour_clock; + } + void UpdateClockType() { if (!user_pref_registrar_) return; - clock_type_ = - user_pref_registrar_->prefs()->GetBoolean(prefs::kUse24HourClock) ? - base::k24HourClock : base::k12HourClock; + + const bool use_24_hour_clock = ShouldUse24HourClock(); + clock_type_ = use_24_hour_clock ? base::k24HourClock : base::k12HourClock; GetSystemTrayNotifier()->NotifyDateFormatChanged(); + // This also works for enterprise-managed devices because they never have + // local owner. + if (chromeos::UserManager::Get()->IsCurrentUserOwner()) + CrosSettings::Get()->SetBoolean(kSystemUse24HourClock, use_24_hour_clock); } void UpdateShowLogoutButtonInTray() { diff --git a/chrome/browser/policy/proto/chromeos/chrome_device_policy.proto b/chrome/browser/policy/proto/chromeos/chrome_device_policy.proto index 06deb8ba8a89..a88f58f52527 100644 --- a/chrome/browser/policy/proto/chromeos/chrome_device_policy.proto +++ b/chrome/browser/policy/proto/chromeos/chrome_device_policy.proto @@ -236,6 +236,12 @@ message SystemTimezoneProto { optional string timezone = 1; } +message SystemUse24HourClockProto { + // Specifies an owner-determined clock format that applies to the login + // screen and all users. + optional bool use_24hour_clock = 1; +} + // Parameters for Kiosk App device-local accounts. message KioskAppInfoProto { // Indicates the Kiosk App for the corresponding device-local account. The @@ -539,4 +545,5 @@ message ChromeDeviceSettingsProto { optional AccessibilitySettingsProto accessibility_settings = 27; optional SupervisedUsersSettingsProto supervised_users_settings = 28; optional LoginScreenPowerManagementProto login_screen_power_management = 29; + optional SystemUse24HourClockProto use_24hour_clock = 30; } diff --git a/chrome/test/data/policy/policy_test_cases.json b/chrome/test/data/policy/policy_test_cases.json index 5ad437161e2c..d47daca79b0b 100644 --- a/chrome/test/data/policy/policy_test_cases.json +++ b/chrome/test/data/policy/policy_test_cases.json @@ -2002,6 +2002,9 @@ "SystemTimezone": { }, + "SystemUse24HourClock": { + }, + "DeviceLocalAccounts": { }, -- 2.11.4.GIT