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

Side by Side Diff: chrome/browser/resources/settings/date_time_page/date_time_page.js

Issue 2849823003: ChromeOS: implement per-user time zone preferences. (Closed)
Patch Set: Rebased. Created 3 years, 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * 'settings-date-time-page' is the settings page containing date and time 7 * 'settings-date-time-page' is the settings page containing date and time
8 * settings. 8 * settings.
9 */ 9 */
10 10
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 * by network time, so default to false to initially hide the button. 83 * by network time, so default to false to initially hide the button.
84 * @private 84 * @private
85 */ 85 */
86 canSetDateTime_: { 86 canSetDateTime_: {
87 type: Boolean, 87 type: Boolean,
88 value: false, 88 value: false,
89 }, 89 },
90 }, 90 },
91 91
92 observers: [ 92 observers: [
93 'maybeGetTimeZoneList_(' + 93 'maybeGetTimeZoneListPerUser_(' +
94 'prefs.settings.timezone.value, timeZoneAutoDetect_)',
95 'maybeGetTimeZoneListPerSystem_(' +
94 'prefs.cros.system.timezone.value, timeZoneAutoDetect_)', 96 'prefs.cros.system.timezone.value, timeZoneAutoDetect_)',
95 ], 97 ],
96 98
97 /** @override */ 99 /** @override */
98 attached: function() { 100 attached: function() {
99 this.addWebUIListener( 101 this.addWebUIListener(
100 'time-zone-auto-detect-policy', 102 'time-zone-auto-detect-policy',
101 this.onTimeZoneAutoDetectPolicyChanged_.bind(this)); 103 this.onTimeZoneAutoDetectPolicyChanged_.bind(this));
102 this.addWebUIListener( 104 this.addWebUIListener(
103 'can-set-date-time-changed', this.onCanSetDateTimeChanged_.bind(this)); 105 'can-set-date-time-changed', this.onCanSetDateTimeChanged_.bind(this));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 return true; 169 return true;
168 case settings.TimeZoneAutoDetectPolicy.FORCED_OFF: 170 case settings.TimeZoneAutoDetectPolicy.FORCED_OFF:
169 return false; 171 return false;
170 default: 172 default:
171 assertNotReached(); 173 assertNotReached();
172 } 174 }
173 }, 175 },
174 176
175 /** 177 /**
176 * Fetches the list of time zones if necessary. 178 * Fetches the list of time zones if necessary.
179 * @param {boolean=} perUserTimeZoneMode Expected value of per-user time zone.
177 * @private 180 * @private
178 */ 181 */
179 maybeGetTimeZoneList_: function() { 182 maybeGetTimeZoneList_: function(perUserTimeZoneMode) {
183 if (typeof(perUserTimeZoneMode) !== 'undefined') {
184 /* This method is called as observer. Skip if if current mode does not
185 * match expected.
186 */
187 if (perUserTimeZoneMode !=
188 this.getPref('cros.flags.per_user_timezone_enabled').value) {
189 return;
190 }
191 }
180 // Only fetch the list once. 192 // Only fetch the list once.
181 if (this.timeZoneList_.length > 1 || !CrSettingsPrefs.isInitialized) 193 if (this.timeZoneList_.length > 1 || !CrSettingsPrefs.isInitialized)
182 return; 194 return;
183 195
184 // If auto-detect is enabled, we only need the current time zone. 196 // If auto-detect is enabled, we only need the current time zone.
185 if (this.timeZoneAutoDetect_ && 197 if (this.timeZoneAutoDetect_) {
186 this.getPref('cros.system.timezone').value == 198 var isPerUserTimezone =
187 this.timeZoneList_[0].value) { 199 this.getPref('cros.flags.per_user_timezone_enabled').value;
188 return; 200 if (this.timeZoneList_[0].value ==
201 (isPerUserTimezone ? this.getPref('settings.timezone').value :
202 this.getPref('cros.system.timezone').value)) {
203 return;
204 }
189 } 205 }
190 206
191 cr.sendWithPromise('getTimeZones').then(this.setTimeZoneList_.bind(this)); 207 cr.sendWithPromise('getTimeZones').then(this.setTimeZoneList_.bind(this));
192 }, 208 },
193 209
194 /** 210 /**
211 * Prefs observer for Per-user time zone enabled mode.
212 * @private
213 */
214 maybeGetTimeZoneListPerUser_: function() {
215 this.maybeGetTimeZoneList_(true);
216 },
217
218 /**
219 * Prefs observer for Per-user time zone disabled mode.
220 * @private
221 */
222 maybeGetTimeZoneListPerSystem_: function() {
223 this.maybeGetTimeZoneList_(false);
224 },
225
226 /**
195 * Converts the C++ response into an array of menu options. 227 * Converts the C++ response into an array of menu options.
196 * @param {!Array<!Array<string>>} timeZones C++ time zones response. 228 * @param {!Array<!Array<string>>} timeZones C++ time zones response.
197 * @private 229 * @private
198 */ 230 */
199 setTimeZoneList_: function(timeZones) { 231 setTimeZoneList_: function(timeZones) {
200 this.timeZoneList_ = timeZones.map(function(timeZonePair) { 232 this.timeZoneList_ = timeZones.map(function(timeZonePair) {
201 return { 233 return {
202 name: timeZonePair[1], 234 name: timeZonePair[1],
203 value: timeZonePair[0], 235 value: timeZonePair[0],
204 }; 236 };
205 }); 237 });
206 }, 238 },
239
240 /**
241 * Computes visibility of user timezone preference.
242 * @param {?chrome.settingsPrivate.PrefObject} prefUserTimezone
243 * pref.settings.timezone
244 * @param {boolean} prefResolveValue
245 * prefs.settings.resolve_timezone_by_geolocation.value
246 * @private
247 */
248 isUserTimeZoneSelectorHidden_: function(prefUserTimezone, prefResolveValue) {
249 return (prefUserTimezone && prefUserTimezone.controlledBy != null) ||
250 prefResolveValue;
251 },
207 }); 252 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/date_time_page/date_time_page.html ('k') | chrome/browser/ui/webui/chromeos/set_time_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698