Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: chrome/browser/ui/webui/options2/browser_options_handler.cc

Issue 10689175: Refactored code for timezone settings. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed a comment and annotation. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/chromeos/system_settings_provider.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/options2/browser_options_handler.h" 5 #include "chrome/browser/ui/webui/options2/browser_options_handler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/i18n/rtl.h"
14 #include "base/memory/singleton.h" 15 #include "base/memory/singleton.h"
15 #include "base/path_service.h" 16 #include "base/path_service.h"
16 #include "base/stl_util.h" 17 #include "base/stl_util.h"
17 #include "base/string_number_conversions.h" 18 #include "base/string_number_conversions.h"
19 #include "base/stringprintf.h"
18 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
19 #include "base/value_conversions.h" 21 #include "base/value_conversions.h"
20 #include "base/values.h" 22 #include "base/values.h"
21 #include "chrome/browser/auto_launch_trial.h" 23 #include "chrome/browser/auto_launch_trial.h"
22 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/chrome_page_zoom.h" 25 #include "chrome/browser/chrome_page_zoom.h"
24 #include "chrome/browser/custom_home_pages_table_model.h" 26 #include "chrome/browser/custom_home_pages_table_model.h"
25 #include "chrome/browser/download/download_prefs.h" 27 #include "chrome/browser/download/download_prefs.h"
26 #include "chrome/browser/instant/instant_controller.h" 28 #include "chrome/browser/instant/instant_controller.h"
27 #include "chrome/browser/net/url_fixer_upper.h" 29 #include "chrome/browser/net/url_fixer_upper.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 #include "grit/theme_resources.h" 77 #include "grit/theme_resources.h"
76 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 78 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
77 #include "ui/base/l10n/l10n_util.h" 79 #include "ui/base/l10n/l10n_util.h"
78 80
79 #if !defined(OS_CHROMEOS) 81 #if !defined(OS_CHROMEOS)
80 #include "chrome/browser/printing/cloud_print/cloud_print_setup_handler.h" 82 #include "chrome/browser/printing/cloud_print/cloud_print_setup_handler.h"
81 #include "chrome/browser/ui/webui/options2/advanced_options_utils.h" 83 #include "chrome/browser/ui/webui/options2/advanced_options_utils.h"
82 #endif 84 #endif
83 85
84 #if defined(OS_CHROMEOS) 86 #if defined(OS_CHROMEOS)
87 #include "base/lazy_instance.h"
88 #include "base/synchronization/lock.h"
85 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" 89 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
86 #include "chrome/browser/chromeos/cros_settings.h"
87 #include "chrome/browser/chromeos/login/user_manager.h" 90 #include "chrome/browser/chromeos/login/user_manager.h"
88 #include "chrome/browser/chromeos/options/take_photo_dialog.h" 91 #include "chrome/browser/chromeos/options/take_photo_dialog.h"
89 #include "chrome/browser/chromeos/system_settings_provider.h" 92 #include "chrome/browser/chromeos/system/timezone_settings.h"
90 #include "chrome/browser/ui/browser_window.h" 93 #include "chrome/browser/ui/browser_window.h"
91 #include "ui/gfx/image/image_skia.h" 94 #include "ui/gfx/image/image_skia.h"
95 #include "unicode/calendar.h"
96 #include "unicode/timezone.h"
97 #include "unicode/ures.h"
92 #endif // defined(OS_CHROMEOS) 98 #endif // defined(OS_CHROMEOS)
93 99
94 #if defined(OS_WIN) 100 #if defined(OS_WIN)
95 #include "chrome/installer/util/auto_launch_util.h" 101 #include "chrome/installer/util/auto_launch_util.h"
96 #endif // defined(OS_WIN) 102 #endif // defined(OS_WIN)
97 103
98 #if defined(TOOLKIT_GTK) 104 #if defined(TOOLKIT_GTK)
99 #include "chrome/browser/ui/gtk/gtk_theme_service.h" 105 #include "chrome/browser/ui/gtk/gtk_theme_service.h"
100 #endif // defined(TOOLKIT_GTK) 106 #endif // defined(TOOLKIT_GTK)
101 107
102 using content::BrowserContext; 108 using content::BrowserContext;
103 using content::BrowserThread; 109 using content::BrowserThread;
104 using content::DownloadManager; 110 using content::DownloadManager;
105 using content::OpenURLParams; 111 using content::OpenURLParams;
106 using content::Referrer; 112 using content::Referrer;
107 using content::UserMetricsAction; 113 using content::UserMetricsAction;
108 114
115 #if defined(OS_CHROMEOS)
James Hawkins 2012/07/13 14:25:04 I'm not a fan of having this much CrOS-specific co
pneubeck2 2012/07/16 11:32:38 Done.
116 namespace {
117
118 struct UResClose {
119 inline void operator() (UResourceBundle* b) const {
120 ures_close(b);
121 }
122 };
123
124 static base::LazyInstance<base::Lock>::Leaky
125 g_timezone_bundle_lock = LAZY_INSTANCE_INITIALIZER;
126
127 string16 GetExemplarCity(const icu::TimeZone& zone) {
128 // TODO(jungshik): After upgrading to ICU 4.6, use U_ICUDATA_ZONE
129 static const char* zone_bundle_name = NULL;
130
131 // These will be leaked at the end.
132 static UResourceBundle *zone_bundle = NULL;
133 static UResourceBundle *zone_strings = NULL;
134
135 UErrorCode status = U_ZERO_ERROR;
136 {
137 base::AutoLock lock(g_timezone_bundle_lock.Get());
138 if (zone_bundle == NULL)
139 zone_bundle = ures_open(zone_bundle_name, uloc_getDefault(), &status);
140
141 if (zone_strings == NULL)
142 zone_strings = ures_getByKey(zone_bundle, "zone_strings", NULL, &status);
143 }
144
145 icu::UnicodeString zone_id;
146 zone.getID(zone_id);
147 std::string zone_id_str;
148 zone_id.toUTF8String(zone_id_str);
149
150 // Resource keys for timezones use ':' in place of '/'.
151 ReplaceSubstringsAfterOffset(&zone_id_str, 0, "/", ":");
152 scoped_ptr_malloc<UResourceBundle, UResClose> zone_item(
153 ures_getByKey(zone_strings, zone_id_str.c_str(), NULL, &status));
154 icu::UnicodeString city;
155 if (!U_FAILURE(status)) {
156 city = icu::ures_getUnicodeStringByKey(zone_item.get(), "ec", &status);
157 if (U_SUCCESS(status))
158 return string16(city.getBuffer(), city.length());
159 }
160
161 // Fallback case in case of failure.
162 ReplaceSubstringsAfterOffset(&zone_id_str, 0, ":", "/");
163 // Take the last component of a timezone id (e.g. 'Baz' in 'Foo/Bar/Baz').
164 // Depending on timezones, keeping all but the 1st component
165 // (e.g. Bar/Baz) may be better, but our current list does not have
166 // any timezone for which that's the case.
167 std::string::size_type slash_pos = zone_id_str.rfind('/');
168 if (slash_pos != std::string::npos && slash_pos < zone_id_str.size())
169 zone_id_str.erase(0, slash_pos + 1);
170 // zone id has '_' in place of ' '.
171 ReplaceSubstringsAfterOffset(&zone_id_str, 0, "_", " ");
172 return ASCIIToUTF16(zone_id_str);
173 }
174
175 // Gets the given timezone's name for visualization.
176 string16 GetTimezoneName(const icu::TimeZone& timezone) {
177 // Instead of using the raw_offset, use the offset in effect now.
178 // For instance, US Pacific Time, the offset shown will be -7 in summer
179 // while it'll be -8 in winter.
180 int raw_offset, dst_offset;
181 UDate now = icu::Calendar::getNow();
182 UErrorCode status = U_ZERO_ERROR;
183 timezone.getOffset(now, false, raw_offset, dst_offset, status);
184 DCHECK(U_SUCCESS(status));
185 int offset = raw_offset + dst_offset;
186 // |offset| is in msec.
187 int minute_offset = std::abs(offset) / 60000;
188 int hour_offset = minute_offset / 60;
189 int min_remainder = minute_offset % 60;
190 // Some timezones have a non-integral hour offset. So, we need to use hh:mm
191 // form.
192 std::string offset_str = base::StringPrintf(offset >= 0 ?
193 "UTC+%d:%02d" : "UTC-%d:%02d", hour_offset, min_remainder);
194
195 // TODO(jungshik): When coming up with a better list of timezones, we also
196 // have to come up with better 'display' names. One possibility is to list
197 // multiple cities (e.g. "Los Angeles, Vancouver .." in the order of
198 // the population of a country the city belongs to.).
199 // We can also think of using LONG_GENERIC or LOCATION once we upgrade
200 // to ICU 4.6.
201 // In the meantime, we use "LONG" name with "Exemplar City" to distinguish
202 // multiple timezones with the same "LONG" name but with different
203 // rules (e.g. US Mountain Time in Denver vs Phoenix).
204 icu::UnicodeString name;
205 timezone.getDisplayName(dst_offset != 0, icu::TimeZone::LONG, name);
206 string16 result(l10n_util::GetStringFUTF16(
207 IDS_OPTIONS_SETTINGS_TIMEZONE_DISPLAY_TEMPLATE, ASCIIToUTF16(offset_str),
208 string16(name.getBuffer(), name.length()), GetExemplarCity(timezone)));
209 base::i18n::AdjustStringForLocaleDirection(&result);
210 return result;
211 }
212
213 // Creates a list of pairs of each timezone's ID and name.
214 ListValue* GetTimezoneList() {
215 const std::vector<icu::TimeZone*> &timezones =
216 chromeos::system::TimezoneSettings::GetInstance()->GetTimezoneList();
217 ListValue* timezoneList = new ListValue();
218 for (std::vector<icu::TimeZone*>::const_iterator iter = timezones.begin();
219 iter != timezones.end(); ++iter) {
220 const icu::TimeZone* timezone = *iter;
221 ListValue* option = new ListValue();
222 option->Append(Value::CreateStringValue(
223 chromeos::system::TimezoneSettings::GetTimezoneID(*timezone)));
224 option->Append(Value::CreateStringValue(GetTimezoneName(*timezone)));
225 timezoneList->Append(option);
226 }
227 return timezoneList;
228 }
229
230 } // namespace
231 #endif // defined(OS_CHROMEOS)
232
109 namespace options2 { 233 namespace options2 {
110 234
111 BrowserOptionsHandler::BrowserOptionsHandler() 235 BrowserOptionsHandler::BrowserOptionsHandler()
112 : template_url_service_(NULL), 236 : template_url_service_(NULL),
113 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_for_file_(this)), 237 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_for_file_(this)),
114 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_for_ui_(this)) { 238 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_for_ui_(this)) {
115 multiprofile_ = ProfileManager::IsMultipleProfilesEnabled(); 239 multiprofile_ = ProfileManager::IsMultipleProfilesEnabled();
116 #if !defined(OS_MACOSX) 240 #if !defined(OS_MACOSX)
117 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this); 241 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this);
118 #endif 242 #endif
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 "languageSectionLabel", 502 "languageSectionLabel",
379 l10n_util::GetStringFUTF16( 503 l10n_util::GetStringFUTF16(
380 IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL, 504 IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL,
381 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); 505 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)));
382 506
383 #if defined(OS_CHROMEOS) 507 #if defined(OS_CHROMEOS)
384 values->SetString("cloudPrintLearnMoreURL", chrome::kCloudPrintLearnMoreURL); 508 values->SetString("cloudPrintLearnMoreURL", chrome::kCloudPrintLearnMoreURL);
385 509
386 // TODO(pastarmovj): replace this with a call to the CrosSettings list 510 // TODO(pastarmovj): replace this with a call to the CrosSettings list
387 // handling functionality to come. 511 // handling functionality to come.
388 values->Set("timezoneList", 512 values->Set("timezoneList", GetTimezoneList());
389 static_cast<chromeos::SystemSettingsProvider*>(
390 chromeos::CrosSettings::Get()->GetProvider(
391 chromeos::kSystemTimezone))->GetTimezoneList());
392 #endif 513 #endif
393 #if defined(OS_MACOSX) 514 #if defined(OS_MACOSX)
394 values->SetString("macPasswordsWarning", 515 values->SetString("macPasswordsWarning",
395 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MAC_WARNING)); 516 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MAC_WARNING));
396 values->SetBoolean("multiple_profiles", 517 values->SetBoolean("multiple_profiles",
397 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1); 518 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1);
398 #endif 519 #endif
399 520
400 if (multiprofile_) 521 if (multiprofile_)
401 values->Set("profilesInfo", GetProfilesInfoList().release()); 522 values->Set("profilesInfo", GetProfilesInfoList().release());
(...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 } 1564 }
1444 1565
1445 void BrowserOptionsHandler::SetupSSLConfigSettings() { 1566 void BrowserOptionsHandler::SetupSSLConfigSettings() {
1446 base::FundamentalValue checked(rev_checking_enabled_.GetValue()); 1567 base::FundamentalValue checked(rev_checking_enabled_.GetValue());
1447 base::FundamentalValue disabled(rev_checking_enabled_.IsManaged()); 1568 base::FundamentalValue disabled(rev_checking_enabled_.IsManaged());
1448 web_ui()->CallJavascriptFunction( 1569 web_ui()->CallJavascriptFunction(
1449 "BrowserOptions.setCheckRevocationCheckboxState", checked, disabled); 1570 "BrowserOptions.setCheckRevocationCheckboxState", checked, disabled);
1450 } 1571 }
1451 1572
1452 } // namespace options2 1573 } // namespace options2
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/system_settings_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698