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 IfTimezonePrefsmanaged(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 } | |
stevenjb
2017/05/15 17:08:02
nit: blank line
Alexander Alekseev
2017/05/16 01:11:56
Done.
| |
200 const PrefService* local_state = g_browser_process->local_state(); | |
201 const bool is_resolve_managed = local_state->IsManagedPreference( | |
stevenjb
2017/05/15 17:08:02
I'm confused about what 'resolve' refers to here a
Alexander Alekseev
2017/05/16 01:11:56
This was lame abbreviation of "resolve timezone au
| |
202 prefs::kSystemTimezoneAutomaticDetectionPolicy); | |
203 if (!is_resolve_managed) | |
204 return false; | |
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 return true; | |
michaelpg
2017/05/15 23:01:50
nit: use fall-through for trivial cases
Alexander Alekseev
2017/05/16 01:11:56
Done.
| |
217 case enterprise_management::SystemTimezoneProto::SEND_WIFI_ACCESS_POINTS: | |
218 return true; | |
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 // Actual system timezone change will happen automatically. | |
stevenjb
2017/05/15 17:08:02
Could you elaborate on 'automatically'? Where does
Alexander Alekseev
2017/05/16 01:11:56
Done.
| |
247 } else { | |
248 g_browser_process->local_state()->SetString(prefs::kSigninScreenTimezone, | |
249 timezone->timeZoneId); | |
250 chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID( | |
251 base::UTF8ToUTF16(timezone->timeZoneId)); | |
252 } | |
200 } | 253 } |
201 } | 254 } |
202 | 255 |
256 void UpdateSystemTimezone(Profile* profile) { | |
257 if (IfTimezonePrefsmanaged(prefs::kUserTimezone)) { | |
258 VLOG(1) << "Ignoring user timezone change, because timezone is enterprise " | |
259 "managed."; | |
260 return; | |
261 } | |
262 | |
263 const user_manager::UserManager* user_manager = | |
264 user_manager::UserManager::Get(); | |
265 const user_manager::User* user = | |
266 ProfileHelper::Get()->GetUserByProfile(profile); | |
267 | |
268 const AccountId owner(user_manager->GetOwnerAccountId()); | |
269 const bool user_is_owner = | |
270 owner.is_valid() && (owner == user->GetAccountId()); | |
271 | |
272 const bool user_is_primary = user_manager->GetPrimaryUser() == user; | |
stevenjb
2017/05/15 17:08:02
Move this to where it is used (better yet, just re
Alexander Alekseev
2017/05/16 01:11:56
Done.
| |
273 | |
274 const std::string value = | |
275 profile->GetPrefs()->GetString(prefs::kUserTimezone); | |
276 if (user_is_owner) { | |
277 g_browser_process->local_state()->SetString(prefs::kSigninScreenTimezone, | |
278 value); | |
279 } | |
280 if (user_is_primary) | |
281 CrosSettings::Get()->SetString(kSystemTimezone, value); | |
282 } | |
283 | |
203 } // namespace system | 284 } // namespace system |
204 } // namespace chromeos | 285 } // namespace chromeos |
OLD | NEW |