OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/webui/options/chromeos/system_settings_provider.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/system_settings_provider.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/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
12 #include "base/string_util.h" | 13 #include "base/string_util.h" |
13 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
14 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
15 #include "base/time.h" | 16 #include "base/time.h" |
16 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "chrome/browser/chromeos/cros/cros_library.h" | 19 #include "chrome/browser/chromeos/cros/cros_library.h" |
19 #include "chrome/browser/chromeos/cros_settings.h" | 20 #include "chrome/browser/chromeos/cros_settings.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 "Australia/Hobart", | 114 "Australia/Hobart", |
114 "Australia/Sydney", | 115 "Australia/Sydney", |
115 "Asia/Vladivostok", | 116 "Asia/Vladivostok", |
116 "Pacific/Guam", | 117 "Pacific/Guam", |
117 "Asia/Magadan", | 118 "Asia/Magadan", |
118 "Pacific/Auckland", | 119 "Pacific/Auckland", |
119 "Pacific/Fiji", | 120 "Pacific/Fiji", |
120 "Pacific/Tongatapu", | 121 "Pacific/Tongatapu", |
121 }; | 122 }; |
122 | 123 |
123 static base::Lock timezone_bundle_lock; | 124 static base::LazyInstance<base::Lock, |
| 125 base::LeakyLazyInstanceTraits<base::Lock> > |
| 126 g_timezone_bundle_lock = LAZY_INSTANCE_INITIALIZER; |
124 | 127 |
125 struct UResClose { | 128 struct UResClose { |
126 inline void operator() (UResourceBundle* b) const { | 129 inline void operator() (UResourceBundle* b) const { |
127 ures_close(b); | 130 ures_close(b); |
128 } | 131 } |
129 }; | 132 }; |
130 | 133 |
131 string16 GetExemplarCity(const icu::TimeZone& zone) { | 134 string16 GetExemplarCity(const icu::TimeZone& zone) { |
132 // TODO(jungshik): After upgrading to ICU 4.6, use U_ICUDATA_ZONE | 135 // TODO(jungshik): After upgrading to ICU 4.6, use U_ICUDATA_ZONE |
133 static const char* zone_bundle_name = NULL; | 136 static const char* zone_bundle_name = NULL; |
134 | 137 |
135 // These will be leaked at the end. | 138 // These will be leaked at the end. |
136 static UResourceBundle *zone_bundle = NULL; | 139 static UResourceBundle *zone_bundle = NULL; |
137 static UResourceBundle *zone_strings = NULL; | 140 static UResourceBundle *zone_strings = NULL; |
138 | 141 |
139 UErrorCode status = U_ZERO_ERROR; | 142 UErrorCode status = U_ZERO_ERROR; |
140 { | 143 { |
141 base::AutoLock lock(timezone_bundle_lock); | 144 base::AutoLock lock(g_timezone_bundle_lock.Get()); |
142 if (zone_bundle == NULL) | 145 if (zone_bundle == NULL) |
143 zone_bundle = ures_open(zone_bundle_name, uloc_getDefault(), &status); | 146 zone_bundle = ures_open(zone_bundle_name, uloc_getDefault(), &status); |
144 | 147 |
145 if (zone_strings == NULL) | 148 if (zone_strings == NULL) |
146 zone_strings = ures_getByKey(zone_bundle, "zone_strings", NULL, &status); | 149 zone_strings = ures_getByKey(zone_bundle, "zone_strings", NULL, &status); |
147 } | 150 } |
148 | 151 |
149 icu::UnicodeString zone_id; | 152 icu::UnicodeString zone_id; |
150 zone.getID(zone_id); | 153 zone.getID(zone_id); |
151 std::string zone_id_str; | 154 std::string zone_id_str; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 const icu::TimeZone* known_timezone = *iter; | 310 const icu::TimeZone* known_timezone = *iter; |
308 if (known_timezone->hasSameRules(timezone)) | 311 if (known_timezone->hasSameRules(timezone)) |
309 return GetTimezoneID(*known_timezone); | 312 return GetTimezoneID(*known_timezone); |
310 } | 313 } |
311 | 314 |
312 // Not able to find a matching timezone in our list. | 315 // Not able to find a matching timezone in our list. |
313 return string16(); | 316 return string16(); |
314 } | 317 } |
315 | 318 |
316 } // namespace chromeos | 319 } // namespace chromeos |
OLD | NEW |