Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/system/timezone_util.h" | 5 #include "chrome/browser/chromeos/system/timezone_util.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
| 14 #include "base/i18n/unicodestring.h" | 14 #include "base/i18n/unicodestring.h" |
| 15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 23 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 23 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 24 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | |
| 24 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 25 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 25 #include "chrome/browser/chromeos/settings/cros_settings.h" | 26 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 26 #include "chrome/browser/chromeos/system/timezone_resolver_manager.h" | 27 #include "chrome/browser/chromeos/system/timezone_resolver_manager.h" |
| 28 #include "chrome/common/pref_names.h" | |
| 27 #include "chrome/grit/generated_resources.h" | 29 #include "chrome/grit/generated_resources.h" |
| 28 #include "chromeos/settings/timezone_settings.h" | 30 #include "chromeos/settings/timezone_settings.h" |
| 29 #include "chromeos/timezone/timezone_request.h" | 31 #include "chromeos/timezone/timezone_request.h" |
| 30 #include "components/prefs/pref_service.h" | 32 #include "components/prefs/pref_service.h" |
| 33 #include "components/user_manager/user.h" | |
| 31 #include "components/user_manager/user_manager.h" | 34 #include "components/user_manager/user_manager.h" |
| 32 #include "third_party/icu/source/common/unicode/ures.h" | 35 #include "third_party/icu/source/common/unicode/ures.h" |
| 33 #include "third_party/icu/source/common/unicode/utypes.h" | 36 #include "third_party/icu/source/common/unicode/utypes.h" |
| 34 #include "third_party/icu/source/i18n/unicode/calendar.h" | 37 #include "third_party/icu/source/i18n/unicode/calendar.h" |
| 35 #include "third_party/icu/source/i18n/unicode/timezone.h" | 38 #include "third_party/icu/source/i18n/unicode/timezone.h" |
| 36 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
| 37 | 40 |
| 38 namespace { | 41 namespace { |
| 39 | 42 |
| 40 struct UResClose { | 43 struct UResClose { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 if (chromeos::CrosSettings::Get()->GetString(chromeos::kSystemTimezonePolicy, | 180 if (chromeos::CrosSettings::Get()->GetString(chromeos::kSystemTimezonePolicy, |
| 178 &policy_timezone) && | 181 &policy_timezone) && |
| 179 !policy_timezone.empty()) { | 182 !policy_timezone.empty()) { |
| 180 VLOG(1) << "Refresh TimeZone: TimeZone settings are overridden" | 183 VLOG(1) << "Refresh TimeZone: TimeZone settings are overridden" |
| 181 << " by DevicePolicy."; | 184 << " by DevicePolicy."; |
| 182 return true; | 185 return true; |
| 183 } | 186 } |
| 184 return false; | 187 return false; |
| 185 } | 188 } |
| 186 | 189 |
| 190 bool IsTimezonePrefsManaged(const std::string& pref_name) { | |
| 191 DCHECK(pref_name == prefs::kUserTimezone || | |
| 192 pref_name == prefs::kResolveTimezoneByGeolocation); | |
| 193 | |
| 194 std::string policy_timezone; | |
| 195 if (chromeos::CrosSettings::Get()->GetString(chromeos::kSystemTimezonePolicy, | |
| 196 &policy_timezone) && | |
| 197 !policy_timezone.empty()) { | |
| 198 return true; | |
| 199 } | |
| 200 | |
| 201 const PrefService* local_state = g_browser_process->local_state(); | |
| 202 if (!local_state->IsManagedPreference( | |
| 203 prefs::kSystemTimezoneAutomaticDetectionPolicy)) | |
| 204 return false; | |
|
stevenjb
2017/05/16 17:16:57
nit: {}
Alexander Alekseev
2017/05/19 11:25:29
Done.
| |
| 205 | |
| 206 int resolve_policy_value = | |
| 207 local_state->GetInteger(prefs::kSystemTimezoneAutomaticDetectionPolicy); | |
| 208 | |
| 209 switch (resolve_policy_value) { | |
| 210 case enterprise_management::SystemTimezoneProto::USERS_DECIDE: | |
| 211 return false; | |
| 212 case enterprise_management::SystemTimezoneProto::DISABLED: | |
| 213 // This only disables resolving. | |
| 214 return pref_name == prefs::kResolveTimezoneByGeolocation; | |
| 215 case enterprise_management::SystemTimezoneProto::IP_ONLY: | |
| 216 // fall-through | |
|
stevenjb
2017/05/16 17:16:56
nit: 'fall-through' comment really isn't necessary
Alexander Alekseev
2017/05/19 11:25:29
Done.
| |
| 217 case enterprise_management::SystemTimezoneProto::SEND_WIFI_ACCESS_POINTS: | |
| 218 // fall-through | |
| 219 case enterprise_management::SystemTimezoneProto::SEND_ALL_LOCATION_INFO: | |
| 220 return true; | |
| 221 } | |
| 222 // Default for unknown policy value. | |
| 223 NOTREACHED() << "Unrecognized policy value: " << resolve_policy_value; | |
| 224 return true; | |
| 225 } | |
| 226 | |
| 187 void ApplyTimeZone(const TimeZoneResponseData* timezone) { | 227 void ApplyTimeZone(const TimeZoneResponseData* timezone) { |
| 188 if (!g_browser_process->platform_part() | 228 if (!g_browser_process->platform_part() |
| 189 ->GetTimezoneResolverManager() | 229 ->GetTimezoneResolverManager() |
| 190 ->ShouldApplyResolvedTimezone()) { | 230 ->ShouldApplyResolvedTimezone()) { |
| 191 return; | 231 return; |
| 192 } | 232 } |
| 193 | 233 |
| 194 if (!timezone->timeZoneId.empty()) { | 234 if (!timezone->timeZoneId.empty()) { |
| 195 VLOG(1) << "Refresh TimeZone: setting timezone to '" << timezone->timeZoneId | 235 VLOG(1) << "Refresh TimeZone: setting timezone to '" << timezone->timeZoneId |
| 196 << "'"; | 236 << "'"; |
| 197 | 237 |
| 198 chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID( | 238 const user_manager::UserManager* user_manager = |
| 199 base::UTF8ToUTF16(timezone->timeZoneId)); | 239 user_manager::UserManager::Get(); |
| 240 const user_manager::User* primary_user = user_manager->GetPrimaryUser(); | |
| 241 | |
| 242 if (primary_user) { | |
| 243 Profile* profile = ProfileHelper::Get()->GetProfileByUser(primary_user); | |
| 244 profile->GetPrefs()->SetString(prefs::kUserTimezone, | |
| 245 timezone->timeZoneId); | |
| 246 // Preferences will automatically change system timezone because user is | |
| 247 // primary. | |
|
stevenjb
2017/05/16 17:16:57
Better, but I'm still unclear where/how "preferenc
Alexander Alekseev
2017/05/19 11:25:29
From the point of view of English language, "pref"
| |
| 248 } else { | |
| 249 SetSigninScreenTimezone(timezone->timeZoneId, | |
| 250 true /* set_system_timezone */); | |
| 251 } | |
| 200 } | 252 } |
| 201 } | 253 } |
| 202 | 254 |
| 255 void UpdateSystemTimezone(Profile* profile) { | |
| 256 if (IsTimezonePrefsManaged(prefs::kUserTimezone)) { | |
| 257 VLOG(1) << "Ignoring user timezone change, because timezone is enterprise " | |
| 258 "managed."; | |
| 259 return; | |
| 260 } | |
| 261 | |
| 262 const user_manager::UserManager* user_manager = | |
| 263 user_manager::UserManager::Get(); | |
| 264 const user_manager::User* user = | |
| 265 ProfileHelper::Get()->GetUserByProfile(profile); | |
| 266 | |
| 267 const AccountId owner(user_manager->GetOwnerAccountId()); | |
| 268 const bool user_is_owner = | |
| 269 owner.is_valid() && (owner == user->GetAccountId()); | |
| 270 | |
| 271 const std::string value = | |
| 272 profile->GetPrefs()->GetString(prefs::kUserTimezone); | |
| 273 if (user_is_owner) | |
| 274 SetSigninScreenTimezone(value, false /* set_system_timezone */); | |
|
stevenjb
2017/05/16 17:16:57
Is this the only place we call SetSigninScreenTime
Alexander Alekseev
2017/05/19 11:25:29
Done.
| |
| 275 | |
| 276 if (user_manager->GetPrimaryUser() == user) | |
| 277 CrosSettings::Get()->SetString(kSystemTimezone, value); | |
| 278 } | |
| 279 | |
| 280 void SetSigninScreenTimezone(const std::string& timezone, | |
| 281 bool set_system_timezone) { | |
| 282 if (timezone.empty()) | |
| 283 return; | |
| 284 | |
| 285 g_browser_process->local_state()->SetString(prefs::kSigninScreenTimezone, | |
| 286 timezone); | |
| 287 | |
| 288 if (set_system_timezone) { | |
|
stevenjb
2017/05/16 17:16:56
nit: if (!set_system_timezone) return;
Alexander Alekseev
2017/05/19 11:25:29
This line has been removed.
| |
| 289 std::string current_timezone_id; | |
| 290 CrosSettings::Get()->GetString(kSystemTimezone, ¤t_timezone_id); | |
| 291 if (current_timezone_id != timezone) { | |
| 292 system::TimezoneSettings::GetInstance()->SetTimezoneFromID( | |
| 293 base::UTF8ToUTF16(timezone)); | |
| 294 } | |
| 295 } | |
| 296 } | |
| 297 | |
| 203 } // namespace system | 298 } // namespace system |
| 204 } // namespace chromeos | 299 } // namespace chromeos |
| OLD | NEW |