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/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
15 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
19 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
20 #include "base/values.h" | 21 #include "base/values.h" |
21 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 23 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
23 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 24 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 zone_id.toUTF8String(zone_id_str); | 71 zone_id.toUTF8String(zone_id_str); |
71 | 72 |
72 // Resource keys for timezones use ':' in place of '/'. | 73 // Resource keys for timezones use ':' in place of '/'. |
73 base::ReplaceSubstringsAfterOffset(&zone_id_str, 0, "/", ":"); | 74 base::ReplaceSubstringsAfterOffset(&zone_id_str, 0, "/", ":"); |
74 std::unique_ptr<UResourceBundle, UResClose> zone_item( | 75 std::unique_ptr<UResourceBundle, UResClose> zone_item( |
75 ures_getByKey(zone_strings, zone_id_str.c_str(), NULL, &status)); | 76 ures_getByKey(zone_strings, zone_id_str.c_str(), NULL, &status)); |
76 icu::UnicodeString city; | 77 icu::UnicodeString city; |
77 if (!U_FAILURE(status)) { | 78 if (!U_FAILURE(status)) { |
78 city = icu::ures_getUnicodeStringByKey(zone_item.get(), "ec", &status); | 79 city = icu::ures_getUnicodeStringByKey(zone_item.get(), "ec", &status); |
79 if (U_SUCCESS(status)) | 80 if (U_SUCCESS(status)) |
80 return base::string16(city.getBuffer(), city.length()); | 81 return base::i18n::UnicodeStringToString16(city); |
81 } | 82 } |
82 | 83 |
83 // Fallback case in case of failure. | 84 // Fallback case in case of failure. |
84 base::ReplaceSubstringsAfterOffset(&zone_id_str, 0, ":", "/"); | 85 base::ReplaceSubstringsAfterOffset(&zone_id_str, 0, ":", "/"); |
85 // Take the last component of a timezone id (e.g. 'Baz' in 'Foo/Bar/Baz'). | 86 // Take the last component of a timezone id (e.g. 'Baz' in 'Foo/Bar/Baz'). |
86 // Depending on timezones, keeping all but the 1st component | 87 // Depending on timezones, keeping all but the 1st component |
87 // (e.g. Bar/Baz) may be better, but our current list does not have | 88 // (e.g. Bar/Baz) may be better, but our current list does not have |
88 // any timezone for which that's the case. | 89 // any timezone for which that's the case. |
89 std::string::size_type slash_pos = zone_id_str.rfind('/'); | 90 std::string::size_type slash_pos = zone_id_str.rfind('/'); |
90 if (slash_pos != std::string::npos && slash_pos < zone_id_str.size()) | 91 if (slash_pos != std::string::npos && slash_pos < zone_id_str.size()) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 if (id == icu::UnicodeString(chromeos::system::kUTCTimezoneName)) { | 130 if (id == icu::UnicodeString(chromeos::system::kUTCTimezoneName)) { |
130 name = icu::UnicodeString( | 131 name = icu::UnicodeString( |
131 l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_TIMEZONE_DISPLAY_NAME_UTC) | 132 l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_TIMEZONE_DISPLAY_NAME_UTC) |
132 .c_str()); | 133 .c_str()); |
133 } else { | 134 } else { |
134 timezone.getDisplayName(dst_offset != 0, icu::TimeZone::LONG, name); | 135 timezone.getDisplayName(dst_offset != 0, icu::TimeZone::LONG, name); |
135 } | 136 } |
136 base::string16 result(l10n_util::GetStringFUTF16( | 137 base::string16 result(l10n_util::GetStringFUTF16( |
137 IDS_OPTIONS_SETTINGS_TIMEZONE_DISPLAY_TEMPLATE, | 138 IDS_OPTIONS_SETTINGS_TIMEZONE_DISPLAY_TEMPLATE, |
138 base::ASCIIToUTF16(offset_str), | 139 base::ASCIIToUTF16(offset_str), |
139 base::string16(name.getBuffer(), name.length()), | 140 base::i18n::UnicodeStringToString16(name), |
140 GetExemplarCity(timezone))); | 141 GetExemplarCity(timezone))); |
141 base::i18n::AdjustStringForLocaleDirection(&result); | 142 base::i18n::AdjustStringForLocaleDirection(&result); |
142 return result; | 143 return result; |
143 } | 144 } |
144 | 145 |
145 } // namespace | 146 } // namespace |
146 | 147 |
147 namespace chromeos { | 148 namespace chromeos { |
148 namespace system { | 149 namespace system { |
149 | 150 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 VLOG(1) << "Refresh TimeZone: setting timezone to '" << timezone->timeZoneId | 196 VLOG(1) << "Refresh TimeZone: setting timezone to '" << timezone->timeZoneId |
196 << "'"; | 197 << "'"; |
197 | 198 |
198 chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID( | 199 chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID( |
199 base::UTF8ToUTF16(timezone->timeZoneId)); | 200 base::UTF8ToUTF16(timezone->timeZoneId)); |
200 } | 201 } |
201 } | 202 } |
202 | 203 |
203 } // namespace system | 204 } // namespace system |
204 } // namespace chromeos | 205 } // namespace chromeos |
OLD | NEW |