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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/prefs/pref_service.h" |
11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
15 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 19 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 20 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 21 #include "chrome/common/pref_names.h" |
16 #include "chrome/grit/generated_resources.h" | 22 #include "chrome/grit/generated_resources.h" |
17 #include "chromeos/settings/timezone_settings.h" | 23 #include "chromeos/settings/timezone_settings.h" |
| 24 #include "chromeos/timezone/timezone_request.h" |
| 25 #include "components/user_manager/user_manager.h" |
18 #include "third_party/icu/source/common/unicode/ures.h" | 26 #include "third_party/icu/source/common/unicode/ures.h" |
19 #include "third_party/icu/source/common/unicode/utypes.h" | 27 #include "third_party/icu/source/common/unicode/utypes.h" |
20 #include "third_party/icu/source/i18n/unicode/calendar.h" | 28 #include "third_party/icu/source/i18n/unicode/calendar.h" |
21 #include "third_party/icu/source/i18n/unicode/timezone.h" | 29 #include "third_party/icu/source/i18n/unicode/timezone.h" |
22 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
23 | 31 |
24 namespace { | 32 namespace { |
25 | 33 |
26 struct UResClose { | 34 struct UResClose { |
27 inline void operator() (UResourceBundle* b) const { | 35 inline void operator() (UResourceBundle* b) const { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 const icu::TimeZone* timezone = *iter; | 144 const icu::TimeZone* timezone = *iter; |
137 base::ListValue* option = new base::ListValue(); | 145 base::ListValue* option = new base::ListValue(); |
138 option->Append(new base::StringValue( | 146 option->Append(new base::StringValue( |
139 chromeos::system::TimezoneSettings::GetTimezoneID(*timezone))); | 147 chromeos::system::TimezoneSettings::GetTimezoneID(*timezone))); |
140 option->Append(new base::StringValue(GetTimezoneName(*timezone))); | 148 option->Append(new base::StringValue(GetTimezoneName(*timezone))); |
141 timezoneList->Append(option); | 149 timezoneList->Append(option); |
142 } | 150 } |
143 return timezoneList.Pass(); | 151 return timezoneList.Pass(); |
144 } | 152 } |
145 | 153 |
| 154 bool HasSystemTimezonePolicy() { |
| 155 policy::BrowserPolicyConnectorChromeOS* connector = |
| 156 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 157 if (!connector->IsEnterpriseManaged()) |
| 158 return false; |
| 159 |
| 160 std::string policy_timezone; |
| 161 if (chromeos::CrosSettings::Get()->GetString(chromeos::kSystemTimezonePolicy, |
| 162 &policy_timezone) && |
| 163 !policy_timezone.empty()) { |
| 164 VLOG(1) << "Refresh TimeZone: TimeZone settings are overridden" |
| 165 << " by DevicePolicy."; |
| 166 return true; |
| 167 } |
| 168 return false; |
| 169 } |
| 170 |
| 171 void ApplyTimeZone(const TimeZoneResponseData* timezone) { |
| 172 if (HasSystemTimezonePolicy()) |
| 173 return; |
| 174 |
| 175 const user_manager::User* primary_user = |
| 176 user_manager::UserManager::Get()->GetPrimaryUser(); |
| 177 if (primary_user) { |
| 178 if (!primary_user->is_profile_created()) |
| 179 return; |
| 180 |
| 181 Profile* profile = |
| 182 chromeos::ProfileHelper::Get()->GetProfileByUser(primary_user); |
| 183 if (!profile->GetPrefs()->GetBoolean( |
| 184 prefs::kResolveTimezoneByGeolocation)) { |
| 185 return; |
| 186 } |
| 187 } |
| 188 |
| 189 if (!timezone->timeZoneId.empty()) { |
| 190 VLOG(1) << "Refresh TimeZone: setting timezone to '" << timezone->timeZoneId |
| 191 << "'"; |
| 192 |
| 193 chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID( |
| 194 base::UTF8ToUTF16(timezone->timeZoneId)); |
| 195 } |
| 196 } |
| 197 |
146 } // namespace system | 198 } // namespace system |
147 } // namespace chromeos | 199 } // namespace chromeos |
OLD | NEW |